View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @author Kuali Rice Team (rice.collab@kuali.org)
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  //    @Test
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          // marshaller.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", new CustomNamespacePrefixMapper());
87          marshaller.marshal(naturalLanguageTemplateAttribute, stringWriter);
88          String xml = stringWriter.toString();
89  
90          System.out.println(xml); // TODO run test, paste xml output into XML, comment out this line.
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 }