- added abstract method createTestData() to CdmIntegrationalTest
[cdmlib.git] / cdmlib-services / src / test / java / eu / etaxonomy / cdm / api / service / PolytomousKeyServiceImplTest.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.cdm.api.service;
11
12 import static org.junit.Assert.*;
13
14 import java.io.FileNotFoundException;
15 import java.util.UUID;
16
17 import org.apache.log4j.Logger;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.BeforeClass;
21 import org.junit.Ignore;
22 import org.junit.Test;
23 import org.unitils.dbunit.annotation.DataSet;
24 import org.unitils.spring.annotation.SpringBeanByType;
25
26 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
27 import eu.etaxonomy.cdm.model.description.PolytomousKey;
28 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
29 import eu.etaxonomy.cdm.model.taxon.Taxon;
30 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
31
32 /**
33 * @author a.mueller
34 * @date 23.08.2011
35 *
36 */
37 @Ignore
38 public class PolytomousKeyServiceImplTest extends CdmTransactionalIntegrationTest {
39 private static final Logger logger = Logger.getLogger(PolytomousKeyServiceImplTest.class);
40
41 @SpringBeanByType
42 private IPolytomousKeyService service;
43
44 @SpringBeanByType
45 private IPolytomousKeyNodeService nodeService;
46
47 /**
48 * @throws java.lang.Exception
49 */
50 @BeforeClass
51 public static void setUpBeforeClass() throws Exception {
52 }
53
54 /**
55 * @throws java.lang.Exception
56 */
57 @Before
58 public void setUp() throws Exception {
59 }
60
61 //************************* TESTS ********************************************/
62
63 /**
64 * Test method for {@link eu.etaxonomy.cdm.api.service.ServiceBase#count(java.lang.Class)}.
65 */
66 @Test
67 public void testCount() {
68 PolytomousKey key = PolytomousKey.NewTitledInstance("My test key");
69 service.save(key);
70 Taxon taxon = Taxon.NewInstance(null, null);
71
72
73 key.addTaxonomicScope(taxon);
74
75 // Annotation annotation = Annotation.NewInstance("Any annotation", Language.DEFAULT());
76 // key.addAnnotation(annotation);
77
78 PolytomousKeyNode child = PolytomousKeyNode.NewInstance();
79 Taxon taxon2 = Taxon.NewInstance(null, null);
80
81 child.setTaxon(taxon2);
82 key.getRoot().addChild(child);
83
84 service.save(key);
85 setComplete();
86 endTransaction();
87 System.out.println("Count");
88 printDataSet(System.out, new String[]{"PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING",
89 "POLYTOMOUSKEY_ANNOTATION","POLYTOMOUSKEY_CREDIT",
90 "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA",
91 "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE",
92 "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE",
93 "ANNOTATION","TAXONBASE"});
94 // printDataSet(System.out);
95
96 }
97
98 /**
99 * Test method for {@link eu.etaxonomy.cdm.api.service.ServiceBase#delete(eu.etaxonomy.cdm.model.common.CdmBase)}.
100 */
101 @Test
102 @DataSet
103 public void testDelete() {
104 System.out.println("Delete start");
105 printDataSet(System.out, new String[]{"PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING",
106 "POLYTOMOUSKEY_ANNOTATION","POLYTOMOUSKEY_CREDIT",
107 "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA",
108 "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE",
109 "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE",
110 "ANNOTATION","TAXONBASE"});
111
112 UUID uuid = UUID.fromString("0a709940-4f2e-43c1-8db1-f4745f2a4889");
113 PolytomousKey key = service.find(uuid);
114 PolytomousKeyNode someChild = key.getRoot().getChildren().iterator().next();
115 // service.delete(key);
116 key.getRoot().removeChild(someChild);
117 nodeService.delete(someChild);
118
119
120 setComplete();
121 endTransaction();
122 System.out.println("Delete End");
123
124 printDataSet(System.out, new String[]{"PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING",
125 "POLYTOMOUSKEY_ANNOTATION","POLYTOMOUSKEY_CREDIT",
126 "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA",
127 "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE",
128 "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE"});
129 }
130
131 /**
132 * Test method for {@link eu.etaxonomy.cdm.api.service.ServiceBase#exists(java.util.UUID)}.
133 */
134 @Test
135 public void testExists() {
136 logger.warn("testExists not yet implemented");
137 }
138
139 /* (non-Javadoc)
140 * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
141 */
142 @Override
143 protected void createTestDataSet() throws FileNotFoundException {
144 // TODO Auto-generated method stub
145
146 }
147
148 }