001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krms.api.repository; 017 018import org.junit.Assert; 019import org.junit.Test; 020import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplateAttribute; 021 022import javax.xml.bind.JAXBContext; 023import javax.xml.bind.Marshaller; 024import javax.xml.bind.Unmarshaller; 025import java.io.StringReader; 026import java.io.StringWriter; 027 028/** 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 * 031 */ 032public final class NaturalLanguageTemplateAttributeGenTest { 033 034 private final static String XML = "paste xml output here"; 035 private final static String ATTRIBUTE_DEFINITION_ID = "ATTRIBUTE_DEFINITION_ID"; 036 private final static String ID = "ID"; 037 private final static String NATURAL_LANGUAGE_TEMPLATE_ID = "NATURAL_LANGUAGE_TEMPLATE_ID"; 038 private final static String VALUE = "VALUE"; 039 040 @Test 041 public void test_NaturalLanguageTemplateAttribute_set_validation_id_success_null() { 042 NaturalLanguageTemplateAttribute.Builder builder = NaturalLanguageTemplateAttribute.Builder.create(); 043 builder.setId(null); 044 } 045 046 @Test(expected = java.lang.IllegalArgumentException.class) 047 public void test_NaturalLanguageTemplateAttribute_set_validation_id_fail_empty() { 048 NaturalLanguageTemplateAttribute.Builder builder = NaturalLanguageTemplateAttribute.Builder.create(); 049 builder.setId(""); 050 } 051 052 @Test(expected = java.lang.IllegalArgumentException.class) 053 public void test_NaturalLanguageTemplateAttribute_set_validation_id_fail_whitespace() { 054 NaturalLanguageTemplateAttribute.Builder builder = NaturalLanguageTemplateAttribute.Builder.create(); 055 builder.setId(" "); 056 } 057 058 @Test 059 public void test_NaturalLanguageTemplateAttribute_Builder_create() { 060 NaturalLanguageTemplateAttribute.Builder.create(); 061 } 062 063 @Test 064 public void test_NaturalLanguageTemplateAttribute_Builder_create_and_build() { 065 NaturalLanguageTemplateAttribute.Builder builder = NaturalLanguageTemplateAttribute.Builder.create(); 066 builder.build(); 067 } 068 069// @Test 070 public void test_NaturalLanguageTemplateAttribute_xml_marshaling() 071 throws Exception 072 { 073 NaturalLanguageTemplateAttribute naturalLanguageTemplateAttribute = buildFullNaturalLanguageTemplateAttribute(); 074 075 assertXmlMarshaling(naturalLanguageTemplateAttribute, XML); 076 } 077 078 public void assertXmlMarshaling(Object naturalLanguageTemplateAttribute, String expectedXml) 079 throws Exception 080 { 081 JAXBContext jc = JAXBContext.newInstance(NaturalLanguageTemplateAttribute.class); 082 083 Marshaller marshaller = jc.createMarshaller(); 084 StringWriter stringWriter = new StringWriter(); 085 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 086 // marshaller.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", new CustomNamespacePrefixMapper()); 087 marshaller.marshal(naturalLanguageTemplateAttribute, stringWriter); 088 String xml = stringWriter.toString(); 089 090 System.out.println(xml); // TODO run test, paste xml output into XML, comment out this line. 091 092 Unmarshaller unmarshaller = jc.createUnmarshaller(); 093 Object actual = unmarshaller.unmarshal(new StringReader(xml)); 094 Object expected = unmarshaller.unmarshal(new StringReader(expectedXml)); 095 Assert.assertEquals(expected, actual); 096 } 097 098 public static NaturalLanguageTemplateAttribute buildFullNaturalLanguageTemplateAttribute() { 099 NaturalLanguageTemplateAttribute.Builder builder = NaturalLanguageTemplateAttribute.Builder.create(); 100 builder.setId(ID); 101 NaturalLanguageTemplateAttribute naturalLanguageTemplateAttribute = builder.build(); 102 return naturalLanguageTemplateAttribute; 103 } 104 105}