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

buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new b902794  testutils: cleanup
b902794 is described below

commit b902794f187035a6efe39e3632ccc7be0adc8a89
Author: Alexey Markevich <[email protected]>
AuthorDate: Wed Mar 24 00:59:15 2021 +0300

    testutils: cleanup
---
 .../cxf/aegis/standalone/StandaloneReadTest.java   | 58 ++++++++--------------
 .../java/org/apache/cxf/test/AbstractCXFTest.java  | 12 -----
 .../java/org/apache/cxf/test/TestUtilities.java    | 40 ---------------
 3 files changed, 21 insertions(+), 89 deletions(-)

diff --git 
a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/StandaloneReadTest.java
 
b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/StandaloneReadTest.java
index 99b2918..97b231b 100644
--- 
a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/StandaloneReadTest.java
+++ 
b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/StandaloneReadTest.java
@@ -19,10 +19,9 @@
 
 package org.apache.cxf.aegis.standalone;
 
-import java.util.ArrayList;
-import java.util.HashSet;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
-import java.util.Set;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
@@ -31,9 +30,8 @@ import org.apache.cxf.aegis.AegisContext;
 import org.apache.cxf.aegis.AegisReader;
 import org.apache.cxf.aegis.services.SimpleBean;
 import org.apache.cxf.aegis.type.AegisType;
-import org.apache.cxf.test.TestUtilities;
+import org.apache.cxf.staxutils.StaxUtils;
 
-import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -43,23 +41,17 @@ import static org.junit.Assert.assertTrue;
  *
  */
 public class StandaloneReadTest {
-    private AegisContext context;
-    private TestUtilities testUtilities;
+    private final AegisContext context = new AegisContext();
 
     private interface ListStringInterface {
         List<String> method();
     }
 
-    @Before
-    public void before() {
-        testUtilities = new TestUtilities(getClass());
-    }
-
     @Test
     public void testBasicTypeRead() throws Exception {
-        context = new AegisContext();
         context.initialize();
-        XMLStreamReader streamReader = 
testUtilities.getResourceAsXMLStreamReader("stringElement.xml");
+        XMLStreamReader streamReader =
+            
StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("stringElement.xml"));
         AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
         Object something = reader.read(streamReader);
         assertEquals("ball-of-yarn", something);
@@ -67,15 +59,12 @@ public class StandaloneReadTest {
 
     @Test
     public void testCollectionReadNoXsiType() throws Exception {
-        context = new AegisContext();
-        Set<java.lang.reflect.Type> roots = new HashSet<>();
         java.lang.reflect.Type listStringType
             = ListStringInterface.class.getMethods()[0].getGenericReturnType();
-        roots.add(listStringType);
-        context.setRootClasses(roots);
+        context.setRootClasses(Collections.singleton(listStringType));
         context.initialize();
         XMLStreamReader streamReader
-            = testUtilities.getResourceAsXMLStreamReader("topLevelList.xml");
+            = 
StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("topLevelList.xml"));
         AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
         // until I fix type mapping to use java.lang.reflect.Type instead of
         // Class, I need to do the following
@@ -83,31 +72,28 @@ public class StandaloneReadTest {
         AegisType aegisRegisteredType = 
context.getTypeMapping().getType(magicTypeQName);
 
         Object something = reader.read(streamReader, aegisRegisteredType);
-        List<String> correctAnswer = new ArrayList<>();
-        correctAnswer.add("cat");
-        correctAnswer.add("dog");
-        correctAnswer.add("hailstorm");
+        List<String> correctAnswer = Arrays.asList(
+            "cat",
+            "dog",
+            "hailstorm");
         assertEquals(correctAnswer, something);
     }
 
     @Test
     public void testCollectionReadXsiType() throws Exception {
-        context = new AegisContext();
-        Set<java.lang.reflect.Type> roots = new HashSet<>();
         java.lang.reflect.Type listStringType
             = ListStringInterface.class.getMethods()[0].getGenericReturnType();
-        roots.add(listStringType);
-        context.setRootClasses(roots);
+        context.setRootClasses(Collections.singleton(listStringType));
         context.initialize();
         XMLStreamReader streamReader
-            = 
testUtilities.getResourceAsXMLStreamReader("topLevelListWithXsiType.xml");
+            = 
StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("topLevelListWithXsiType.xml"));
         AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
 
         Object something = reader.read(streamReader);
-        List<String> correctAnswer = new ArrayList<>();
-        correctAnswer.add("cat");
-        correctAnswer.add("dog");
-        correctAnswer.add("hailstorm");
+        List<String> correctAnswer = Arrays.asList(
+            "cat",
+            "dog",
+            "hailstorm");
         assertEquals(correctAnswer, something);
     }
 
@@ -115,17 +101,15 @@ public class StandaloneReadTest {
     // test using a .aegis.xml
     @Test
     public void testSimpleBeanRead() throws Exception {
-        context = new AegisContext();
-        Set<java.lang.reflect.Type> rootClasses = new HashSet<>();
-        rootClasses.add(SimpleBean.class);
-        context.setRootClasses(rootClasses);
+        context.setRootClasses(Collections.singleton(SimpleBean.class));
         context.initialize();
         XMLStreamReader streamReader =
-            testUtilities.getResourceAsXMLStreamReader("simpleBean1.xml");
+            
StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("simpleBean1.xml"));
         AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
         Object something = reader.read(streamReader);
         assertTrue(something instanceof SimpleBean);
         SimpleBean simpleBean = (SimpleBean) something;
         assertEquals("howdy", simpleBean.getHowdy());
     }
+
 }
diff --git a/testutils/src/main/java/org/apache/cxf/test/AbstractCXFTest.java 
b/testutils/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
index 78ae3cd..13a8118 100644
--- a/testutils/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
+++ b/testutils/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
@@ -94,12 +94,6 @@ public abstract class AbstractCXFTest {
         return testUtilities.invoke(address, transport, message);
     }
 
-    protected Node invoke(String address,
-                          String transport,
-                          byte[] message) throws Exception {
-        return testUtilities.invoke(address, transport, message);
-    }
-
     /**
      * Assert that the following XPath query selects one or more nodes.
      *
@@ -200,10 +194,4 @@ public abstract class AbstractCXFTest {
         return testUtilities.getWSDLDocument(server);
     }
 
-    public static class TestMessageObserver extends 
TestUtilities.TestMessageObserver {
-
-        public TestMessageObserver() {
-            super();
-        }
-    }
 }
diff --git a/testutils/src/main/java/org/apache/cxf/test/TestUtilities.java 
b/testutils/src/main/java/org/apache/cxf/test/TestUtilities.java
index bbb7cb5..8dec5e1 100644
--- a/testutils/src/main/java/org/apache/cxf/test/TestUtilities.java
+++ b/testutils/src/main/java/org/apache/cxf/test/TestUtilities.java
@@ -37,9 +37,6 @@ import javax.wsdl.WSDLException;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLWriter;
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
 
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
@@ -74,7 +71,6 @@ public class TestUtilities {
     private static String basedirPath;
     protected Bus bus;
     protected Class<?> classpathAnchor;
-    private XMLInputFactory xmlInputFactory;
 
     /**
      * Namespaces for the XPath expressions.
@@ -91,7 +87,6 @@ public class TestUtilities {
      */
     public TestUtilities(Class<?> classpathReference) {
         classpathAnchor = classpathReference;
-        xmlInputFactory = XMLInputFactory.newInstance();
     }
 
     public static void setKeepAliveSystemProperty(boolean setAlive) {
@@ -232,43 +227,12 @@ public class TestUtilities {
         return obs.getResponseStream().toByteArray();
     }
 
-    public byte[] invokeBytes(String address, String transport, byte[] 
message) throws Exception {
-        EndpointInfo ei = new EndpointInfo(null, 
"http://schemas.xmlsoap.org/soap/http";);
-        ei.setAddress(address);
-
-        ConduitInitiatorManager conduitMgr = 
getBus().getExtension(ConduitInitiatorManager.class);
-        ConduitInitiator conduitInit = 
conduitMgr.getConduitInitiator(transport);
-        Conduit conduit = conduitInit.getConduit(ei, getBus());
-
-        TestMessageObserver obs = new TestMessageObserver();
-        conduit.setMessageObserver(obs);
-
-        Message m = new MessageImpl();
-        conduit.prepare(m);
-
-        OutputStream os = m.getContent(OutputStream.class);
-        os.write(message);
-
-        // TODO: shouldn't have to do this. IO caching needs cleaning
-        // up or possibly removal...
-        os.flush();
-        os.close();
-
-        return obs.getResponseStream().toByteArray();
-    }
-
     public Node invoke(String address, String transport, String message) 
throws Exception {
         byte[] bs = invokeBytes(address, transport, message);
 
         ByteArrayInputStream input = new ByteArrayInputStream(bs);
         return StaxUtils.read(input);
     }
-    public Node invoke(String address, String transport, byte[] message) 
throws Exception {
-        byte[] bs = invokeBytes(address, transport, message);
-
-        ByteArrayInputStream input = new ByteArrayInputStream(bs);
-        return StaxUtils.read(input);
-    }
 
     public InputStream getResourceAsStream(String resource) {
         return classpathAnchor.getResourceAsStream(resource);
@@ -278,10 +242,6 @@ public class TestUtilities {
         return new InputStreamReader(getResourceAsStream(resource), UTF_8);
     }
 
-    public XMLStreamReader getResourceAsXMLStreamReader(String resource) 
throws XMLStreamException {
-        return 
xmlInputFactory.createXMLStreamReader(getResourceAsStream(resource));
-    }
-
     public File getTestFile(String relativePath) {
         return new File(getBasedir(), relativePath);
     }

Reply via email to