1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.api.repository;
17
18 import org.junit.Assert;
19 import org.junit.Test;
20 import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
21 import javax.xml.bind.JAXBContext;
22 import javax.xml.bind.Marshaller;
23 import javax.xml.bind.Unmarshaller;
24 import java.io.StringReader;
25 import java.io.StringWriter;
26
27
28
29
30
31 public final class NaturalLanguageUsageGenTest {
32
33 private final static String XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
34 + "<naturalLanguageUsage xmlns=\"http://rice.kuali.org/krms/v2_0\">\n"
35 + " <name>NAME</name>\n"
36 + " <namespace>NAMESPACE</namespace>\n"
37 + " <id>ID</id>\n"
38 + " <active>false</active>\n"
39 + "</naturalLanguageUsage>";
40 private final static boolean ACTIVE = false;
41 private final static String DESCRIPTION = "DESCRIPTION";
42 private final static String ID = "ID";
43 private final static String NAME = "NAME";
44 private final static String NAMESPACE = "NAMESPACE";
45 private final static Long VERSION_NUMBER = 0L;
46
47 @Test(expected = java.lang.IllegalArgumentException.class)
48 public void test_NaturalLanguageUsage_Builder_create_fail_all_null() {
49 NaturalLanguageUsage.Builder.create(null, null);
50 }
51
52 @Test
53 public void test_NaturalLanguageUsage_set_validation_id_success_null() {
54 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
55 builder.setId(null);
56 }
57
58 @Test(expected = java.lang.IllegalArgumentException.class)
59 public void test_NaturalLanguageUsage_set_validation_id_fail_empty() {
60 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
61 builder.setId("");
62 }
63
64 @Test(expected = java.lang.IllegalArgumentException.class)
65 public void test_NaturalLanguageUsage_set_validation_id_fail_whitespace() {
66 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
67 builder.setId(" ");
68 }
69
70 @Test(expected = java.lang.IllegalArgumentException.class)
71 public void test_NaturalLanguageUsage_set_validation_name_fail_null() {
72 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
73 builder.setName(null);
74 }
75
76 @Test(expected = java.lang.IllegalArgumentException.class)
77 public void test_NaturalLanguageUsage_set_validation_name_fail_empty() {
78 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
79 builder.setName("");
80 }
81
82 @Test(expected = java.lang.IllegalArgumentException.class)
83 public void test_NaturalLanguageUsage_set_validation_name_fail_whitespace() {
84 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
85 builder.setName(" ");
86 }
87
88 @Test(expected = java.lang.IllegalArgumentException.class)
89 public void test_NaturalLanguageUsage_set_validation_namespace_fail_null() {
90 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
91 builder.setNamespace(null);
92 }
93
94 @Test(expected = java.lang.IllegalArgumentException.class)
95 public void test_NaturalLanguageUsage_set_validation_namespace_fail_empty() {
96 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
97 builder.setNamespace("");
98 }
99
100 @Test(expected = java.lang.IllegalArgumentException.class)
101 public void test_NaturalLanguageUsage_set_validation_namespace_fail_whitespace() {
102 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
103 builder.setNamespace(" ");
104 }
105
106 @Test
107 public void test_NaturalLanguageUsage_Builder_create() {
108 NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
109 }
110
111 @Test
112 public void test_NaturalLanguageUsage_Builder_create_and_build() {
113 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
114 builder.build();
115 }
116
117 @Test
118 public void test_NaturalLanguageUsage_xml_marshaling()
119 throws Exception
120 {
121 NaturalLanguageUsage naturalLanguageUsage = buildFullNaturalLanguageUsage();
122
123 assertXmlMarshaling(naturalLanguageUsage, XML);
124 }
125
126 public void assertXmlMarshaling(Object naturalLanguageUsage, String expectedXml)
127 throws Exception
128 {
129 JAXBContext jc = JAXBContext.newInstance(NaturalLanguageUsage.class);
130
131 Marshaller marshaller = jc.createMarshaller();
132 StringWriter stringWriter = new StringWriter();
133 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
134
135 marshaller.marshal(naturalLanguageUsage, stringWriter);
136 String xml = stringWriter.toString();
137
138
139
140 Unmarshaller unmarshaller = jc.createUnmarshaller();
141 Object actual = unmarshaller.unmarshal(new StringReader(xml));
142 Object expected = unmarshaller.unmarshal(new StringReader(expectedXml));
143 Assert.assertEquals(expected, actual);
144 }
145
146 public static NaturalLanguageUsage buildFullNaturalLanguageUsage() {
147 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
148 builder.setId(ID);
149 NaturalLanguageUsage naturalLanguageUsage = builder.build();
150 return naturalLanguageUsage;
151 }
152
153 public static NaturalLanguageUsage buildFullNaturalLanguageUsageNoId() {
154 NaturalLanguageUsage.Builder builder = NaturalLanguageUsage.Builder.create(NAME, NAMESPACE);
155 NaturalLanguageUsage naturalLanguageUsage = builder.build();
156 return naturalLanguageUsage;
157 }
158
159 }