Search in sources :

Example 1 with DummyDBClient

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

the class DbEventRetrieverTest method meteringServiceNullDBclientTestXML.

@Test
public void meteringServiceNullDBclientTestXML() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = null;
    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("DB"));
    } 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 2 with DummyDBClient

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

the class DbStatRetrieverTest method xmlStatIllegalTimeBucketArgumentTest.

@Test
public void xmlStatIllegalTimeBucketArgumentTest() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = new DummyDBClient();
    MeteringService statResource = new MeteringService();
    statResource.setDbClient(dbClient);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
    try {
        statResource.getStats("xxxyyy", header);
        Assert.fail("Expected a BadRequestException");
    } catch (BadRequestException e) {
        Assert.assertEquals(ServiceCode.API_PARAMETER_INVALID_TIME_FORMAT, e.getServiceCode());
    }
}
Also used : DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) MeteringService(com.emc.storageos.api.service.impl.resource.MeteringService) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) Test(org.junit.Test)

Example 3 with DummyDBClient

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

the class DbStatRetrieverTest method meteringXmlServiceDBRetrieverTest.

@Test
public void meteringXmlServiceDBRetrieverTest() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = new DummyDBClient();
    MeteringService statResource = new MeteringService();
    // statResource.setDbClient(dbClient);
    DbStatRetriever dummyDbStatRetriever = new DbStatRetriever();
    dummyDbStatRetriever.setDbClient(dbClient);
    statResource.setStatRetriever(dummyDbStatRetriever);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
    Response r = statResource.getStats("2012-01-01T00: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(Stats.class);
    unmarshaller = context.createUnmarshaller();
    Object o = unmarshaller.unmarshal(new File(XmlTestOutputFile));
    Assert.assertTrue(o instanceof Stats);
    Stats stats = (Stats) o;
    // expected number of stats unmarshaled
    Assert.assertEquals(10, stats.stats.size());
    deleteIfExists(XmlTestOutputFile);
}
Also used : DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) DbStatRetriever(com.emc.storageos.api.service.impl.resource.utils.DbStatRetriever) 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) MeteringService(com.emc.storageos.api.service.impl.resource.MeteringService) FileOutputStream(java.io.FileOutputStream) Stats(com.emc.storageos.api.service.utils.Stats) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) Test(org.junit.Test)

Example 4 with DummyDBClient

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

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

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