@Test public void testWithString() throws Exception { String docString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><item>one</item>"; StringSource source = (StringSource) sourceFactory.createSource(docString); BufferedReader reader = new BufferedReader(source.getReader()); String docAsString = reader.readLine(); assertThat(docAsString).isXmlEqualTo(docString); }
@Test public void testWithDocumentPayload() throws Exception { Source source = sourceFactory.createSource(doc); assertThat(source).isNotNull(); assertThat(source).isInstanceOf(DOMSource.class); assertThat(XmlTestUtil.sourceToString(source)).isXmlEqualTo(docContent); }
@Test public void testWithStringPayload() throws Exception { Source source = sourceFactory.createSource(docContent); assertThat(source).isNotNull(); assertThat(source).isInstanceOf(DOMSource.class); assertThat(XmlTestUtil.sourceToString(source)).isXmlEqualTo(docContent); }
@Test public void testConvertBytesToDocument() throws Exception { Document doc = converter.convertToDocument(TEST_DOCUMENT_AS_STRING.getBytes()); assertThat(XmlTestUtil.docToString(doc)).isXmlEqualTo(TEST_DOCUMENT_AS_STRING); }
@Test public void testWithDocument() throws Exception { String docString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><item>one</item>"; Document doc = XmlTestUtil.getDocumentForString(docString); StringSource source = (StringSource) sourceFactory.createSource(doc); BufferedReader reader = new BufferedReader(source.getReader()); String docAsString = reader.readLine(); assertThat(docAsString).isXmlEqualTo(docString); }
@Test public void testConvertStreamSourceToDocument() throws Exception { ClassPathResource resource = new ClassPathResource("org/springframework/integration/xml/customSource.data"); StreamSource source = new StreamSource(resource.getInputStream()); Document doc = converter.convertToDocument(source); assertThat(XmlTestUtil.docToString(doc)).isXmlEqualTo(TEST_DOCUMENT_AS_STRING); }
@Test public void testGetNodePassingDocument() throws Exception { Node n = converter.convertToNode(testDocument); assertThat(XmlTestUtil.docToString((Document) n)).isXmlEqualTo(TEST_DOCUMENT_AS_STRING); }
@Test public void testGetDocumentWithString() throws Exception { Document doc = converter.convertToDocument(TEST_DOCUMENT_AS_STRING); assertThat(XmlTestUtil.docToString(doc)).isXmlEqualTo(TEST_DOCUMENT_AS_STRING); }
@Test public void testGetNodePassingString() throws Exception { Node n = converter.convertToNode(TEST_DOCUMENT_AS_STRING); assertThat(XmlTestUtil.docToString((Document) n)).isXmlEqualTo(TEST_DOCUMENT_AS_STRING); }
@Test public void testConvertInputStreamToDocument() throws Exception { InputStream inputStream = new ClassPathResource("org/springframework/integration/xml/customSource.data") .getInputStream(); Document doc = converter.convertToDocument(inputStream); assertThat(XmlTestUtil.docToString(doc)).isXmlEqualTo(TEST_DOCUMENT_AS_STRING); }
@Test public void testWithDomResult() throws Exception { DOMResult result = XmlTestUtil.getDomResultForString(this.doc); Object transformed = transformer.transformResult(result); assertThat(transformed).isInstanceOf(String.class); String transformedString = (String) transformed; assertThat(transformedString).isXmlEqualTo(this.doc); }
@Test public void testWithStringResult() throws Exception { StringResult result = XmlTestUtil.getStringResultForString(doc); Object transformed = transformer.transformResult(result); assertThat(transformed).isInstanceOf(String.class); String transformedString = (String) transformed; assertThat(transformedString).isXmlEqualTo(this.doc); }
@Test public void testConvertFileToDocument() throws Exception { File file = new ClassPathResource("org/springframework/integration/xml/customSource.data").getFile(); Document doc = converter.convertToDocument(file); assertThat(XmlTestUtil.docToString(doc)).isXmlEqualTo(TEST_DOCUMENT_AS_STRING); }
@Test public void testConvertCustomSourceToDocument() throws Exception { Document doc = converter.convertToDocument(new MySource()); assertThat(XmlTestUtil.docToString(doc)).isXmlEqualTo(TEST_DOCUMENT_AS_STRING); }
@Test public void testStringAsPayload() throws Exception { Object transformed = this.transformer.doTransform(new GenericMessage<>(this.docAsString)); assertThat(transformed) .as("Wrong return type for document payload") .isInstanceOf(String.class); String transformedString = (String) transformed; assertThat(transformedString) .as("String incorrect after transform") .isXmlEqualTo(this.outputAsString); }
@Test public void testStringAsPayloadUseResultFactoryTrue() throws Exception { this.transformer.setAlwaysUseResultFactory(true); Object transformed = transformer.doTransform(new GenericMessage<>(this.docAsString)); assertThat(transformed) .as("Wrong return type for useFactories true") .isInstanceOf(DOMResult.class); DOMResult result = (DOMResult) transformed; assertThat(XmlTestUtil.docToString((Document) result.getNode())) .as("Document incorrect after transformation") .isXmlEqualTo(this.outputAsString); }
@Test public void testDocumentAsPayload() throws Exception { Message<?> message = new GenericMessage<>(XmlTestUtil.getDocumentForString(this.docAsString)); Object transformed = this.transformer.doTransform(message); assertThat(transformed) .as("Wrong return type for document payload") .isInstanceOf(Document.class); Document transformedDocument = (Document) transformed; assertThat(XmlTestUtil.docToString(transformedDocument)).isXmlEqualTo(this.outputAsString); }
@Test public void testSourceAsPayload() throws Exception { GenericMessage<?> message = new GenericMessage<>(new StringSource(this.docAsString)); Object transformed = transformer.doTransform(message); assertThat(transformed) .as("Wrong return type for document payload") .isInstanceOf(DOMResult.class); DOMResult result = (DOMResult) transformed; assertThat(XmlTestUtil.docToString((Document) result.getNode())) .as("Document incorrect after transformation") .isXmlEqualTo(this.outputAsString); }
@Test public void shouldCreateArrayFromExamples() { final Map<String, ArrayProperty> namedPropertyMap = propertyFrom(jsonSchemaSnippet); final Entry<String, ArrayProperty> namedProperty = namedPropertyMap.entrySet().iterator().next(); final String propertyName = namedProperty.getKey(); final ArrayProperty array = namedProperty.getValue(); final Document document = DocumentHelper.createDocument(); final Element parent = document.addElement("xsd:sequence", XmlSchemaHelper.XML_SCHEMA_NS); assertThat(UnifiedXmlDataShapeGenerator.determineArrayItemName(propertyName, array)).isEqualTo(arrayItemName); assertThat(UnifiedXmlDataShapeGenerator.determineArrayElementName(propertyName, array)).isEqualTo(arrayElementName); UnifiedXmlDataShapeGenerator.defineArrayElement(array, propertyName, parent, NO_SWAGGER, NO_MORE_SCHEMAS); assertThat(XmlSchemaHelper.serialize(document)).isXmlEqualTo(schema(xmlSchemaSnippet)); }
@Test public void shouldGenerateAtlasmapSchemaSetForUpdatePetRequest() throws IOException { final Operation swaggerOperation = swagger.getPaths().get(path).getOperationMap().get(operation); final DataShape shape = generator.createShapeFromRequest(json, swagger, swaggerOperation); final SoftAssertions softly = new SoftAssertions(); softly.assertThat(shape.getKind()).isEqualTo(DataShapeKinds.XML_SCHEMA); softly.assertThat(shape.getName()).isEqualTo("Request"); softly.assertThat(shape.getDescription()).isEqualTo("API request payload"); softly.assertThat(shape.getExemplar()).isNotPresent(); softly.assertAll(); final String expectedSpecification; try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream("/swagger/" + schemaset)) { expectedSpecification = IOUtils.toString(in, StandardCharsets.UTF_8); } final String specification = shape.getSpecification(); assertThat(specification).isXmlEqualTo(expectedSpecification); }