1 /* Copyright (C) 2006-2007  Egon Willighagen <egonw@users.sf.net>
2  *
3  * Contact: cdk-devel@slists.sourceforge.net
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation; either version 2.1
8  * of the License, or (at your option) any later version.
9  * All we ask is that proper credit is given for our work, which includes
10  * - but is not limited to - adding the above copyright notice to the beginning
11  * of your source code files, and to any copyright notice that you may distribute
12  * with programs based on this work.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22  *  */
23 package org.openscience.cdk.io;
24 
25 import java.io.InputStream;
26 
27 import org.junit.Assert;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.openscience.cdk.CDKConstants;
31 import org.openscience.cdk.ChemFile;
32 import org.openscience.cdk.ChemObject;
33 import org.openscience.cdk.interfaces.IAtomContainer;
34 import org.openscience.cdk.interfaces.IAtomContainerSet;
35 import org.openscience.cdk.interfaces.IChemFile;
36 import org.openscience.cdk.interfaces.IChemModel;
37 import org.openscience.cdk.interfaces.IChemSequence;
38 import org.openscience.cdk.tools.ILoggingTool;
39 import org.openscience.cdk.tools.LoggingToolFactory;
40 
41 /**
42  * TestCase for the reading CTX files using a test file.
43  *
44  * @cdk.module test-io
45  *
46  * @see org.openscience.cdk.io.CrystClustReader
47  */
48 public class CTXReaderTest extends SimpleChemObjectReaderTest {
49 
50     private static ILoggingTool logger = LoggingToolFactory.createLoggingTool(CTXReaderTest.class);
51 
52     @BeforeClass
setup()53     public static void setup() {
54         setSimpleChemObjectReader(new CTXReader(), "data/ctx/methanol_with_descriptors.ctx");
55     }
56 
57     @Test
testAccepts()58     public void testAccepts() {
59         CTXReader reader = new CTXReader();
60         Assert.assertTrue(reader.accepts(ChemFile.class));
61     }
62 
63     @Test
testMethanol()64     public void testMethanol() throws Exception {
65         String filename = "data/ctx/methanol_with_descriptors.ctx";
66         logger.info("Testing: " + filename);
67         InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
68         CTXReader reader = new CTXReader(ins);
69         IChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
70         reader.close();
71 
72         Assert.assertNotNull(chemFile);
73         Assert.assertEquals(1, chemFile.getChemSequenceCount());
74         IChemSequence seq = chemFile.getChemSequence(0);
75         Assert.assertNotNull(seq);
76         Assert.assertEquals(1, seq.getChemModelCount());
77         IChemModel model = seq.getChemModel(0);
78         Assert.assertNotNull(model);
79 
80         IAtomContainerSet moleculeSet = model.getMoleculeSet();
81         Assert.assertNotNull(moleculeSet);
82         Assert.assertEquals(1, moleculeSet.getAtomContainerCount());
83 
84         IAtomContainer container = moleculeSet.getAtomContainer(0);
85         Assert.assertNotNull(container);
86         Assert.assertEquals("Incorrect atom count.", 6, container.getAtomCount());
87         Assert.assertEquals(5, container.getBondCount());
88 
89         Assert.assertEquals("Petra", container.getID());
90 
91         Assert.assertNotNull(container.getTitle());
92         Assert.assertEquals("CH4O", container.getTitle());
93     }
94 }
95