Project

General

Profile

« Previous | Next » 

Revision 69e00fde

Added by Andreas Müller almost 8 years ago

Further develop the CDM preferences #3958

View differences:

cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/metadata/CdmPreferenceTest.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
13 13
import org.junit.Before;
14 14
import org.junit.Test;
15 15

  
16
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
17

  
18 16
/**
19 17
 * @author a.mueller
20 18
 * @created 2013-07-03
......
23 21
public class CdmPreferenceTest {
24 22

  
25 23
	private String subject;
24
	private String subject2;
26 25
	private String predicate;
27 26
	private String value;
28
	
27

  
29 28
	/**
30 29
	 * @throws java.lang.Exception
31 30
	 */
32 31
	@Before
33 32
	public void setUp() throws Exception {
34
		subject = "database";
33
		subject = "/";
35 34
		predicate = "eu.etaxonomy.cdm.model.name.NomenclaturalCode";
36 35
		value = "ICZN";
36

  
37 37
	}
38 38

  
39 39
	/**
......
45 45
		Assert.assertEquals(subject, prefs.getSubject());
46 46
		Assert.assertEquals(predicate, prefs.getPredicate());
47 47
		Assert.assertEquals(value, prefs.getValue());
48

  
49

  
48 50
	}
49
	
50
	 
51

  
52

  
51 53
	@Test
52 54
	public void testConstraints() {
53
		String veryLongText100 = 
55
		String veryLongText100 =
54 56
"This is a very long text it is even longer then any other long text which is already long. size =100";
55 57
		String veryLongText200 = veryLongText100 + veryLongText100;
56 58
		String veryLongText400 = veryLongText200 + veryLongText200;
57 59
		String veryLongText1200 = veryLongText400 + veryLongText400 + veryLongText400;
58
		
60

  
59 61
		CdmPreference prefs = null;
60 62
		try {
61 63
			prefs = new CdmPreference(null, predicate, value);
......
69 71
		} catch (Exception e) {
70 72
			//ok
71 73
		}
72
		
74

  
73 75
		try {
74 76
			prefs = new CdmPreference(subject, null, value);
75 77
			Assert.fail("Predicate must not be null");
......
82 84
		} catch (Exception e) {
83 85
			//ok
84 86
		}
85
		
87

  
86 88
		try {
87 89
			prefs = new CdmPreference(subject, predicate, null);
90
	         Assert.assertEquals(subject, prefs.getSubject());
91
	         Assert.assertEquals(predicate, prefs.getPredicate());
92
	         Assert.assertNull(value, null);
88 93
		} catch (Exception e) {
89 94
			Assert.fail("Currently null values are allowed in preferences");
90
			Assert.assertEquals(subject, prefs.getSubject());
91
			Assert.assertEquals(predicate, prefs.getPredicate());
92
			Assert.assertNull(value, null);
95

  
93 96
		}
94 97
		try {
95 98
			prefs = new CdmPreference(subject, predicate, veryLongText1200);
......
97 100
		} catch (Exception e) {
98 101
			//ok
99 102
		}
100
		
101
		
102

  
103 103
	}
104 104

  
105
    @Test
106
    public void testSubjectSyntax() {
107
        CdmPreference prefs = null;
108
        String subject2 = null;
109
        try {
110
            subject2 = "/TaxonNode[#t1#18681#6392#5358#9#2#]";
111
            prefs = new CdmPreference(subject2, predicate, value);
112
            Assert.assertEquals(subject2, prefs.getSubject());
113
            Assert.assertEquals(predicate, prefs.getPredicate());
114
            Assert.assertEquals(value, prefs.getValue());
115
        } catch (Exception e) {
116
            Assert.fail("Syntax for " + subject2 + " should be ok");
117
        }
118

  
119
        try {
120
            subject2 = "/TaxonNode[#t1#18681#6392#5358#9#2#]x";
121
            prefs = new CdmPreference(subject2, predicate, value);
122
            Assert.fail("Syntax for " + subject2 + " should fail");
123
        } catch (Exception e) {
124
            //ok
125
        }
126

  
127
        try {
128
            subject2 = "/Taxon3Node[#t1#18681#6392#5358#9#2#]";
129
            prefs = new CdmPreference(subject2, predicate, value);
130
            Assert.fail("Syntax for " + subject2 + " should fail");
131
        } catch (Exception e) {
132
            //ok
133
        }
134

  
135
    }
136

  
105 137
}

Also available in: Unified diff