GSoC 2020 : Upgrade Platform Core Libraries Project

This is the public thread for the GSOC 2020 project Upgrade Platform Core Libraries Project . the goal of this project is to update the OpenMRS platform libraries this will include : Openmrs core API , Fhir module , WebRestServices module, OpenWebapps Module .

so far we are still working on the openmrs Core api to update these libraries. this are related ticket : https://issues.openmrs.org/browse/TRUNK-5496 , https://issues.openmrs.org/browse/TRUNK-5745, https://issues.openmrs.org/browse/TRUNK-5521.

my main mentor are @mozzy , @sharif and everyone who will help me complete the project. I’ll be sharing all the project details, problems I’ll face etc on this thread. Hoping to have a wonderful summer with this community .

cc @dkayiwa @ibacher @burke

3 Likes

hello @sharif @ibacher @mozzy please i working actually on this issue

I managed the first part which is to update junit from 4 to 5 without problem. Now I am working on the second part which consists in converting all the tests from junit 4 to junit 5.but I’m stuck on the conversion of this java class

and i also need an example on how to convert this 2 expression from junit 4 to junit 5

   @Test(expected = APIException.class)
public void add_shouldNotAllowDuplicateCodedAllergen(){
	Allergy allergy1 = new Allergy();
    Concept concept = new Concept();
	allergy1.setAllergen(new Allergen(null, concept, null));
	
	Allergy allergy2 = new Allergy();
	allergy2.setAllergen(new Allergen(null, concept, null));
	
	allergies.add(allergy1);
	allergies.add(allergy2);
}

and

 @Rule
public ExpectedException expectedException = ExpectedException.none();

this the related PR : https://github.com/openmrs/openmrs-core/pull/3217

1 Like

cc: @ibacher @dkayiwa @sharif @mozzy . i am working on this project

https://issues.openmrs.org/browse/TRUNK-5356

the first is complete.i am working now on the second part of the ticket that is to migrate mysql-MXJ to MariaDB4J .change the dependencies from com.mysql:mysql-connector-mxj:5.0.11 to ch.vorburger.mariaDB4j:mariaDB4j:2.4.0 . after executing the command: mvn clean test -Pskip-default-test -Pintegration-test, it create this file : Screenshot from 2020-06-03 22-38-51 Screenshot from 2020-06-03 22-39-22

what can that mean please? am i on the right track if not how continues?

1 Like

@achilep thanks for this , have never run into that but i will also try it outon my machine

So the canonical example for this:

@Test(expected = APIException.class)
public void add_shouldNotAllowDuplicateCodedAllergen(){
	Allergy allergy1 = new Allergy();
	Concept concept = new Concept();
	allergy1.setAllergen(new Allergen(null, concept, null));
	
	Allergy allergy2 = new Allergy();
	allergy2.setAllergen(new Allergen(null, concept, null));
	
	allergies.add(allergy1);
	allergies.add(allergy2);
}

In JUnit5 would be something like this:

@Test
public void add_shouldNotAllowDuplicateCodedAllergen(){
	Allergy allergy1 = new Allergy();
	Concept concept = new Concept();
	allergy1.setAllergen(new Allergen(null, concept, null));
	
	Allergy allergy2 = new Allergy();
	allergy2.setAllergen(new Allergen(null, concept, null));
	
	allergies.add(allergy1);
	assertThrows(APIException.class, () -> allergies.add(allergy2));
}

By itself:

@Rule
public ExpectedException expectedException = ExpectedException.none();

Does not have any equivalent in JUnit5, so this code should be removed. However, where expectedException is something other than ExpectedException.none() it’s normally used for something like this:

@Test
public void savePatientProgram_shouldTestThrowPatientStateRequiresException() {
	expectedException.expect(APIException.class);
	expectedException.expectMessage("'PatientProgram(id=1, patient=Patient#2, program=Program(id=1, concept=Concept #1738, " +
										"workflows=[ProgramWorkflow(id=1), ProgramWorkflow(id=2)]))' failed to validate with reason: states: State is required for a patient state");
	PatientProgram patientProgram = pws.getPatientProgram(1);
	for (PatientState state : patientProgram.getStates()) {
		state.setState(null);
	}
	pws.savePatientProgram(patientProgram);
}

The JUnit5 idiom for this is:

@Test
public void savePatientProgram_shouldTestThrowPatientStateRequiresException() {
	PatientProgram patientProgram = pws.getPatientProgram(1);
	for (PatientState state : patientProgram.getStates()) {
		state.setState(null);
	}
	
        APIException exception = assertThrows(APIException.class, () -> pws.savePatientProgram(patientProgram));
        // you could also use assertEquals() here
        assertThat(exception.getMessage(), is("'PatientProgram(id=1, patient=Patient#2, program=Program(id=1, concept=Concept #1738, workflows=[ProgramWorkflow(id=1), ProgramWorkflow(id=2)]))' failed to validate with reason: states: State is required for a patient state"));
}
2 Likes

big thanks @ibacher , it will help me a lot.

You’re probably alright. Those look to me like Lucene indexes and can be safely deleted. I’m guessing you ran that command from inside the API sub-project? In any case, the more interesting thing is whether or not the tests succeeded.

1 Like

thanks @ibacher ,yes all the tests pass successfully . this is the link to that Ticket :

https://issues.openmrs.org/browse/TRUNK-5767

please to be able to continue i need someone to assess that ticket .in addition i will need the assessment of this tickets too:

https://issues.openmrs.org/browse/TRUNK-5759

https://issues.openmrs.org/browse/TRUNK-5761

https://issues.openmrs.org/browse/TRUNK-5764

cc @sharif @mozzy thanks

1 Like

made them ready for work

1 Like

@mozzy thanks

thanks its my help a lot. but I’m still blocked by this expression:

1

@Rule
public TemporaryFolder folder= new TemporaryFolder();

2

@RunWith(PowerMockRunner.class)
public abstract class BaseContextSensitiveTest extends AbstractJUnit4SpringContextTests 

The TemporaryFolder does not exist and has no equivalence in junit 5.

Is the same problem with PowerMockRunner there is not PowerMockExtension in junit 5.

for this one AbstractJUnit4SpringContextTests ,i try to use jupiter.SpringExtension but i did not succeed .

any help will be welcome.

thanks @ibacher @mozzy @sharif @dkayiwa @burke

hello @sharif @mozzy @ibacher @burke @dkayiwa please help me evaluate this ticket. it’s all the rest of the dependencies which will be updated on the core API .it has 8 sub-task .thanks

I have gone through them. For unrelated dependencies, it would be great to have separate tickets.

1 Like

Sure you are right. i think it will hep us track those tickets progress.we will however add other tickets just incase we come around it

1 Like

thanks @dkayiwa I will no longer add 2 unrelated dependencies in the Same Ticket .

hello @sharif @mozzy @ibacher please I have this problem after running the command mvn jetty:run in the webapp folder

Update your openmrs-core to the latest.

done , but i am still get the same error @dkayiwa.

I think the problem may be at the level of openmrs-runtime-properties file. please can someone send it to me, so i can edit it and put it in the webapp folder. thanks @dkayiwa

Drop the database and delete the runtime properties file. Then run afresh.