1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.model.molecular;
|
10
|
|
11
|
import static org.junit.Assert.assertNotNull;
|
12
|
import static org.junit.Assert.assertNotSame;
|
13
|
import static org.junit.Assert.assertTrue;
|
14
|
|
15
|
import java.net.URISyntaxException;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.junit.Before;
|
19
|
import org.junit.BeforeClass;
|
20
|
import org.junit.Test;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
23
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
24
|
import eu.etaxonomy.cdm.model.common.Language;
|
25
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
26
|
import eu.etaxonomy.cdm.model.media.Media;
|
27
|
|
28
|
|
29
|
public class MolecularTest {
|
30
|
@SuppressWarnings("unused")
|
31
|
private static Logger logger = Logger.getLogger(MolecularTest.class);
|
32
|
|
33
|
private DnaSample dnaSample;
|
34
|
private DefinedTerm marker;
|
35
|
private PhylogeneticTree phyloTree;
|
36
|
private Sequence seq;
|
37
|
|
38
|
|
39
|
@BeforeClass
|
40
|
public static void setUpBeforeClass() {
|
41
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
42
|
vocabularyStore.initialize();
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* @throws java.lang.Exception
|
47
|
*/
|
48
|
@Before
|
49
|
public void setUp() throws Exception {
|
50
|
dnaSample = DnaSample.NewInstance();
|
51
|
seq = new Sequence();
|
52
|
|
53
|
// seq.setBarcode(true);
|
54
|
seq.getConsensusSequence().setString("ATTGCCATC");
|
55
|
|
56
|
seq.setGeneticAccessionNumber("HM347273");
|
57
|
// seq.setGenBankUri(URI.create("http://www.abc.de"));
|
58
|
Media chromatogram = Media.NewInstance();
|
59
|
chromatogram.putTitle(LanguageString.NewInstance("chromatogram", Language.ENGLISH()));
|
60
|
// seq.addChromatogram(chromatogram);
|
61
|
|
62
|
Sequence otherSeq = Sequence.NewInstance("CATCGAGTTGC");
|
63
|
|
64
|
otherSeq.getBarcodeSequencePart().setString("ATTGCC");
|
65
|
dnaSample.addSequence(seq);
|
66
|
dnaSample.addSequence(otherSeq);
|
67
|
|
68
|
marker = DefinedTerm.NewDnaMarkerInstance("Test", "test marker", null);
|
69
|
|
70
|
phyloTree = PhylogeneticTree.NewInstance();
|
71
|
phyloTree.addUsedSequences(seq);
|
72
|
phyloTree.addUsedSequences(otherSeq);
|
73
|
}
|
74
|
|
75
|
/* ************************** TESTS **********************************************************/
|
76
|
|
77
|
@Test
|
78
|
public void testClone() throws URISyntaxException{
|
79
|
|
80
|
|
81
|
PhylogeneticTree phyloTreeClone = (PhylogeneticTree)phyloTree.clone();
|
82
|
assertTrue(phyloTreeClone.getUsedSequences().size() == 2);
|
83
|
|
84
|
assertNotSame(phyloTreeClone.getUsedSequences().iterator().next(), phyloTree.getUsedSequences().iterator().next());
|
85
|
|
86
|
|
87
|
Sequence sequenceClone = (Sequence)seq.clone();
|
88
|
// assertEquals(sequenceClone.getChromatograms().iterator().next().getAllTitles().get(0),seq.getChromatograms().iterator().next().getAllTitles().get(0));
|
89
|
//
|
90
|
// Iterator<Media> mediaIteratorClone = sequenceClone.getChromatograms().iterator();
|
91
|
// Iterator<Media> mediaIterator = seq.getChromatograms().iterator();
|
92
|
// Media test = (Media)mediaIterator.next();
|
93
|
// LanguageString title = test.getTitle(Language.ENGLISH());
|
94
|
// test = (Media)mediaIteratorClone.next();
|
95
|
// LanguageString titleClone = test.getTitle(Language.ENGLISH());
|
96
|
// assertEquals(title, titleClone);
|
97
|
|
98
|
|
99
|
assertTrue (sequenceClone.getGeneticAccessionNumber().equals(seq.getGeneticAccessionNumber()));
|
100
|
assertNotNull(sequenceClone.getGenBankUri());
|
101
|
assertTrue (sequenceClone.getGenBankUri().equals(seq.getGenBankUri()));
|
102
|
|
103
|
DnaSample dnaSampleClone = dnaSample.clone();
|
104
|
Sequence[] seqArray = new Sequence[dnaSample.getSequences().size()];
|
105
|
seqArray = dnaSample.getSequences().toArray(seqArray);
|
106
|
Sequence[] seqArrayClone = dnaSampleClone.getSequences().toArray(seqArray);
|
107
|
boolean testBool = true;
|
108
|
for (Sequence seqTest: seqArray){
|
109
|
if (testBool == false) {
|
110
|
break;
|
111
|
}
|
112
|
testBool = false;
|
113
|
for (Sequence seq: seqArrayClone){
|
114
|
if (seq.equals(seqTest)) {
|
115
|
testBool = true;
|
116
|
break;
|
117
|
} else {
|
118
|
testBool = false;
|
119
|
}
|
120
|
|
121
|
}
|
122
|
}
|
123
|
assertTrue(testBool);
|
124
|
|
125
|
|
126
|
|
127
|
|
128
|
}
|
129
|
|
130
|
}
|