Search in sources :

Example 1 with DbAuditLogRetriever

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

the class DbAuditLogRetrieverTest method auditServiceDBExceptionsTestJSON.

@Test
public void auditServiceDBExceptionsTestJSON() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(JsonTestOutputFile);
    DummyDBClient dbClient = new DummyDBClient();
    DbAuditLogRetriever dummyDbAuditLogRetriever = new DbAuditLogRetriever();
    dummyDbAuditLogRetriever.setDbClient(dbClient);
    String timeBucket = "2012-01-07T00";
    DateTime startTime = new DateTime(timeBucket, DateTimeZone.UTC);
    DateTime endTime = startTime.plusMinutes(59);
    AuditLogRequest auditLogRequest = new AuditLogRequest.Builder().timeBucket(timeBucket).start(startTime).end(endTime).lang("en_US").build();
    MediaType mediaType = MediaType.APPLICATION_JSON_TYPE;
    File of = new File(JsonTestOutputFile);
    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();
    ObjectMapper mapper = null;
    mapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    mapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
    AuditLogs auditLogs = mapper.readValue(new File(JsonTestOutputFile), AuditLogs.class);
    Assert.assertEquals(10, auditLogs.auditLogs.size());
    deleteIfExists(JsonTestOutputFile);
}
Also used : AuditLogs(com.emc.storageos.api.service.utils.AuditLogs) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) DateTime(org.joda.time.DateTime) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) 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) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) AuditLogRequest(com.emc.storageos.security.audit.AuditLogRequest) Test(org.junit.Test)

Example 2 with DbAuditLogRetriever

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

the class DbAuditLogRetrieverTest method auditServiceNullDBclientTestXML.

@Test
public void auditServiceNullDBclientTestXML() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = null;
    AuditService auditResource = new AuditService();
    DbAuditLogRetriever dummyDbAuditLogRetriever = new DbAuditLogRetriever();
    dummyDbAuditLogRetriever.setDbClient(dbClient);
    auditResource.setAuditLogRetriever(dummyDbAuditLogRetriever);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
    Response r = auditResource.getAuditLogs("2012-01-05T00:00", "en_US", 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("DB"));
    }
    os.close();
}
Also used : Response(javax.ws.rs.core.Response) DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) DbAuditLogRetriever(com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) StreamingOutput(javax.ws.rs.core.StreamingOutput) AuditService(com.emc.storageos.api.service.impl.resource.AuditService) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) Test(org.junit.Test)

Example 3 with DbAuditLogRetriever

use of com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever 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 4 with DbAuditLogRetriever

use of com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever 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 5 with DbAuditLogRetriever

use of com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever 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)

Aggregations

DbAuditLogRetriever (com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever)5 DummyDBClient (com.emc.storageos.api.service.utils.DummyDBClient)5 Test (org.junit.Test)5 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 AuditLogs (com.emc.storageos.api.service.utils.AuditLogs)2 AuditService (com.emc.storageos.api.service.impl.resource.AuditService)1 DummyHttpHeaders (com.emc.storageos.api.service.utils.DummyHttpHeaders)1 RetryableDatabaseException (com.emc.storageos.db.exceptions.RetryableDatabaseException)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 Response (javax.ws.rs.core.Response)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)1 DateTime (org.joda.time.DateTime)1