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);
}
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();
}
}
Aggregations