Search in sources :

Example 1 with XMLStatMarshaller

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

the class XMLStatMarshallerTest method testXmlStatMarshallingForError.

@Test
public void testXmlStatMarshallingForError() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(XmlTestOutputFile);
    XMLStatMarshaller xm = new XMLStatMarshaller();
    Stat stat = new Stat();
    stat.setTenant(new URI("http://tenant.1"));
    stat.setTenant(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";
    xm.error(writer, error);
    writer.close();
    Assert.assertTrue(output.toString().contains("<stats>" + "someerror" + "</stats>"));
    deleteIfExists(XmlTestOutputFile);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) OutputStream(java.io.OutputStream) URI(java.net.URI) XMLStatMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLStatMarshaller) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with XMLStatMarshaller

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

the class XMLStatMarshallerTest method testXmlStatMarshalling.

@Test
public void testXmlStatMarshalling() throws MarshallingExcetion, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    XMLStatMarshaller xmlMarshaller = new XMLStatMarshaller();
    Stat st = new Stat();
    String svcType = "block";
    st.setServiceType(svcType);
    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);
    xmlMarshaller.marshall(st, writer);
    writer.close();
    FileWriter fileWriter = new FileWriter(XmlTestOutputFile);
    fileWriter.write(output.toString());
    fileWriter.close();
    JAXBContext context = null;
    Unmarshaller unmarshaller = null;
    context = JAXBContext.newInstance(Stat.class);
    unmarshaller = context.createUnmarshaller();
    File f = new File(XmlTestOutputFile);
    Stat stat = (Stat) unmarshaller.unmarshal(f);
    Assert.assertEquals("block", stat.getServiceType().toString());
    deleteIfExists(XmlTestOutputFile);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) XMLStatMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLStatMarshaller) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

XMLStatMarshaller (com.emc.storageos.api.service.impl.resource.utils.XMLStatMarshaller)2 Stat (com.emc.storageos.db.client.model.Stat)2 OutputStream (java.io.OutputStream)2 PrintWriter (java.io.PrintWriter)2 Test (org.junit.Test)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 URI (java.net.URI)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1