This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new e4583bf CAMEL-14126: Fixed test e4583bf is described below commit e4583bf4df910475b33ff14d1f58a1cd3191b060 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Nov 19 10:44:30 2019 +0100 CAMEL-14126: Fixed test --- .../component/stax/IssueWithWrongEncodingTest.java | 28 +++++++++++++++++++--- .../src/test/resources/products_with_non_utf8.xml | 27 --------------------- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/components/camel-stax/src/test/java/org/apache/camel/component/stax/IssueWithWrongEncodingTest.java b/components/camel-stax/src/test/java/org/apache/camel/component/stax/IssueWithWrongEncodingTest.java index 3c3c314..1e4c3f8 100644 --- a/components/camel-stax/src/test/java/org/apache/camel/component/stax/IssueWithWrongEncodingTest.java +++ b/components/camel-stax/src/test/java/org/apache/camel/component/stax/IssueWithWrongEncodingTest.java @@ -17,6 +17,8 @@ package org.apache.camel.component.stax; import java.io.File; +import java.io.FileOutputStream; +import java.nio.charset.StandardCharsets; import org.apache.camel.Exchange; import org.apache.camel.RoutesBuilder; @@ -29,6 +31,17 @@ import static org.apache.camel.component.stax.StAXBuilder.stax; public class IssueWithWrongEncodingTest extends CamelTestSupport { + private static final String XML_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<products>\n" + + " <product>\n" + + " <name>first product "; + + private static final String XML_2 = "</name>\n" + + " </product>\n" + + " <product>\n" + + " <name>second product</name>\n" + + " </product>\n" + + "</products>"; + @Override public void setUp() throws Exception { deleteDirectory("target/encoding"); @@ -48,10 +61,19 @@ public class IssueWithWrongEncodingTest extends CamelTestSupport { @Test public void testInvalidEncoding() throws Exception { getMockEndpoint("mock:result").expectedMessageCount(0); - getMockEndpoint("mock:result").expectedFileExists("target/encoding/error/products_with_non_utf8.xml"); + getMockEndpoint("mock:result").expectedFileExists("target/encoding/error/invalid.xml"); - File file = new File("src/test/resources/products_with_non_utf8.xml"); - template.sendBodyAndHeader("file:target/encoding", file, Exchange.FILE_NAME, "products_with_non_utf8.xml"); + File file = new File("target/encoding/invalid.xml"); + FileOutputStream fos = new FileOutputStream(file, false); + fos.write(XML_1.getBytes(StandardCharsets.UTF_8)); + // thai elephant is 4 bytes + fos.write(0xF0); + fos.write(0x9F); + fos.write(0x90); + // lets force an error by only have 3 bytes + // fos.write(0x98); + fos.write(XML_2.getBytes(StandardCharsets.UTF_8)); + fos.close(); assertMockEndpointsSatisfied(); } diff --git a/components/camel-stax/src/test/resources/products_with_non_utf8.xml b/components/camel-stax/src/test/resources/products_with_non_utf8.xml deleted file mode 100755 index a523ee8..0000000 --- a/components/camel-stax/src/test/resources/products_with_non_utf8.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<products> - <product> - <name>first product ��</name> - </product> - <product> - <name>second product</name> - </product> -</products> \ No newline at end of file