use of com.emc.storageos.api.service.impl.resource.utils.EventRetriever in project coprhd-controller by CoprHD.
the class MonitoringServiceTest method testEventRetriverXML.
@Test
public void testEventRetriverXML() throws WebApplicationException, IOException, JAXBException {
deleteIfExists(XmlTestOutputFile);
EventRetriever eventRetriever = new DummyEventRetriever();
MonitoringService eventResource = new MonitoringService();
eventResource.setEventRetriever(eventRetriever);
DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
Response r = eventResource.getEvents("2012-05-05T00:00", header);
Assert.assertNotNull(r);
Assert.assertEquals(Status.OK.getStatusCode(), r.getStatus());
Assert.assertTrue(r.getEntity() instanceof StreamingOutput);
StreamingOutput so = (StreamingOutput) r.getEntity();
File of = new File(XmlTestOutputFile);
OutputStream os = new FileOutputStream(of);
so.write(os);
os.close();
JAXBContext context = null;
Unmarshaller unmarshaller = null;
context = JAXBContext.newInstance(Events.class);
unmarshaller = context.createUnmarshaller();
Object o = unmarshaller.unmarshal(new File(XmlTestOutputFile));
Assert.assertTrue(o instanceof Events);
Events events = (Events) o;
// expected number of events unmarshaled
Assert.assertEquals(100, events.events.size());
}
use of com.emc.storageos.api.service.impl.resource.utils.EventRetriever in project coprhd-controller by CoprHD.
the class MonitoringServiceTest method testEventRetriverJSON.
@Test
public void testEventRetriverJSON() throws WebApplicationException, IOException, JsonParseException {
deleteIfExists(JsonTestOutputFile);
EventRetriever eventRetriever = new DummyEventRetriever();
MonitoringService eventResource = new MonitoringService();
eventResource.setEventRetriever(eventRetriever);
DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_JSON_TYPE);
Response r = eventResource.getEvents("2012-05-05T00", header);
Assert.assertNotNull(r);
Assert.assertEquals(Status.OK.getStatusCode(), r.getStatus());
Assert.assertTrue(r.getEntity() instanceof StreamingOutput);
StreamingOutput so = (StreamingOutput) r.getEntity();
File of = new File(JsonTestOutputFile);
OutputStream os = new FileOutputStream(of);
try {
so.write(os);
} finally {
os.close();
}
ObjectMapper mapper = null;
mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
mapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
Events events = mapper.readValue(new File(JsonTestOutputFile), Events.class);
Assert.assertEquals(100, events.events.size());
}
use of com.emc.storageos.api.service.impl.resource.utils.EventRetriever in project coprhd-controller by CoprHD.
the class MonitoringServiceTest method testEventRetriverNonSupportedType.
@Test
public void testEventRetriverNonSupportedType() {
EventRetriever eventRetriever = new DummyEventRetriever();
MonitoringService eventResource = new MonitoringService();
eventResource.setEventRetriever(eventRetriever);
DummyHttpHeaders header = new DummyHttpHeaders(MediaType.TEXT_PLAIN_TYPE);
Response r = eventResource.getEvents("2012-05-05T00", header);
Assert.assertNotNull(r);
Assert.assertEquals(Status.OK.getStatusCode(), r.getStatus(), r.getStatus());
}
Aggregations