Skip to content

Commit

Permalink
EVNT-45: Adding Java 17 Compatability.
Browse files Browse the repository at this point in the history
  • Loading branch information
wikumChamith committed Dec 11, 2023
2 parents cc4a6c5 + 59e0c72 commit 4a7633c
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 72 deletions.
67 changes: 41 additions & 26 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
# this build is designed to replicate the Travis CI workflow
name: Build with Maven
name: Java CI with Maven

on:
push:
branches: [ master ]
branches: [ "master" ]
pull_request:
branches: [ master ]
workflow_dispatch:
branches: [ "master" ]

jobs:
build:
strategy:
matrix:
platform: [ ubuntu-latest ]
java-version: [ 8 ]
java-8:

runs-on: ${{ matrix.platform }}
env:
PLATFORM: ${{ matrix.platform }}
JAVA_VERSION: ${{ matrix.java-version }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java-version }}
- name: Cache local Maven repository
uses: actions/cache@v2
java-version: '8'
distribution: 'adopt'
cache: maven
- name: Build with Maven
run: mvn clean install --file pom.xml

java-11:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
cache: maven
- name: Build with Maven
run: mvn clean install --file pom.xml

java-17:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Install dependencies
run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true --batch-mode --show-version --file pom.xml
java-version: '17'
distribution: 'adopt'
cache: maven
- name: Build with Maven
run: mvn test --batch-mode --file pom.xml
run: mvn clean install --file pom.xml
4 changes: 0 additions & 4 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@
</dependency>

<!-- End OpenMRS core -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package org.openmrs.module.event.advice;

import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import java.util.Arrays;
import java.util.Locale;

import org.aopalliance.intercept.MethodInvocation;
import org.hibernate.proxy.HibernateProxy;
import org.junit.After;
Expand Down Expand Up @@ -35,10 +27,19 @@
import org.openmrs.event.MockEventListener;
import org.openmrs.event.MockNestedService;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Transactional(propagation = Propagation.NOT_SUPPORTED)
import java.util.Arrays;
import java.util.Locale;

import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

@Transactional(propagation = Propagation.NOT_SUPPORTED, rollbackFor = Exception.class, isolation = Isolation.REPEATABLE_READ)
public class EventBehaviorTest extends BaseModuleContextSensitiveTest {

private static EventEngine eventEngine;
Expand Down Expand Up @@ -215,6 +216,7 @@ public void shouldFireEventOnVoidingAnObject() throws Exception {
}

@Test

public void shouldFireEventOnUnVoidingAnObject() throws Exception {
PatientService ps = Context.getPatientService();
PatientIdentifier pId = ps.getPatientIdentifier(6);
Expand All @@ -227,21 +229,7 @@ public void shouldFireEventOnUnVoidingAnObject() throws Exception {
verify(eventEngine).fireAction(Event.Action.UNVOIDED.name(), pId);
}

@Test
public void shouldFireEventsOnNestedTransactions() throws Exception {

Concept concept = new Concept();
ConceptName name = new ConceptName("Name", Locale.ENGLISH);
concept.addName(name);
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

Context.getService(MockNestedService.class).outerTransaction(concept, false, false);

Patient patient = Context.getPatientService().getPatient(2);
verify(eventEngine).fireAction(Event.Action.UPDATED.name(), patient);
verify(eventEngine).fireAction(Event.Action.CREATED.name(), concept);

}

@Test
public void shouldNotFireInnerEventOnInnerTransactionIfRollback() throws Exception {
Expand All @@ -263,24 +251,6 @@ public void shouldNotFireInnerEventOnInnerTransactionIfRollback() throws Excepti

}

@Test
public void shouldNotFireOuterEventOnOuterTransactionIfRollback() throws Exception {

Concept concept = new Concept();
ConceptName name = new ConceptName("Name", Locale.ENGLISH);
concept.addName(name);

try {
Context.getService(MockNestedService.class).outerTransaction(concept, true, false);
}
catch (Exception e) {
}

Patient patient = Context.getPatientService().getPatient(2);
verify(eventEngine).fireAction(Event.Action.UPDATED.name(), patient);
verify(eventEngine, never()).fireAction(Event.Action.CREATED.name(), concept);
}

@Test
public void shouldNotFireEitherEventOnBothTransactionsIfBothRollbacked() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.openmrs.module.event.advice;

import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.Patient;
import org.openmrs.api.context.Context;
import org.openmrs.event.Event;
import org.openmrs.event.EventEngine;
import org.openmrs.event.EventEngineUtil;
import org.openmrs.event.MockNestedService;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Locale;

import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

public class EventBehaviourIsolatedTest extends BaseModuleContextSensitiveTest {

private static EventEngine eventEngine;

@BeforeClass
public static void beforeClass() {
eventEngine = spy(new EventEngine());
EventEngineUtil.setEventEngine(eventEngine);
}

@After
public void afterTest() {
reset(eventEngine); // need to manually reset the event engine to clean up from previous test
}

@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void shouldFireEventsOnNestedTransactions() throws Exception {

Concept concept = new Concept();
ConceptName name = new ConceptName("Name", Locale.ENGLISH);
concept.addName(name);
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

Context.getService(MockNestedService.class).outerTransaction(concept, false, false);

Patient patient = Context.getPatientService().getPatient(2);
verify(eventEngine).fireAction(Event.Action.UPDATED.name(), patient);
verify(eventEngine).fireAction(Event.Action.CREATED.name(), concept);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.openmrs.module.event.advice;

import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.Patient;
import org.openmrs.api.context.Context;
import org.openmrs.event.Event;
import org.openmrs.event.EventEngine;
import org.openmrs.event.EventEngineUtil;
import org.openmrs.event.MockNestedService;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.springframework.transaction.annotation.Transactional;

import java.util.Locale;

import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

public class EventBehaviourTransactionalTest extends BaseModuleContextSensitiveTest {

private static EventEngine eventEngine;

@BeforeClass
public static void beforeClass() {
eventEngine = spy(new EventEngine());
EventEngineUtil.setEventEngine(eventEngine);
}

@After
public void afterTest() {
reset(eventEngine); // need to manually reset the event engine to clean up from previous test
}

@Test
@Transactional
public void shouldNotFireOuterEventOnOuterTransactionIfRollback() throws Exception {

Concept concept = new Concept();
ConceptName name = new ConceptName("Name", Locale.ENGLISH);
concept.addName(name);
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

try {
Context.getService(MockNestedService.class).outerTransaction(concept, true, false);
}
catch (Exception e) {
}

Patient patient = Context.getPatientService().getPatient(2);
verify(eventEngine).fireAction(Event.Action.UPDATED.name(), patient);
verify(eventEngine, never()).fireAction(Event.Action.CREATED.name(), concept);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.20</version>
<version>1.4.17</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down

0 comments on commit 4a7633c

Please sign in to comment.