Changeset 4191


Ignore:
Timestamp:
11/09/08 10:59:56 (11 years ago)
Author:
cbyrom
Message:

Update test case suite for Discovery WS - making more detailed checks +
more adaptable - testing for docs already known to be in the postgres
DB + add new utility method to parse out XML element values.

Location:
TI01-discovery/branches/ws-Discovery2-upgrade/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI01-discovery/branches/ws-Discovery2-upgrade/src/ndg/common/discovery/Utilities.java

    r4142 r4191  
    11package ndg.common.discovery; 
     2 
     3import java.util.ArrayList; 
     4import java.util.regex.Matcher; 
     5import java.util.regex.Pattern; 
    26 
    37public class Utilities  
     
    4246                return count; 
    4347        } 
     48         
     49 
     50        /** 
     51         * Retrieves the value of a specified element 
     52         *  
     53         * @param xmlString - String, in XML format, to check through 
     54         * @param elementName - name of element whose value should be extracted 
     55         * @return array of values of elementName 
     56         */ 
     57        public static String[] getElementValue(String xmlString, String elementName)  
     58        { 
     59                ArrayList<String> results = new ArrayList<String>(); 
     60                Pattern pattern = Pattern.compile( 
     61                                "<" + elementName + ">(.*?)</" + elementName + ">"); 
     62                Matcher matcher = pattern.matcher(xmlString); 
     63                while (matcher.find()) 
     64                { 
     65                        results.add(matcher.group(1)); 
     66                } 
     67                String[] outArray = new String [results.size()]; 
     68                results.toArray(outArray); 
     69                return outArray; 
     70        } 
    4471 
    4572 
  • TI01-discovery/branches/ws-Discovery2-upgrade/src/unittests/ndg/testclient/discovery/DiscoveryServiceClientTest.java

    r4142 r4191  
    2121{ 
    2222        private static DiscoveryServiceClient client = null; 
    23         // this is the dummy doc to use for all tests - NB, it is available under resources and should be ingested 
    24         // using the oai_document_ingester.py script as a badc file 
    25         private static final String DOC_NAME_1 = "badc.nerc.ac.uk__DIF__test_file.xml"; 
    26          
    27         private static final String DOC_NAME_2 = "badc.nerc.ac.uk__DIF__test_file2.xml"; 
     23 
     24        private static String DOC_NAME_1 = null; 
     25         
     26        private static String DOC_NAME_2 = null; 
    2827 
    2928        private static final String VALID_TERM = "circulation";  
     
    4544        private static final String VALID_COLUMN_NAME2 = "original_document_id"; 
    4645 
    47         private static final String VALID_START_DATE = "2023-02-02"; 
     46        private static final String VALID_START_DATE = "2000-02-02"; 
    4847         
    4948        private static final String VALID_END_DATE = "2055-02-02"; 
     
    6564        { 
    6665                client = new DiscoveryServiceClient("http://localhost:8080/axis2/services/DiscoveryService"); 
    67                  
     66 
     67                // populate the valid doc names 
     68                String results = client.runSearch(null, null, null, null, null, null, null,  
     69                                null, null, null, null, null, null, null, null); 
     70                String[] docs = Utilities.getElementValue(results, "urn:document"); 
     71                DOC_NAME_1 = docs[0]; 
     72                DOC_NAME_2 = docs[1]; 
     73 
    6874        } 
    6975 
     
    174180        { 
    175181                // NB, this will result in no rows being returned 
    176                 String results = client.runSearch(null, null, "100", null, null, null, null,  
     182                String results = client.runSearch(null, null, "100000", null, null, null, null,  
    177183                                null, null, null, null, null, null, null, null); 
    178184                assertNotNull(results); 
     
    227233        public void differentStartSearchCompare()  
    228234        { 
    229                 String results = client.runSearch(null, null, "0", null, null, null, null,  
    230                                 null, null, null, null, null, null, null, null); 
    231                 assertNotNull(results); 
    232                 assertFalse(results.contains("<urn:status>false</urn:status>")); 
    233  
    234                 String results1 = client.runSearch(null, null, "1", null, null, null, null,  
     235                String results = client.runSearch(null, null, "1", null, null, null, null,  
     236                                null, null, null, null, null, null, null, null); 
     237                assertNotNull(results); 
     238                assertFalse(results.contains("<urn:status>false</urn:status>")); 
     239 
     240                String results1 = client.runSearch(null, null, "2", null, null, null, null,  
     241                                null, null, null, null, null, null, null, null); 
     242 
     243                String results2 = client.runSearch(null, null, "2", null, null, null, null,  
    235244                                null, null, null, null, null, null, null, null); 
    236245                assertNotNull(results1); 
    237246                assertFalse(results1.contains("<urn:status>false</urn:status>")); 
    238247                 
    239                 assertNotSame(Utilities.getSubStringCount("<urn:document>", results),  
    240                                 Utilities.getSubStringCount("<urn:document>", results1)); 
     248                assertNotSame(results, results1); 
     249                assertEquals(results2, results1); 
    241250        } 
    242251 
     
    416425                                null, null, null, null, null, null, null, null); 
    417426                assertNotNull(results); 
    418                 assertTrue(results.contains("<urn:status>false</urn:status>")); 
     427                assertTrue(results.contains("<urn:status>true</urn:status>")); 
    419428        } 
    420429 
     
    422431        public void validOrScopeSearch()  
    423432        { 
    424                 // NB, this is a slight hack; can use '|' characters in the scope field to do 'or' searches 
    425433                String results = client.runSearch(null, null, null, null, null, null,  
    426434                                getVector(VALID_SCOPE1 + "|" + VALID_SCOPE2),  
     
    428436                assertNotNull(results); 
    429437                assertFalse(results.contains("<urn:status>false</urn:status>")); 
    430                 assertEquals(Utilities.getSubStringCount("<urn:document>", results), 2); 
     438                assertTrue(Utilities.getSubStringCount("<urn:document>", results) > 0); 
     439        } 
     440 
     441        @Test 
     442        public void validOrScopeSearchCheckTotals()  
     443        { 
     444                String results = client.runSearch(null, null, null, null, null, null,  
     445                                getVector(VALID_SCOPE1 + "|" + VALID_SCOPE2),  
     446                                null, null, null, null, null, null, null, null); 
     447                int orDocsNum = Integer.parseInt(Utilities.getElementValue(results, "urn:hits")[0]); 
     448 
     449                results = client.runSearch(null, null, null, null, null, null,  
     450                                getVector(VALID_SCOPE1),  
     451                                null, null, null, null, null, null, null, null); 
     452                int scope1Num = Integer.parseInt(Utilities.getElementValue(results, "urn:hits")[0]); 
     453 
     454                results = client.runSearch(null, null, null, null, null, null,  
     455                                getVector(VALID_SCOPE2),  
     456                                null, null, null, null, null, null, null, null); 
     457                int scope2Num = Integer.parseInt(Utilities.getElementValue(results, "urn:hits")[0]); 
     458 
     459                Vector<String> vector = getVector(VALID_SCOPE1); 
     460                vector.add(VALID_SCOPE2); 
     461                results = client.runSearch(null, null, null, null, null, null,  
     462                                vector,  
     463                                null, null, null, null, null, null, null, null); 
     464                int andDocNum = Integer.parseInt(Utilities.getElementValue(results, "urn:hits")[0]); 
     465                 
     466                assertEquals(orDocsNum, scope1Num + scope2Num - andDocNum); 
    431467        } 
    432468 
     
    488524                assertNotNull(results); 
    489525                assertFalse(results.contains("<urn:status>false</urn:status>")); 
    490                 assertEquals(Utilities.getSubStringCount("<urn:document>", results), 2); 
     526                assertTrue(Utilities.getSubStringCount("<urn:document>", results) > 0); 
    491527        } 
    492528 
     
    507543                assertNotNull(results); 
    508544                assertFalse(results.contains("<urn:status>false</urn:status>")); 
    509                 assertEquals(Utilities.getSubStringCount("<urn:document>", results), 1); 
     545                assertTrue(Utilities.getSubStringCount("<urn:document>", results) > 0); 
    510546        } 
    511547 
     
    536572 
    537573        @Test 
    538         public void overlapOperatorWithInvalidBBoxSearch()  
     574        public void overlapOperatorWithRestrictedBBoxSearch()  
    539575        { 
    540576                String results = client.runSearch(null, null, null, null, null, null, null,  
    541577                                DiscoveryServiceSkeleton.OVERLAPS_OPERATOR_TYPE, "90", "89.999", "-180.", "-179.999", null, null, null); 
    542578                assertNotNull(results); 
    543                 assertTrue(results.contains("<urn:status>false</urn:status>")); 
     579                assertFalse(results.contains("<urn:status>false</urn:status>")); 
     580                String val = Utilities.getElementValue(results, "urn:hits")[0]; 
     581                 
     582                String results1 = client.runSearch(null, null, null, null, null, null, null,  
     583                                "within", null, null, null, null, null, null, null); 
     584                String val1 = Utilities.getElementValue(results1, "urn:hits")[0]; 
     585                assertFalse(val.equals(val1)); 
     586 
    544587        } 
    545588 
     
    551594                assertNotNull(results); 
    552595                assertFalse(results.contains("<urn:status>false</urn:status>")); 
    553                 assertEquals(Utilities.getSubStringCount("<urn:document>", results), 1); 
     596                assertTrue(Utilities.getSubStringCount("<urn:document>", results) > 0); 
    554597        } 
    555598 
     
    615658                assertNotNull(results); 
    616659                assertFalse(results.contains("<urn:status>false</urn:status>")); 
    617                 assertEquals(Utilities.getSubStringCount("<urn:document>", results), 1); 
     660                assertTrue(Utilities.getSubStringCount("<urn:document>", results) > 0); 
    618661        } 
    619662 
     
    625668                assertNotNull(results); 
    626669                assertFalse(results.contains("<urn:status>false</urn:status>")); 
    627                 assertEquals(Utilities.getSubStringCount("<urn:document>", results), 2); 
     670                assertTrue(Utilities.getSubStringCount("<urn:document>", results) > 0); 
    628671        } 
    629672 
     
    657700                                null, null, null, null, null, null, null, VALID_END_DATE); 
    658701                assertNotNull(results); 
    659                 assertTrue(results.contains("<urn:status>false</urn:status>")); 
     702                assertFalse(results.contains("<urn:status>false</urn:status>")); 
    660703        } 
    661704 
     
    701744 
    702745        @Test 
    703         public void withinOperatorWithValidBBoxSearchAndValidDateSearchAndInvalidScope()  
     746        public void withinOperatorWithValidBBoxSearchAndValidDateSearchAndDifferentScope()  
    704747        { 
    705748                String results = client.runSearch(null, null, null, null, null, null, getVector(VALID_SCOPE1),  
    706749                                DiscoveryServiceSkeleton.WITHIN_OPERATOR_TYPE, "80", "-80", "-170.", "170.", null, VALID_WIDE_START_DATE, VALID_END_DATE); 
    707750                assertNotNull(results); 
    708                 assertTrue(results.contains("<urn:status>false</urn:status>")); 
     751                assertFalse(results.contains("<urn:status>false</urn:status>")); 
     752        } 
     753         
     754 
     755        @Test 
     756        public void withinOperatorWithValidBBoxSearchAndValidDateSearchAndDifferentScopeCompare()  
     757        { 
     758                String results = client.runSearch(null, null, null, null, null, null, getVector(VALID_SCOPE1),  
     759                                DiscoveryServiceSkeleton.WITHIN_OPERATOR_TYPE, "80", "-80", "-170.", "170.", null, VALID_WIDE_START_DATE, VALID_END_DATE); 
     760                String val = Utilities.getElementValue(results, "urn:hits")[0]; 
     761                String results1 = client.runSearch(null, null, null, null, null, null, getVector(VALID_SCOPE2),  
     762                                DiscoveryServiceSkeleton.WITHIN_OPERATOR_TYPE, "80", "-80", "-170.", "170.", null, VALID_WIDE_START_DATE, VALID_END_DATE); 
     763                String val1 = Utilities.getElementValue(results1, "urn:hits")[0]; 
     764                assertFalse(val.equals(val1)); 
    709765        } 
    710766         
Note: See TracChangeset for help on using the changeset viewer.