File tree Expand file tree Collapse file tree
main/java/org/openmrs/module/referenceapplication/administrativenotification
java/org/openmrs/module/referenceapplication/administrativenotification Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ */
110package org .openmrs .module .referenceapplication .administrativenotification ;
211
312import 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 number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments