Search in sources :

Example 1 with CustomTypeContent

use of eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContent in project hale by halestudio.

the class CustomTypeContentAssociationTypeTest method testBothWays.

/**
 * Test converting to DOM and back again.
 */
@Test
public void testBothWays() {
    QName name1 = new QName("typespace", "some type");
    QName name2 = new QName("a1");
    QName name3 = new QName("b1");
    List<QName> property = new ArrayList<>();
    property.add(name1);
    property.add(name2);
    property.add(name3);
    QName elem1 = new QName("mimimi");
    QName elem2 = new QName("some namespace", "some name");
    List<QName> elements = new ArrayList<QName>();
    elements.add(elem1);
    elements.add(elem2);
    CustomTypeContent content = new CustomTypeContent(CustomTypeContentMode.elements, elements);
    CustomTypeContentAssociation assoc = new CustomTypeContentAssociation(property, content);
    // convert to DOM
    Element fragment = HaleIO.getComplexElement(assoc);
    // System.out.println(XmlUtil.serialize(fragment));
    // convert back
    CustomTypeContentAssociation conv = HaleIO.getComplexValue(fragment, CustomTypeContentAssociation.class, null);
    assertNotNull(conv.getProperty());
    assertEquals(3, conv.getProperty().size());
    assertEquals(name1, conv.getProperty().get(0));
    assertEquals(name2, conv.getProperty().get(1));
    assertEquals(name3, conv.getProperty().get(2));
    assertEquals("Mode does not match", CustomTypeContentMode.elements, conv.getConfig().getMode());
    assertEquals(2, conv.getConfig().getElements().size());
    assertEquals(elem1, conv.getConfig().getElements().get(0));
    assertEquals(elem2, conv.getConfig().getElements().get(1));
}
Also used : CustomTypeContentAssociation(eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContentAssociation) CustomTypeContent(eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContent) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with CustomTypeContent

use of eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContent in project hale by halestudio.

the class CustomTypeContentConfigurationTypeTest method testBothWays.

/**
 * Test converting to DOM and back again.
 */
@Test
public void testBothWays() {
    QName name1 = new QName("http://www.opengis.net/om/2.0", "OM_ObservationType");
    QName name2 = new QName("http://www.opengis.net/om/2.0", "result");
    List<QName> property = new ArrayList<>();
    property.add(name1);
    property.add(name2);
    QName elem1 = new QName("http://www.opengis.net/swe/2.0", "Quantity");
    List<QName> elements = new ArrayList<QName>();
    elements.add(elem1);
    CustomTypeContent content = new CustomTypeContent(CustomTypeContentMode.elements, elements);
    CustomTypeContentAssociation assoc = new CustomTypeContentAssociation(property, content);
    List<CustomTypeContentAssociation> associations = new ArrayList<>();
    associations.add(assoc);
    CustomTypeContentConfiguration config = new CustomTypeContentConfiguration(associations);
    // convert to DOM
    Element fragment = HaleIO.getComplexElement(config);
    // System.out.println(XmlUtil.serialize(fragment));
    // convert back
    CustomTypeContentConfiguration conv = HaleIO.getComplexValue(fragment, CustomTypeContentConfiguration.class, null);
    assertEquals(1, conv.getAssociations().size());
    List<QName> cproperty = conv.getAssociations().get(0).getProperty();
    assertNotNull(cproperty);
    assertEquals(2, cproperty.size());
    assertEquals(name1, cproperty.get(0));
    assertEquals(name2, cproperty.get(1));
    CustomTypeContent ccontent = conv.getAssociations().get(0).getConfig();
    assertEquals("Mode does not match", CustomTypeContentMode.elements, ccontent.getMode());
    assertEquals(1, ccontent.getElements().size());
    assertEquals(elem1, ccontent.getElements().get(0));
}
Also used : CustomTypeContentAssociation(eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContentAssociation) CustomTypeContentConfiguration(eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContentConfiguration) CustomTypeContent(eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContent) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with CustomTypeContent

use of eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContent in project hale by halestudio.

the class CustomTypeContentTypeTest method testElements.

/**
 * Test with mode simple.
 */
@Test
public void testElements() {
    QName name1 = new QName("mimimi");
    QName name2 = new QName("some namespace", "some name");
    List<QName> elements = new ArrayList<QName>();
    elements.add(name1);
    elements.add(name2);
    CustomTypeContent content = new CustomTypeContent(CustomTypeContentMode.elements, elements);
    // convert to DOM
    Element fragment = HaleIO.getComplexElement(content);
    // System.out.println(XmlUtil.serialize(fragment));
    // convert back
    CustomTypeContent conv = HaleIO.getComplexValue(fragment, CustomTypeContent.class, null);
    assertEquals("Mode does not match", CustomTypeContentMode.elements, conv.getMode());
    assertEquals(2, conv.getElements().size());
    assertEquals(name1, conv.getElements().get(0));
    assertEquals(name2, conv.getElements().get(1));
}
Also used : CustomTypeContent(eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContent) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with CustomTypeContent

use of eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContent in project hale by halestudio.

the class CustomTypeContentTypeTest method testSimple.

/**
 * Test with mode simple.
 */
@Test
public void testSimple() {
    CustomTypeContent content = new CustomTypeContent(CustomTypeContentMode.simple, new ArrayList<QName>());
    // convert to DOM
    Element fragment = HaleIO.getComplexElement(content);
    // convert back
    CustomTypeContent conv = HaleIO.getComplexValue(fragment, CustomTypeContent.class, null);
    assertEquals("Mode does not match", CustomTypeContentMode.simple, conv.getMode());
    assertEquals(0, conv.getElements().size());
}
Also used : CustomTypeContent(eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContent) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Test(org.junit.Test)

Example 5 with CustomTypeContent

use of eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContent in project hale by halestudio.

the class CustomTypeContentConfigurationTypeTest method testLoad.

/**
 * Test loading from XML.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testLoad() throws Exception {
    QName name1 = new QName("http://www.opengis.net/om/2.0", "OM_ObservationType");
    QName name2 = new QName("http://www.opengis.net/om/2.0", "result");
    QName elem1 = new QName("http://www.opengis.net/swe/2.0", "Quantity");
    // load as DOM
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputStream inputStream = getClass().getResourceAsStream("configSample.xml");
    Element root;
    try {
        root = builder.parse(inputStream).getDocumentElement();
    } finally {
        inputStream.close();
    }
    // convert back
    CustomTypeContentConfiguration conv = HaleIO.getComplexValue(root, CustomTypeContentConfiguration.class, null);
    assertEquals(1, conv.getAssociations().size());
    List<QName> cproperty = conv.getAssociations().get(0).getProperty();
    assertNotNull(cproperty);
    assertEquals(2, cproperty.size());
    assertEquals(name1, cproperty.get(0));
    assertEquals(name2, cproperty.get(1));
    CustomTypeContent ccontent = conv.getAssociations().get(0).getConfig();
    assertEquals("Mode does not match", CustomTypeContentMode.elements, ccontent.getMode());
    assertEquals(1, ccontent.getElements().size());
    assertEquals(elem1, ccontent.getElements().get(0));
}
Also used : CustomTypeContentConfiguration(eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContentConfiguration) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) CustomTypeContent(eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContent) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) Test(org.junit.Test)

Aggregations

CustomTypeContent (eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContent)5 QName (javax.xml.namespace.QName)5 Test (org.junit.Test)5 Element (org.w3c.dom.Element)5 ArrayList (java.util.ArrayList)3 CustomTypeContentAssociation (eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContentAssociation)2 CustomTypeContentConfiguration (eu.esdihumboldt.hale.io.xsd.anytype.CustomTypeContentConfiguration)2 InputStream (java.io.InputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1