Package uk.nhs.interoperability.payloads.example

Source Code of uk.nhs.interoperability.payloads.example.ExampleTest

/*
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package uk.nhs.interoperability.payloads.example;

import java.io.IOException;

import org.junit.Test;
import org.xml.sax.SAXException;

import uk.nhs.interoperability.payloads.AbstractTest;
import uk.nhs.interoperability.payloads.CodedValue;
import uk.nhs.interoperability.payloads.DateValue;
import uk.nhs.interoperability.payloads.util.FileLoader;
import uk.nhs.interoperability.payloads.vocabularies.generated.HumanLanguage;
import uk.nhs.interoperability.payloads.vocabularies.internal.IDType;
import uk.nhs.interoperability.payloads.vocabularies.internal.PatientIDType;

public class ExampleTest extends AbstractTest {

        @Test
        public void testSerialise() throws SAXException, IOException {
          try {
            super.init("example/", "Example-Serialise", "Example: Serialise Test", "This is a test of serialising some test objects, and compares the output to an expected XML file.");   
            Example example = new Example();
               
                example.setAttribute("AttributeValue");
                example.setCodedValue(new CodedValue(HumanLanguage._en));
                example.addID(new PatientID()
                                 .setPatientIDType(PatientIDType.UnverifiedNHSNumber.code)
                                 .setPatientID("1234567890"));
                example.addListItem("Item1");
                example.addListItem("Item2");
               
                Child c = new Child();
                c.setFieldWithNamespace("FieldWithNamespace");
                c.setText("SimpleTextField");
                example.setChild(c);
               
                example.setLongXPathItem("LongXPathItem");
                example.setText("SimpleTextField");
                example.setTextIncl("TextInIncludedConfig");
                example.setTextIncl2("AnotherFieldInIncludedConfig");
                example.setTime(new DateValue("20130101010101+0000"));
               
                //Template1 t1 = new Template1();
                //t1.setValue("template1");
                //example.setTemplatedField(t1);
               
                // Test templates
                Template2 t2 = new Template2();
                t2.setValue("template2");
                example.setTemplatedField(t2);
               
                String result = example.serialise();
                System.out.println(result);
                testXMLisSimilar("/TestData/Example.xml", result, false);
          } catch (Exception e) {
          super.exception(e);
        } finally {
          super.writeResults();
        }
        }
       
        @Test
        public void testParse() throws SAXException, IOException {
                String expected = FileLoader.loadFileOnClasspath("/TestData/Example.xml");
                Example example = new Example();
                example.parse(expected);
               
                Template2 t2 = (Template2)example.getTemplatedField();
                System.out.println("Template name: " + t2.getVersionedName());
                System.out.println("Template field value: " + t2.getValue());
        }
       
        /*@Test
        public void testRoundTrip() {
                String expectedResult = loadExpectedResult("/TestData/Example.xml", true);
                Example template = new Example();
                template.parse(expectedResult);
                String result = template.serialise();
                testXMLisSimilar("/TestData/Example.xml", result, true);
        }*/
}
TOP

Related Classes of uk.nhs.interoperability.payloads.example.ExampleTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.