C32ToGreenCcdTransformerImpl implements C32ToGreenCcdTransformer { @Override public String TransformC32ToGreenCcd(String c32xml) throws C32ToGreenCcdTransformerException { Assert.hasText(c32xml); try { final String xslUrl = Thread.currentThread() .getContextClassLoader().getResource(XSLTURI).toString(); final Optional<URIResolver> uriResolver = Optional .of(new UriResolverImpl()); final String greenCcd = xmlTransformer.transform(c32xml, xslUrl, Optional.empty(), uriResolver); logger.debug("greenCcd:"); logger.debug(greenCcd); return greenCcd; } catch (final Exception e) { final String errorMessage = "Error happended when trying to transform C32 to Green CCD"; logger.error(errorMessage, e); final C32ToGreenCcdTransformerException transformerException = new C32ToGreenCcdTransformerException( errorMessage, e); throw transformerException; } } C32ToGreenCcdTransformerImpl(XmlTransformer xmlTransformer); @Override String TransformC32ToGreenCcd(String c32xml);  }
@Test(expected = IllegalArgumentException.class) public void testTransformC32ToGreenCcd_Given_Empty_C32Xml_Throws_IllegalArgumentException() throws Throwable { sut.TransformC32ToGreenCcd(""); }
@Test(expected = C32ToGreenCcdTransformerException.class) public void testTransformC32ToGreenCcd_Given_Invalid_C32Xml_Succeeds_IT() throws Throwable { ReflectionTestUtils.setField(sut, "xmlTransformer", createXmlTransformer()); final String c32 = "Invalid C32"; @SuppressWarnings("unused") final String greenCcd = sut.TransformC32ToGreenCcd(c32); }
@SuppressWarnings("unchecked") @Test(expected = C32ToGreenCcdTransformerException.class) public void testTransformC32ToGreenCcd_Given_Invalid_C32Xml_Succeeds_Unit() throws Throwable { final String c32 = "Invalid C32"; when( xmlTransformer.transform(eq(c32), anyString(), any(Optional.class), any(Optional.class))).thenThrow( DS4PException.class); @SuppressWarnings("unused") final String greenCcd = sut.TransformC32ToGreenCcd(c32); }
@Test(expected = IllegalArgumentException.class) public void testTransformC32ToGreenCcd_Given_NoText_C32Xml_Throws_IllegalArgumentException() throws Throwable { sut.TransformC32ToGreenCcd(" "); }
@Test(expected = IllegalArgumentException.class) public void testTransformC32ToGreenCcd_Given_Null_C32Xml_Throws_IllegalArgumentException() throws Throwable { sut.TransformC32ToGreenCcd(null); }
@Test public void testTransformC32ToGreenCcd_Given_Valid_C32Xml_Succeeds_IT() throws Throwable { ReflectionTestUtils.setField(sut, "xmlTransformer", createXmlTransformer()); final String c32FileUri = "c32.xml"; final String c32Xml = ResourceFileReader .getStringFromResourceFile(c32FileUri); final String greenCcd = sut.TransformC32ToGreenCcd(c32Xml); final String greenCcdFileUri = "green_ccd_transformed_from_c32.xml"; final String expectedGreenCcd = ResourceFileReader .getStringFromResourceFile(greenCcdFileUri); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); assertXMLEqual("", expectedGreenCcd, greenCcd); }
@SuppressWarnings("unchecked") @Test public void testTransformC32ToGreenCcd_Given_Valid_C32Xml_Succeeds_Unit() throws Throwable { final String greenCcdToReturn = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><greenCCD xmlns:xsi=\"http: final String c32FileUri = "c32.xml"; final String c32Xml = ResourceFileReader .getStringFromResourceFile(c32FileUri); when( xmlTransformer.transform(eq(c32Xml), anyString(), any(Optional.class), any(Optional.class))).thenReturn( greenCcdToReturn); final String greenCcd = sut.TransformC32ToGreenCcd(c32Xml); final String greenCcdFileUri = "green_ccd_transformed_from_c32.xml"; final String expectedGreenCcd = ResourceFileReader .getStringFromResourceFile(greenCcdFileUri); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); assertXMLEqual("", expectedGreenCcd, greenCcd); }