From: tcofoegbu Date: Mon, 25 Apr 2016 10:36:59 +0000 (+0100) Subject: JAL-2071 added unit tests for FTSRestClient X-Git-Tag: Release_2_10_0~258 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=174606cd2bcaed91adb0a39639e8905fa9a8a6d2;p=jalview.git JAL-2071 added unit tests for FTSRestClient --- diff --git a/examples/testdata/test_fts_data_columns.conf b/examples/testdata/test_fts_data_columns.conf new file mode 100644 index 0000000..10f5043 --- /dev/null +++ b/examples/testdata/test_fts_data_columns.conf @@ -0,0 +1,153 @@ +uniprot_data_columns +# +_group.id +_group.name +_group.sort_order +g1;Quality Measures;3 +g2;Cross References;2 +g3;Names & Taxonomy;1 +g4;Procedures & Softwares;4 +g5;Date Of;5 +g6;Miscellenous;6 +g7;Sequences;7 +g8;Function;8 +g9;Interaction;9 +g10;Expression;10 +g11;Gene Ontology;11 +g12;Pathology & Biotech;12 +g13;Subcellular location;13 +g14;PTM / Processing;14 +g15;Structure;15 +g16;Publications;16 +g17;Date of;17 +g18;Family & Domain;18 +# +_data_column.primary_key;entry name +_data_column.default_response_page_size;100 +# +_data_column.name +_data_column.code +_data_column.group_id +_data_column.data_type +_data_column.min_col_width +_data_column.max_col_width +_data_column.preferred_col_width +_data_column.is_shown_by_default +_data_column.is_searchable +Entry Name;entry name;String;g3;80;100;85;true;true +Protein names;protein names;String;g3;300;1500;500;true;true +Gene Names;genes;String;g3;50;1000;95;true;true +Organism;organism;String;g3;50;1000;95;true;true +Organism ID;organism-id;int;g3;60;100;80;false;true +Proteomes;proteome;String;g3;50;1000;95;false;true +Taxonomic lineage (ALL);lineage(ALL);String;g3;50;400;95;false;false +Virus hosts;virus hosts;String;g3;50;1000;95;false;true +Fragment;fragment;String;g7;50;1000;95;false;true +Gene encoded by;encodedon;String;g7;50;1000;95;false;true +Alternative products (isoforms);comment(ALTERNATIVE PRODUCTS);String;g7;50;1000;95;false;false +Erroneous gene model prediction;comment(ERRONEOUS GENE MODEL PREDICTION);String;g7;50;1000;95;false;false +Erroneous initiation;comment(ERRONEOUS INITIATION);String;g7;50;1000;95;false;false +Erroneous translation;comment(ERRONEOUS TRANSLATION);String;g7;50;1000;95;false;false +Frameshift;comment(FRAMESHIFT);String;g7;50;1000;95;false;false +Mass spectrometry;comment(MASS SPECTROMETRY);String;g7;50;1000;95;false;false +Polymorphism;comment(POLYMORPHISM);String;g7;50;1000;95;false;false +RNA editing;comment(RNA EDITING);String;g7;50;1000;95;false;false +Sequence caution;comment(SEQUENCE CAUTION);String;g7;50;1000;95;false;false +Length;length;int;g7;50;100;95;false;true +Mass;mass;String;g7;50;100;80;false;true +Sequence;sequence;String;g7;50;1000;95;false;true +Alternative sequence;feature(ALTERNATIVE SEQUENCE);String;g7;50;1000;95;false;false +Natural variant;feature(NATURAL VARIANT);String;g7;50;1000;95;false;false +Non-adjacent residues;feature(NON ADJACENT RESIDUES);String;g7;50;1000;95;false;false +Non-standard residue;feature(NON STANDARD RESIDUE);String;g7;50;1000;95;false;false +Non-terminal residue;feature(NON TERMINAL RESIDUE);String;g7;50;1000;95;false;false +Sequence conflict;feature(SEQUENCE CONFLICT);String;g7;50;1000;95;false;false +Sequence uncertainty;feature(SEQUENCE UNCERTAINTY);String;g7;50;1000;95;false;false +Version (Sequence);version(sequence);String;g7;50;1000;95;false;false +EC number;ec;String;g8;50;1000;95;false;true +Absorption;comment(ABSORPTION);String;g8;50;1000;95;false;false +Catalytic activity;comment(CATALYTIC ACTIVITY);String;g8;50;1000;95;false;false +Cofactor;comment(COFACTOR);String;g8;50;1000;95;false;false +Enzyme regulation;comment(ENZYME REGULATION);String;g8;50;1000;95;false;false +Function [CC];comment(FUNCTION);String;g8;50;1000;95;false;false +Kinetics;comment(KINETICS);String;g8;50;1000;95;false;false +Pathway;comment(PATHWAY);String;g8;50;1000;95;false;false +Redox potential;comment(REDOX POTENTIAL);String;g8;50;1000;95;false;false +Temperature dependence;comment(TEMPERATURE DEPENDENCE);String;g8;50;1000;95;false;false +pH dependence;comment(PH DEPENDENCE);String;g8;50;1000;95;false;false +Active site;feature(ACTIVE SITE);String;g8;50;1000;95;false;false +Binding site;feature(BINDING SITE);String;g8;50;1000;95;false;false +DNA binding;feature(DNA BINDING);String;g8;50;1000;95;false;false +Metal binding;feature(METAL BINDING);String;g8;50;1000;95;false;false +Nucleotide binding;feature(NP BIND);String;g8;50;1000;95;false;false +Site;feature(SITE);String;g8;50;1000;95;false;false +Annotation;annotation score;String;g6;50;1000;95;false;true +Features;features;String;g6;50;1000;95;false;true +Caution;comment(CAUTION);String;g6;50;1000;95;false;false +Miscellaneous [CC];comment(GENERAL);String;g6;50;1000;95;false;false +Keywords;keywords;String;g6;50;1000;95;false;true +Protein existence;existence;String;g6;50;1000;95;false;true +Status;reviewed;String;g6;50;1000;95;false;true +ALL;entry name;String;g7;50;1000;95;false;true; +Subunit structure [CC];comment(SUBUNIT);String;g9;50;1000;95;false;false +Interacts with;interactor;String;g9;50;1000;95;false;true +Developmental stage;comment(DEVELOPMENTAL STAGE);String;g10;50;1000;95;false;false +Induction;comment(INDUCTION);String;g10;50;1000;95;false;false +Tissue specificity;comment(TISSUE SPECIFICITY);String;g10;50;1000;95;false;false +Gene ontology (GO);go;String;g11;50;1000;95;false;true +Gene ontology (biological process);go(biological process);String;g11;50;1000;95;false;false +Gene ontology (molecular function);go(molecular function);String;g11;50;1000;95;false;false +Gene ontology (cellular component);go(cellular component);String;g11;50;1000;95;false;false +Gene ontology IDs;go-id;String;g11;50;1000;95;false;true +Allergenic properties;comment(ALLERGEN);String;g12;50;1000;95;false;false +Biotechnological use;comment(BIOTECHNOLOGY);String;g12;50;1000;95;false;false +Disruption phenotype;comment(DISRUPTION PHENOTYPE);String;g12;50;1000;95;false;false +Involvement in disease;comment(DISEASE);String;g12;50;1000;95;false;false +Pharmaceutical use;comment(PHARMACEUTICAL);String;g12;50;1000;95;false;false +Toxic dose;comment(TOXIC DOSE);String;g12;50;1000;95;false;false +Subcellular location [CC];comment(SUBCELLULAR LOCATION);String;g13;50;1000;95;false;false +Intramembrane;feature(INTRAMEMBRANE);String;g13;50;1000;95;false;false +Topological domain;feature(TOPOLOGICAL DOMAIN);String;g13;50;1000;95;false;false +Transmembrane;feature(TRANSMEMBRANE);String;g13;50;1000;95;false;false +Post-translational modification;comment(PTM);String;g14;50;1000;95;false;false +Chain;feature(CHAIN);String;g14;50;1000;95;false;false +Cross-link;feature(CROSS LINK);String;g14;50;1000;95;false;false +Disulfide bond;feature(DISULFIDE BOND);String;g14;50;1000;95;false;false +Glycosylation;feature(GLYCOSYLATION);String;g14;50;1000;95;false;false +Initiator methionine;feature(INITIATOR METHIONINE);String;g14;50;1000;95;false;false +Lipidation;feature(LIPIDATION);String;g14;50;1000;95;false;false +Modified residue;feature(MODIFIED RESIDUE);String;g14;50;1000;95;false;false +Peptide;feature(PEPTIDE);String;g14;50;1000;95;false;false +Propeptide;feature(PROPEPTIDE);String;g14;50;1000;95;false;false +Signal peptide;feature(SIGNAL);String;g14;50;1000;95;false;false +Transit peptide;feature(TRANSIT);String;g14;50;1000;95;false;false +3D;3d;String;g15;50;1000;95;false;false +Beta strand;feature(BETA STRAND);String;g15;50;1000;95;false;false +Helix;feature(HELIX);String;g15;50;1000;95;false;false +Turn;feature(TURN);String;g15;50;1000;95;false;false +PubMed ID;citation;String;g16;50;1000;95;false;true +Date of creation;created;String;g17;80;150;100;true;true +Date of last modification;last-modified;String;g17;80;150;100;true;true +Date of last sequence modification;sequence-modified;String;g17;80;150;100;false;true +Version (entry);version(entry);int;g17;80;100;80;false;false +Domain [CC];comment(DOMAIN);String;g18;80;1000;95;false;false +Sequence similarities;comment(SIMILARITY);String;g18;50;1000;95;false;false +Protein families;families;String;g18;50;1000;95;false;true +Coiled coil;feature(COILED COIL);String;g18;50;1000;95;false;false +Compositional bias;feature(COMPOSITIONAL BIAS);String;g18;50;1000;95;false;false +Domain [FT];feature(DOMAIN EXTENT);String;g18;50;1000;95;false;false +Motif;feature(MOTIF);String;g18;50;1000;95;false;false +Region;feature(REGION);String;g18;50;1000;95;false;false +Repeat;feature(REPEAT);String;g18;50;1000;95;false;false +Zinc finger;feature(ZINC FINGER);String;g18;50;1000;95;false;false +Cross-reference (EMBL);database(EMBL);String;g2;50;1000;95;false;false +Cross-reference (PDB);database(PDB);String;g2;50;1000;95;false;false +Cross-reference (ENSEMBL);database(ENSEMBL);String;g2;50;1000;95;false;false +Cross-reference (PFAM);database(PFAM);String;g2;50;1000;95;false;false +Cross-reference (RFAM);database(RFAM);String;g2;50;1000;95;false;false +Cross-reference (CATH);database(CATH);String;g2;50;1000;95;false;false +Cross-reference (SCOPE);database(SCOPE);String;g2;50;1000;95;false;false +Cross-reference (GO);database(GO);String;g2;50;1000;95;false;false +Cross-reference (INTERPRO);database(INTERPRO);String;g2;50;1000;95;false;false +Mapped PubMed ID;citationmapping;String;g16;50;1000;95;false;true +# diff --git a/src/jalview/fts/core/FTSRestClient.java b/src/jalview/fts/core/FTSRestClient.java index eeb7ec6..8ac740c 100644 --- a/src/jalview/fts/core/FTSRestClient.java +++ b/src/jalview/fts/core/FTSRestClient.java @@ -239,6 +239,13 @@ public abstract class FTSRestClient implements FTSRestClientI e.printStackTrace(); } } + try + { + this.primaryKeyColumn = getDataColumnByNameOrCode(primaryKeyColumnCode); + } catch (Exception e) + { + e.printStackTrace(); + } } catch (IOException e) { e.printStackTrace(); @@ -344,6 +351,11 @@ public abstract class FTSRestClient implements FTSRestClientI @Override public FTSDataColumnI getPrimaryKeyColumn() { + if (defaulDisplayedDataColumns == null + || defaulDisplayedDataColumns.isEmpty()) + { + parseDataColumnsConfigFile(); + } return primaryKeyColumn; } diff --git a/test/jalview/fts/core/FTSRestClientTest.java b/test/jalview/fts/core/FTSRestClientTest.java new file mode 100644 index 0000000..fa36cac --- /dev/null +++ b/test/jalview/fts/core/FTSRestClientTest.java @@ -0,0 +1,310 @@ +package jalview.fts.core; + +import jalview.fts.api.FTSDataColumnI; +import jalview.fts.api.FTSDataColumnI.FTSDataColumnGroupI; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class FTSRestClientTest +{ + private FTSRestClient ftsRestClient; + + @BeforeMethod(alwaysRun = true) + public void setup() + { + ftsRestClient = new FTSRestClient() + { + + @Override + public String getColumnDataConfigFileName() + { + return "examples/testdata/test_fts_data_columns.conf"; + } + + @Override + public FTSRestResponse executeRequest(FTSRestRequest ftsRequest) + throws Exception + { + return null; + } + }; + } + + @Test(groups = { "Functional" }) + public void getPrimaryKeyColumIndexTest() + { + Collection wantedFields = ftsRestClient + .getAllDefaulDisplayedDataColumns(); + int foundIndex = -1; + try + { + Assert.assertEquals(foundIndex, -1); + foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields, + false); + Assert.assertEquals(foundIndex, 0); + foundIndex = ftsRestClient + .getPrimaryKeyColumIndex(wantedFields, true); + Assert.assertEquals(foundIndex, 1); + } catch (Exception e) + { + e.printStackTrace(); + Assert.fail("Exception thrown while testing..."); + } + } + + @Test(groups = { "Functional" }) + public void getAllDefaulDisplayedDataColumns() + { + Assert.assertNotNull(ftsRestClient.getAllDefaulDisplayedDataColumns()); + Assert.assertTrue(!ftsRestClient.getAllDefaulDisplayedDataColumns() + .isEmpty()); + Assert.assertEquals(ftsRestClient.getAllDefaulDisplayedDataColumns() + .size(), 6); + } + + @Test(groups = { "Functional" }) + public void getDataColumnsFieldsAsCommaDelimitedString() + { + Collection wantedFields = ftsRestClient + .getAllDefaulDisplayedDataColumns(); + String actual = ftsRestClient + .getDataColumnsFieldsAsCommaDelimitedString(wantedFields); + Assert.assertEquals(actual, + "entry name,protein names,genes,organism,created,last-modified"); + } + + @Test(groups = { "Functional" }) + public void getDataColumnsFieldsAsTabDelimitedString() + { + Collection wantedFields = ftsRestClient + .getAllDefaulDisplayedDataColumns(); + String actual = ftsRestClient + .getDataColumnsFieldsAsTabDelimitedString(wantedFields); + Assert.assertEquals(actual, + "Entry Name\tProtein names\tGene Names\tOrganism\tDate of creation\tDate of last modification"); + } + + @Test(groups = { "Functional" }) + public void getAllFTSDataColumns() + { + Collection allFields = ftsRestClient + .getAllFTSDataColumns(); + Assert.assertNotNull(allFields); + Assert.assertEquals(allFields.size(), 116); + } + + @Test(groups = { "Functional" }) + public void getSearchableDataColumns() + { + Collection searchalbeFields = ftsRestClient + .getSearchableDataColumns(); + Assert.assertNotNull(searchalbeFields); + Assert.assertEquals(searchalbeFields.size(), 28); + } + + @Test(groups = { "Functional" }) + public void getPrimaryKeyColumn() + { + FTSDataColumnI expectedPKColumn; + try + { + expectedPKColumn = ftsRestClient + .getDataColumnByNameOrCode("Entry Name"); + Assert.assertNotNull(ftsRestClient.getPrimaryKeyColumn()); + Assert.assertEquals(ftsRestClient.getPrimaryKeyColumn(), + expectedPKColumn); + } catch (Exception e) + { + e.printStackTrace(); + Assert.fail("Exception thrown while testing..."); + } + } + + @Test(groups = { "Functional" }) + public void getDataColumnByNameOrCode() + { + try + { + FTSDataColumnI foundDataCol = ftsRestClient + .getDataColumnByNameOrCode("genes"); + Assert.assertNotNull(foundDataCol); + Assert.assertEquals(foundDataCol.getName(), "Gene Names"); + } catch (Exception e) + { + e.printStackTrace(); + Assert.fail("Exception thrown while testing..."); + } + } + + @Test(groups = { "Functional" }) + public void getDataColumnGroupById() + { + FTSDataColumnGroupI foundDataColGroup; + try + { + foundDataColGroup = ftsRestClient.getDataColumnGroupById("g3"); + Assert.assertNotNull(foundDataColGroup); + Assert.assertEquals(foundDataColGroup.getName(), "Names & Taxonomy"); + } catch (Exception e) + { + e.printStackTrace(); + } + } + + @Test(groups = { "Functional" }) + public void getDefaultResponsePageSize() + { + int defaultResSize = ftsRestClient.getDefaultResponsePageSize(); + Assert.assertEquals(defaultResSize, 100); + } + + @Test(groups = { "Functional" }) + public void getColumnMinWidthTest() + { + try + { + FTSDataColumnI foundDataCol = ftsRestClient + .getDataColumnByNameOrCode("Protein names"); + Assert.assertNotNull(foundDataCol); + int actualColMinWidth = foundDataCol.getMinWidth(); + Assert.assertEquals(actualColMinWidth, 300); + } catch (Exception e) + { + e.printStackTrace(); + Assert.fail("Exception thrown while testing..."); + } + } + + @Test(groups = { "Functional" }) + public void getColumnMaxWidthTest() + { + try + { + FTSDataColumnI foundDataCol = ftsRestClient + .getDataColumnByNameOrCode("Protein names"); + Assert.assertNotNull(foundDataCol); + int actualColMinWidth = foundDataCol.getMaxWidth(); + Assert.assertEquals(actualColMinWidth, 1500); + } catch (Exception e) + { + e.printStackTrace(); + Assert.fail("Exception thrown while testing..."); + } + } + + @Test(groups = { "Functional" }) + public void getColumnPreferredWidthTest() + { + try + { + FTSDataColumnI foundDataCol = ftsRestClient + .getDataColumnByNameOrCode("Protein names"); + Assert.assertNotNull(foundDataCol); + int actualColMinWidth = foundDataCol.getPreferredWidth(); + Assert.assertEquals(actualColMinWidth, 500); + } catch (Exception e) + { + e.printStackTrace(); + Assert.fail("Exception thrown while testing..."); + } + } + + @Test(groups = { "Functional" }) + public void getColumnClassTest() + { + try + { + FTSDataColumnI foundDataCol = ftsRestClient + .getDataColumnByNameOrCode("Protein names"); + Assert.assertNotNull(foundDataCol); + Assert.assertEquals(foundDataCol.getDataColumnClass(), String.class); + foundDataCol = ftsRestClient.getDataColumnByNameOrCode("length"); + Assert.assertNotNull(foundDataCol); + Assert.assertEquals(foundDataCol.getDataColumnClass(), Integer.class); + // foundDataCol = ftsRestClient.getDataColumnByNameOrCode("length"); + // Assert.assertNotNull(foundDataCol); + // Assert.assertEquals(foundDataCol.getDataColumnClass(), Double.class); + } catch (Exception e) + { + e.printStackTrace(); + Assert.fail("Exception thrown while testing..."); + } + } + + @Test(groups = { "Functional" }) + public void coverageForEqualsAndHashFunction() + { + Set uniqueSet = new HashSet(); + Collection searchableCols = ftsRestClient + .getSearchableDataColumns(); + for (FTSDataColumnI foundCol : searchableCols) + { + uniqueSet.add(foundCol); + uniqueSet.add(foundCol); + } + Assert.assertTrue(!uniqueSet.isEmpty()); + Assert.assertEquals(uniqueSet.size(), 28); + } + + @Test(groups = { "Functional" }) + public void coverageForMiscellaneousBranches() + { + String actual = ftsRestClient.getPrimaryKeyColumn().toString(); + Assert.assertEquals(actual, "Entry Name"); + + String actualGroupStr; + try + { + actualGroupStr = ftsRestClient.getDataColumnGroupById("g4") + .toString(); + Assert.assertEquals(actualGroupStr, "Procedures & Softwares"); + actualGroupStr = ftsRestClient.getDataColumnGroupById( + "unavailable group").toString(); + } catch (Exception e) + { + e.printStackTrace(); + } + + String actualResourseFile = ftsRestClient + .getResourceFile("fts/uniprot_data_columns.conf"); + Assert.assertNotNull(actualResourseFile); + Assert.assertTrue(actualResourseFile.length() > 31); + } + + @Test(groups = { "Functional" }, expectedExceptions = Exception.class) + public void coverageForExceptionBranches() throws Exception + { + try + { + ftsRestClient.getDataColumnByNameOrCode("unavailable column"); + } catch (Exception e) + { + e.printStackTrace(); + System.out.println(e.getMessage()); + String expectedMessage = "Couldn't find data column with name : unavailable column"; + Assert.assertEquals(e.getMessage(), expectedMessage); + } + try + { + ftsRestClient.getDataColumnGroupById("unavailable column group Id"); + } catch (Exception e) + { + e.printStackTrace(); + System.out.println(e.getMessage()); + String expectedMessage = "Couldn't find data column group with id : unavailable column group Id"; + Assert.assertEquals(e.getMessage(), expectedMessage); + } + + ftsRestClient.getDataColumnByNameOrCode("unavailable column"); + + ftsRestClient.getResourceFile("unavailable resource file"); + + } + +}