Search in sources :

Example 6 with MeteringService

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

the class MeteringServiceTest method testMeteringServiceJSON.

@Test
public void testMeteringServiceJSON() throws WebApplicationException, IOException, JsonParseException {
    deleteIfExists(JsonTestOutputFile);
    DummyStatRetriever dbStatRetriever = new DummyStatRetriever();
    MeteringService statResource = new MeteringService();
    statResource.setStatRetriever(dbStatRetriever);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_JSON_TYPE);
    Response r = statResource.getStats("2012-08-08T00", 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);
    Stats stats = mapper.readValue(new File(JsonTestOutputFile), Stats.class);
    Assert.assertEquals(100, stats.stats.size());
    deleteIfExists(JsonTestOutputFile);
}
Also used : Response(javax.ws.rs.core.Response) DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) MeteringService(com.emc.storageos.api.service.impl.resource.MeteringService) DummyStatRetriever(com.emc.storageos.api.service.utils.DummyStatRetriever) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) Stats(com.emc.storageos.api.service.utils.Stats) StreamingOutput(javax.ws.rs.core.StreamingOutput) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) Test(org.junit.Test)

Aggregations

MeteringService (com.emc.storageos.api.service.impl.resource.MeteringService)6 DummyHttpHeaders (com.emc.storageos.api.service.utils.DummyHttpHeaders)6 Test (org.junit.Test)6 DummyDBClient (com.emc.storageos.api.service.utils.DummyDBClient)4 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 OutputStream (java.io.OutputStream)4 Response (javax.ws.rs.core.Response)4 StreamingOutput (javax.ws.rs.core.StreamingOutput)4 Stats (com.emc.storageos.api.service.utils.Stats)3 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)3 DbStatRetriever (com.emc.storageos.api.service.impl.resource.utils.DbStatRetriever)2 DummyStatRetriever (com.emc.storageos.api.service.utils.DummyStatRetriever)2 JAXBContext (javax.xml.bind.JAXBContext)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 IOException (java.io.IOException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 JAXBException (javax.xml.bind.JAXBException)1 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1