/* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.ws.sifts; import jalview.datamodel.DBRefEntry; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.util.HashMap; import org.testng.Assert; import org.testng.FileAssert; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import MCview.PDBfile; public class SiftsClientTest { private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System .getProperty("user.home") + File.separatorChar + ".sifts_downloads" + File.separatorChar; private String testPDBId = "1a70"; private SiftsClient siftsClient = null; SequenceI testSeq = new Sequence( "P00221", "MAAT..TTTMMG..MATTFVPKPQAPPMMAALPSNTGR..SLFGLKT.GSR..GGRMTMA" + "AYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDD" + "QSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA.", 1, 147); int u = SiftsClient.UNASSIGNED; HashMap expectedMapping = new HashMap(); @BeforeTest(alwaysRun = true) public void populateExpectedMapping() throws SiftsException { for (int x = 1; x <= 97; x++) { expectedMapping.put(50 + x, new int[] { x, u }); } } @BeforeTest(alwaysRun = true) public void setUpSiftsClient() throws SiftsException { // SIFTs entries are updated weekly - so use saved SIFTs file to enforce // test reproducibility SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache.getDefault( "sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR)); File testSiftsFile = new File("test/jalview/io/" + testPDBId + ".xml.gz"); PDBfile pdbFile = new PDBfile(false, false, false); pdbFile.setId(testPDBId); siftsClient = new SiftsClient(pdbFile, testSiftsFile); } @AfterTest(alwaysRun = true) public void cleanUpSiftsClient() { siftsClient = null; } @BeforeTest(alwaysRun = true) public void setUpStreams() { System.setOut(new PrintStream(outContent)); } @AfterTest(alwaysRun = true) public void cleanUpStreams() { System.setOut(null); } @Test(groups = { "Functional" }) public void getSIFTsFileTest() throws SiftsException { Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId)); SiftsClient.getSiftsFile(testPDBId); Assert.assertFalse(outContent.toString().contains( ">>> SIFTS File already downloaded for " + testPDBId)); // test for SIFTs file caching SiftsClient.getSiftsFile(testPDBId); Assert.assertTrue(outContent.toString().contains( ">>> SIFTS File already downloaded for " + testPDBId)); } @Test(groups = { "Functional" }) public void downloadSiftsFileTest() throws SiftsException { // Assert that file isn't yet downloaded - if already downloaded, assert it // is deleted Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId)); File siftsFile; try { siftsFile = SiftsClient.downloadSiftsFile(testPDBId); FileAssert.assertFile(siftsFile); SiftsClient.downloadSiftsFile(testPDBId); } catch (IOException e) { e.printStackTrace(); } } @Test(groups = { "Functional" }) public void getAllMappingAccessionTest() { Assert.assertNotNull(siftsClient); Assert.assertNotNull(siftsClient.getAllMappingAccession()); Assert.assertTrue(siftsClient.getAllMappingAccession().size() > 1); } @Test(groups = { "Functional" }) public void getGreedyMappingTest() { Assert.assertNotNull(siftsClient); Assert.assertNotNull(testSeq); Assert.assertNotNull(expectedMapping); // TODO delete when auto-fetching of DBRefEntry is implemented DBRefEntry dbRef = new DBRefEntry("uniprot", "", "P00221"); dbRef.setStartRes(1); dbRef.setEndRes(147); testSeq.addDBRef(dbRef); // testSeq.setSourceDBRef(dbRef); try { HashMap actualMapping = siftsClient.getGreedyMapping( "A", testSeq, null); Assert.assertEquals(actualMapping, expectedMapping); Assert.assertEquals(testSeq.getStart(), 1); Assert.assertEquals(testSeq.getEnd(), 147); } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception thrown while generating mapping..."); } } @Test(groups = { "Functional" }) private void getAtomIndexTest() { // siftsClient.getAtomIndex(1, null); // Assert.assertTrue(true); } @Test( groups = { "Functional" }, expectedExceptions = IllegalArgumentException.class) private void getAtomIndexNullTest() { siftsClient.getAtomIndex(1, null); } @Test(groups = { "Functional" }) private void padWithGapsTest() { } @Test(groups = { "Functional" }) private void populateAtomPositionsTest() { } @Test(groups = { "Functional" }) public void getValidSourceDBRefTest() { } @Test(groups = { "Functional" }) public void isValidDBRefEntryTest() { } }