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.NaturalLanguageTemplateAttribute;
21
22 import javax.xml.bind.JAXBContext;
23 import javax.xml.bind.Marshaller;
24 import javax.xml.bind.Unmarshaller;
25 import java.io.StringReader;
26 import java.io.StringWriter;
27
28
29
30
31
32 public final class NaturalLanguageTemplateAttributeGenTest {
33
34 private final static String XML = "paste xml output here";
35 private final static String ATTRIBUTE_DEFINITION_ID = "ATTRIBUTE_DEFINITION_ID";
36 private final static String ID = "ID";
37 private final static String NATURAL_LANGUAGE_TEMPLATE_ID = "NATURAL_LANGUAGE_TEMPLATE_ID";
38 private final static String VALUE = "VALUE";
39
40 @Test
41 public void test_NaturalLanguageTemplateAttribute_set_validation_id_success_null() {
42 NaturalLanguageTemplateAttribute.Builder builder = NaturalLanguageTemplateAttribute.Builder.create();
43 builder.setId(null);
44 }
45
46 @Test(expected = java.lang.IllegalArgumentException.class)
47 public void test_NaturalLanguageTemplateAttribute_set_validation_id_fail_empty() {
48 NaturalLanguageTemplateAttribute.Builder builder = NaturalLanguageTemplateAttribute.Builder.create();
49 builder.setId("");
50 }
51
52 @Test(expected = java.lang.IllegalArgumentException.class)
53 public void test_NaturalLanguageTemplateAttribute_set_validation_id_fail_whitespace() {
54 NaturalLanguageTemplateAttribute.Builder builder = NaturalLanguageTemplateAttribute.Builder.create();
55 builder.setId(" ");
56 }
57
58 @Test
59 public void test_NaturalLanguageTemplateAttribute_Builder_create() {
60 NaturalLanguageTemplateAttribute.Builder.create();
61 }
62
63 @Test
64 public void test_NaturalLanguageTemplateAttribute_Builder_create_and_build() {
65 NaturalLanguageTemplateAttribute.Builder builder = NaturalLanguageTemplateAttribute.Builder.create();
66 builder.build();
67 }
68
69
70 public void test_NaturalLanguageTemplateAttribute_xml_marshaling()
71 throws Exception
72 {
73 NaturalLanguageTemplateAttribute naturalLanguageTemplateAttribute = buildFullNaturalLanguageTemplateAttribute();
74
75 assertXmlMarshaling(naturalLanguageTemplateAttribute, XML);
76 }
77
78 public void assertXmlMarshaling(Object naturalLanguageTemplateAttribute, String expectedXml)
79 throws Exception
80 {
81 JAXBContext jc = JAXBContext.newInstance(NaturalLanguageTemplateAttribute.class);
82
83 Marshaller marshaller = jc.createMarshaller();
84 StringWriter stringWriter = new StringWriter();
85 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
86
87 marshaller.marshal(naturalLanguageTemplateAttribute, stringWriter);
88 String xml = stringWriter.toString();
89
90 System.out.println(xml);
91
92 Unmarshaller unmarshaller = jc.createUnmarshaller();
93 Object actual = unmarshaller.unmarshal(new StringReader(xml));
94 Object expected = unmarshaller.unmarshal(new StringReader(expectedXml));
95 Assert.assertEquals(expected, actual);
96 }
97
98 public static NaturalLanguageTemplateAttribute buildFullNaturalLanguageTemplateAttribute() {
99 NaturalLanguageTemplateAttribute.Builder builder = NaturalLanguageTemplateAttribute.Builder.create();
100 builder.setId(ID);
101 NaturalLanguageTemplateAttribute naturalLanguageTemplateAttribute = builder.build();
102 return naturalLanguageTemplateAttribute;
103 }
104
105 }