use of com.emc.storageos.api.service.utils.DummyDBClient in project coprhd-controller by CoprHD.
the class DbAuditLogRetrieverTest method auditServiceMarshallingExceptionsTestXML.
@Test
public void auditServiceMarshallingExceptionsTestXML() throws WebApplicationException, IOException, JAXBException {
deleteIfExists(XmlTestOutputFile);
DummyDBClient dbClient = new DummyDBClient();
DbAuditLogRetriever dummyDbAuditLogRetriever = new DbAuditLogRetriever();
dummyDbAuditLogRetriever.setDbClient(dbClient);
String timeBucket = "2012-01-08T00";
AuditLogRequest auditLogRequest = getAuditLogRequest(timeBucket);
MediaType mediaType = MediaType.APPLICATION_XML_TYPE;
File of = new File(XmlTestOutputFile);
OutputStream os = new FileOutputStream(of);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(os));
try {
dummyDbAuditLogRetriever.getBulkAuditLogs(auditLogRequest, mediaType, out);
} catch (MarshallingExcetion e) {
Assert.assertTrue(true);
}
out.close();
}
use of com.emc.storageos.api.service.utils.DummyDBClient in project coprhd-controller by CoprHD.
the class DbAuditLogRetrieverTest method auditServiceDBRetrieverTestXML.
@Test
public void auditServiceDBRetrieverTestXML() throws WebApplicationException, IOException, JAXBException {
deleteIfExists(XmlTestOutputFile);
DummyDBClient dbClient = new DummyDBClient();
DbAuditLogRetriever dummyDbAuditLogRetriever = new DbAuditLogRetriever();
dummyDbAuditLogRetriever.setDbClient(dbClient);
String timeBucket = "2012-01-07T00";
AuditLogRequest auditLogRequest = getAuditLogRequest(timeBucket);
MediaType mediaType = MediaType.APPLICATION_XML_TYPE;
File of = new File(XmlTestOutputFile);
OutputStream os = new FileOutputStream(of);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(os));
try {
dummyDbAuditLogRetriever.getBulkAuditLogs(auditLogRequest, mediaType, out);
} catch (MarshallingExcetion e) {
Assert.fail(e.getMessage());
}
out.close();
JAXBContext context = null;
Unmarshaller unmarshaller = null;
context = JAXBContext.newInstance(AuditLogs.class);
unmarshaller = context.createUnmarshaller();
Object o = unmarshaller.unmarshal(new File(XmlTestOutputFile));
Assert.assertTrue(o instanceof AuditLogs);
AuditLogs auditLogs = (AuditLogs) o;
// expected number of events unmarshaled
Assert.assertEquals(10, auditLogs.auditLogs.size());
deleteIfExists(XmlTestOutputFile);
}
use of com.emc.storageos.api.service.utils.DummyDBClient in project coprhd-controller by CoprHD.
the class DbAuditLogRetrieverTest method auditServiceDBExceptionsTestXML.
@Test
public void auditServiceDBExceptionsTestXML() throws WebApplicationException, IOException, JAXBException {
deleteIfExists(XmlTestOutputFile);
DummyDBClient dbClient = new DummyDBClient();
DbAuditLogRetriever dummyDbAuditLogRetriever = new DbAuditLogRetriever();
dummyDbAuditLogRetriever.setDbClient(dbClient);
String timeBucket = "2012-01-02T00";
AuditLogRequest auditLogRequest = getAuditLogRequest(timeBucket);
MediaType mediaType = MediaType.APPLICATION_XML_TYPE;
File of = new File(XmlTestOutputFile);
OutputStream os = new FileOutputStream(of);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(os));
try {
dummyDbAuditLogRetriever.getBulkAuditLogs(auditLogRequest, mediaType, out);
} catch (RetryableDatabaseException e) {
Assert.assertTrue(e.toString().contains("I/O"));
} catch (MarshallingExcetion e) {
Assert.fail(e.getMessage());
}
out.close();
}
use of com.emc.storageos.api.service.utils.DummyDBClient in project coprhd-controller by CoprHD.
the class DbEventRetrieverTest method meteringServiceDBExceptionsTestXML.
@Test
public void meteringServiceDBExceptionsTestXML() throws WebApplicationException, IOException, JAXBException {
deleteIfExists(XmlTestOutputFile);
DummyDBClient dbClient = new DummyDBClient();
MonitoringService eventResource = new MonitoringService();
// statResource.setDbClient(dbClient);
DbEventRetriever dummyDbStatRetriever = new DbEventRetriever();
dummyDbStatRetriever.setDbClient(dbClient);
eventResource.setEventRetriever(dummyDbStatRetriever);
DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
Response r = eventResource.getEvents("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 (InternalServerErrorException 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 DbEventRetrieverTest method monitoringServiceDBRetrieverTestXML.
@Test
public void monitoringServiceDBRetrieverTestXML() throws WebApplicationException, IOException, JAXBException {
deleteIfExists(XmlTestOutputFile);
DummyDBClient dbClient = new DummyDBClient();
MonitoringService eventResource = new MonitoringService();
DbEventRetriever dummyDbStatRetriever = new DbEventRetriever();
dummyDbStatRetriever.setDbClient(dbClient);
eventResource.setEventRetriever(dummyDbStatRetriever);
DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_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(XmlTestOutputFile);
OutputStream os = new FileOutputStream(of);
try {
so.write(os);
} finally {
os.close();
}
JAXBContext context = null;
Unmarshaller unmarshaller = null;
context = JAXBContext.newInstance(Events.class);
unmarshaller = context.createUnmarshaller();
Object o = unmarshaller.unmarshal(new File(XmlTestOutputFile));
Assert.assertTrue(o instanceof Events);
Events events = (Events) o;
// expected number of events unmarshaled
Assert.assertEquals(10, events.events.size());
deleteIfExists(XmlTestOutputFile);
}
Aggregations