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.reference.ReferenceObjectBinding;
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 ReferenceObjectBindingGenTest {
32
33 private final static String XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
34 + "<referenceObjectBinding xmlns=\"http://rice.kuali.org/krms/v2_0\">\n"
35 + " <krmsDiscriminatorType>KRMS_DISCRIMINATOR_TYPE</krmsDiscriminatorType>\n"
36 + " <krmsObjectId>KRMS_OBJECT_ID</krmsObjectId>\n"
37 + " <namespace>NAMESPACE</namespace>\n"
38 + " <referenceDiscriminatorType>REFERENCE_DISCRIMINATOR_TYPE</referenceDiscriminatorType>\n"
39 + " <referenceObjectId>REFERENCE_OBJECT_ID</referenceObjectId>\n"
40 + " <id>ID</id>\n"
41 + " <active>false</active>\n"
42 + "</referenceObjectBinding>";
43 private final static boolean ACTIVE = false;
44 private final static String COLLECTION_NAME = "COLLECTION_NAME";
45 private final static String ID = "ID";
46 private final static String KRMS_DISCRIMINATOR_TYPE = "KRMS_DISCRIMINATOR_TYPE";
47 private final static String KRMS_OBJECT_ID = "KRMS_OBJECT_ID";
48 private final static String NAMESPACE = "NAMESPACE";
49 private final static String REFERENCE_DISCRIMINATOR_TYPE = "REFERENCE_DISCRIMINATOR_TYPE";
50 private final static String REFERENCE_OBJECT_ID = "REFERENCE_OBJECT_ID";
51 private final static Long VERSION_NUMBER = 0L;
52
53 @Test(expected = java.lang.IllegalArgumentException.class)
54 public void test_ReferenceObjectBinding_Builder_create_fail_all_null() {
55 ReferenceObjectBinding.Builder.create(null, null, null, null, null);
56 }
57
58 @Test
59 public void test_ReferenceObjectBinding_set_validation_id_success_null() {
60 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
61 builder.setId(null);
62 }
63
64 @Test(expected = java.lang.IllegalArgumentException.class)
65 public void test_ReferenceObjectBinding_set_validation_id_fail_empty() {
66 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
67 builder.setId("");
68 }
69
70 @Test(expected = java.lang.IllegalArgumentException.class)
71 public void test_ReferenceObjectBinding_set_validation_id_fail_whitespace() {
72 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
73 builder.setId(" ");
74 }
75
76 @Test(expected = java.lang.IllegalArgumentException.class)
77 public void test_ReferenceObjectBinding_set_validation_krmsDiscriminatorType_fail_null() {
78 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
79 builder.setKrmsDiscriminatorType(null);
80 }
81
82 @Test(expected = java.lang.IllegalArgumentException.class)
83 public void test_ReferenceObjectBinding_set_validation_krmsDiscriminatorType_fail_empty() {
84 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
85 builder.setKrmsDiscriminatorType("");
86 }
87
88 @Test(expected = java.lang.IllegalArgumentException.class)
89 public void test_ReferenceObjectBinding_set_validation_krmsDiscriminatorType_fail_whitespace() {
90 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
91 builder.setKrmsDiscriminatorType(" ");
92 }
93
94 @Test(expected = java.lang.IllegalArgumentException.class)
95 public void test_ReferenceObjectBinding_set_validation_krmsObjectId_fail_null() {
96 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
97 builder.setKrmsObjectId(null);
98 }
99
100 @Test(expected = java.lang.IllegalArgumentException.class)
101 public void test_ReferenceObjectBinding_set_validation_krmsObjectId_fail_empty() {
102 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
103 builder.setKrmsObjectId("");
104 }
105
106 @Test(expected = java.lang.IllegalArgumentException.class)
107 public void test_ReferenceObjectBinding_set_validation_krmsObjectId_fail_whitespace() {
108 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
109 builder.setKrmsObjectId(" ");
110 }
111
112 @Test(expected = java.lang.IllegalArgumentException.class)
113 public void test_ReferenceObjectBinding_set_validation_namespace_fail_null() {
114 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
115 builder.setNamespace(null);
116 }
117
118 @Test(expected = java.lang.IllegalArgumentException.class)
119 public void test_ReferenceObjectBinding_set_validation_namespace_fail_empty() {
120 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
121 builder.setNamespace("");
122 }
123
124 @Test(expected = java.lang.IllegalArgumentException.class)
125 public void test_ReferenceObjectBinding_set_validation_namespace_fail_whitespace() {
126 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
127 builder.setNamespace(" ");
128 }
129
130 @Test(expected = java.lang.IllegalArgumentException.class)
131 public void test_ReferenceObjectBinding_set_validation_referenceDiscriminatorType_fail_null() {
132 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
133 builder.setReferenceDiscriminatorType(null);
134 }
135
136 @Test(expected = java.lang.IllegalArgumentException.class)
137 public void test_ReferenceObjectBinding_set_validation_referenceDiscriminatorType_fail_empty() {
138 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
139 builder.setReferenceDiscriminatorType("");
140 }
141
142 @Test(expected = java.lang.IllegalArgumentException.class)
143 public void test_ReferenceObjectBinding_set_validation_referenceDiscriminatorType_fail_whitespace() {
144 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
145 builder.setReferenceDiscriminatorType(" ");
146 }
147
148 @Test(expected = java.lang.IllegalArgumentException.class)
149 public void test_ReferenceObjectBinding_set_validation_referenceObjectId_fail_null() {
150 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
151 builder.setReferenceObjectId(null);
152 }
153
154 @Test(expected = java.lang.IllegalArgumentException.class)
155 public void test_ReferenceObjectBinding_set_validation_referenceObjectId_fail_empty() {
156 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
157 builder.setReferenceObjectId("");
158 }
159
160 @Test(expected = java.lang.IllegalArgumentException.class)
161 public void test_ReferenceObjectBinding_set_validation_referenceObjectId_fail_whitespace() {
162 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
163 builder.setReferenceObjectId(" ");
164 }
165
166 @Test
167 public void test_ReferenceObjectBinding_Builder_create() {
168 ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
169 }
170
171 @Test
172 public void test_ReferenceObjectBinding_Builder_create_and_build() {
173 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
174 builder.build();
175 }
176
177 @Test
178 public void test_ReferenceObjectBinding_xml_marshaling()
179 throws Exception
180 {
181 ReferenceObjectBinding referenceObjectBinding = buildFullReferenceObjectBinding();
182
183 assertXmlMarshaling(referenceObjectBinding, XML);
184 }
185
186 public void assertXmlMarshaling(Object referenceObjectBinding, String expectedXml)
187 throws Exception
188 {
189 JAXBContext jc = JAXBContext.newInstance(ReferenceObjectBinding.class);
190
191 Marshaller marshaller = jc.createMarshaller();
192 StringWriter stringWriter = new StringWriter();
193 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
194
195 marshaller.marshal(referenceObjectBinding, stringWriter);
196 String xml = stringWriter.toString();
197
198
199
200 Unmarshaller unmarshaller = jc.createUnmarshaller();
201 Object actual = unmarshaller.unmarshal(new StringReader(xml));
202 Object expected = unmarshaller.unmarshal(new StringReader(expectedXml));
203 Assert.assertEquals(expected, actual);
204 }
205
206 public static ReferenceObjectBinding buildFullReferenceObjectBinding() {
207 ReferenceObjectBinding.Builder builder = ReferenceObjectBinding.Builder.create(KRMS_DISCRIMINATOR_TYPE, KRMS_OBJECT_ID, NAMESPACE, REFERENCE_DISCRIMINATOR_TYPE, REFERENCE_OBJECT_ID);
208 builder.setId(ID);
209 ReferenceObjectBinding referenceObjectBinding = builder.build();
210 return referenceObjectBinding;
211 }
212
213 }