Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
08/02/08 06:38:25 (5 months ago)
Author:
jmiranda
Message:

data_synchronization_bidirectional: Fixed bug that was causing several concept service unit tests to fail. The bug involved searching for concepts by name and locale. Also, refactored unit tests to use assert statements correctly (always use asserts with a brief message about what is being asserted and put the expected/actual values in the right order to avoid confusion).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/data_synchronization_bidirectional/test/api/org/openmrs/test/synchronization/engine/SyncConceptTest.java

    r4969 r5133  
    4040    } 
    4141 
    42         public void testAddNameToConcept() throws Exception { 
    43                 runSyncTest(new SyncTestHelper() { 
    44                         ConceptService cs = Context.getConceptService(); 
    45                         int numNamesBefore; 
    46                         public void runOnChild() { 
    47                                 Concept wt = cs.getConceptByName("WEIGHT"); 
    48                                 numNamesBefore = wt.getNames().size(); 
    49                                 wt.addName(new ConceptName("POIDS", null, "Weight in french", Locale.FRENCH)); 
    50                                 cs.saveConcept(wt); 
    51                         } 
    52                         public void runOnParent() { 
    53                                 Concept wt = cs.getConceptByName("WEIGHT"); 
    54                                 assertNotNull(wt); 
    55                                 assertEquals("Should be one more name than before", numNamesBefore + 1, wt.getNames().size()); 
    56                                 assertEquals("Incorrect french name", wt.getName(Locale.FRENCH).getName(), "POIDS"); 
    57                         } 
    58                 }); 
    59         } 
    60          
    61  
    62         public void testCreateCodedConcept() throws Exception { 
    63                 runSyncTest(new SyncTestHelper() { 
    64                         private int conceptId = 0; 
     42        public void testSaveConceptCoded() throws Exception { 
     43                runSyncTest(new SyncTestHelper() { 
     44                        private int conceptId = 99999; 
    6545                        public void runOnChild() { 
    6646                                ConceptService cs = Context.getConceptService(); 
    6747                                 
    68                                 //this doesn't work with in-mem DB 
     48                                //this doesn't work with in-mem DB 
    6949                                //conceptId = cs.getNextAvailableId(); 
    70                                 conceptId = 99999; 
    7150                                Concept coded = new Concept(conceptId); 
    7251                                coded.setDatatype(cs.getConceptDatatypeByName("Coded")); 
     
    7756                                coded.addAnswer(new ConceptAnswer(cs.getConceptByName("OTHER NON-CODED"))); 
    7857                                coded.addAnswer(new ConceptAnswer(cs.getConceptByName("NONE"))); 
    79                                 cs.createConcept(coded); 
     58                                cs.saveConcept(coded); 
    8059                        } 
    8160                        public void runOnParent() {                                                              
     
    8463                                Concept c = cs.getConcept(conceptId); 
    8564                                log.info("names: " + c.getNames().size()); 
    86                                 assertNotNull("Failed to create coded", c); 
     65                                assertNotNull("Failed to create coded concept", c); 
    8766                                assertEquals(c.getConceptClass().getConceptClassId(), cs.getConceptClassByName("Question").getConceptClassId()); 
    8867                                assertEquals(c.getDatatype().getConceptDatatypeId(), cs.getConceptDatatypeByName("Coded").getConceptDatatypeId()); 
     
    9372                        } 
    9473                }); 
    95         }        
    96          
    97         public void testCreateConcepts() throws Exception { 
     74        }                
     75        public void testSaveConceptNumeric() throws Exception { 
    9876                runSyncTest(new SyncTestHelper() { 
    9977                        ConceptService cs; 
    100                         private int conceptIdNum= 0; 
    101                         private int conceptIdCoded= 0; 
    102                         private int conceptIdSet= 0; 
     78                        private int conceptId=99999; 
    10379                         
    10480                        public void runOnChild() { 
     
    10682                                //this doesn't work with in-mem DB 
    10783                                //conceptIdNum = cs.getNextAvailableId(); 
    108                                 //conceptIdCoded = cs.getNextAvailableId(); 
    109                                 //conceptIdSet = cs.getNextAvailableId(); 
    110                                 conceptIdNum = 99997; 
    111                                 conceptIdCoded = 99998; 
    112                                 conceptIdSet = 99999; 
    113          
    114                                 ConceptNumeric cn = new ConceptNumeric(conceptIdNum); 
     84                                ConceptNumeric cn = new ConceptNumeric(conceptId); 
    11585                                cn.addName(new ConceptName("SOMETHING NUMERIC", "SUM NUM", "A numeric concept", Context.getLocale())); 
    11686                                cn.setDatatype(cs.getConceptDatatypeByName("Numeric")); 
     
    12191                                cn.setHiCritical(100d); 
    12292                                cs.saveConcept(cn); 
    123                                  
    124                                 Concept coded = new Concept(conceptIdCoded); 
     93                        } 
     94                        public void runOnParent() { 
     95                                //Concept c = cs.getConceptByName("SOMETHING NUMERIC"); 
     96                                // assertNotNull("Failed to create numeric", c); 
     97                                assertEquals(cs.getConcept(conceptId).getName().getName(), "SOMETHING NUMERIC"); 
     98                                ConceptNumeric cn = cs.getConceptNumeric(conceptId); 
     99                                assertEquals("Concept numeric absolute low values do not match", 0d, cn.getLowAbsolute()); 
     100                                assertEquals("Concept nuermic high critical values do not match", 100d, cn.getHiCritical()); 
     101                                assertEquals("Concept numeric datatypes does not match", "Numeric", cn.getDatatype().getName()); 
     102                                assertEquals("Concept numeric classes does not match", "Question", cn.getConceptClass().getName()); 
     103                                 
     104                        } 
     105                }); 
     106        } 
     107         
     108         
     109 
     110         
     111         
     112         
     113        public void testSaveConceptSet() throws Exception { 
     114                runSyncTest(new SyncTestHelper() { 
     115                        ConceptService cs; 
     116                        private int conceptNumericId=99997; 
     117                        private int conceptCodedId=99998; 
     118                        private int conceptSetId=99999; 
     119                         
     120                        private String guid = ""; 
     121                         
     122                        public void runOnChild() { 
     123                                cs = Context.getConceptService(); 
     124 
     125                                ConceptNumeric cn = new ConceptNumeric(conceptNumericId); 
     126                                cn.addName(new ConceptName("SOMETHING NUMERIC", "SUM NUM", "A numeric concept", Context.getLocale())); 
     127                                cn.setDatatype(cs.getConceptDatatypeByName("Numeric")); 
     128                                cn.setConceptClass(cs.getConceptClassByName("Question")); 
     129                                cn.setSet(false); 
     130                                cn.setPrecise(true); 
     131                                cn.setLowAbsolute(0d); 
     132                                cn.setHiCritical(100d); 
     133                                cs.saveConcept(cn); 
     134                                 
     135                                Concept coded = new Concept(conceptCodedId); 
    125136                                coded.addName(new ConceptName("SOMETHING CODED", "SUM CODE", "A coded concept", Context.getLocale())); 
    126137                                coded.setDatatype(cs.getConceptDatatypeByName("Coded")); 
     
    128139                                coded.setSet(false); 
    129140                                coded.setSynonyms(new HashSet<ConceptSynonym>()); 
    130                                 coded.addAnswer(new ConceptAnswer(cs.getConceptByName("OTHER NON-CODED"))); 
    131                                 coded.addAnswer(new ConceptAnswer(cs.getConceptByName("NONE"))); 
     141                                 
     142                                Concept other = cs.getConceptByName("OTHER NON-CODED"); 
     143                                assertNotNull("Failed to get concept OTHER NON-CODED", other); 
     144 
     145                                Concept none = cs.getConceptByName("NONE"); 
     146                                assertNotNull("Failed to get concept NONE", none); 
     147                                 
     148                                coded.addAnswer(new ConceptAnswer(other)); 
     149                                coded.addAnswer(new ConceptAnswer(none)); 
    132150                                coded.addAnswer(new ConceptAnswer(cn)); 
    133151                                cs.saveConcept(coded); 
    134                                  
    135                                 Concept set = new Concept(conceptIdSet); 
     152                         
     153                                 
     154                                //ConceptSet conceptSet = new ConceptSet(); 
     155                                 
     156                                 
     157                                Concept set = new Concept(conceptSetId); 
     158                                 
     159                                log.info("Locale: " + Context.getLocale()); 
     160                                 
    136161                                set.addName(new ConceptName("A CONCEPT SET", "SET", "A set of concepts", Context.getLocale())); 
    137162                                set.setDatatype(cs.getConceptDatatypeByName("N/A")); 
     
    144169                                set.setConceptSets(cset); 
    145170                                cs.saveConcept(set); 
    146                         } 
    147                         public void runOnParent() { 
    148                                 //Concept c = cs.getConceptByName("SOMETHING NUMERIC"); 
    149 //                              assertNotNull("Failed to create numeric", c); 
    150                                 assertEquals(cs.getConcept(99997).getName().getName(), "SOMETHING NUMERIC"); 
    151                                 ConceptNumeric cn = cs.getConceptNumeric(99997); 
    152                                 assertEquals(cn.getLowAbsolute(), 0d); 
    153                                 assertEquals(cn.getHiCritical(), 100d); 
    154                                 assertEquals(cn.getDatatype().getName(), "Numeric"); 
    155                                 assertEquals(cn.getConceptClass().getName(), "Question"); 
    156                                  
    157                                 Concept c = cs.getConceptByName("SOMETHING CODED"); 
    158                                 assertNotNull("Failed to create coded", c); 
     171                                 
     172                                guid = set.getGuid(); 
     173                                log.info("GUID:  " + set.getGuid()); 
     174                        } 
     175                        public void runOnParent() { 
     176                                Concept c = cs.getConceptByName("SOMETHING NUMERIC"); 
     177                                assertNotNull("Failed to create numeric", c); 
     178                         
     179                                Concept set = cs.getConcept(conceptSetId); 
     180                                                                 
     181                                set = cs.getConceptByName("A CONCEPT SET"); 
     182                                 
     183                                 
     184                                assertEquals("Concept names do not match", "SOMETHING NUMERIC", cs.getConcept(conceptNumericId).getName().getName()); 
     185                                 
     186                                 
     187                                ConceptNumeric cn = cs.getConceptNumeric(conceptNumericId); 
     188                                assertEquals("Concept numeric absolute low values do not match", 0d, cn.getLowAbsolute()); 
     189                                assertEquals("Concept numeric critical high values do not match", 100d, cn.getHiCritical()); 
     190                                assertEquals("Concept numeric datatypes do not match", "Numeric", cn.getDatatype().getName()); 
     191                                assertEquals("Concept numeric classes do not match", "Question", cn.getConceptClass().getName()); 
    159192                                 
    160193                                //doesn't work in junit/in-mem DB; tested manually only 
     
    162195                                //for (ConceptAnswer a : c.getAnswers()) 
    163196                                //      answers.add(a.getAnswerConcept().getName().getName()); 
    164                                                                  
    165                                 c = cs.getConceptByName("A CONCEPT SET"); 
    166                                 assertNotNull("Failed to create set", c); 
    167                                 assertEquals(c.getConceptSets().size(), 2); 
    168                         } 
    169                 }); 
    170         } 
     197                                 
     198                                // Test the coded concept                        
     199                                Concept conceptCoded = cs.getConcept(conceptCodedId); 
     200                                assertNotNull("Failed to save coded concept - Could not retrieve concept by ID", conceptCoded); 
     201 
     202                                conceptCoded = cs.getConceptByName("SOMETHING CODED"); 
     203                                assertNotNull("Failed to save coded concept - Could not retrieve concept by name", conceptCoded); 
     204                                         
     205                                 
     206                                // Test the concept set  
     207                                 
     208                                Concept conceptSet = cs.getConcept(conceptSetId); 
     209                                assertNotNull("Failed to save concept set - Could not retrieve concept by ID", conceptSet); 
     210                                 
     211                                conceptSet = cs.getConceptByName("A CONCEPT SET"); 
     212                                assertNotNull("Failed to create coded concept - Could not retrieve code concept by name", conceptSet); 
     213 
     214                                 
     215                                assertEquals("Failed to create concept set - Concept set should have two elements", conceptSet.getConceptSets().size(), 2); 
     216                                 
     217                         
     218                        } 
     219                }); 
     220        }                
     221         
    171222 
    172223        public void testEditConcepts() throws Exception { 
     
    179230                                ConceptNumeric weight = cs.getConceptNumeric(wt.getConceptId()); 
    180231                                weight.setHiCritical(200d); 
    181                                 cs.updateConcept(weight); 
     232                                cs.saveConcept(weight); 
    182233                                 
    183234                                Concept coded = cs.getConceptByName("CAUSE OF DEATH"); 
     
    188239                                malaria.setConceptClass(cs.getConceptClassByName("Diagnosis")); 
    189240                                malaria.setSynonyms(new HashSet<ConceptSynonym>()); 
    190                                 cs.createConcept(malaria); 
     241                                cs.saveConcept(malaria); 
    191242                                numAnswersBefore = coded.getAnswers().size(); 
    192243                                coded.addAnswer(new ConceptAnswer(malaria)); 
    193244                                coded.addSynonym("DEATH REASON", Context.getLocale()); 
    194                                 cs.updateConcept(coded); 
     245                                cs.saveConcept(coded); 
    195246                        } 
    196247                        public void runOnParent() { 
     
    213264        } 
    214265 
     266         
     267        public void testAddNameToConcept() throws Exception { 
     268                runSyncTest(new SyncTestHelper() { 
     269                        ConceptService cs = Context.getConceptService(); 
     270                        int numNamesBefore; 
     271                        public void runOnChild() { 
     272                                Concept wt = cs.getConceptByName("WEIGHT"); 
     273                                numNamesBefore = wt.getNames().size(); 
     274                                wt.addName(new ConceptName("POIDS", null, "Weight in french", Locale.FRENCH)); 
     275                                cs.saveConcept(wt); 
     276                        } 
     277                        public void runOnParent() { 
     278                                Concept wt = cs.getConceptByName("WEIGHT"); 
     279                                assertNotNull(wt); 
     280                                assertEquals("Should be one more name than before", numNamesBefore + 1, wt.getNames().size()); 
     281                                assertEquals("Incorrect french name", wt.getName(Locale.FRENCH).getName(), "POIDS"); 
     282                        } 
     283                }); 
     284        } 
     285         
     286 
     287         
    215288}