Search in sources :

Example 6 with Event

use of com.emc.storageos.db.client.model.Event 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 7 with Event

use of com.emc.storageos.db.client.model.Event 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 8 with Event

use of com.emc.storageos.db.client.model.Event 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 9 with Event

use of com.emc.storageos.db.client.model.Event in project coprhd-controller by CoprHD.

the class DummyEventRetriever method getDummyEvents.

private List<Event> getDummyEvents() throws URISyntaxException {
    // @TODO - dummy events at the moment.
    List<Event> elist = new ArrayList<Event>();
    for (int i = 0; i < 100; i++) {
        Event e = new Event();
        e.setEventId(String.valueOf(i));
        e.setDescription("Test Event " + e.getEventId());
        e.setProjectId(new URI("http://p." + e.getEventId()));
        e.setTenantId(new URI("http://t." + e.getEventId()));
        e.setUserId(new URI("http://u." + e.getEventId()));
        e.setVirtualPool(new URI("http://vpool.gold"));
        e.setExtensions("");
        e.setEventType("some type");
        e.setResourceId(new URI("http://r." + e.getEventId()));
        e.setEventSource("Some Source");
        e.setOperationalStatusCodes("Test Codes");
        e.setOperationalStatusDescriptions("Test Descriptions");
        // e._time = new DateTime().toString();
        elist.add(e);
    }
    return elist;
}
Also used : ArrayList(java.util.ArrayList) Event(com.emc.storageos.db.client.model.Event) URI(java.net.URI)

Example 10 with Event

use of com.emc.storageos.db.client.model.Event 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

Event (com.emc.storageos.db.client.model.Event)14 Test (org.junit.Test)9 BufferedWriter (java.io.BufferedWriter)7 OutputStream (java.io.OutputStream)7 OutputStreamWriter (java.io.OutputStreamWriter)7 URI (java.net.URI)6 XMLEventMarshaller (com.emc.storageos.api.service.impl.resource.utils.XMLEventMarshaller)5 File (java.io.File)5 JSONEventMarshaller (com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller)4 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 MarshallingExcetion (com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion)3 Constraint (com.emc.storageos.db.client.constraint.Constraint)3 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 FileWriter (java.io.FileWriter)3 JAXBContext (javax.xml.bind.JAXBContext)3 Unmarshaller (javax.xml.bind.Unmarshaller)3 DbClient (com.emc.storageos.db.client.DbClient)2 AggregatedConstraint (com.emc.storageos.db.client.constraint.AggregatedConstraint)2 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)2