Search in sources :

Example 16 with DummyHttpHeaders

use of com.emc.storageos.api.service.utils.DummyHttpHeaders 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 17 with DummyHttpHeaders

use of com.emc.storageos.api.service.utils.DummyHttpHeaders 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

DummyHttpHeaders (com.emc.storageos.api.service.utils.DummyHttpHeaders)17 Test (org.junit.Test)17 Response (javax.ws.rs.core.Response)15 StreamingOutput (javax.ws.rs.core.StreamingOutput)14 File (java.io.File)13 FileOutputStream (java.io.FileOutputStream)13 OutputStream (java.io.OutputStream)13 DummyDBClient (com.emc.storageos.api.service.utils.DummyDBClient)10 MonitoringService (com.emc.storageos.api.service.impl.resource.MonitoringService)8 MeteringService (com.emc.storageos.api.service.impl.resource.MeteringService)6 DbEventRetriever (com.emc.storageos.api.service.impl.resource.utils.DbEventRetriever)5 JAXBContext (javax.xml.bind.JAXBContext)5 Unmarshaller (javax.xml.bind.Unmarshaller)5 Events (com.emc.storageos.api.service.utils.Events)4 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)4 AuditService (com.emc.storageos.api.service.impl.resource.AuditService)3 EventRetriever (com.emc.storageos.api.service.impl.resource.utils.EventRetriever)3 DummyEventRetriever (com.emc.storageos.api.service.utils.DummyEventRetriever)3