1
|
/**
|
2
|
* Copyright (C) 2009 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.validation;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertFalse;
|
14
|
import static org.junit.Assert.assertNotNull;
|
15
|
import static org.junit.Assert.assertTrue;
|
16
|
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import javax.validation.ConstraintViolation;
|
21
|
import javax.validation.Validator;
|
22
|
import javax.validation.groups.Default;
|
23
|
|
24
|
import junit.framework.Assert;
|
25
|
|
26
|
import org.apache.log4j.Logger;
|
27
|
import org.junit.Before;
|
28
|
import org.junit.Ignore;
|
29
|
import org.junit.Test;
|
30
|
import org.unitils.dbunit.annotation.DataSet;
|
31
|
import org.unitils.spring.annotation.SpringBeanByType;
|
32
|
|
33
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
34
|
import eu.etaxonomy.cdm.model.agent.Person;
|
35
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
36
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
37
|
import eu.etaxonomy.cdm.model.common.Group;
|
38
|
import eu.etaxonomy.cdm.model.common.Language;
|
39
|
import eu.etaxonomy.cdm.model.common.User;
|
40
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
41
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
42
|
import eu.etaxonomy.cdm.model.name.Rank;
|
43
|
import eu.etaxonomy.cdm.model.occurrence.Specimen;
|
44
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
45
|
import eu.etaxonomy.cdm.model.reference.IArticle;
|
46
|
import eu.etaxonomy.cdm.model.reference.IBook;
|
47
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
48
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
49
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
50
|
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
|
51
|
|
52
|
/**
|
53
|
*
|
54
|
* @author ben.clark
|
55
|
*
|
56
|
*/
|
57
|
@SuppressWarnings("unused")
|
58
|
@Ignore //FIXME ignoring only for merging 8.6.2010 a.kohlbecker
|
59
|
public class ReferenceValidationTest extends CdmIntegrationTest {
|
60
|
private static final Logger logger = Logger.getLogger(ReferenceValidationTest.class);
|
61
|
|
62
|
@SpringBeanByType
|
63
|
private Validator validator;
|
64
|
|
65
|
private IBook book;
|
66
|
ReferenceFactory refFactory;
|
67
|
@Before
|
68
|
public void setUp() {
|
69
|
refFactory = ReferenceFactory.newInstance();
|
70
|
book = refFactory.newBook();
|
71
|
book.setTitleCache("Lorem ipsum", true);
|
72
|
}
|
73
|
|
74
|
|
75
|
/****************** TESTS *****************************/
|
76
|
|
77
|
/**
|
78
|
* Test validation at the second level with a valid reference
|
79
|
*/
|
80
|
@Test
|
81
|
public final void testLevel2ValidationWithValidBook() {
|
82
|
Set<ConstraintViolation<IBook>> constraintViolations = validator.validate(book, Level2.class);
|
83
|
assertTrue("There should be no constraint violations as this book is valid at level 2",constraintViolations.isEmpty());
|
84
|
}
|
85
|
|
86
|
@Test
|
87
|
public final void testLevel2ValidationWithValidISBN() {
|
88
|
book.setIsbn("1-919795-99-5");
|
89
|
Set<ConstraintViolation<IBook>> constraintViolations = validator.validate(book, Level2.class);
|
90
|
assertTrue("There should be no constraint violations as this book is valid at level 2",constraintViolations.isEmpty());
|
91
|
}
|
92
|
|
93
|
@Test
|
94
|
public final void testLevel2ValidationWithInValidISBN() {
|
95
|
book.setIsbn("1-9197954-99-5");
|
96
|
Set<ConstraintViolation<IBook>> constraintViolations = validator.validate(book, Level2.class);
|
97
|
assertFalse("There should be a constraint violation as this book has an invalid ISBN number",constraintViolations.isEmpty());
|
98
|
}
|
99
|
|
100
|
@Test
|
101
|
public final void testLevel2ValidationWithValidUri() {
|
102
|
book.setUri("http://www.e-taxonomy.eu");
|
103
|
Set<ConstraintViolation<IBook>> constraintViolations = validator.validate(book, Level2.class);
|
104
|
assertTrue("There should be no constraint violations as this book is valid at level 2",constraintViolations.isEmpty());
|
105
|
}
|
106
|
|
107
|
@Test
|
108
|
public final void testLevel2ValidationWithInValidUri() {
|
109
|
book.setUri("http://www.e-\taxonomy.eu");
|
110
|
Set<ConstraintViolation<IBook>> constraintViolations = validator.validate(book, Level2.class);
|
111
|
assertFalse("There should be a constraint violation as this book has an invalid URI",constraintViolations.isEmpty());
|
112
|
}
|
113
|
}
|