001/**
002 * Copyright (C) 2010-2015 The Roslin Institute <contact andy.law@roslin.ed.ac.uk>
003 *
004 * This file is part of JEnsembl: a Java API to Ensembl data sources developed by the
005 * Bioinformatics Group at The Roslin Institute, The Royal (Dick) School of
006 * Veterinary Studies, University of Edinburgh.
007 *
008 * Project hosted at: http://jensembl.sourceforge.net
009 *
010 * This is free software: you can redistribute it and/or modify
011 * it under the terms of the GNU General Public License (version 3) as published by
012 * the Free Software Foundation.
013 *
014 * This software is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 *
019 * You should have received a copy of the GNU General Public License
020 * in this software distribution. If not, see: http://opensource.org/licenses/gpl-3.0.html
021 */
022package uk.ac.roslin.ensembl.test;
023
024import static org.junit.Assert.*;
025import uk.ac.roslin.ensembl.config.EnsemblDBType;
026import uk.ac.roslin.ensembl.dao.database.DBRegistry;
027import uk.ac.roslin.ensembl.exception.NonUniqueException;
028
029/**
030 *
031 * @author tpaterso
032 */
033public class Registry {
034
035    static DBRegistry eReg = null;
036    static DBRegistry gReg = null;
037    static DBRegistry bReg = null;
038
039    public static void main(String[] args) throws NonUniqueException, Exception {
040        Registry r = new Registry();
041        try {   
042            r.testEnsemblRegistry();
043            r.testGenomesRegistry();
044            r.testBacterialRegistry();
045        } catch (Exception e) {
046            System.out.println(e.getMessage());
047            throw new Exception(e);
048        
049        } catch (Error a) {
050            System.out.println(a.getMessage());
051            throw new Exception(a);
052        }
053        
054        System.out.println("Successfuly completes Registry.java");
055    }
056    
057    public  void testEnsemblRegistry() throws NonUniqueException {
058        
059        eReg = RegistryProvider.geteReg();
060
061        assertNotNull(eReg.getSpecies());
062        assertNotNull(eReg.getSpeciesByAlias("human"));
063        assertFalse(eReg.getSpecies().isEmpty());
064
065        String v = eReg.getMostRecentEnsemblVersion();
066
067        assertNotNull(eReg.getDatabase("human", EnsemblDBType.core, null));
068        assertTrue(eReg.getDatabase("human", EnsemblDBType.core, null).getSchemaVersion().equals(v));
069
070        assertNotNull(eReg.getDatabase("multi", EnsemblDBType.compara, null));
071        assertTrue(eReg.getDatabase("multi", EnsemblDBType.compara, null).getSchemaVersion().equals(v));
072
073
074        assertNotNull(eReg.getDatabase("human", EnsemblDBType.variation, null));
075        assertTrue(eReg.getDatabase("human", EnsemblDBType.variation, null).getSchemaVersion().equals(v));
076
077    }
078
079    public  void testGenomesRegistry() throws Exception {
080
081        gReg = RegistryProvider.getgReg();
082
083        assertNotNull("Registry apparently lacks Species List", gReg.getSpecies());
084        assertFalse("Registry has empty Species List", gReg.getSpecies().isEmpty());
085        assertNotNull("Registry apparently lacks Species 'rice'", gReg.getSpeciesByAlias("oryza_sativa"));
086        assertFalse("Registry  Species 'rice' has no aliases", gReg.getSpeciesByAlias("oryza_sativa").getDatabases().isEmpty());
087
088        assertNotNull(gReg.getCollections());
089        assertTrue(gReg.getCollections().isEmpty());
090
091        assertNotNull(gReg.getCollectionSpecies());
092        assertTrue(gReg.getCollectionSpecies().isEmpty());
093        assertNull(gReg.getSpeciesByAlias("Escherichia coli K12"));
094
095        assertNotNull(gReg.getDatabase("oryza_sativa", EnsemblDBType.core, null));
096        assertNotNull(gReg.getDatabase("plants", EnsemblDBType.compara, null));
097        assertNotNull(gReg.getDatabase("oryza_sativa", EnsemblDBType.variation, null));
098        assertNull(gReg.getDatabase("escherichia_shigella", EnsemblDBType.collection_core, null));
099
100
101    }
102    
103    public  void testBacterialRegistry() throws Exception {
104
105        bReg = RegistryProvider.getbReg();
106
107        assertNotNull("Registry apparently lacks Species List", bReg.getSpecies());
108        assertTrue("Registry has empty Species List", bReg.getSpecies().isEmpty());
109
110        assertNotNull(bReg.getCollections());
111        assertFalse(bReg.getCollections().isEmpty());
112        assertNotNull(bReg.getCollectionRegistriesByName("escherichia_shigella"));
113        assertTrue(bReg.getCollectionRegistriesByName("escherichia_shigella").isEmpty());
114
115        assertNotNull(bReg.getCollectionSpecies());
116        assertFalse(bReg.getCollectionSpecies().isEmpty());
117        assertNotNull(bReg.getSpeciesByAlias("escherichia_coli_str_k_12_substr_mg1655"));
118        assertFalse(bReg.getSpeciesByAlias("escherichia_coli_str_k_12_substr_mg1655").getDatabases().isEmpty());
119
120        assertNull(bReg.getDatabase("escherichia_shigella", EnsemblDBType.collection_core, null));
121        assertNotNull(bReg.getDatabase("bacteria", EnsemblDBType.compara, null));
122
123    }
124}