@Test public void test_transform_anno_types_defined() { org.switchyard.transform.Transformer transformer = TransformerUtil.newTransformer( TestTransformer.class, QName.valueOf("X"), QName.valueOf("Y")); Assert.assertTrue(!(transformer instanceof TestTransformer)); Assert.assertEquals("Y", transformer.transform("X")); }
@Test public void test_listNSdTransformations() { List<TransformerTypes> transformTypes = TransformerUtil.listTransformations(NSdTestTransformer.class); Assert.assertEquals(1, transformTypes.size()); Assert.assertEquals(new QName("http://b", "B"), transformTypes.get(0).getFrom()); Assert.assertEquals(new QName("http://a", "A"), transformTypes.get(0).getTo()); }
@Test public void test_transform_anno_no_types_defined() { org.switchyard.transform.Transformer transformer = TransformerUtil.newTransformer( TestTransformer.class, JavaService.toMessageType(B.class), JavaService.toMessageType(A.class)); Assert.assertTrue(!(transformer instanceof TestTransformer)); Assert.assertTrue(transformer.transform(new B()) instanceof A); }
@Test public void test_transform_interface_impl() { org.switchyard.transform.Transformer transformer = TransformerUtil.newTransformer( TestTransformer.class, JavaService.toMessageType(A.class), JavaService.toMessageType(B.class)); Assert.assertTrue(transformer instanceof TestTransformer); Assert.assertTrue(transformer.transform(new A()) instanceof B); }
@Test public void test_transform_unknown() { try { TransformerUtil.newTransformer( TestTransformer.class, QName.valueOf("AAA"), QName.valueOf("BBB")); Assert.fail("Expected Exception"); } catch (RuntimeException e) { Assert.assertEquals( "Error constructing Transformer instance for class 'org.switchyard.transform.config.model.TransformerUtilTest$TestTransformer'. " + "Class does not support a transformation from type 'AAA' to type 'BBB'.", e.getMessage()); } }
@Test public void test_listTransformations() { List<TransformerTypes> transformTypes = TransformerUtil.listTransformations(TestTransformer.class); Assert.assertEquals(5, transformTypes.size()); Assert.assertEquals(QName.valueOf("X"), transformTypes.get(0).getFrom()); Assert.assertEquals(QName.valueOf("Y"), transformTypes.get(0).getTo()); Assert.assertEquals(QName.valueOf("Z"), transformTypes.get(1).getFrom()); Assert.assertEquals(JavaService.toMessageType(A.class), transformTypes.get(1).getTo()); Assert.assertEquals(JavaService.toMessageType(A.class), transformTypes.get(2).getFrom()); Assert.assertEquals(JavaService.toMessageType(B.class), transformTypes.get(2).getTo()); Assert.assertEquals(JavaService.toMessageType(B.class), transformTypes.get(3).getFrom()); Assert.assertEquals(QName.valueOf("Z"), transformTypes.get(3).getTo()); Assert.assertEquals(JavaService.toMessageType(B.class), transformTypes.get(4).getFrom()); Assert.assertEquals(JavaService.toMessageType(A.class), transformTypes.get(4).getTo()); }