Search in sources :

Example 1 with AuditLogs

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

the class AuditServiceTest method auditServiceTestJSON.

@Test
public void auditServiceTestJSON() throws WebApplicationException, IOException, JsonParseException {
    deleteIfExists(JsonTestOutputFile);
    DummyAuditLogRetriever dbAuditLogRetriever = new DummyAuditLogRetriever();
    AuditService auditResource = new AuditService();
    auditResource.setAuditLogRetriever(dbAuditLogRetriever);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_JSON_TYPE);
    Response r = auditResource.getAuditLogs("2012-08-08T00", "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(JsonTestOutputFile);
    OutputStream os = new FileOutputStream(of);
    so.write(os);
    os.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(100, auditLogs.auditLogs.size());
    deleteIfExists(JsonTestOutputFile);
}
Also used : DummyAuditLogRetriever(com.emc.storageos.api.service.utils.DummyAuditLogRetriever) Response(javax.ws.rs.core.Response) DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) AuditLogs(com.emc.storageos.api.service.utils.AuditLogs) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) StreamingOutput(javax.ws.rs.core.StreamingOutput) AuditService(com.emc.storageos.api.service.impl.resource.AuditService) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) Test(org.junit.Test)

Example 2 with AuditLogs

use of com.emc.storageos.api.service.utils.AuditLogs 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 3 with AuditLogs

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

the class AuditServiceTest method auditServiceTestXML.

@Test
public void auditServiceTestXML() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyAuditLogRetriever dbAuditLogRetriever = new DummyAuditLogRetriever();
    AuditService auditResource = new AuditService();
    auditResource.setAuditLogRetriever(dbAuditLogRetriever);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
    Response r = auditResource.getAuditLogs("2012-08-08T00: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);
    so.write(os);
    os.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 auditLogs unmarshaled
    Assert.assertEquals(100, auditLogs.auditLogs.size());
    deleteIfExists(XmlTestOutputFile);
}
Also used : DummyAuditLogRetriever(com.emc.storageos.api.service.utils.DummyAuditLogRetriever) Response(javax.ws.rs.core.Response) DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) AuditLogs(com.emc.storageos.api.service.utils.AuditLogs) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) AuditService(com.emc.storageos.api.service.impl.resource.AuditService) File(java.io.File) Test(org.junit.Test)

Example 4 with AuditLogs

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

Aggregations

AuditLogs (com.emc.storageos.api.service.utils.AuditLogs)4 Test (org.junit.Test)4 AuditService (com.emc.storageos.api.service.impl.resource.AuditService)2 DbAuditLogRetriever (com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever)2 MarshallingExcetion (com.emc.storageos.api.service.impl.resource.utils.MarshallingExcetion)2 DummyAuditLogRetriever (com.emc.storageos.api.service.utils.DummyAuditLogRetriever)2 DummyDBClient (com.emc.storageos.api.service.utils.DummyDBClient)2 DummyHttpHeaders (com.emc.storageos.api.service.utils.DummyHttpHeaders)2 AuditLogRequest (com.emc.storageos.security.audit.AuditLogRequest)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 MediaType (javax.ws.rs.core.MediaType)2 Response (javax.ws.rs.core.Response)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 JAXBContext (javax.xml.bind.JAXBContext)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)2