Search in sources :

Example 1 with XMLEventMarshaller

use of com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller in project coprhd-controller by CoprHD.

the class XMLEventMarshallerTest method testXmlEventMarshallingForNullEvent.

@Test
public void testXmlEventMarshallingForNullEvent() throws URISyntaxException, IOException, MarshallingExcetion, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    XMLEventMarshaller jm = new XMLEventMarshaller();
    Event evt = null;
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
    jm.header(writer);
    jm.marshal(evt, writer);
    jm.tailer(writer);
    writer.close();
    JAXBContext context = null;
    Unmarshaller unmarshaller = null;
    context = JAXBContext.newInstance(Event.class);
    unmarshaller = context.createUnmarshaller();
    File f = new File(XmlTestOutputFile);
    try {
        @SuppressWarnings("unused") Event event = (Event) unmarshaller.unmarshal(f);
    } catch (Exception e) {
        Assert.assertTrue(e.toString().contains("java.io.FileNotFoundException"));
    }
    deleteIfExists(XmlTestOutputFile);
}
Also used : XMLEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller) OutputStream(java.io.OutputStream) Event(com.emc.storageos.db.client.model.Event) OutputStreamWriter(java.io.OutputStreamWriter) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 2 with XMLEventMarshaller

use of com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller in project coprhd-controller by CoprHD.

the class XMLStatMarshallerTest method testXmlStatMarshallingForNullEvent.

@Test
public void testXmlStatMarshallingForNullEvent() throws URISyntaxException, IOException, MarshallingExcetion, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    XMLEventMarshaller jm = new XMLEventMarshaller();
    Event evt = null;
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
    jm.header(writer);
    jm.marshal(evt, writer);
    jm.tailer(writer);
    writer.close();
    JAXBContext context = null;
    Unmarshaller unmarshaller = null;
    context = JAXBContext.newInstance(Event.class);
    unmarshaller = context.createUnmarshaller();
    File f = new File(XmlTestOutputFile);
    try {
        @SuppressWarnings("unused") Event event = (Event) unmarshaller.unmarshal(f);
    } catch (Exception e) {
        Assert.assertTrue(e.toString().contains("java.io.FileNotFoundException"));
    }
    deleteIfExists(XmlTestOutputFile);
}
Also used : XMLEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller) OutputStream(java.io.OutputStream) Event(com.emc.storageos.db.client.model.Event) OutputStreamWriter(java.io.OutputStreamWriter) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 3 with XMLEventMarshaller

use of com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller in project coprhd-controller by CoprHD.

the class XMLEventMarshallerTest method testXmlEventMarshalling.

@Test
public void testXmlEventMarshalling() throws URISyntaxException, IOException, MarshallingExcetion, JAXBException {
    XMLEventMarshaller xm = new XMLEventMarshaller();
    Event e = new Event();
    e.setEventId("eid1");
    e.setTenantId(new URI("http://tenant.1"));
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
    xm.marshal(e, writer);
    writer.close();
    FileWriter fileWriter = new FileWriter(XmlTestOutputFile);
    fileWriter.write(output.toString());
    fileWriter.close();
    JAXBContext context = null;
    Unmarshaller unmarshaller = null;
    context = JAXBContext.newInstance(Event.class);
    unmarshaller = context.createUnmarshaller();
    File f = new File(XmlTestOutputFile);
    Event event = (Event) unmarshaller.unmarshal(f);
    Assert.assertEquals("eid1", event.getEventId().toString());
    Assert.assertEquals("http://tenant.1", event.getTenantId().toString());
    deleteIfExists(XmlTestOutputFile);
}
Also used : XMLEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) Event(com.emc.storageos.db.client.model.Event) OutputStreamWriter(java.io.OutputStreamWriter) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) URI(java.net.URI) File(java.io.File) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 4 with XMLEventMarshaller

use of com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller in project coprhd-controller by CoprHD.

the class XMLEventMarshallerTest method testXmlEventMarshallingForIOExceptions.

@Test
public void testXmlEventMarshallingForIOExceptions() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(XmlTestOutputFile);
    XMLEventMarshaller jm = new XMLEventMarshaller();
    Event evt = new Event();
    evt.setEventId("eid1");
    evt.setTenantId(new URI("http://tenant.1"));
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    try {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
        writer.close();
        jm.header(writer);
    } catch (MarshallingExcetion e) {
        Assert.assertTrue(e.toString().contains("XML head Streaming failed"));
    }
    try {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
        writer.close();
        jm.marshal(evt, writer);
    } catch (MarshallingExcetion e) {
        Assert.assertTrue(e.toString().contains("XML Streaming Error"));
    }
    try {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
        writer.close();
        jm.tailer(writer);
    } catch (MarshallingExcetion e) {
        Assert.assertTrue(e.toString().contains("XML tail Streaming failed"));
    }
    deleteIfExists(XmlTestOutputFile);
}
Also used : MarshallingExcetion(com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion) XMLEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller) OutputStream(java.io.OutputStream) Event(com.emc.storageos.db.client.model.Event) OutputStreamWriter(java.io.OutputStreamWriter) URI(java.net.URI) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 5 with XMLEventMarshaller

use of com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller in project coprhd-controller by CoprHD.

the class DummyEventRetriever method getBulkEvents.

@Override
public void getBulkEvents(DateTime time, TimeSeriesMetadata.TimeBucket bucket, MediaType type, Writer writer) throws MarshallingExcetion {
    EventMarshaller marshaller = null;
    if (type == MediaType.APPLICATION_XML_TYPE) {
        marshaller = new XMLEventMarshaller();
    } else if (type == MediaType.APPLICATION_JSON_TYPE) {
        marshaller = new JSONEventMarshaller();
    }
    marshaller.header(writer);
    List<Event> events = null;
    try {
        events = getDummyEvents();
    } catch (URISyntaxException e) {
        _logger.error("Error getting events", e);
    }
    for (Event event : events) {
        if (type == MediaType.APPLICATION_XML_TYPE) {
            marshaller.marshal(event, writer);
        } else if (type == MediaType.APPLICATION_JSON_TYPE) {
            marshaller.marshal(event, writer);
        }
    }
    marshaller.tailer(writer);
}
Also used : XMLEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller) JSONEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller) Event(com.emc.storageos.db.client.model.Event) JSONEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller) XMLEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller) EventMarshaller(com.emc.storageos.api.service.impl.resource.utils.EventMarshaller) URISyntaxException(java.net.URISyntaxException)

Aggregations

XMLEventMarshaller (com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller)6 Event (com.emc.storageos.db.client.model.Event)5 BufferedWriter (java.io.BufferedWriter)4 OutputStream (java.io.OutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 Test (org.junit.Test)4 File (java.io.File)3 URISyntaxException (java.net.URISyntaxException)3 JAXBContext (javax.xml.bind.JAXBContext)3 Unmarshaller (javax.xml.bind.Unmarshaller)3 JSONEventMarshaller (com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller)2 IOException (java.io.IOException)2 URI (java.net.URI)2 JAXBException (javax.xml.bind.JAXBException)2 EventMarshaller (com.emc.storageos.api.service.impl.resource.utils.EventMarshaller)1 MarshallingExcetion (com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion)1 MonitoringEventQueryResult (com.emc.storageos.api.service.impl.resource.utils.MonitoringEventQueryResult)1 FileWriter (java.io.FileWriter)1