Search in sources :

Example 21 with DynamicJAXBContext

use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project aai-aai-common by onap.

the class OxmSchemaProvider method getVertexSchema.

@Override
public VertexSchema getVertexSchema(String vertexName, String schemaVersion) throws SchemaProviderException {
    DynamicJAXBContext jaxbContext = OxmSchemaLoader.getContextForVersion(schemaVersion);
    FromOxmVertexSchema vs = new FromOxmVertexSchema();
    try {
        vs.fromOxm(vertexName, jaxbContext, OxmSchemaLoader.getXmlLookupMap(schemaVersion));
    } catch (SchemaProviderException ex) {
        // Node doesn't exist in schema.  Return null.
        return null;
    }
    return vs;
}
Also used : DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) SchemaProviderException(org.onap.aai.schemaif.SchemaProviderException)

Example 22 with DynamicJAXBContext

use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project aai-aai-common by onap.

the class StoreNotificationEventTest method testStoreDynamicEventNullObj.

@Test(expected = AAIException.class)
public void testStoreDynamicEventNullObj() throws AAIException {
    DynamicEntity eventHeader = Mockito.mock(DynamicEntity.class);
    DynamicJAXBContext notificationJaxbContext = nodeIngestor.getContextForVersion(schemaVersions.getEdgeLabelVersion());
    sne.storeDynamicEvent(notificationJaxbContext, "v12", eventHeader, null);
}
Also used : DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) Test(org.junit.Test)

Example 23 with DynamicJAXBContext

use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project aai-aai-common by onap.

the class NodeIngestorLocalTest method testGetContextForVersion11.

@Test
public void testGetContextForVersion11() {
    DynamicJAXBContext ctx10 = nodeIngestor.getContextForVersion(new SchemaVersion("v10"));
    // should work bc Foo is valid in test_network_v10 schema
    DynamicEntity foo10 = ctx10.newDynamicEntity("Foo");
    foo10.set("fooId", "bar");
    assertEquals("bar", foo10.get("fooId"));
    // should work bc Bar is valid in test_business_v10 schema
    DynamicEntity bar10 = ctx10.newDynamicEntity("Bar");
    bar10.set("barId", "bar2");
    assertEquals("bar2", bar10.get("barId"));
    XSDOutputResolver outputResolver10 = new XSDOutputResolver();
    ctx10.generateSchema(outputResolver10);
    DynamicJAXBContext ctx11 = nodeIngestor.getContextForVersion(new SchemaVersion("v11"));
    // should work bc Foo.quantity is valid in test_network_v11 schema
    DynamicEntity foo11 = ctx11.newDynamicEntity("Foo");
    foo11.set("quantity", "12");
    assertEquals("12", foo11.get("quantity"));
    DynamicEntity quux11 = ctx11.newDynamicEntity("Quux");
    quux11.set("qManagerName", "some guy");
    assertEquals("some guy", quux11.get("qManagerName"));
    XSDOutputResolver outputResolver11 = new XSDOutputResolver();
    ctx11.generateSchema(outputResolver11);
    thrown.expect(IllegalArgumentException.class);
    // should fail bc Quux not in v10 test schema
    ctx10.newDynamicEntity("Quux");
}
Also used : DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) SchemaVersion(org.onap.aai.setup.SchemaVersion) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with DynamicJAXBContext

use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project aai-aai-common by onap.

the class NodeIngestorLocalTest method testCombinedSchema.

@Test
public void testCombinedSchema() throws TransformerException, IOException {
    DynamicJAXBContext ctx13 = nodeIngestor.getContextForVersion(new SchemaVersion("v13"));
    XSDOutputResolver outputResolver13 = new XSDOutputResolver();
    ctx13.generateSchema(outputResolver13);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    printDocument(nodeIngestor.getSchema(new SchemaVersion("v13")), buffer);
    String content = new String(Files.readAllBytes(Paths.get("src/test/resources/forWiringTests/aai_oxm_v13.xml")));
    content = content.replaceAll("\\s+", "");
    String expected = buffer.toString().replaceAll("\\s+", "");
    assertThat("OXM:\n" + expected, expected, is(content));
}
Also used : DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) SchemaVersion(org.onap.aai.setup.SchemaVersion) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with DynamicJAXBContext

use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project aai-aai-common by onap.

the class NodeIngestorTest method testCombinedSchema.

@Test
public void testCombinedSchema() throws TransformerException, IOException {
    DynamicJAXBContext ctx13 = nodeIngestor.getContextForVersion(new SchemaVersion("v13"));
    XSDOutputResolver outputResolver13 = new XSDOutputResolver();
    ctx13.generateSchema(outputResolver13);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    printDocument(nodeIngestor.getSchema(new SchemaVersion("v13")), buffer);
    String content = new String(Files.readAllBytes(Paths.get("src/test/resources/forWiringTests/aai_oxm_v13.xml")));
    content = content.replaceAll("\\s+", "");
    String expected = buffer.toString().replaceAll("\\s+", "");
    assertThat("OXM:\n" + expected, expected, is(content));
}
Also used : DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) SchemaVersion(org.onap.aai.setup.SchemaVersion) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

DynamicJAXBContext (org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext)44 DynamicEntity (org.eclipse.persistence.dynamic.DynamicEntity)32 InputStream (java.io.InputStream)21 HashMap (java.util.HashMap)17 Document (org.w3c.dom.Document)12 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)10 StreamSource (javax.xml.transform.stream.StreamSource)10 Source (javax.xml.transform.Source)8 JAXBException (jakarta.xml.bind.JAXBException)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 DocumentBuilder (javax.xml.parsers.DocumentBuilder)6 DOMSource (javax.xml.transform.dom.DOMSource)6 SchemaVersion (org.onap.aai.setup.SchemaVersion)6 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Element (org.w3c.dom.Element)5 JAXBElement (jakarta.xml.bind.JAXBElement)4 Map (java.util.Map)4 DynamicException (org.eclipse.persistence.exceptions.DynamicException)4