Search in sources :

Example 1 with JSONStatMarshaller

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

the class JSONStatMarshallerTest method testJsonStatMarshalling.

@Test
public void testJsonStatMarshalling() throws JsonParseException, JsonMappingException, IOException {
    deleteIfExists(JsonTestOutputFile);
    JSONStatMarshaller jMarshaller = new JSONStatMarshaller();
    Stat st = new Stat();
    long smbSize = 10000000;
    st.setSmdSize(smbSize);
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    PrintWriter writer = new PrintWriter(output);
    jMarshaller.marshall(st, writer);
    writer.close();
    FileWriter fileWriter = new FileWriter(JsonTestOutputFile);
    fileWriter.write(output.toString());
    fileWriter.close();
    ObjectMapper mapper = null;
    mapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    mapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
    Stat stat = mapper.readValue(new File(JsonTestOutputFile), Stat.class);
    Assert.assertEquals("10000000", stat.getSmdSize().toString());
    deleteIfExists(JsonTestOutputFile);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) JSONStatMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONStatMarshaller) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with JSONStatMarshaller

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

the class JSONStatMarshallerTest method testJsonStatMarshallingForNullEvent.

@Test
public void testJsonStatMarshallingForNullEvent() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(JsonTestOutputFile);
    JSONStatMarshaller jm = new JSONStatMarshaller();
    Stat st = null;
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    PrintWriter writer = new PrintWriter(output);
    jm.header(writer);
    jm.marshall(st, writer);
    jm.tailer(writer);
    writer.close();
    FileWriter fileWriter = new FileWriter(JsonTestOutputFile);
    fileWriter.write(output.toString());
    fileWriter.close();
    ObjectMapper mapper = null;
    mapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    mapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
    try {
        @SuppressWarnings("unused") Stat stat = mapper.readValue(new File(JsonTestOutputFile), Stat.class);
    } catch (UnrecognizedPropertyException e) {
        Assert.assertTrue(e.toString().contains("Unrecognized"));
    }
    deleteIfExists(JsonTestOutputFile);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) UnrecognizedPropertyException(org.codehaus.jackson.map.exc.UnrecognizedPropertyException) JSONStatMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONStatMarshaller) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with JSONStatMarshaller

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

the class JSONStatMarshallerTest method testJsonStatMarshallingForError.

@Test
public void testJsonStatMarshallingForError() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(JsonTestOutputFile);
    JSONStatMarshaller jm = new JSONStatMarshaller();
    Stat st = new Stat();
    st.setTenant(new URI("http://tenant.1"));
    st.setProject(new URI("http://project.1"));
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    PrintWriter writer = new PrintWriter(output);
    String error = "someerror";
    jm.error(writer, error);
    writer.close();
    Assert.assertTrue(output.toString().contains("{ \"error\": [" + "someerror" + "] }"));
    deleteIfExists(JsonTestOutputFile);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) OutputStream(java.io.OutputStream) JSONStatMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONStatMarshaller) URI(java.net.URI) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

JSONStatMarshaller (com.emc.storageos.api.service.impl.resource.utils.JSONStatMarshaller)3 Stat (com.emc.storageos.db.client.model.Stat)3 OutputStream (java.io.OutputStream)3 PrintWriter (java.io.PrintWriter)3 Test (org.junit.Test)3 File (java.io.File)2 FileWriter (java.io.FileWriter)2 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)2 URI (java.net.URI)1 UnrecognizedPropertyException (org.codehaus.jackson.map.exc.UnrecognizedPropertyException)1