Search in sources :

Example 1 with DynamicJAXBContext

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

the class StoreNotificationEventTest method testStoreDynamicEventAAIException.

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

Example 2 with DynamicJAXBContext

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

the class NodeIngestorTest method testGetContextForVersion.

@Test
public void testGetContextForVersion() {
    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 3 with DynamicJAXBContext

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

the class OxmModelLoader method loadModel.

private static synchronized void loadModel(String version, String resourceName, InputStream inputStream) throws JAXBException, IOException {
    Map<String, Object> properties = new HashMap<>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, inputStream);
    final DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromOXM(Thread.currentThread().getContextClassLoader(), properties);
    versionContextMap.put(version, jaxbContext);
    LOGGER.info(OxmModelLoaderMsgs.LOADED_OXM_FILE, resourceName);
}
Also used : DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 4 with DynamicJAXBContext

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

the class NodeIngestor method translateAll.

private void translateAll(Translator translator) throws ExceptionInInitializerError {
    if (translator instanceof ConfigTranslator) {
        this.localSchema = "true";
    }
    Boolean retrieveLocalSchema = Boolean.parseBoolean(this.localSchema);
    /*
         * Set this to default schemaVersion
         */
    this.schemaVersions = translator.getSchemaVersions();
    List<SchemaVersion> schemaVersionList = translator.getSchemaVersions().getVersions();
    try {
        for (SchemaVersion version : schemaVersionList) {
            LOGGER.debug("Version being processed" + version);
            List<InputStream> inputStreams = retrieveOXM(version, translator);
            LOGGER.debug("Retrieved OXMs from SchemaService");
            /*
                 * IOUtils.copy and copy the inputstream
                 */
            if (inputStreams.isEmpty()) {
                continue;
            }
            final DynamicJAXBContext ctx = ingest(inputStreams);
            versionContextMap.put(version, ctx);
            setAllTypesAndProperties(version, inputStreams);
            schemaPerVersion.put(version, createCombinedSchema(inputStreams, version, retrieveLocalSchema));
        }
    } catch (JAXBException | ParserConfigurationException | SAXException | IOException e) {
        throw new ExceptionInInitializerError(e);
    }
}
Also used : SchemaVersion(org.onap.aai.setup.SchemaVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigTranslator(org.onap.aai.setup.ConfigTranslator)

Example 5 with DynamicJAXBContext

use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project eclipselink by eclipse-ee4j.

the class DynamicJAXBFromSessionsXMLTestCases method testSecondProject.

public void testSecondProject() throws Exception {
    // Ensure that the second project's descriptor is also available from this context
    DynamicEntity emp = ((DynamicJAXBContext) jaxbContext).newDynamicEntity(EMP_CLASS_NAME);
    assertNotNull("Could not instantiate Descriptor from second project.", emp);
}
Also used : DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity)

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