Search in sources :

Example 6 with MonitoringService

use of com.emc.storageos.api.service.impl.resource.MonitoringService in project coprhd-controller by CoprHD.

the class DbEventRetrieverTest method meteringServiceMarshallingExceptionsTestXML.

@Test
public void meteringServiceMarshallingExceptionsTestXML() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = new DummyDBClient();
    MonitoringService eventResource = new MonitoringService();
    // statResource.setDbClient(dbClient);
    DbEventRetriever dummyDbStatRetriever = new DbEventRetriever();
    dummyDbStatRetriever.setQueryThreadCount(queryThreadCount);
    dummyDbStatRetriever.setDbClient(dbClient);
    eventResource.setEventRetriever(dummyDbStatRetriever);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
    Response r = eventResource.getEvents("2012-01-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);
    try {
        so.write(os);
    } finally {
        os.close();
    }
}
Also used : Response(javax.ws.rs.core.Response) DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) DbEventRetriever(com.emc.storageos.api.service.impl.resource.utils.DbEventRetriever) MonitoringService(com.emc.storageos.api.service.impl.resource.MonitoringService) File(java.io.File) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) Test(org.junit.Test)

Example 7 with MonitoringService

use of com.emc.storageos.api.service.impl.resource.MonitoringService 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 8 with MonitoringService

use of com.emc.storageos.api.service.impl.resource.MonitoringService 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)8 DummyHttpHeaders (com.emc.storageos.api.service.utils.DummyHttpHeaders)8 Response (javax.ws.rs.core.Response)8 Test (org.junit.Test)8 File (java.io.File)7 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 StreamingOutput (javax.ws.rs.core.StreamingOutput)7 DbEventRetriever (com.emc.storageos.api.service.impl.resource.utils.DbEventRetriever)5 DummyDBClient (com.emc.storageos.api.service.utils.DummyDBClient)5 Events (com.emc.storageos.api.service.utils.Events)4 EventRetriever (com.emc.storageos.api.service.impl.resource.utils.EventRetriever)3 DummyEventRetriever (com.emc.storageos.api.service.utils.DummyEventRetriever)3 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)2 JAXBContext (javax.xml.bind.JAXBContext)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)2