Show
Ignore:
Timestamp:
06/02/10 22:19:39 (2 years ago)
Author:
bturner
Message:

Need to handle case where user doesn't have config file.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/org.bridgedb.server/test/org/bridgedb/server/Test.java

    r395 r397  
    1717package org.bridgedb.server; 
    1818 
     19import java.io.File; 
     20import java.io.FileNotFoundException; 
    1921import java.util.Map; 
    2022import java.util.Set; 
    2123 
    2224import junit.framework.TestCase; 
     25import junit.framework.TestResult; 
    2326 
    2427import org.bridgedb.AttributeMapper; 
     
    3538        private IDMapper mapper; 
    3639        private Server server; 
     40        private boolean configExists; 
    3741         
    3842        @Override 
    3943        protected void setUp() throws Exception { 
    4044             
    41             if (server == null) 
    42         { 
    43             server = new Server(); 
    44             server.run(8183, null); 
    45         } 
    46                 if(mapper == null) { 
    47                         // Start local service 
    48                  
    49  
    50                         // Create a client 
    51                         Class.forName("org.bridgedb.webservice.bridgerest.BridgeRest"); 
    52                         mapper = BridgeDb.connect("idmapper-bridgerest:http://localhost:8183/Human"); 
    53                 } 
     45            
     46            File f= new File(IDMapperService.CONF_GDBS); 
     47             
     48            configExists = f.exists(); 
     49             
     50            if (configExists) 
     51            { 
     52             
     53            if (server == null) 
     54            { 
     55                server = new Server(); 
     56                server.run(8183, null); 
     57            } 
     58                if(mapper == null) { 
     59                     
     60                        // Create a client 
     61                        Class.forName("org.bridgedb.webservice.bridgerest.BridgeRest"); 
     62                        mapper = BridgeDb.connect("idmapper-bridgerest:http://localhost:8183/Human"); 
     63                } 
     64            } 
     65            else 
     66            { 
     67                System.err.println("Skipping server tests. No " + IDMapperService.CONF_GDBS + " found."); 
     68            } 
    5469                 
    5570        } 
     
    6075    protected void tearDown() throws Exception 
    6176    { 
    62         // TODO Auto-generated method stub 
    63         super.tearDown(); 
    64         server.stop(); 
     77            super.tearDown(); 
     78     
     79            if (server != null) 
     80            { 
     81                server.stop(); 
     82            } 
    6583    } 
    6684 
     
    7290         
    7391        public void testLocalMapID() throws IDMapperException, ClassNotFoundException { 
    74                 IDMapper mapper = getLocalService(); 
    7592                 
    76                 Xref insr = new Xref ("3643", BioDataSource.ENTREZ_GENE); 
    77                 Xref affy = new Xref ("33162_at", BioDataSource.AFFY); 
    78                 Set<Xref> result = mapper.mapID(insr); 
    79                 assertTrue (result.contains(affy)); 
    80                  
    81                 assertTrue(mapper.xrefExists(insr)); 
     93            if (configExists) 
     94            { 
     95            IDMapper mapper = getLocalService(); 
     96                 
     97                Xref insr = new Xref ("3643", BioDataSource.ENTREZ_GENE); 
     98                Xref affy = new Xref ("33162_at", BioDataSource.AFFY); 
     99                Set<Xref> result = mapper.mapID(insr); 
     100                assertTrue (result.contains(affy)); 
     101                 
     102                assertTrue(mapper.xrefExists(insr)); 
     103            } 
    82104        } 
    83105         
    84106        public void testLocalCapabilities() throws IDMapperException, ClassNotFoundException { 
    85                 IDMapper mapper = getLocalService(); 
    86107                 
    87                 IDMapperCapabilities cap = mapper.getCapabilities(); 
    88                  
    89                 Set<DataSource> supported = cap.getSupportedSrcDataSources(); 
    90                 assertTrue (supported.contains(DataSource.getBySystemCode("L"))); 
    91  
    92                 String val = cap.getProperty("SCHEMAVERSION"); 
    93                 assertNotNull(val); 
    94                  
    95                 Set<DataSource> srcDs = cap.getSupportedSrcDataSources(); 
    96                 assertTrue(srcDs.size() > 0); 
    97                  
    98                 assertTrue(cap.isFreeSearchSupported()); 
    99                  
    100                 assertTrue(cap.isMappingSupported(BioDataSource.UNIPROT, BioDataSource.ENTREZ_GENE)); 
    101                  
    102                 assertFalse(cap.isMappingSupported( 
    103                                 DataSource.getBySystemCode("??"), DataSource.getBySystemCode("!!"))); 
     108            if (configExists) 
     109            { 
     110            IDMapper mapper = getLocalService(); 
     111                 
     112                IDMapperCapabilities cap = mapper.getCapabilities(); 
     113                 
     114                Set<DataSource> supported = cap.getSupportedSrcDataSources(); 
     115                assertTrue (supported.contains(DataSource.getBySystemCode("L"))); 
     116     
     117                String val = cap.getProperty("SCHEMAVERSION"); 
     118                assertNotNull(val); 
     119                 
     120                Set<DataSource> srcDs = cap.getSupportedSrcDataSources(); 
     121                assertTrue(srcDs.size() > 0); 
     122                 
     123                assertTrue(cap.isFreeSearchSupported()); 
     124                 
     125                assertTrue(cap.isMappingSupported(BioDataSource.UNIPROT, BioDataSource.ENTREZ_GENE)); 
     126                 
     127                assertFalse(cap.isMappingSupported( 
     128                                DataSource.getBySystemCode("??"), DataSource.getBySystemCode("!!"))); 
     129            } 
    104130        } 
    105131         
    106132        public void testLocalSearch() throws IDMapperException, ClassNotFoundException { 
    107                 IDMapper mapper = getLocalService(); 
    108133                 
    109                 Set<Xref> result = mapper.freeSearch("1234", 100); 
    110                 System.out.println(result); 
    111                 assertTrue(result.size() > 0); 
     134            if (configExists) 
     135        { 
     136            IDMapper mapper = getLocalService(); 
     137                 
     138                Set<Xref> result = mapper.freeSearch("1234", 100); 
     139                System.out.println(result); 
     140                assertTrue(result.size() > 0); 
     141        } 
    112142        } 
    113143         
    114144        public void testLocalAttributes() throws ClassNotFoundException, IDMapperException { 
    115                 AttributeMapper mapper = (AttributeMapper)getLocalService(); 
    116145                 
    117                 Xref insr = new Xref("3643", BioDataSource.ENTREZ_GENE); 
    118                 Map<String, Set<String>> attrMap = mapper.getAttributes(insr); 
    119                 assertNotNull(attrMap.get("Symbol")); 
    120                 assertTrue(attrMap.get("Symbol").size() == 2); 
    121                  
    122                 Set<String> attrValues = mapper.getAttributes(insr, "Symbol"); 
    123                 assertTrue(attrValues.size() == 2); 
    124                  
    125                 Map<Xref, String> xrefMap = mapper.freeAttributeSearch("INSR", "Symbol", 1); 
    126                 assertTrue(xrefMap.size() == 1); 
     146            if (configExists) 
     147        { 
     148            AttributeMapper mapper = (AttributeMapper)getLocalService(); 
     149                 
     150                Xref insr = new Xref("3643", BioDataSource.ENTREZ_GENE); 
     151                Map<String, Set<String>> attrMap = mapper.getAttributes(insr); 
     152                assertNotNull(attrMap.get("Symbol")); 
     153                assertTrue(attrMap.get("Symbol").size() == 2); 
     154                 
     155                Set<String> attrValues = mapper.getAttributes(insr, "Symbol"); 
     156                assertTrue(attrValues.size() == 2); 
     157                 
     158                Map<Xref, String> xrefMap = mapper.freeAttributeSearch("INSR", "Symbol", 1); 
     159                assertTrue(xrefMap.size() == 1); 
     160     
     161                xrefMap = mapper.freeAttributeSearch("INSR", "Symbol", 100); 
     162                assertTrue(xrefMap.containsKey(insr)); 
     163                assertTrue(xrefMap.size() > 1); 
     164                 
     165                Set<String> attrs = mapper.getAttributeSet(); 
     166                assertTrue(attrs.size() > 0); 
     167        } 
     168        } 
    127169 
    128                 xrefMap = mapper.freeAttributeSearch("INSR", "Symbol", 100); 
    129                 assertTrue(xrefMap.containsKey(insr)); 
    130                 assertTrue(xrefMap.size() > 1); 
    131                  
    132                 Set<String> attrs = mapper.getAttributeSet(); 
    133                 assertTrue(attrs.size() > 0); 
    134         } 
     170 
     171 
    135172}