Search in sources :

Example 6 with DummyDBClient

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();
}
Also used : MarshallingExcetion(com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion) DbAuditLogRetriever(com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever) MediaType(javax.ws.rs.core.MediaType) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) AuditLogRequest(com.emc.storageos.security.audit.AuditLogRequest) Test(org.junit.Test)

Example 7 with DummyDBClient

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);
}
Also used : AuditLogs(com.emc.storageos.api.service.utils.AuditLogs) JAXBContext(javax.xml.bind.JAXBContext) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) MarshallingExcetion(com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion) DbAuditLogRetriever(com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever) MediaType(javax.ws.rs.core.MediaType) Unmarshaller(javax.xml.bind.Unmarshaller) AuditLogRequest(com.emc.storageos.security.audit.AuditLogRequest) Test(org.junit.Test)

Example 8 with DummyDBClient

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();
}
Also used : MarshallingExcetion(com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion) DbAuditLogRetriever(com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever) MediaType(javax.ws.rs.core.MediaType) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) AuditLogRequest(com.emc.storageos.security.audit.AuditLogRequest) RetryableDatabaseException(com.emc.storageos.db.exceptions.RetryableDatabaseException) Test(org.junit.Test)

Example 9 with DummyDBClient

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();
    }
}
Also used : Response(javax.ws.rs.core.Response) DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) StreamingOutput(javax.ws.rs.core.StreamingOutput) DbEventRetriever(com.emc.storageos.api.service.impl.resource.utils.DbEventRetriever) MonitoringService(com.emc.storageos.api.service.impl.resource.MonitoringService) File(java.io.File) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) Test(org.junit.Test)

Example 10 with DummyDBClient

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);
}
Also used : DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) 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) Events(com.emc.storageos.api.service.utils.Events) FileOutputStream(java.io.FileOutputStream) DbEventRetriever(com.emc.storageos.api.service.impl.resource.utils.DbEventRetriever) Unmarshaller(javax.xml.bind.Unmarshaller) MonitoringService(com.emc.storageos.api.service.impl.resource.MonitoringService) File(java.io.File) Test(org.junit.Test)

Aggregations

DummyDBClient (com.emc.storageos.api.service.utils.DummyDBClient)14 Test (org.junit.Test)14 DummyHttpHeaders (com.emc.storageos.api.service.utils.DummyHttpHeaders)10 Response (javax.ws.rs.core.Response)8 StreamingOutput (javax.ws.rs.core.StreamingOutput)8 File (java.io.File)7 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 MonitoringService (com.emc.storageos.api.service.impl.resource.MonitoringService)5 DbAuditLogRetriever (com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever)5 DbEventRetriever (com.emc.storageos.api.service.impl.resource.utils.DbEventRetriever)5 MeteringService (com.emc.storageos.api.service.impl.resource.MeteringService)4 MarshallingExcetion (com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion)4 AuditLogRequest (com.emc.storageos.security.audit.AuditLogRequest)4 MediaType (javax.ws.rs.core.MediaType)4 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)3 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)3 JAXBContext (javax.xml.bind.JAXBContext)3 Unmarshaller (javax.xml.bind.Unmarshaller)3 DbStatRetriever (com.emc.storageos.api.service.impl.resource.utils.DbStatRetriever)2