Project

General

Profile

« Previous | Next » 

Revision c38734e6

Added by Andreas Müller over 8 years ago

Add some more BeanUtil test to other classes #5307

View differences:

cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/reference/PublicationBaseTest.java
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.reference;
11

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

  
14
import java.util.List;
15

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

  
24
/**
25
 * @author a.mueller
26
 * @created 23.03.2009
27
 * @version 1.0
28
 */
29
//@Ignore
30
public class PublicationBaseTest {
31
	@SuppressWarnings("unused")
32
	private static Logger logger = Logger.getLogger(PublicationBaseTest.class);
33

  
34
	private IBook publicationBase;
35
	private IArticle publicationBase2;
36
	private String publisher1;
37
	private String publisher2;
38
	private String place1;
39
	private String place2;
40
	
41
	/**
42
	 * @throws java.lang.Exception
43
	 */
44
	@BeforeClass
45
	public static void setUpBeforeClass() throws Exception {
46
	}
47

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

  
55
	/**
56
	 * @throws java.lang.Exception
57
	 */
58
	@Before
59
	public void setUp() throws Exception {
60
		publisher1 = "publisher1";
61
		publisher2 = "publisher2";
62
		place1 = "place1";
63
		place2 = "place2";
64
		
65
		
66
		publicationBase = ReferenceFactory.newBook();
67
		
68
		publicationBase2 = ReferenceFactory.newArticle();
69
		
70
	}
71

  
72
	/**
73
	 * @throws java.lang.Exception
74
	 */
75
	@After
76
	public void tearDown() throws Exception {
77
	}
78

  
79
	
80
	
81
	/**
82
	 * Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#addPublisher(java.lang.String, java.lang.String)}.
83
	 */
84
	@Test
85
	public void testAddPublisherStringString() {
86
		assertEquals("No publisher is set", null, publicationBase.getPublisher());
87
		publicationBase.setPublisher(publisher1, place1);
88
		assertEquals("The publishers is publisher1", publisher1, publicationBase.getPublisher());
89
		assertEquals("The place is place1", place1, publicationBase.getPlacePublished());
90
		publicationBase.setPublisher(publisher2, place2);
91
		assertEquals("Second publisher must be publisher2", publisher2, publicationBase.getPublisher());
92

  
93
		assertEquals("Second publication place must be place2", place2, publicationBase.getPlacePublished());
94
	}
95
	
96
	@Test
97
	public void testInReferenceValidation(){
98
		IJournal journal = ReferenceFactory.newJournal();
99
		publicationBase2.setInJournal(journal);
100
		//TODO: to validate it, the object has to be saved to the db
101
		IBookSection booksection = ((Reference)publicationBase2).castReferenceToBookSection();
102
		
103
		
104
	}
105

  
106
	
107
//	/**
108
//	 * Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#addPublisher(java.lang.String, java.lang.String, int)}.
109
//	 */
110
//	@Test(expected=IndexOutOfBoundsException.class)
111
//	public void testAddPublisherStringStringInt() {
112
//		publicationBase.addPublisher(publisher1, place1);
113
//		publicationBase.addPublisher(publisher2, place2);
114
//		assertEquals("Publishers list must contains exactly 2 entry", 2, publicationBase.getPublishers().size());
115
//		String indexPublisher = "indexPublisher";
116
//		String indexPlace = "indexPlace";
117
//		publicationBase.addPublisher(indexPublisher, indexPlace, 1);
118
//		assertEquals("Publisher at position 1 (starting at 0) should be 'indexPublisher'", indexPublisher, publicationBase.getPublishers().get(1).getPublisherName());
119
//		publicationBase.addPublisher(indexPublisher, indexPlace, 5);
120
//	}
121

  
122

  
123
//	/**
124
//	 * Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#getPublisher(java.lang.int}.
125
//	 */
126
//	@Test(expected=IndexOutOfBoundsException.class)
127
//	public void testGetPublisherInt() {
128
//		publicationBase.addPublisher(publisher1, place1);
129
//		publicationBase.addPublisher(publisher2, place2);
130
//		assertEquals("Publishers list must contains exactly 2 entry", 2, publicationBase.getPublishers().size());
131
//		assertEquals("First publisher must be publisher1", publisher1, publicationBase.getPublisher(0).getPublisherName());
132
//		publicationBase.getPublisher(2);
133
//		publicationBase.getPublisher(-1);
134
//	}
135

  
136
//	/**
137
//	 * Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#removePublisher(eu.etaxonomy.cdm.model.reference.Publisher)}.
138
//	 */
139
//	@Test
140
//	public void testRemovePublisher() {
141
//		publicationBase.addPublisher(publisher1, place1);
142
//		publicationBase.addPublisher(publisher2, place2);
143
//		assertEquals("Publishers list must contains exactly 2 entry", 2, publicationBase.getPublishers().size());
144
//		publicationBase.removePublisher(publicationBase.getPublishers().get(0));
145
//		assertEquals("Publishers list must contains exactly 1 entry", 1, publicationBase.getPublishers().size());
146
//		List<Publisher> publishers = publicationBase.getPublishers();
147
//		assertEquals("Only publisher must be publisher2", publisher2, publishers.get(0).getPublisherName());
148
//		assertEquals("only publication place  must be place2", place2, publishers.get(0).getPlace());
149
//	}
150

  
151
//	/**
152
//	 * Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#clone()}.
153
//	 */
154
//	@Test
155
//	public void testClone() {
156
//		publicationBase.addPublisher(publisher1, place1);
157
//		publicationBase.addPublisher(publisher2, place2);
158
//		assertEquals("Publishers list must contains exactly 2 entry", 2, publicationBase.getPublishers().size());
159
//		CdDvd clone = (CdDvd)publicationBase.clone();
160
//		assertEquals("Publisher place must be equal in original publication and cloned publication", place1, clone.getPublisher(0).getPlace());
161
//		assertNotSame(place1, publicationBase.getPublisher(0), clone.getPublisher(0));	
162
//	}
163
}
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.reference;
11

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

  
14
import org.apache.log4j.Logger;
15
import org.junit.After;
16
import org.junit.AfterClass;
17
import org.junit.Assert;
18
import org.junit.Before;
19
import org.junit.BeforeClass;
20
import org.junit.Test;
21
import org.springframework.beans.BeanUtils;
22

  
23
/**
24
 * @author a.mueller
25
 * @created 23.03.2009
26
 * @version 1.0
27
 */
28
//@Ignore
29
public class PublicationBaseTest {
30
	@SuppressWarnings("unused")
31
	private static Logger logger = Logger.getLogger(PublicationBaseTest.class);
32

  
33
	private IBook reference;
34
	private IArticle reference2;
35
	private String publisher1;
36
	private String publisher2;
37
	private String place1;
38
	private String place2;
39

  
40
	/**
41
	 * @throws java.lang.Exception
42
	 */
43
	@BeforeClass
44
	public static void setUpBeforeClass() throws Exception {
45
	}
46

  
47
	/**
48
	 * @throws java.lang.Exception
49
	 */
50
	@AfterClass
51
	public static void tearDownAfterClass() throws Exception {
52
	}
53

  
54
	/**
55
	 * @throws java.lang.Exception
56
	 */
57
	@Before
58
	public void setUp() throws Exception {
59
		publisher1 = "publisher1";
60
		publisher2 = "publisher2";
61
		place1 = "place1";
62
		place2 = "place2";
63
		reference = ReferenceFactory.newBook();
64
		reference2 = ReferenceFactory.newArticle();
65

  
66
	}
67

  
68
	/**
69
	 * @throws java.lang.Exception
70
	 */
71
	@After
72
	public void tearDown() throws Exception {
73
	}
74

  
75

  
76

  
77
	/**
78
	 * Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#addPublisher(java.lang.String, java.lang.String)}.
79
	 */
80
	@Test
81
	public void testAddPublisherStringString() {
82
		assertEquals("No publisher is set", null, reference.getPublisher());
83
		reference.setPublisher(publisher1, place1);
84
		assertEquals("The publishers is publisher1", publisher1, reference.getPublisher());
85
		assertEquals("The place is place1", place1, reference.getPlacePublished());
86
		reference.setPublisher(publisher2, place2);
87
		assertEquals("Second publisher must be publisher2", publisher2, reference.getPublisher());
88

  
89
		assertEquals("Second publication place must be place2", place2, reference.getPlacePublished());
90
	}
91

  
92
	@Test
93
	public void testInReferenceValidation(){
94
		IJournal journal = ReferenceFactory.newJournal();
95
		reference2.setInJournal(journal);
96
		//TODO: to validate it, the object has to be saved to the db
97
		IBookSection booksection = ((Reference)reference2).castReferenceToBookSection();
98

  
99
	}
100

  
101

  
102
	/**
103
	 * Test method for {@link eu.etaxonomy.cdm.model.reference.Reference#clone()}.
104
	 * This test was originally designed for the case when publisher was still
105
	 * a subclass holding publishing information. The current model is simplified
106
	 * and therefore this test is more or less obsolet
107
	 */
108
	@Test
109
	public void testClone() {
110
		reference.setPublisher(publisher1, place1);
111
//		publicationBase.addPublisher(publisher2, place2);
112
		Reference<?> clone = (Reference<?>)reference.clone();
113
		assertEquals("Publisher place must be equal in original publication and cloned publication", place1, clone.getPlacePublished());
114
		Assert.assertSame(place1, reference.getPublisher(), clone.getPublisher());
115
	}
116

  
117
    @Test
118
    public void beanTests(){
119
//      #5307 Test that BeanUtils does not fail
120
        BeanUtils.getPropertyDescriptors(Reference.class);
121
    }
122
}

Also available in: Unified diff