You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2015/03/02 06:58:48 UTC
[1/4] camel git commit: CAMEL-8356 corrections to default charset
Repository: camel
Updated Branches:
refs/heads/camel-2.14.x 7ecd45225 -> 8db720c62
CAMEL-8356 corrections to default charset
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7f6538cb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7f6538cb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7f6538cb
Branch: refs/heads/camel-2.14.x
Commit: 7f6538cb1b30a80eef3f743d0f9e98b3e7b8f1bc
Parents: 7ecd452
Author: Stefan Mandel <ma...@gmail.com>
Authored: Sun Mar 1 12:26:15 2015 +0100
Committer: Stefan Mandel <ma...@gmail.com>
Committed: Sun Mar 1 12:32:55 2015 +0100
----------------------------------------------------------------------
.../org/apache/camel/converter/IOConverter.java | 2 +-
.../camel/converter/IOConverterCharsetTest.java | 41 ++++++++-
.../apache/camel/jsonpath/JsonPathEngine.java | 16 +++-
.../camel/jsonpath/JsonPathSourceTest.java | 94 ++++++++++++++++++++
.../test/resources/germanbooks-iso-8859-1.json | 23 +++++
.../src/test/resources/germanbooks-utf8.json | 23 +++++
6 files changed, 191 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7f6538cb/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java b/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
index cf33390..24a296f 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
@@ -80,7 +80,7 @@ public final class IOConverter {
public static InputStream toInputStream(File file, String charset) throws IOException {
if (charset != null) {
final BufferedReader reader = toReader(file, charset);
- final Charset defaultStreamCharset = Charset.forName("UTF-8");
+ final Charset defaultStreamCharset = Charset.defaultCharset();
return new InputStream() {
private ByteBuffer bufferBytes;
private CharBuffer bufferedChars = CharBuffer.allocate(4096);
http://git-wip-us.apache.org/repos/asf/camel/blob/7f6538cb/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java b/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
index fe74d75..52f2d10 100644
--- a/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
@@ -21,6 +21,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.lang.reflect.Field;
+import java.nio.charset.Charset;
import java.util.Arrays;
import org.apache.camel.ContextTestSupport;
@@ -29,10 +31,30 @@ public class IOConverterCharsetTest extends ContextTestSupport {
private static final String CONTENT = "G\u00f6tzend\u00e4mmerung,Joseph und seine Br\u00fcder";
public void testToInputStreamFileWithCharsetUTF8() throws Exception {
+ switchToDefaultCharset("UTF-8");
File file = new File("src/test/resources/org/apache/camel/converter/german.utf-8.txt");
InputStream in = IOConverter.toInputStream(file, "UTF-8");
- // need to specify the encoding of the input stream bytes
- BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
+ // do read with default charset!
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
+ try {
+ String line = reader.readLine();
+ String naiveLine = naiveReader.readLine();
+ assertEquals(naiveLine, line);
+ assertEquals(CONTENT, line);
+ } finally {
+ reader.close();
+ naiveReader.close();
+ }
+
+ }
+
+ public void testToInputStreamFileWithCharsetUTF8withOtherDefaultEncoding() throws Exception {
+ switchToDefaultCharset("ISO-8859-1");
+ File file = new File("src/test/resources/org/apache/camel/converter/german.utf-8.txt");
+ InputStream in = IOConverter.toInputStream(file, "UTF-8");
+ // do read with default charset!
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
try {
String line = reader.readLine();
@@ -47,10 +69,11 @@ public class IOConverterCharsetTest extends ContextTestSupport {
}
public void testToInputStreamFileWithCharsetLatin1() throws Exception {
+ switchToDefaultCharset("UTF-8");
File file = new File("src/test/resources/org/apache/camel/converter/german.iso-8859-1.txt");
InputStream in = IOConverter.toInputStream(file, "ISO-8859-1");
- // need to specify the encoding of the input stream bytes
- BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
+ // do read with default charset!
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "ISO-8859-1"));
try {
String line = reader.readLine();
@@ -64,6 +87,7 @@ public class IOConverterCharsetTest extends ContextTestSupport {
}
public void testToInputStreamFileDirectByteDumpWithCharsetLatin1() throws Exception {
+ switchToDefaultCharset("UTF-8");
File file = new File("src/test/resources/org/apache/camel/converter/german.iso-8859-1.txt");
InputStream in = IOConverter.toInputStream(file, "ISO-8859-1");
InputStream naiveIn = new FileInputStream(file);
@@ -109,4 +133,13 @@ public class IOConverterCharsetTest extends ContextTestSupport {
}
}
+
+ private void switchToDefaultCharset(String charset) {
+ try {
+ Field defaultCharset = Charset.class.getDeclaredField("defaultCharset");
+ defaultCharset.setAccessible(true);
+ defaultCharset.set(null, Charset.forName(charset));
+ } catch (Exception e) {
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7f6538cb/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
----------------------------------------------------------------------
diff --git a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
index 3616dbc..ccda30e 100644
--- a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
+++ b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
@@ -21,11 +21,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import com.jayway.jsonpath.Configuration;
-import com.jayway.jsonpath.JsonPath;
import org.apache.camel.Exchange;
import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.NoTypeConversionAvailableException;
import org.apache.camel.WrappedFile;
+import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.component.file.GenericFileConverter;
+
+import com.jayway.jsonpath.Configuration;
+import com.jayway.jsonpath.JsonPath;
public class JsonPathEngine {
@@ -40,7 +44,13 @@ public class JsonPathEngine {
public Object read(Exchange exchange) throws IOException, InvalidPayloadException {
Object json = exchange.getIn().getBody();
- if (json instanceof WrappedFile) {
+ if (json instanceof GenericFile) {
+ try {
+ json = GenericFileConverter.genericFileToInputStream(((GenericFile<?>) json), exchange);
+ } catch (NoTypeConversionAvailableException e) {
+ json = ((WrappedFile<?>) json).getFile();
+ }
+ } else if (json instanceof WrappedFile) {
json = ((WrappedFile<?>) json).getFile();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7f6538cb/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSourceTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSourceTest.java b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSourceTest.java
new file mode 100644
index 0000000..db0a273
--- /dev/null
+++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSourceTest.java
@@ -0,0 +1,94 @@
+/**
+ * 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.
+ */
+package org.apache.camel.jsonpath;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.nio.charset.Charset;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.file.FileConsumer;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class JsonPathSourceTest extends CamelTestSupport {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .transform().jsonpath("$.store.book[0].title", String.class)
+ .to("mock:title");
+
+ from("direct:second")
+ .transform().jsonpath("$.store.book[1].title", String.class)
+ .to("mock:title");
+ }
+ };
+ }
+
+ @Test
+ public void testPriceResultTypeOnGenericFileUTF8() throws Exception {
+ switchToDefaultCharset("UTF-8");
+ getMockEndpoint("mock:title").expectedMessageCount(2);
+ getMockEndpoint("mock:title").message(0).body().isEqualTo("Joseph und seine Brüder");
+ getMockEndpoint("mock:title").message(1).body().isEqualTo("Götzendämmerung");
+
+ template.sendBody("direct:start", FileConsumer.asGenericFile("src/test/resources/germanbooks-utf8.json", new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
+ template.sendBody("direct:second", FileConsumer.asGenericFile("src/test/resources/germanbooks-utf8.json", new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testPriceResultTypeOnGenericFileUTF8OnWindows() throws Exception {
+ switchToDefaultCharset("windows-1252");
+ getMockEndpoint("mock:title").expectedMessageCount(2);
+ getMockEndpoint("mock:title").message(0).body().isEqualTo("Joseph und seine Brüder");
+ getMockEndpoint("mock:title").message(1).body().isEqualTo("Götzendämmerung");
+
+ template.sendBody("direct:start", FileConsumer.asGenericFile("src/test/resources/germanbooks-utf8.json", new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
+ template.sendBody("direct:second", FileConsumer.asGenericFile("src/test/resources/germanbooks-utf8.json", new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testPriceResultTypeOnGenericFileISO88591() throws Exception {
+ switchToDefaultCharset("UTF-8");
+ getMockEndpoint("mock:title").expectedMessageCount(2);
+ getMockEndpoint("mock:title").message(0).body().isEqualTo("Joseph und seine Brüder");
+ getMockEndpoint("mock:title").message(1).body().isEqualTo("Götzendämmerung");
+
+ template.sendBody("direct:start", FileConsumer.asGenericFile("src/test/resources/germanbooks-iso-8859-1.json", new File("src/test/resources/germanbooks-iso-8859-1.json"), "ISO-8859-1"));
+ template.sendBody("direct:second", FileConsumer.asGenericFile("src/test/resources/germanbooks-iso-8859-1.json", new File("src/test/resources/germanbooks-iso-8859-1.json"), "ISO-8859-1"));
+
+ assertMockEndpointsSatisfied();
+ }
+
+ private void switchToDefaultCharset(String charset) {
+ try {
+ Field defaultCharset = Charset.class.getDeclaredField("defaultCharset");
+ defaultCharset.setAccessible(true);
+ defaultCharset.set(null, Charset.forName(charset));
+ } catch (Exception e) {
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/7f6538cb/components/camel-jsonpath/src/test/resources/germanbooks-iso-8859-1.json
----------------------------------------------------------------------
diff --git a/components/camel-jsonpath/src/test/resources/germanbooks-iso-8859-1.json b/components/camel-jsonpath/src/test/resources/germanbooks-iso-8859-1.json
new file mode 100644
index 0000000..74759da
--- /dev/null
+++ b/components/camel-jsonpath/src/test/resources/germanbooks-iso-8859-1.json
@@ -0,0 +1,23 @@
+{
+ "store": {
+ "book": [
+ {
+ "category": "novel",
+ "author": "Thomas Mann",
+ "title": "Joseph und seine Br�der",
+ "price": 25.00
+ },
+ {
+ "category": "fiction",
+ "author": "Friedrich Nietzsche",
+ "title": "G�tzend�mmerung",
+ "price": 9.00,
+ "isbn": "3-458-32522-0"
+ }
+ ],
+ "bicycle": {
+ "color": "red",
+ "price": 19.95
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/7f6538cb/components/camel-jsonpath/src/test/resources/germanbooks-utf8.json
----------------------------------------------------------------------
diff --git a/components/camel-jsonpath/src/test/resources/germanbooks-utf8.json b/components/camel-jsonpath/src/test/resources/germanbooks-utf8.json
new file mode 100644
index 0000000..ca84e6f
--- /dev/null
+++ b/components/camel-jsonpath/src/test/resources/germanbooks-utf8.json
@@ -0,0 +1,23 @@
+{
+ "store": {
+ "book": [
+ {
+ "category": "novel",
+ "author": "Thomas Mann",
+ "title": "Joseph und seine Brüder",
+ "price": 25.00
+ },
+ {
+ "category": "fiction",
+ "author": "Friedrich Nietzsche",
+ "title": "Götzendämmerung",
+ "price": 9.00,
+ "isbn": "3-458-32522-0"
+ }
+ ],
+ "bicycle": {
+ "color": "red",
+ "price": 19.95
+ }
+ }
+}
\ No newline at end of file
[2/4] camel git commit: Fixed the test error of HazelcastTest
Posted by ni...@apache.org.
Fixed the test error of HazelcastTest
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/79e38460
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/79e38460
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/79e38460
Branch: refs/heads/camel-2.14.x
Commit: 79e384600d4c6ca6f416888bca4af61cb42750bf
Parents: 7f6538c
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Mar 2 10:12:02 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Mar 2 10:12:20 2015 +0800
----------------------------------------------------------------------
.../java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/79e38460/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java
index 8ff20c8..d0636a1 100644
--- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java
+++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hazelcast/HazelcastTest.java
@@ -120,7 +120,7 @@ public class HazelcastTest extends OSGiIntegrationTestSupport {
Option[] options = combine(
getDefaultCamelKarafOptions(),
// using the features to install the other camel components
- loadCamelFeatures("camel-hazelcast"));
+ loadCamelFeatures("camel-script", "camel-hazelcast"));
return options;
}
[4/4] camel git commit: CAMEL-8346 Poilsh the test code
Posted by ni...@apache.org.
CAMEL-8346 Poilsh the test code
Conflicts:
components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSourceTest.java
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8db720c6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8db720c6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8db720c6
Branch: refs/heads/camel-2.14.x
Commit: 8db720c62449586eeba21ab21f66828f930e46bf
Parents: 81b4527
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Mar 2 13:37:40 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Mar 2 13:58:11 2015 +0800
----------------------------------------------------------------------
.../apache/camel/jsonpath/JsonPathEngine.java | 9 +-
.../camel/jsonpath/JsonPathSourceTest.java | 149 +++++++++++--------
2 files changed, 90 insertions(+), 68 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8db720c6/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
----------------------------------------------------------------------
diff --git a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
index ccda30e..c0fb720 100644
--- a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
+++ b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
@@ -20,6 +20,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.nio.charset.Charset;
import org.apache.camel.Exchange;
import org.apache.camel.InvalidPayloadException;
@@ -46,10 +47,10 @@ public class JsonPathEngine {
if (json instanceof GenericFile) {
try {
- json = GenericFileConverter.genericFileToInputStream(((GenericFile<?>) json), exchange);
- } catch (NoTypeConversionAvailableException e) {
- json = ((WrappedFile<?>) json).getFile();
- }
+ json = GenericFileConverter.genericFileToInputStream((GenericFile<?>)json, exchange);
+ } catch (NoTypeConversionAvailableException e) {
+ json = ((WrappedFile<?>)json).getFile();
+ }
} else if (json instanceof WrappedFile) {
json = ((WrappedFile<?>) json).getFile();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/8db720c6/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSourceTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSourceTest.java b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSourceTest.java
index db0a273..561db09 100644
--- a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSourceTest.java
+++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSourceTest.java
@@ -23,72 +23,93 @@ import java.nio.charset.Charset;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.file.FileConsumer;
import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.AfterClass;
import org.junit.Test;
-public class JsonPathSourceTest extends CamelTestSupport {
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .transform().jsonpath("$.store.book[0].title", String.class)
- .to("mock:title");
-
- from("direct:second")
- .transform().jsonpath("$.store.book[1].title", String.class)
- .to("mock:title");
- }
- };
- }
-
- @Test
- public void testPriceResultTypeOnGenericFileUTF8() throws Exception {
- switchToDefaultCharset("UTF-8");
- getMockEndpoint("mock:title").expectedMessageCount(2);
- getMockEndpoint("mock:title").message(0).body().isEqualTo("Joseph und seine Brüder");
- getMockEndpoint("mock:title").message(1).body().isEqualTo("Götzendämmerung");
-
- template.sendBody("direct:start", FileConsumer.asGenericFile("src/test/resources/germanbooks-utf8.json", new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
- template.sendBody("direct:second", FileConsumer.asGenericFile("src/test/resources/germanbooks-utf8.json", new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
-
- assertMockEndpointsSatisfied();
- }
-
- @Test
- public void testPriceResultTypeOnGenericFileUTF8OnWindows() throws Exception {
- switchToDefaultCharset("windows-1252");
- getMockEndpoint("mock:title").expectedMessageCount(2);
- getMockEndpoint("mock:title").message(0).body().isEqualTo("Joseph und seine Brüder");
- getMockEndpoint("mock:title").message(1).body().isEqualTo("Götzendämmerung");
-
- template.sendBody("direct:start", FileConsumer.asGenericFile("src/test/resources/germanbooks-utf8.json", new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
- template.sendBody("direct:second", FileConsumer.asGenericFile("src/test/resources/germanbooks-utf8.json", new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
-
- assertMockEndpointsSatisfied();
- }
-
- @Test
- public void testPriceResultTypeOnGenericFileISO88591() throws Exception {
- switchToDefaultCharset("UTF-8");
- getMockEndpoint("mock:title").expectedMessageCount(2);
- getMockEndpoint("mock:title").message(0).body().isEqualTo("Joseph und seine Brüder");
- getMockEndpoint("mock:title").message(1).body().isEqualTo("Götzendämmerung");
-
- template.sendBody("direct:start", FileConsumer.asGenericFile("src/test/resources/germanbooks-iso-8859-1.json", new File("src/test/resources/germanbooks-iso-8859-1.json"), "ISO-8859-1"));
- template.sendBody("direct:second", FileConsumer.asGenericFile("src/test/resources/germanbooks-iso-8859-1.json", new File("src/test/resources/germanbooks-iso-8859-1.json"), "ISO-8859-1"));
-
- assertMockEndpointsSatisfied();
- }
-
- private void switchToDefaultCharset(String charset) {
- try {
- Field defaultCharset = Charset.class.getDeclaredField("defaultCharset");
- defaultCharset.setAccessible(true);
- defaultCharset.set(null, Charset.forName(charset));
- } catch (Exception e) {
- }
- }
+public class JsonPathSourceTest extends CamelTestSupport {
+ private static final String MESSAGE1 = "Joseph und seine Br\u00fcder";
+ private static final String MESSAGE2 = "G\u00f6tzend\u00e4mmerung";
+ private static final Charset DEFAULT_CHARSET = Charset.defaultCharset();
+
+ @AfterClass
+ public static void setDefaultCharsetBack() {
+ switchToDefaultCharset(DEFAULT_CHARSET.displayName());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").transform().jsonpath("$.store.book[0].title", String.class)
+ .to("mock:title");
+
+ from("direct:second").transform().jsonpath("$.store.book[1].title", String.class)
+ .to("mock:title");
+ }
+ };
+ }
+
+ @Test
+ public void testPriceResultTypeOnGenericFileUTF8() throws Exception {
+ switchToDefaultCharset("UTF-8");
+ getMockEndpoint("mock:title").expectedMessageCount(2);
+ getMockEndpoint("mock:title").message(0).body().isEqualTo(MESSAGE1);
+ getMockEndpoint("mock:title").message(1).body().isEqualTo(MESSAGE2);
+
+ template.sendBody("direct:start", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-utf8.json",
+ new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
+ template.sendBody("direct:second", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-utf8.json",
+ new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testPriceResultTypeOnGenericFileUTF8OnWindows() throws Exception {
+ switchToDefaultCharset("windows-1252");
+ getMockEndpoint("mock:title").expectedMessageCount(2);
+ getMockEndpoint("mock:title").message(0).body().isEqualTo(MESSAGE1);
+ getMockEndpoint("mock:title").message(1).body().isEqualTo(MESSAGE2);
+
+ template.sendBody("direct:start", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-utf8.json",
+ new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
+ template.sendBody("direct:second", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-utf8.json",
+ new File("src/test/resources/germanbooks-utf8.json"), "UTF-8"));
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testPriceResultTypeOnGenericFileISO88591() throws Exception {
+ switchToDefaultCharset("ISO-8859-1");
+ getMockEndpoint("mock:title").expectedMessageCount(2);
+ getMockEndpoint("mock:title").message(0).body().isEqualTo(MESSAGE1);
+ getMockEndpoint("mock:title").message(1).body().isEqualTo(MESSAGE2);
+
+ template.sendBody("direct:start", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-iso-8859-1.json",
+ new File("src/test/resources/germanbooks-iso-8859-1.json"), "ISO-8859-1"));
+ template.sendBody("direct:second", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-iso-8859-1.json",
+ new File("src/test/resources/germanbooks-iso-8859-1.json"), "ISO-8859-1"));
+
+ assertMockEndpointsSatisfied();
+ }
+
+ private static void switchToDefaultCharset(String charset) {
+ try {
+ Field defaultCharset = Charset.class.getDeclaredField("defaultCharset");
+ defaultCharset.setAccessible(true);
+ defaultCharset.set(null, Charset.forName(charset));
+ } catch (Exception e) {
+ // Do nothing here
+ }
+ }
}
[3/4] camel git commit: CAMEL-8356 Polish the code
Posted by ni...@apache.org.
CAMEL-8356 Polish the code
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/81b4527d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/81b4527d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/81b4527d
Branch: refs/heads/camel-2.14.x
Commit: 81b4527dfe0619dc4020f39228284f134de3900b
Parents: 79e3846
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Mar 2 13:37:14 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Mar 2 13:44:57 2015 +0800
----------------------------------------------------------------------
.../camel/converter/IOConverterCharsetTest.java | 32 ++++++++++++--------
1 file changed, 20 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/81b4527d/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java b/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
index 52f2d10..b96175e 100644
--- a/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
@@ -29,9 +29,16 @@ import org.apache.camel.ContextTestSupport;
public class IOConverterCharsetTest extends ContextTestSupport {
private static final String CONTENT = "G\u00f6tzend\u00e4mmerung,Joseph und seine Br\u00fcder";
+ private static final Charset DEFAULT_CHARSET = Charset.defaultCharset();
+
+ // Just set the default charset back
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ switchToDefaultCharset(DEFAULT_CHARSET.displayName());
+ }
public void testToInputStreamFileWithCharsetUTF8() throws Exception {
- switchToDefaultCharset("UTF-8");
+ switchToDefaultCharset("UTF-8");
File file = new File("src/test/resources/org/apache/camel/converter/german.utf-8.txt");
InputStream in = IOConverter.toInputStream(file, "UTF-8");
// do read with default charset!
@@ -50,7 +57,7 @@ public class IOConverterCharsetTest extends ContextTestSupport {
}
public void testToInputStreamFileWithCharsetUTF8withOtherDefaultEncoding() throws Exception {
- switchToDefaultCharset("ISO-8859-1");
+ switchToDefaultCharset("ISO-8859-1");
File file = new File("src/test/resources/org/apache/camel/converter/german.utf-8.txt");
InputStream in = IOConverter.toInputStream(file, "UTF-8");
// do read with default charset!
@@ -69,7 +76,7 @@ public class IOConverterCharsetTest extends ContextTestSupport {
}
public void testToInputStreamFileWithCharsetLatin1() throws Exception {
- switchToDefaultCharset("UTF-8");
+ switchToDefaultCharset("UTF-8");
File file = new File("src/test/resources/org/apache/camel/converter/german.iso-8859-1.txt");
InputStream in = IOConverter.toInputStream(file, "ISO-8859-1");
// do read with default charset!
@@ -87,7 +94,7 @@ public class IOConverterCharsetTest extends ContextTestSupport {
}
public void testToInputStreamFileDirectByteDumpWithCharsetLatin1() throws Exception {
- switchToDefaultCharset("UTF-8");
+ switchToDefaultCharset("UTF-8");
File file = new File("src/test/resources/org/apache/camel/converter/german.iso-8859-1.txt");
InputStream in = IOConverter.toInputStream(file, "ISO-8859-1");
InputStream naiveIn = new FileInputStream(file);
@@ -134,12 +141,13 @@ public class IOConverterCharsetTest extends ContextTestSupport {
}
- private void switchToDefaultCharset(String charset) {
- try {
- Field defaultCharset = Charset.class.getDeclaredField("defaultCharset");
- defaultCharset.setAccessible(true);
- defaultCharset.set(null, Charset.forName(charset));
- } catch (Exception e) {
- }
- }
+ private void switchToDefaultCharset(String charset) {
+ try {
+ Field defaultCharset = Charset.class.getDeclaredField("defaultCharset");
+ defaultCharset.setAccessible(true);
+ defaultCharset.set(null, Charset.forName(charset));
+ } catch (Exception e) {
+ // Do nothing here
+ }
+ }
}