Search in sources :

Example 6 with DummyHttpHeaders

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

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

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

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

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

DummyHttpHeaders (com.emc.storageos.api.service.utils.DummyHttpHeaders)17 Test (org.junit.Test)17 Response (javax.ws.rs.core.Response)15 StreamingOutput (javax.ws.rs.core.StreamingOutput)14 File (java.io.File)13 FileOutputStream (java.io.FileOutputStream)13 OutputStream (java.io.OutputStream)13 DummyDBClient (com.emc.storageos.api.service.utils.DummyDBClient)10 MonitoringService (com.emc.storageos.api.service.impl.resource.MonitoringService)8 MeteringService (com.emc.storageos.api.service.impl.resource.MeteringService)6 DbEventRetriever (com.emc.storageos.api.service.impl.resource.utils.DbEventRetriever)5 JAXBContext (javax.xml.bind.JAXBContext)5 Unmarshaller (javax.xml.bind.Unmarshaller)5 Events (com.emc.storageos.api.service.utils.Events)4 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)4 AuditService (com.emc.storageos.api.service.impl.resource.AuditService)3 EventRetriever (com.emc.storageos.api.service.impl.resource.utils.EventRetriever)3 DummyEventRetriever (com.emc.storageos.api.service.utils.DummyEventRetriever)3