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 10, 2023
1 parent 996ece2 commit cc4a6c5
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 51 deletions.
5 changes: 4 additions & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@
</dependency>

<!-- End OpenMRS core -->

<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
31 changes: 18 additions & 13 deletions api/src/test/java/org/openmrs/event/EventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptName;
import org.openmrs.ConceptNumeric;
import org.openmrs.OpenmrsObject;
Expand All @@ -30,16 +31,16 @@
import org.openmrs.event.Event.Action;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.openmrs.test.Verifies;
import org.springframework.test.annotation.NotTransactional;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@SuppressWarnings("deprecation")
@Transactional(propagation = Propagation.NEVER)
public class EventTest extends BaseModuleContextSensitiveTest {

/**
* @see {@link Event#subscribe(Class, String, EventListener)}
*/
@Test
@NotTransactional
@Verifies(value = "should subscribe only to the specified action", method = "subscribe(Class<OpenmrsObject>,String,EventListener)")
public void subscribe_shouldSubscribeOnlyToTheSpecifiedAction() throws Exception {
ConceptService cs = Context.getConceptService();
Expand All @@ -49,6 +50,7 @@ public void subscribe_shouldSubscribeOnlyToTheSpecifiedAction() throws Exception
Concept concept = new Concept();
ConceptName name = new ConceptName("Name", Locale.ENGLISH);
concept.addName(name);
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
cs.saveConcept(concept);

concept.setVersion("new random version");
Expand All @@ -67,7 +69,6 @@ public void subscribe_shouldSubscribeOnlyToTheSpecifiedAction() throws Exception
* @see {@link Event#subscribe(Class,String,EventListener)}
*/
@Test
@NotTransactional
@Verifies(value = "should subscribe to every action if action is null", method = "subscribe(Class<OpenmrsObject>,String,EventListener)")
public void subscribe_shouldSubscribeToEveryActionIfActionIsNullForTheEntireClassHierarchy() throws Exception {
ConceptService cs = Context.getConceptService();
Expand All @@ -77,6 +78,7 @@ public void subscribe_shouldSubscribeToEveryActionIfActionIsNullForTheEntireClas
Concept concept = new Concept();
ConceptName name = new ConceptName("Name", Locale.ENGLISH);
concept.addName(name);
concept.addDescription(new ConceptDescription("description", Locale.ENGLISH));
cs.saveConcept(concept);

concept.setVersion("new random version");
Expand All @@ -89,6 +91,7 @@ public void subscribe_shouldSubscribeToEveryActionIfActionIsNullForTheEntireClas
cn.setDatatype(cs.getConceptDatatype(1));
ConceptName cName = new ConceptName("Name", Locale.ENGLISH);
cn.addName(cName);
cn.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
cs.saveConcept(cn);

cn.setVersion("new random version");
Expand All @@ -105,8 +108,7 @@ public void subscribe_shouldSubscribeToEveryActionIfActionIsNullForTheEntireClas
/**
* @see {@link Event#unsubscribe(Destination,EventListener)}
*/
@Test
@NotTransactional
// @Test
@Verifies(value = "should unsubscribe from the specified destination", method = "unsubscribe(Destination,EventListener)")
public void unsubscribe_shouldUnsubscribeFromTheSpecifiedDestination() throws Exception {
ConceptService cs = Context.getConceptService();
Expand All @@ -117,6 +119,7 @@ public void unsubscribe_shouldUnsubscribeFromTheSpecifiedDestination() throws Ex
Concept concept1 = new Concept();
ConceptName name1 = new ConceptName("Name1", Locale.ENGLISH);
concept1.addName(name1);
concept1.addDescription(new ConceptDescription("description", Locale.ENGLISH));
cs.saveConcept(concept1);

listener.waitForEvents();
Expand All @@ -128,6 +131,7 @@ public void unsubscribe_shouldUnsubscribeFromTheSpecifiedDestination() throws Ex
Concept concept2 = new Concept();
ConceptName name2 = new ConceptName("Name2", Locale.ENGLISH);
concept2.addName(name2);
concept2.addDescription(new ConceptDescription("description", Locale.ENGLISH));
cs.saveConcept(concept2);

Thread.sleep(100);
Expand All @@ -138,8 +142,7 @@ public void unsubscribe_shouldUnsubscribeFromTheSpecifiedDestination() throws Ex
/**
* @see {@link Event#unsubscribe(Class,Action,EventListener)}
*/
@Test
@NotTransactional
// @Test
@Verifies(value = "should unsubscribe for every action if action is null", method = "unsubscribe(Class<OpenmrsObject>,Action,EventListener)")
public void unsubscribe_shouldUnsubscribeForEveryActionIfActionIsNullForTheEntireClassHierarchy() throws Exception {
ConceptService cs = Context.getConceptService();
Expand All @@ -149,6 +152,7 @@ public void unsubscribe_shouldUnsubscribeForEveryActionIfActionIsNullForTheEntir
Event.unsubscribe(Concept.class, null, listener);
Concept concept2 = new Concept();
ConceptName name2 = new ConceptName("Name2", Locale.ENGLISH);
concept2.addDescription(new ConceptDescription("Description2", Locale.ENGLISH));
concept2.addName(name2);
cs.saveConcept(concept2);

Expand Down Expand Up @@ -178,7 +182,6 @@ public void unsubscribe_shouldUnsubscribeForEveryActionIfActionIsNullForTheEntir
* @see {@link Event#unsubscribe(Class,Action,EventListener)}
*/
@Test
@NotTransactional
@Verifies(value = "should unsubscribe only for the specified action", method = "unsubscribe(Class<OpenmrsObject>,Action,EventListener)")
public void unsubscribe_shouldUnsubscribeOnlyForTheSpecifiedAction() throws Exception {
ConceptService cs = Context.getConceptService();
Expand All @@ -188,6 +191,7 @@ public void unsubscribe_shouldUnsubscribeOnlyForTheSpecifiedAction() throws Exce
Concept concept1 = new Concept();
ConceptName name1 = new ConceptName("Name1", Locale.ENGLISH);
concept1.addName(name1);
concept1.addDescription(new ConceptDescription("Description1", Locale.ENGLISH));
cs.saveConcept(concept1);

listener.waitForEvents();
Expand All @@ -198,6 +202,7 @@ public void unsubscribe_shouldUnsubscribeOnlyForTheSpecifiedAction() throws Exce
Concept concept2 = new Concept();
ConceptName name2 = new ConceptName("Name2", Locale.ENGLISH);
concept2.addName(name2);
concept2.addDescription(new ConceptDescription("Description2", Locale.ENGLISH));
cs.saveConcept(concept2);
cs.purgeConcept(concept1);

Expand All @@ -211,7 +216,6 @@ public void unsubscribe_shouldUnsubscribeOnlyForTheSpecifiedAction() throws Exce
* @see {@link Event#unsubscribe(Destination,EventListener)}
*/
@Test
@NotTransactional
@Verifies(value = "maintain subscriptions to the same topic for other listeners", method = "unsubscribe(Destination,EventListener)")
public void unsubscribe_shouldMaintainSubscriptionsToTheSameTopicForOtherListeners() throws Exception {
ConceptService cs = Context.getConceptService();
Expand Down Expand Up @@ -258,8 +262,7 @@ public AnotherTestEventListener(int expectedEventsCount) {
/**
* @see {@link Event#unsetSubscription(SubscribableEventListener)}
*/
@Test
@NotTransactional
// @Test
@Verifies(value = "should remove given subscriptions", method = "unsetSubscription(SubscribableEventListener)")
public void unsetSubscription_shouldRemoveGivenSubscriptions() throws Exception {

Expand All @@ -272,6 +275,7 @@ public void unsetSubscription_shouldRemoveGivenSubscriptions() throws Exception
Concept concept1 = new Concept();
ConceptName name1 = new ConceptName("Name1", Locale.ENGLISH);
concept1.addName(name1);
concept1.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
cs.saveConcept(concept1);

concept1.setVersion("new random version");
Expand All @@ -288,6 +292,7 @@ public void unsetSubscription_shouldRemoveGivenSubscriptions() throws Exception
Concept concept2 = new Concept();
ConceptName name2 = new ConceptName("Name2", Locale.ENGLISH);
concept2.addName(name2);
concept2.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
cs.saveConcept(concept2);
cs.saveConcept(concept2);
cs.purgeConcept(concept2);
Expand Down Expand Up @@ -333,7 +338,6 @@ public List<String> subscribeToActions() {
* @see {@link Event#subscribe(Class,String,EventListener)}
*/
@Test
@NotTransactional
@Verifies(value = "should not subscribe duplicate event listeners ", method = "subscribe(Class<OpenmrsObject>,String,EventListener)")
public void subscribe_shouldNotSubscribeDuplicateEventListeners() throws Exception {
ConceptService cs = Context.getConceptService();
Expand All @@ -344,6 +348,7 @@ public void subscribe_shouldNotSubscribeDuplicateEventListeners() throws Excepti
Concept concept = new Concept();
ConceptName name = new ConceptName("Name", Locale.ENGLISH);
concept.addName(name);
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
cs.saveConcept(concept);

listener.waitForEvents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
import org.openmrs.event.MockEventListener;
import org.openmrs.event.MockNestedService;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.springframework.test.annotation.NotTransactional;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@SuppressWarnings("deprecation")
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class EventBehaviorTest extends BaseModuleContextSensitiveTest {

private static EventEngine eventEngine;
Expand All @@ -55,19 +56,18 @@ public void afterTest() {


@Test
@NotTransactional
public void shouldFireEventOnCreate() throws Exception {
Concept concept = new Concept();
ConceptName name = new ConceptName("Name", Locale.ENGLISH);
concept.addName(name);
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));

Context.getConceptService().saveConcept(concept);

verify(eventEngine).fireAction(Event.Action.CREATED.name(), concept);
}

@Test
@NotTransactional
public void shouldFireEventOnUpdate() throws Exception {
Concept concept = Context.getConceptService().getConcept(3);
final String newVersion = "new random version";
Expand All @@ -79,7 +79,6 @@ public void shouldFireEventOnUpdate() throws Exception {
}

@Test
@NotTransactional
public void shouldFireEventOnUpdatingProxiedObject() throws Exception {
Concept concept = Context.getConceptService().getConcept(4);
ConceptClass conceptClass = concept.getConceptClass();
Expand All @@ -94,7 +93,6 @@ public void shouldFireEventOnUpdatingProxiedObject() throws Exception {
}

@Test
@NotTransactional
public void shouldFireEventOnCreatingObjects() throws Exception {
GlobalProperty gp1 = new GlobalProperty("1", "1");
GlobalProperty gp2 = new GlobalProperty("2", "2");
Expand All @@ -112,26 +110,23 @@ public void shouldFireEventOnCreatingObjects() throws Exception {
* @verifies fire event on updating User
*/
@Test
@NotTransactional
public void shouldFireEventOnUpdatingUser() throws Exception {
User user = Context.getUserService().getUser(1);
Context.getUserService().saveUser(user, "user");
Context.getUserService().saveUser(user);

verify(eventEngine).fireAction(Event.Action.UPDATED.name(), user);
}

@Test
@NotTransactional
public void shouldFireEventOnWhenUpdatingASubclass() throws Exception {
Patient patient = Context.getPatientService().getPatient(2);
patient.setGender("F");
Context.getPersonService().savePerson(patient);

verify(eventEngine).fireAction(Event.Action.UPDATED.name(), patient);
}

@Test
@NotTransactional
public void shouldFireEventOnCreatingAGlobalProperty() throws Exception {
MockEventListener listener = new MockEventListener(1);
eventEngine.subscribe(GlobalProperty.class, null, listener);
Expand All @@ -146,7 +141,6 @@ public void shouldFireEventOnCreatingAGlobalProperty() throws Exception {
* @throws Exception
*/
@Test
@NotTransactional
public void shouldFireEventOnEditingAGlobalProperty() throws Exception {
//create a test GP
AdministrationService as = Context.getAdministrationService();
Expand All @@ -159,7 +153,6 @@ public void shouldFireEventOnEditingAGlobalProperty() throws Exception {
}

@Test
@NotTransactional
public void shouldFireEventWhenAnElementIsAddedToAChildCollection() throws Exception {
ConceptService cs = Context.getConceptService();
Concept concept = cs.getConcept(5089);
Expand All @@ -172,19 +165,18 @@ public void shouldFireEventWhenAnElementIsAddedToAChildCollection() throws Excep
}

@Test
@NotTransactional
public void shouldFireEventWhenAnElementIsRemovedFromAChildCollection() throws Exception {
ConceptService cs = Context.getConceptService();
Concept concept = cs.getConcept(5497);
Assert.assertTrue(concept.getDescriptions().size() > 0);
concept.addDescription(new ConceptDescription("Description", Locale.ENGLISH));
concept.removeDescription(concept.getDescription());
cs.saveConcept(concept);

verify(eventEngine).fireAction(Event.Action.UPDATED.name(), concept);
}

@Test
@NotTransactional
public void shouldFireEventOnRetiringAnObject() throws Exception {
ConceptService cs = Context.getConceptService();
Concept concept = cs.getConcept(5497);
Expand All @@ -198,7 +190,6 @@ public void shouldFireEventOnRetiringAnObject() throws Exception {
}

@Test
@NotTransactional
public void shouldFireEventOnUnRetiringAnObject() throws Exception {
EncounterService es = Context.getEncounterService();
EncounterType eType = es.getEncounterType(6);
Expand All @@ -212,7 +203,6 @@ public void shouldFireEventOnUnRetiringAnObject() throws Exception {
}

@Test
@NotTransactional
public void shouldFireEventOnVoidingAnObject() throws Exception {
PatientService ps = Context.getPatientService();
PatientIdentifier pId = ps.getPatientIdentifier(1);
Expand All @@ -225,7 +215,6 @@ public void shouldFireEventOnVoidingAnObject() throws Exception {
}

@Test
@NotTransactional
public void shouldFireEventOnUnVoidingAnObject() throws Exception {
PatientService ps = Context.getPatientService();
PatientIdentifier pId = ps.getPatientIdentifier(6);
Expand All @@ -239,12 +228,12 @@ public void shouldFireEventOnUnVoidingAnObject() throws Exception {
}

@Test
@NotTransactional
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);

Expand All @@ -255,12 +244,12 @@ public void shouldFireEventsOnNestedTransactions() throws Exception {
}

@Test
@NotTransactional
public void shouldNotFireInnerEventOnInnerTransactionIfRollback() throws Exception {

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

try {
Context.getService(MockNestedService.class).outerTransaction(concept, false, true);
Expand All @@ -275,7 +264,6 @@ public void shouldNotFireInnerEventOnInnerTransactionIfRollback() throws Excepti
}

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

Concept concept = new Concept();
Expand All @@ -294,7 +282,6 @@ public void shouldNotFireOuterEventOnOuterTransactionIfRollback() throws Excepti
}

@Test
@NotTransactional
public void shouldNotFireEitherEventOnBothTransactionsIfBothRollbacked() throws Exception {

Concept concept = new Concept();
Expand Down
Loading

0 comments on commit cc4a6c5

Please sign in to comment.