Project

General

Profile

Download (4.17 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.Database;
28
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
29

    
30
/**
31
 * @author a.mueller
32
 *
33
 */
34
public class AnnotationTest extends EntityTestBase {
35
	private static final Logger logger = Logger.getLogger(AnnotationTest.class);
36
	
37
	private static Annotation annotation1; 
38
	private static Person commentator;
39
	private static URL linkbackUrl;
40
	private static AnnotatableEntity annotatedObject;
41
	
42
	
43
	/**
44
	 * @throws java.lang.Exception
45
	 */
46
	@BeforeClass
47
	public static void setUpBeforeClass() throws Exception {
48
	}
49

    
50
	/**
51
	 * @throws java.lang.Exception
52
	 */
53
	@AfterClass
54
	public static void tearDownAfterClass() throws Exception {
55
	}
56

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

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

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

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

    
110

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

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

    
142
}
(1-1/8)