use of com.emc.storageos.api.service.utils.DummyDBClient in project coprhd-controller by CoprHD.
the class DbEventRetrieverTest method meteringServiceDBExceptionsTestJSON.
@Test
public void meteringServiceDBExceptionsTestJSON() throws WebApplicationException, IOException, JAXBException {
deleteIfExists(JsonTestOutputFile);
DummyDBClient dbClient = new DummyDBClient();
MonitoringService eventResource = new MonitoringService();
DbEventRetriever dummyDbStatRetriever = new DbEventRetriever();
dummyDbStatRetriever.setDbClient(dbClient);
eventResource.setEventRetriever(dummyDbStatRetriever);
DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_JSON_TYPE);
Response r = eventResource.getEvents("2012-01-04T00: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(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(10, events.events.size());
deleteIfExists(JsonTestOutputFile);
}
use of com.emc.storageos.api.service.utils.DummyDBClient 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();
}
}
use of com.emc.storageos.api.service.utils.DummyDBClient 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();
}
}
use of com.emc.storageos.api.service.utils.DummyDBClient in project coprhd-controller by CoprHD.
the class DbStatRetrieverTest method xmlStatEmptyTimeBucketArgumentTest.
@Test
public void xmlStatEmptyTimeBucketArgumentTest() throws WebApplicationException, IOException, JAXBException {
deleteIfExists(XmlTestOutputFile);
DummyDBClient dbClient = new DummyDBClient();
MeteringService statResource = new MeteringService();
statResource.setDbClient(dbClient);
DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
try {
statResource.getStats("", header);
Assert.fail("Expected a BadRequestException");
} catch (BadRequestException e) {
Assert.assertEquals(ServiceCode.API_PARAMETER_INVALID_TIME_FORMAT, e.getServiceCode());
}
}
Aggregations