Search in sources :

Example 1 with EventRetriever

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());
}
Also used : DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) JAXBContext(javax.xml.bind.JAXBContext) Response(javax.ws.rs.core.Response) DummyEventRetriever(com.emc.storageos.api.service.utils.DummyEventRetriever) Events(com.emc.storageos.api.service.utils.Events) FileOutputStream(java.io.FileOutputStream) Unmarshaller(javax.xml.bind.Unmarshaller) MonitoringService(com.emc.storageos.api.service.impl.resource.MonitoringService) File(java.io.File) EventRetriever(com.emc.storageos.api.service.impl.resource.utils.EventRetriever) DummyEventRetriever(com.emc.storageos.api.service.utils.DummyEventRetriever) Test(org.junit.Test)

Example 2 with EventRetriever

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());
}
Also used : DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) StreamingOutput(javax.ws.rs.core.StreamingOutput) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) Response(javax.ws.rs.core.Response) DummyEventRetriever(com.emc.storageos.api.service.utils.DummyEventRetriever) Events(com.emc.storageos.api.service.utils.Events) FileOutputStream(java.io.FileOutputStream) MonitoringService(com.emc.storageos.api.service.impl.resource.MonitoringService) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) EventRetriever(com.emc.storageos.api.service.impl.resource.utils.EventRetriever) DummyEventRetriever(com.emc.storageos.api.service.utils.DummyEventRetriever) Test(org.junit.Test)

Example 3 with EventRetriever

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());
}
Also used : Response(javax.ws.rs.core.Response) DummyEventRetriever(com.emc.storageos.api.service.utils.DummyEventRetriever) DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) MonitoringService(com.emc.storageos.api.service.impl.resource.MonitoringService) EventRetriever(com.emc.storageos.api.service.impl.resource.utils.EventRetriever) DummyEventRetriever(com.emc.storageos.api.service.utils.DummyEventRetriever) Test(org.junit.Test)

Aggregations

MonitoringService (com.emc.storageos.api.service.impl.resource.MonitoringService)3 EventRetriever (com.emc.storageos.api.service.impl.resource.utils.EventRetriever)3 DummyEventRetriever (com.emc.storageos.api.service.utils.DummyEventRetriever)3 DummyHttpHeaders (com.emc.storageos.api.service.utils.DummyHttpHeaders)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 Events (com.emc.storageos.api.service.utils.Events)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)1