Project

General

Profile

Download (2.29 KB) Statistics
| Branch: | Tag: | Revision:
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.assertTrue;
13

    
14
import java.util.Set;
15

    
16
import javax.validation.ConstraintViolation;
17

    
18
import org.apache.log4j.Logger;
19
import org.hibernate.validator.internal.constraintvalidators.bv.NotNullValidator;
20
import org.junit.Before;
21
import org.junit.Test;
22

    
23
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
24
import eu.etaxonomy.cdm.model.location.Point;
25
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
26

    
27

    
28
/**
29
 *
30
 * @author a.mueller
31
 *
32
 */
33
@SuppressWarnings("unused")
34
public class ValidPointTest extends ValidationTestBase{
35
	private static final Logger logger = Logger.getLogger(ValidPointTest.class);
36

    
37

    
38
	GatheringEvent gatheringEvent;
39
	Point point = new Point();
40

    
41
	@Before
42
	public void setUp() {
43
		DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
44
		vocabularyStore.initialize();
45
		gatheringEvent = GatheringEvent.NewInstance();
46

    
47
		Set<ConstraintViolation<GatheringEvent>> constraintViolations  = validator.validate(gatheringEvent, Level2.class);
48
        assertTrue("There should not be a constraint violation as gathering with NO exact location is allowed",constraintViolations.isEmpty());
49

    
50
	}
51

    
52

    
53
/****************** TESTS *****************************/
54

    
55
	@Test
56
	public final void testNoPoint() {
57

    
58
        Set<ConstraintViolation<GatheringEvent>> constraintViolations  = validator.validate(gatheringEvent, Level2.class);
59
        assertTrue("There should not be a constraint violation as gathering with NO exact location is allowed",constraintViolations.isEmpty());
60
 	}
61

    
62
	@Test
63
    public final void testNullLongitude() {
64
	    point.setLatitude(33.3d);
65
	    point.setLongitude(null);
66
	    validateHasConstraint(point, NotNullValidator.class, Level2.class);
67
	    gatheringEvent.setExactLocation(point);
68
	    validateHasConstraint(gatheringEvent, NotNullValidator.class, Level2.class);
69

    
70
	    point.setLongitude(22.2d);
71
	    validateHasNoConstraint(point, NotNullValidator.class, Level2.class);
72
	    validateHasNoConstraint(gatheringEvent, NotNullValidator.class, Level2.class);
73
   }
74

    
75
}
(7-7/10)