merge trunk to hibernate4
[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.util.UUID;
15
16 import org.apache.log4j.Logger;
17 import org.junit.Before;
18 import org.junit.BeforeClass;
19 import org.junit.Ignore;
20 import org.junit.Test;
21 import org.unitils.dbunit.annotation.DataSet;
22 import org.unitils.spring.annotation.SpringBeanByType;
23
24 import eu.etaxonomy.cdm.model.description.PolytomousKey;
25 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
26 import eu.etaxonomy.cdm.model.taxon.Taxon;
27 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
28
29 /**
30 * @author a.mueller
31 * @date 23.08.2011
32 *
33 */
34 @Ignore
35 public class PolytomousKeyServiceImplTest extends CdmTransactionalIntegrationTest {
36 private static final Logger logger = Logger.getLogger(PolytomousKeyServiceImplTest.class);
37
38 @SpringBeanByType
39 private IPolytomousKeyService service;
40
41 @SpringBeanByType
42 private IPolytomousKeyNodeService nodeService;
43
44 /**
45 * @throws java.lang.Exception
46 */
47 @BeforeClass
48 public static void setUpBeforeClass() throws Exception {
49 }
50
51 /**
52 * @throws java.lang.Exception
53 */
54 @Before
55 public void setUp() throws Exception {
56 }
57
58 //************************* TESTS ********************************************/
59
60 /**
61 * Test method for {@link eu.etaxonomy.cdm.api.service.ServiceBase#count(java.lang.Class)}.
62 */
63 @Test
64 public void testCount() {
65 PolytomousKey key = PolytomousKey.NewTitledInstance("My test key");
66 service.save(key);
67 Taxon taxon = Taxon.NewInstance(null, null);
68
69
70 key.addTaxonomicScope(taxon);
71
72 // Annotation annotation = Annotation.NewInstance("Any annotation", Language.DEFAULT());
73 // key.addAnnotation(annotation);
74
75 PolytomousKeyNode child = PolytomousKeyNode.NewInstance();
76 Taxon taxon2 = Taxon.NewInstance(null, null);
77
78 child.setTaxon(taxon2);
79 key.getRoot().addChild(child);
80
81 service.save(key);
82 setComplete();
83 endTransaction();
84 System.out.println("Count");
85 printDataSet(System.out, new String[]{"PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING",
86 "POLYTOMOUSKEY_ANNOTATION","POLYTOMOUSKEY_CREDIT",
87 "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA",
88 "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE",
89 "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE",
90 "ANNOTATION","TAXONBASE"});
91 // printDataSet(System.out);
92
93 }
94
95 /**
96 * Test method for {@link eu.etaxonomy.cdm.api.service.ServiceBase#delete(eu.etaxonomy.cdm.model.common.CdmBase)}.
97 */
98 @Test
99 @DataSet
100 public void testDelete() {
101 System.out.println("Delete start");
102 printDataSet(System.out, new String[]{"PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING",
103 "POLYTOMOUSKEY_ANNOTATION","POLYTOMOUSKEY_CREDIT",
104 "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA",
105 "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE",
106 "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE",
107 "ANNOTATION","TAXONBASE"});
108
109 UUID uuid = UUID.fromString("0a709940-4f2e-43c1-8db1-f4745f2a4889");
110 PolytomousKey key = service.find(uuid);
111 PolytomousKeyNode someChild = key.getRoot().getChildren().iterator().next();
112 // service.delete(key);
113 key.getRoot().removeChild(someChild);
114 nodeService.delete(someChild);
115
116
117 setComplete();
118 endTransaction();
119 System.out.println("Delete End");
120
121 printDataSet(System.out, new String[]{"PolytomousKey", "POLYTOMOUSKEYNODE", "POLYTOMOUSKEYNODE_LANGUAGESTRING",
122 "POLYTOMOUSKEY_ANNOTATION","POLYTOMOUSKEY_CREDIT",
123 "POLYTOMOUSKEY_EXTENSION", "POLYTOMOUSKEY_MARKER", "POLYTOMOUSKEY_NAMEDAREA",
124 "POLYTOMOUSKEY_ORIGINALSOURCEBASE", "POLYTOMOUSKEY_RIGHTS", "POLYTOMOUSKEY_SCOPE",
125 "POLYTOMOUSKEY_TAXON", "POLYTOMOUSKEY_TAXONBASE"});
126 }
127
128 /**
129 * Test method for {@link eu.etaxonomy.cdm.api.service.ServiceBase#exists(java.util.UUID)}.
130 */
131 @Test
132 public void testExists() {
133 logger.warn("testExists not yet implemented");
134 }
135
136 }