Search in sources :

Example 1 with DbStatRetriever

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

the class DbStatRetrieverTest method meteringXmlServiceDBRetrieverTest.

@Test
public void meteringXmlServiceDBRetrieverTest() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = new DummyDBClient();
    MeteringService statResource = new MeteringService();
    // statResource.setDbClient(dbClient);
    DbStatRetriever dummyDbStatRetriever = new DbStatRetriever();
    dummyDbStatRetriever.setDbClient(dbClient);
    statResource.setStatRetriever(dummyDbStatRetriever);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
    Response r = statResource.getStats("2012-01-01T00: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();
    }
    JAXBContext context = null;
    Unmarshaller unmarshaller = null;
    context = JAXBContext.newInstance(Stats.class);
    unmarshaller = context.createUnmarshaller();
    Object o = unmarshaller.unmarshal(new File(XmlTestOutputFile));
    Assert.assertTrue(o instanceof Stats);
    Stats stats = (Stats) o;
    // expected number of stats unmarshaled
    Assert.assertEquals(10, stats.stats.size());
    deleteIfExists(XmlTestOutputFile);
}
Also used : DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) DbStatRetriever(com.emc.storageos.api.service.impl.resource.utils.DbStatRetriever) StreamingOutput(javax.ws.rs.core.StreamingOutput) JAXBContext(javax.xml.bind.JAXBContext) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) Response(javax.ws.rs.core.Response) MeteringService(com.emc.storageos.api.service.impl.resource.MeteringService) FileOutputStream(java.io.FileOutputStream) Stats(com.emc.storageos.api.service.utils.Stats) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) Test(org.junit.Test)

Example 2 with DbStatRetriever

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

the class DbStatRetrieverTest method statXmlServiceDBExceptionsTest.

@Test
public void statXmlServiceDBExceptionsTest() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = new DummyDBClient();
    MeteringService statResource = new MeteringService();
    // statResource.setDbClient(dbClient);
    DbStatRetriever dummyDbStatRetriever = new DbStatRetriever();
    dummyDbStatRetriever.setDbClient(dbClient);
    statResource.setStatRetriever(dummyDbStatRetriever);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
    Response r = statResource.getStats("2012-01-02T00: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);
    } catch (Exception e) {
        Assert.assertTrue(e.toString().contains("I/O"));
    } finally {
        os.close();
    }
}
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) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) DbStatRetriever(com.emc.storageos.api.service.impl.resource.utils.DbStatRetriever) StreamingOutput(javax.ws.rs.core.StreamingOutput) File(java.io.File) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

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