Project

General

Profile

Download (4.31 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.cdm.model.common;
11

    
12
import static org.junit.Assert.*;
13

    
14
import java.net.MalformedURLException;
15
import java.net.URL;
16

    
17
import org.apache.log4j.Logger;
18
import org.junit.After;
19
import org.junit.AfterClass;
20
import org.junit.Before;
21
import org.junit.BeforeClass;
22
import org.junit.Test;
23

    
24
import eu.etaxonomy.cdm.model.agent.Person;
25
import eu.etaxonomy.cdm.model.name.BotanicalName;
26
import eu.etaxonomy.cdm.model.name.Rank;
27
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
30

    
31
/**
32
 * @author a.mueller
33
 *
34
 */
35
public class AnnotationTest extends EntityTestBase {
36
	private static final Logger logger = Logger.getLogger(AnnotationTest.class);
37
	
38
	private static Annotation annotation1; 
39
	private static Person commentator;
40
	private static URL linkbackUrl;
41
	private static AnnotatableEntity annotatedObject;
42
	
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
	@AfterClass
55
	public static void tearDownAfterClass() throws Exception {
56
	}
57

    
58
	/**
59
	 * @throws java.lang.Exception
60
	 */
61
	@Before
62
	public void setUp() throws Exception {
63
		commentator = Person.NewInstance();
64
		commentator.setTitleCache("automatic importer");
65
		annotation1 = Annotation.NewInstance("anno1", Language.DEFAULT());
66
		annotation1.setCommentator(commentator);
67
		annotatedObject = BotanicalName.NewInstance(Rank.SPECIES());
68
		annotatedObject.addAnnotation(annotation1);
69
		try {
70
			linkbackUrl = new URL("http:\\www.abc.de");
71
			annotation1.setLinkbackUrl(linkbackUrl);
72
		} catch (MalformedURLException e) {
73
			logger.warn("MalformedURLException");
74
		}
75
	}
76

    
77
	/**
78
	 * @throws java.lang.Exception
79
	 */
80
	@After
81
	public void tearDown() throws Exception {
82
	}
83

    
84
/* ****************** TESTS *************************************/
85
	
86
	/**
87
	 * Test method for {@link eu.etaxonomy.cdm.model.common.Annotation#Annotation(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}.
88
	 */
89
	@Test
90
	public void testNewInstanceStringLanguage() {
91
		assertNotNull(annotation1);
92
		assertSame(commentator, annotation1.getCommentator());
93
		assertSame(Language.DEFAULT(), annotation1.getLanguage());
94
		assertSame(linkbackUrl, annotation1.getLinkbackUrl());
95
		assertSame(annotatedObject.getAnnotations().iterator().next(), annotation1);
96
	}
97

    
98
	/**
99
	 * Test method for {@link eu.etaxonomy.cdm.model.common.Annotation#getAnnotatedObj()}.
100
	 * Test method for {@link eu.etaxonomy.cdm.model.common.Annotation#setAnnotatedObj(eu.etaxonomy.cdm.model.common.AnnotatableEntity)}.
101
	 */
102
	@Test
103
	public void testGetSetAnnotatedObj() {
104
		ReferenceFactory refFactory = ReferenceFactory.newInstance();
105
		AnnotatableEntity database = refFactory.newDatabase();
106
		annotation1.setAnnotatedObj(database);
107
		assertSame(database, annotation1.getAnnotatedObj());
108
		annotation1.setAnnotatedObj(null);
109
		assertNull(annotation1.getAnnotatedObj());
110
	}
111

    
112

    
113
	/**
114
	 * Test method for {@link eu.etaxonomy.cdm.model.common.Annotation#getCommentator()}.
115
	 * Test method for {@link eu.etaxonomy.cdm.model.common.Annotation#setCommentator(eu.etaxonomy.cdm.model.agent.Person)}.
116
	 */
117
	@Test
118
	public void testGetSetCommentator() {
119
		Person person = Person.NewInstance();
120
		annotation1.setCommentator(person);
121
		assertSame(person, annotation1.getCommentator());
122
		annotation1.setCommentator(null);
123
		assertNull(annotation1.getCommentator());
124
	}
125

    
126
	/**
127
	 * Test method for {@link eu.etaxonomy.cdm.model.common.Annotation#getLinkbackUrl()}.
128
	 * Test method for {@link eu.etaxonomy.cdm.model.common.Annotation#setLinkbackUrl(java.net.URL)}.
129
	 */
130
	@Test
131
	public void testGetSetLinkbackUrl() {
132
		URL url = null;
133
		try {
134
			url = new URL("http:\\test.abc.de");
135
		} catch (MalformedURLException e) {
136
			fail();
137
		}
138
		annotation1.setLinkbackUrl(url);
139
		assertSame(url, annotation1.getLinkbackUrl());
140
		annotation1.setLinkbackUrl(null);
141
		assertNull(annotation1.getLinkbackUrl());
142
	}
143

    
144
}
(1-1/12)