Skip to content

Commit 208d215

Browse files
committed
IDGEN-134: Update to OpenMRS Platform 2.7.x and Support Java 21
1 parent deb7c3e commit 208d215

File tree

17 files changed

+128
-108
lines changed

17 files changed

+128
-108
lines changed

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
platform: [ ubuntu-latest ]
16-
java-version: [ 8 ]
16+
java-version: [ 8, 11, 17, 21 ]
1717

1818
runs-on: ${{ matrix.platform }}
1919
env:

api/pom.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
<artifactId>idgen</artifactId>
66
<version>4.15.0-SNAPSHOT</version>
77
</parent>
8-
<groupId>org.openmrs.module</groupId>
98
<artifactId>idgen-api</artifactId>
109
<packaging>jar</packaging>
1110
<name>ID Generation API</name>
1211
<description>API project for ID Generation</description>
1312

13+
<properties>
14+
<MOCKITO_INLINE_VERSION>3.12.4</MOCKITO_INLINE_VERSION>
15+
</properties>
16+
1417
<dependencies>
1518
<dependency>
16-
<groupId>org.codehaus.jackson</groupId>
17-
<artifactId>jackson-mapper-asl</artifactId>
18-
<version>1.5.0</version>
19-
<type>jar</type>
20-
<scope>provided</scope>
19+
<groupId>org.mockito</groupId>
20+
<artifactId>mockito-inline</artifactId>
21+
<version>${MOCKITO_INLINE_VERSION}</version>
22+
<scope>test</scope>
2123
</dependency>
2224
</dependencies>
2325

api/src/main/java/org/openmrs/module/idgen/PooledIdentifier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
*/
1414
package org.openmrs.module.idgen;
1515

16+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
17+
1618
import java.util.Date;
1719
import java.util.UUID;
1820

19-
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
2021

2122
/**
2223
* Component which encapsulates an identifier that has been allocated to an Identifier Pool

api/src/main/java/org/openmrs/module/idgen/service/BaseIdentifierSourceService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ public List<String> generateIdentifiers(IdentifierSource source, Integer batchSi
188188
* @param processor
189189
* @return
190190
*/
191-
@Transactional(propagation = Propagation.REQUIRES_NEW)
192191
public List<String> generateIdentifiersInternal(Integer sourceId, Integer batchSize, String comment) {
193192

194193
IdentifierSource source = getIdentifierSource(sourceId);

api/src/main/java/org/openmrs/module/idgen/service/IdentifierSourceService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.openmrs.module.idgen.SequentialIdentifierGenerator;
3333
import org.openmrs.module.idgen.processor.IdentifierSourceProcessor;
3434
import org.openmrs.util.OpenmrsConstants;
35+
import org.openmrs.util.PrivilegeConstants;
3536
import org.springframework.transaction.annotation.Transactional;
3637

3738
/**
@@ -117,23 +118,23 @@ public interface IdentifierSourceService extends OpenmrsService {
117118
* Returns null if this PatientIdentifierType is not set to be auto-generated
118119
*/
119120
@Transactional
120-
@Authorized(OpenmrsConstants.PRIV_EDIT_PATIENT_IDENTIFIERS)
121+
@Authorized(PrivilegeConstants.EDIT_PATIENT_IDENTIFIERS)
121122
public String generateIdentifier(PatientIdentifierType type, String comment);
122123

123124
/**
124125
* Given a PatientIdentifierType and Location, generates an identifier using the proper IdentifierSource
125126
* Returns null if this PatientIdentifierType is not set to be auto-generated
126127
*/
127128
@Transactional
128-
@Authorized(OpenmrsConstants.PRIV_EDIT_PATIENT_IDENTIFIERS)
129+
@Authorized(PrivilegeConstants.EDIT_PATIENT_IDENTIFIERS)
129130
public String generateIdentifier(PatientIdentifierType type, Location location, String comment);
130131

131132
/**
132133
* Generates a Single Identifiers from the given source
133134
* @throws APIException
134135
*/
135136
@Transactional
136-
@Authorized( OpenmrsConstants.PRIV_EDIT_PATIENT_IDENTIFIERS )
137+
@Authorized(PrivilegeConstants.EDIT_PATIENT_IDENTIFIERS)
137138
public String generateIdentifier(IdentifierSource source, String comment) throws APIException;
138139

139140
/**

api/src/test/java/org/openmrs/module/idgen/IdgenBaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public Properties getRuntimeProperties() {
1515
Properties props = super.getRuntimeProperties();
1616
String url = props.getProperty(Environment.URL);
1717
if (url.contains("jdbc:h2:") && !url.toLowerCase().contains(";mvcc=true")) {
18-
props.setProperty(Environment.URL, url + ";mvcc=true");
18+
props.setProperty(Environment.URL, url);
1919
}
2020
return props;
2121
}

api/src/test/java/org/openmrs/module/idgen/SequentialIdentifierGeneratorTest.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import static org.hamcrest.core.Is.is;
44
import static org.junit.Assert.assertThat;
55
import static org.mockito.Mockito.mock;
6+
import static org.mockito.Mockito.mockStatic;
67
import static org.mockito.Mockito.when;
7-
import static org.powermock.api.mockito.PowerMockito.mockStatic;
88

9+
import org.junit.After;
910
import org.junit.Assert;
1011
import org.junit.Before;
1112
import org.junit.Test;
12-
import org.junit.runner.RunWith;
13+
import org.mockito.MockedStatic;
1314
import org.openmrs.Location;
1415
import org.openmrs.LocationAttribute;
1516
import org.openmrs.LocationAttributeType;
@@ -20,19 +21,19 @@
2021
import org.openmrs.module.idgen.prefixprovider.PrefixProvider;
2122
import org.openmrs.module.idgen.suffixprovider.LocationBasedSuffixProvider;
2223
import org.openmrs.module.idgen.suffixprovider.SuffixProvider;
23-
import org.powermock.core.classloader.annotations.PrepareForTest;
24-
import org.powermock.modules.junit4.PowerMockRunner;
25-
26-
/**
27-
* test class for {@link SequentialIdentifierGenerator}
28-
*/
29-
@RunWith(PowerMockRunner.class)
30-
@PrepareForTest(Context.class)
24+
3125
public class SequentialIdentifierGeneratorTest {
26+
27+
private MockedStatic<Context> mockedContext;
3228

3329
@Before
3430
public void setup() {
35-
mockStatic(Context.class);
31+
mockedContext = mockStatic(Context.class);
32+
}
33+
34+
@After
35+
public void teardown() {
36+
mockedContext.close();
3637
}
3738

3839
/**

api/src/test/java/org/openmrs/module/idgen/integration/DuplicateIdentifiersPoolComponentTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import org.openmrs.module.idgen.IdentifierSource;
88
import org.openmrs.module.idgen.IdgenBaseTest;
99
import org.openmrs.module.idgen.service.IdentifierSourceService;
10-
import org.springframework.test.annotation.NotTransactional;
10+
import org.springframework.transaction.annotation.Propagation;
11+
import org.springframework.transaction.annotation.Transactional;
1112

1213
import java.util.ArrayList;
1314
import java.util.HashSet;
@@ -37,31 +38,30 @@ public void setUp() throws Exception {
3738
}
3839

3940
@Test
40-
@NotTransactional
41-
public void testUnderLoad() throws Exception {
41+
@Transactional(propagation = Propagation.NEVER)
42+
public void testUnderLoad() {
4243

4344
final List<String> generated = new ArrayList<String>();
4445

45-
List<Thread> threads = new ArrayList<Thread>();
46+
List<Thread> threads = new ArrayList<>();
4647
for (int i = 0; i < NUM_THREADS; ++i) {
47-
Thread thread = new Thread(new Runnable() {
48-
@Override
49-
public void run() {
50-
Context.openSession();
51-
Context.authenticate("admin", "test");
52-
IdentifierSource source = getService().getIdentifierSource(4);
53-
try {
54-
authenticate();
55-
sleep(100);
48+
Thread thread = new Thread(() -> {
49+
Context.openSession();
50+
Context.authenticate("admin", "test");
51+
IdentifierSource source = getService().getIdentifierSource(4);
52+
try {
53+
authenticate();
54+
sleep(100);
55+
synchronized (generated) {
5656
generated.addAll(getService().generateIdentifiers(source, 1, "thread"));
57-
sleep(100);
58-
}
59-
catch (Exception e) {
60-
throw new RuntimeException(e);
61-
}
62-
finally {
63-
Context.closeSession();
6457
}
58+
sleep(100);
59+
}
60+
catch (Exception e) {
61+
throw new RuntimeException(e);
62+
}
63+
finally {
64+
Context.closeSession();
6565
}
6666
});
6767
thread.start();
@@ -77,7 +77,7 @@ public void run() {
7777
}
7878

7979
assertThat(generated.size(), is(NUM_THREADS));
80-
assertThat(new HashSet<String>(generated).size(), is(NUM_THREADS));
80+
assertThat(new HashSet<>(generated).size(), is(NUM_THREADS));
8181
}
8282

8383
public void sleep(long time) {

api/src/test/java/org/openmrs/module/idgen/prefixprovider/LocationBasedPrefixProviderTest.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@
22

33
import static org.hamcrest.core.Is.is;
44
import static org.mockito.Mockito.mock;
5+
import static org.mockito.Mockito.mockStatic;
56
import static org.mockito.Mockito.when;
6-
import static org.powermock.api.mockito.PowerMockito.mockStatic;
77

88
import java.util.Collections;
99

10+
import org.junit.After;
1011
import org.junit.Assert;
1112
import org.junit.Before;
1213
import org.junit.Test;
13-
import org.junit.runner.RunWith;
14+
import org.mockito.MockedStatic;
1415
import org.openmrs.Location;
1516
import org.openmrs.LocationAttribute;
1617
import org.openmrs.LocationAttributeType;
1718
import org.openmrs.api.AdministrationService;
1819
import org.openmrs.api.LocationService;
1920
import org.openmrs.api.context.Context;
2021
import org.openmrs.api.context.UserContext;
21-
import org.openmrs.module.idgen.prefixprovider.LocationBasedPrefixProvider;
22-
import org.powermock.core.classloader.annotations.PrepareForTest;
23-
import org.powermock.modules.junit4.PowerMockRunner;
2422

25-
@RunWith(PowerMockRunner.class)
26-
@PrepareForTest(Context.class)
2723
public class LocationBasedPrefixProviderTest {
2824

2925
LocationBasedPrefixProvider locationPrefixProvider;
@@ -36,24 +32,32 @@ public class LocationBasedPrefixProviderTest {
3632
Location location3;
3733
Location location5;
3834
Location locationA2;
35+
36+
private MockedStatic<Context> mockedContext;
3937

4038
@Before
4139
public void setup() {
40+
mockedContext = mockStatic(Context.class);
4241
locationPrefixProvider = new LocationBasedPrefixProvider();
4342

44-
mockStatic(Context.class);
4543
userContext = mock(UserContext.class);
46-
when(Context.getUserContext()).thenReturn(userContext);
47-
44+
45+
mockedContext.when(Context::getUserContext).thenReturn(userContext);
46+
4847
LocationService ls = mock(LocationService.class);
4948
AdministrationService as = mock(AdministrationService.class);
50-
when(Context.getLocationService()).thenReturn(ls);
51-
when(Context.getAdministrationService()).thenReturn(as);
52-
when(ls.getAllLocationAttributeTypes()).thenReturn(Collections.<LocationAttributeType>emptyList());
49+
mockedContext.when(Context::getLocationService).thenReturn(ls);
50+
mockedContext.when(Context::getAdministrationService).thenReturn(as);
51+
mockedContext.when(ls::getAllLocationAttributeTypes).thenReturn(Collections.<LocationAttributeType>emptyList());
5352
when(as.getGlobalProperty(LocationBasedPrefixProvider.PREFIX_LOCATION_ATTRIBUTE_TYPE_GP))
5453
.thenReturn("Location Code");
5554
setupLocationTree();
5655
}
56+
57+
@After
58+
public void teardown() {
59+
mockedContext.close();
60+
}
5761

5862
@Test
5963
public void getValue_shouldReturnPrefixDependingOnLocationInUserContext() {

api/src/test/resources/TestingApplicationContext.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<ref bean="mappingJarResources" />
2525
</property>
2626
<!-- default properties must be set in the hibernate.default.properties -->
27+
<property name="packagesToScan">
28+
<list>
29+
<value>org.openmrs</value>
30+
</list>
31+
</property>
2732
</bean>
2833

2934
<bean id="idgenTestTimerFactory" class="org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean">
@@ -39,5 +44,9 @@
3944
</list>
4045
</property>
4146
</bean>
47+
48+
49+
<bean id="LocationBasedSuffixProvider" class="org.openmrs.module.idgen.suffixprovider.LocationBasedSuffixProvider" />
50+
<bean id="LocationBasedPrefixProvider" class="org.openmrs.module.idgen.prefixprovider.LocationBasedPrefixProvider" />
4251

4352
</beans>

0 commit comments

Comments
 (0)