@Test public void testDeserializeZipArchiveSimple() throws Exception { // produce a zip archive containing a single serialized stream for this test. ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(baos); ZipArchiveEntry zipEntry = new ZipArchiveEntry(StreamId.APPLICATION_VERSION.name()); zipOut.putArchiveEntry(zipEntry); IOUtils.copy(APPLICATION_VERSION_1.getInputStream(), zipOut); zipOut.closeArchiveEntry(); zipOut.close(); state = new PackageState(); when(mockedMarshallerMap .get(StreamId.APPLICATION_VERSION) .getUnmarshaller() .unmarshal(any(Source.class))) .thenReturn(applicationVersion); ByteArrayInputStream zipIn = new ByteArrayInputStream(baos.toByteArray()); underTest.deserialize(state, StreamId.APPLICATION_VERSION, zipIn); assertNotNull(state.getCreationToolVersion()); assertEquals(applicationVersion, state.getCreationToolVersion()); verify(mockedMarshallerMap.get(StreamId.APPLICATION_VERSION).getUnmarshaller()) .unmarshal(any(Source.class)); }
private XStream configure(XStream x) { x.processAnnotations(PackageState.class); /* APPLICATION_VERSION */ x.alias( StreamId.APPLICATION_VERSION.name(), AbstractSerializationTest.TestObjects.applicationVersion.getClass()); PropertyDescriptor pd = SerializationAnnotationUtil.getStreamDescriptors(PackageState.class) .get(StreamId.APPLICATION_VERSION); x.registerLocalConverter(PackageState.class, pd.getName(), new ApplicationVersionConverter()); /* DOMAIN_PROFILE_LIST */ x.alias( StreamId.DOMAIN_PROFILE_LIST.name(), AbstractSerializationTest.TestObjects.domainProfileUris.getClass()); pd = SerializationAnnotationUtil.getStreamDescriptors(PackageState.class) .get(StreamId.DOMAIN_PROFILE_LIST); x.registerLocalConverter(PackageState.class, pd.getName(), new DomainProfileUriListConverter()); /* PACKAGE_METADATA */ x.alias( StreamId.PACKAGE_METADATA.name(), AbstractSerializationTest.TestObjects.packageMetadata.getClass()); pd = SerializationAnnotationUtil.getStreamDescriptors(PackageState.class) .get(StreamId.PACKAGE_METADATA); x.registerLocalConverter(PackageState.class, pd.getName(), new PackageMetadataConverter()); /* PACKAGE_NAME */ x.alias( StreamId.PACKAGE_NAME.name(), AbstractSerializationTest.TestObjects.packageName.getClass()); pd = SerializationAnnotationUtil.getStreamDescriptors(PackageState.class) .get(StreamId.PACKAGE_NAME); x.registerLocalConverter(PackageState.class, pd.getName(), new PackageNameConverter()); /* USER_SPECIFIED_PROPERTIES */ x.alias( StreamId.USER_SPECIFIED_PROPERTIES.name(), AbstractSerializationTest.TestObjects.userProperties.getClass()); pd = SerializationAnnotationUtil.getStreamDescriptors(PackageState.class) .get(StreamId.USER_SPECIFIED_PROPERTIES); x.registerLocalConverter(PackageState.class, pd.getName(), new UserPropertyConverter()); return x; }