Skip to content

Commit f388706

Browse files
committed
m
1 parent 8c84a04 commit f388706

4 files changed

Lines changed: 85 additions & 8 deletions

File tree

api/src/main/java/org/openmrs/module/referenceapplication/administrativenotification/DuplicateConceptNotification.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
110
package org.openmrs.module.referenceapplication.administrativenotification;
211

312
import java.util.List;
@@ -25,14 +34,12 @@ public List<AdministrativeNotification> generateNotifications() {
2534

2635

2736
// checking whether concepts 1 and 2 exist in the system
28-
try {
29-
Integer concept1 = Context.getConceptService().getConcept(1).getConceptId();
30-
Integer concept2 = Context.getConceptService().getConcept(2).getConceptId();
31-
}catch (NullPointerException e) {
32-
return null;
33-
}
34-
35-
37+
38+
if( Context.getConceptService().getConcept(1)==null || Context.getConceptService().getConcept(2)==null
39+
) {
40+
return null;
41+
}
42+
3643
notification.setId("DuplicateConcepts.id");
3744
notification.setIcon("icon-info-sign");
3845
notification.setCssClass("success");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.openmrs.module.referenceapplication.administrativenotification;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNull;
5+
6+
import java.util.List;
7+
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
import org.openmrs.module.appframework.domain.AdministrativeNotification;
11+
import org.openmrs.test.BaseModuleContextSensitiveTest;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
14+
public class DuplicateConceptNotificationTest extends BaseModuleContextSensitiveTest {
15+
16+
@Autowired
17+
DuplicateConceptNotification producer;
18+
19+
@Before
20+
public void setUp() throws Exception {
21+
initializeInMemoryDatabase();
22+
}
23+
24+
@Test
25+
public void shouldNotProduceNotificationWhenDuplicateConceptsDoesNotExist() throws Exception {
26+
executeDataSet("NoConceptsDuplicates.xml");
27+
authenticate();
28+
assertNull(producer.generateNotifications());
29+
}
30+
31+
32+
@Test
33+
public void shouldProduceNotificationWhenDuplicateConceptsExist() throws Exception {
34+
35+
executeDataSet("ConceptsDuplicates.xml");
36+
authenticate();
37+
38+
List<AdministrativeNotification> notifications = producer.generateNotifications();
39+
assertEquals(notifications.size(), 1);
40+
assertEquals(notifications.get(0).getId(), "DuplicateConcepts.id");
41+
42+
}
43+
44+
;
45+
46+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<dataset>
3+
4+
<concept concept_id="1" retired="0" datatype_id="1" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
5+
<concept_numeric concept_id="1" units="" precise="0"/>
6+
<concept_name concept_id="1" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" concept_name_type="SHORT" locale_preferred="false"/>
7+
8+
<concept concept_id="2" retired="0" datatype_id="2" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2"/>
9+
<concept_numeric concept_id="2" units="" precise="0"/>
10+
<concept_name concept_id="2" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB2" concept_name_type="SHORT" locale_preferred="false"/>
11+
12+
</dataset>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<dataset>
3+
4+
<concept concept_id="3" retired="0" datatype_id="1" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
5+
<concept_numeric concept_id="3" units="" precise="0"/>
6+
<concept_name concept_id="3" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" concept_name_type="SHORT" locale_preferred="false"/>
7+
8+
<concept concept_id="4" retired="0" datatype_id="2" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2"/>
9+
<concept_numeric concept_id="4" units="" precise="0"/>
10+
<concept_name concept_id="4" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB2" concept_name_type="SHORT" locale_preferred="false"/>
11+
12+
</dataset>

0 commit comments

Comments
 (0)