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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations