Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
The BSD License Copyright (c) 2010-2012 RIPE NCC All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the RIPE NCC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 package net.ripe.rpki.commons.xml;
 
 import static org.junit.Assert.*;
 
 import org.junit.Test;
 
 
 
 
     @Test
     public void shouldCreateSerializer() {
         XStreamXmlSerializerBuilder<Stringbuilder = new XStreamXmlSerializerBuilder<String>(String.class);
         XStreamXmlSerializer<Stringserializer = builder.build();
 
         String serializedData = serializer.serialize("foo");
         Assert.assertEquals("<string>foo</string>"serializedData);
     }
 
     @Test
     public void shouldAliasCommonsPackage() {
         XStreamXmlSerializer<ValidityPeriodserializer = builder.build();
 
         String serializedData = serializer.serialize(new ValidityPeriod());
         Assert.assertEquals("<ValidityPeriod/>"serializedData);
     }
 
     @Test
     public void shouldAliasIpResourceAndUseConverter() {
         XStreamXmlSerializer<IpResourceserializer = builder.build();
         IpResource ipResource = IpResource.parse("10/8");
 
         String serializedData = serializer.serialize(ipResource);
         Assert.assertEquals("<resource>10.0.0.0/8</resource>"serializedData);
         assertEquals(ipResourceserializer.deserialize(serializedData));
     }
 
     @Test
     public void shouldAliasIpResourceSetAndUseConverter() {
         XStreamXmlSerializer<IpResourceSetserializer = builder.build();
         IpResourceSet ipResourceSet = IpResourceSet.parse("10/8");
 
         String serializedData = serializer.serialize(ipResourceSet);
         Assert.assertEquals("<resource-set>10.0.0.0/8</resource-set>"serializedData);
         assertEquals(ipResourceSetserializer.deserialize(serializedData));
     }
 
     @Test
     public void shouldAliasDateTimeAndUseConverter() {
        XStreamXmlSerializer<DateTimeserializer = builder.build();
        DateTime dateTime = new DateTime(2011, 1, 31, 13, 59, 59, 0, .);
        String serializedData = serializer.serialize(dateTime);
        Assert.assertEquals("<datetime>2011-01-31T13:59:59Z</datetime>"serializedData);
        assertEquals(dateTimeserializer.deserialize(serializedData));
    }
    @Test
    public void shouldConvertDateTimeFromTimeStamp() {
        XStreamXmlSerializer<Timestampserializer = builder.build();
        Timestamp timestamp = new Timestamp(new DateTime(2011, 1, 31, 13, 59, 59, 0, .).getMillis());
        String serializedData = serializer.serialize(timestamp);
        Assert.assertEquals("<sql-timestamp>2011-01-31T13:59:59.000Z</sql-timestamp>"serializedData);
        assertEquals(timestampserializer.deserialize(serializedData));
    }
    @Test
        XStreamXmlSerializer<Periodserializer = builder.build();
        DateTime now = new DateTime();
        Period period = new Period(nownow.plusHours(1));
        String serializedData = serializer.serialize(period);
        Assert.assertEquals("<org.joda.time.Period>PT1H</org.joda.time.Period>"serializedData);
        assertEquals(periodserializer.deserialize(serializedData));
    }
    @Test
    public void shouldAliasPrincipalAndUseConverter() {
        XStreamXmlSerializer<X500Principalserializer = builder.build();
        X500Principal principal = new X500Principal("CN=nl.bluelight");
        String serializedData = serializer.serialize(principal);
        Assert.assertEquals("<principal>CN=nl.bluelight</principal>"serializedData);
        assertEquals(principalserializer.deserialize(serializedData));
    }
    @Test
    public void shouldConvertVersionedId() {
        XStreamXmlSerializer<VersionedIdserializer = builder.build();
        VersionedId versionedId = new VersionedId(1l, 2l);
        String serializedData = serializer.serialize(versionedId);
        Assert.assertEquals("<versionedId>1:2</versionedId>"serializedData);
        assertEquals(versionedIdserializer.deserialize(serializedData));
    }
    @Test
    public void shouldConvertX509ResourceCertificate() {
        XStreamXmlSerializer<X509ResourceCertificateserializer = builder.build();
        X509ResourceCertificate resourceCertificate = X509ResourceCertificateTest.createSelfSignedCaResourceCertificate();
        String serializedData = serializer.serialize(resourceCertificate);
        Assert.assertTrue(Pattern.matches("<X509ResourceCertificate>\\s*<encoded>[^<]+</encoded>\\s*</X509ResourceCertificate>"serializedData));
        assertEquals(resourceCertificateserializer.deserialize(serializedData));
    }
    @Test
    public void shouldConvertManifestCms() {
        XStreamXmlSerializer<ManifestCmsserializer = builder.build();
        ManifestCms manifestCms = ManifestCmsTest.getRootManifestCms();
        String serializedData = serializer.serialize(manifestCms);
        Assert.assertTrue(Pattern.matches("<ManifestCms>\\s*<encoded>[^<]+</encoded>\\s*</ManifestCms>"serializedData));
        assertEquals(manifestCmsserializer.deserialize(serializedData));
    }
    @Test
    public void shouldConvertRoaCms() {
        XStreamXmlSerializer<RoaCmsserializer = builder.build();
        RoaCms roaCms = RoaCmsTest.getRoaCms();
        String serializedData = serializer.serialize(roaCms);
        Assert.assertTrue(Pattern.matches("<RoaCms>\\s*<encoded>[^<]+</encoded>\\s*</RoaCms>"serializedData));
        assertEquals(roaCmsserializer.deserialize(serializedData));
    }
    @Test
    public void shouldIgnoreUnknownElements() {
        XStreamXmlSerializer<Stringserializer = builder.build();
        String deserializedData = serializer.deserialize("<string>sample string</string><foo/>");
        Assert.assertEquals("sample string"deserializedData);
    }
    @Test
    public void shouldAliasPackage() {
        builder.withAliasPackage("test-alias"SerializeMe.class.getPackage().getName());
        XStreamXmlSerializer<SerializeMeserializer = builder.build();
        String serializedData = serializer.serialize(new SerializeMe());
        Assert.assertEquals("<test-alias.XStreamXmlSerializerBuilderTest_-SerializeMe/>"serializedData);
    }
    private static class SerializeMe {
    }
New to GrepCode? Check out our FAQ X