You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2018/11/08 15:00:20 UTC

[camel] 06/08: Fix failing test caused by using a static list of converters

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch sandbox/camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7c54a1bb69270078ce89e2547f30bc7a20da73ec
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Nov 8 10:27:40 2018 +0100

    Fix failing test caused by using a static list of converters
---
 .../apache/camel/builder/xml/XPathFeatureTest.java  | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java b/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java
index d78dbef..9ea4f24 100644
--- a/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java
+++ b/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java
@@ -17,6 +17,9 @@
 package org.apache.camel.builder.xml;
 
 import java.io.FileNotFoundException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
 
 import org.xml.sax.SAXParseException;
 
@@ -26,6 +29,7 @@ import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.TypeConversionException;
 import org.apache.camel.converter.jaxp.XmlConverter;
+import org.apache.camel.impl.converter.CoreStaticTypeConverterLoader;
 import org.junit.Test;
 
 import static org.apache.camel.builder.xml.XPathBuilder.xpath;
@@ -39,6 +43,23 @@ public class XPathFeatureTest extends ContextTestSupport {
             + " <!ELEMENT foo ANY > <!ENTITY xxe SYSTEM \"file:///bin/test.sh\" >]> <test> &xxe; </test><notwellformed>";
 
     @Override
+    public void setUp() throws Exception {
+        resetCoreConverters();
+        super.setUp();
+    }
+
+    private void resetCoreConverters() throws Exception {
+        Field field = CoreStaticTypeConverterLoader.class.getDeclaredField("INSTANCE");
+        field.setAccessible(true);
+        Field modifiersField = Field.class.getDeclaredField("modifiers");
+        modifiersField.setAccessible(true);
+        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+        Constructor<?> cns = CoreStaticTypeConverterLoader.class.getDeclaredConstructor();
+        cns.setAccessible(true);
+        field.set(null, cns.newInstance());
+    }
+
+    @Override
     public boolean isUseRouteBuilder() {
         return false;
     }