This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new dead61b Tests.
dead61b is described below
commit dead61b5d10b595746da25b6c694466cf3af5fcb
Author: JamesBognar <[email protected]>
AuthorDate: Thu Jun 25 16:33:13 2020 -0400
Tests.
---
.../java/org/apache/juneau/ComboRoundTripTest.java | 1 -
.../java/org/apache/juneau/ComboSerializeTest.java | 1 -
.../juneau/serializer/UriResolutionTest.java | 1 -
.../org/apache/juneau/testutils/TestUtils.java | 18 ----------
.../org/apache/juneau/utils/MethodInvokerTest.java | 8 ++---
.../juneau/utils/StackTraceDatabaseTest.java | 5 ++-
.../org/apache/juneau/internal/StringUtils.java | 30 ++++++++++++++++
.../juneau/microservice/testutils/TestUtils.java | 41 ---------------------
.../apache/juneau/rest/testutils/TestUtils.java | 42 ----------------------
.../juneau/rest/headers/AcceptEncodingTest.java | 18 +++++-----
.../juneau/rest/headers/ContentEncodingTest.java | 6 ++--
11 files changed, 48 insertions(+), 123 deletions(-)
diff --git
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java
index ad88e5a..b55b656 100644
---
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java
+++
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java
@@ -26,7 +26,6 @@ import org.apache.juneau.json.*;
import org.apache.juneau.msgpack.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.serializer.*;
-import org.apache.juneau.testutils.*;
import org.apache.juneau.uon.*;
import org.apache.juneau.urlencoding.*;
import org.apache.juneau.xml.*;
diff --git
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboSerializeTest.java
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboSerializeTest.java
index 4290aca..da1cba6 100644
---
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboSerializeTest.java
+++
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboSerializeTest.java
@@ -25,7 +25,6 @@ import org.apache.juneau.jena.*;
import org.apache.juneau.json.*;
import org.apache.juneau.msgpack.*;
import org.apache.juneau.serializer.*;
-import org.apache.juneau.testutils.*;
import org.apache.juneau.uon.*;
import org.apache.juneau.urlencoding.*;
import org.apache.juneau.xml.*;
diff --git
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/serializer/UriResolutionTest.java
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/serializer/UriResolutionTest.java
index 9defdc0..69774d7 100644
---
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/serializer/UriResolutionTest.java
+++
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/serializer/UriResolutionTest.java
@@ -23,7 +23,6 @@ import org.apache.juneau.jena.*;
import org.apache.juneau.json.*;
import org.apache.juneau.msgpack.*;
import org.apache.juneau.parser.*;
-import org.apache.juneau.testutils.*;
import org.apache.juneau.uon.*;
import org.apache.juneau.urlencoding.*;
import org.apache.juneau.xml.*;
diff --git
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/testutils/TestUtils.java
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/testutils/TestUtils.java
index c2fa556..5e4e3ee 100644
---
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/testutils/TestUtils.java
+++
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/testutils/TestUtils.java
@@ -21,7 +21,6 @@ import javax.xml.parsers.*;
import org.apache.juneau.*;
import org.apache.juneau.internal.*;
-import org.apache.juneau.json.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.utils.*;
import org.apache.juneau.xml.*;
@@ -32,11 +31,6 @@ import org.xml.sax.*;
@SuppressWarnings({})
public class TestUtils {
- private static JsonSerializer js2 = JsonSerializer.create()
- .ssq()
- .addBeanTypes().addRootType()
- .build();
-
private static final BeanSession beanSession =
BeanContext.DEFAULT.createSession();
/**
@@ -230,18 +224,6 @@ public class TestUtils {
Assert.assertEquals(sortXml(expected), sortXml(actual));
}
- public static final void assertObjectMatches(String s, Object o) {
- assertObjectMatches(s, o, js2);
- }
-
- public static final void assertObjectMatches(String s, Object o,
WriterSerializer ws) {
- if ("xxx".equals(s))
- System.err.println(ws.toString(o).replaceAll("\\\\",
"\\\\\\\\")); // NOT DEBUG
- String o2 = ws.toString(o);
- if (! StringUtils.getMatchPattern(s).matcher(o2).matches())
- throw new ComparisonFailure(null, s, o2);
- }
-
private static ThreadLocal<TimeZone> systemTimeZone = new
ThreadLocal<>();
private static ThreadLocal<Locale> systemLocale = new ThreadLocal<>();
diff --git
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/utils/MethodInvokerTest.java
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/utils/MethodInvokerTest.java
index fe3512d..8b9e433 100644
---
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/utils/MethodInvokerTest.java
+++
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/utils/MethodInvokerTest.java
@@ -12,7 +12,7 @@
//
***************************************************************************************************************************
package org.apache.juneau.utils;
-import static org.apache.juneau.testutils.TestUtils.*;
+import static org.apache.juneau.assertions.ObjectAssertion.*;
import static org.junit.Assert.assertEquals;
import static org.junit.runners.MethodSorters.*;
@@ -42,7 +42,7 @@ public class MethodInvokerTest {
mi.invoke(a);
mi.invoke(a);
-
assertObjectMatches("{method:'A.foo',runs:3,running:0,errors:0,minTime:*,maxTime:*,avgTime:*,totalTime:*,exceptions:[]}",
mes);
+
assertObject(mes).json().matchesSimple("{method:'A.foo',runs:3,running:0,errors:0,minTime:*,maxTime:*,avgTime:*,totalTime:*,exceptions:[]}");
}
@Test
@@ -63,7 +63,7 @@ public class MethodInvokerTest {
mi.invoke(a);
} catch (Exception e) {}
-
assertObjectMatches("{method:'A.bar',runs:3,running:0,errors:3,minTime:*,maxTime:*,avgTime:*,totalTime:*,exceptions:[{hash:'*',count:3,exceptionClass:*,message:*,stackTrace:*}]}",
mes);
+
assertObject(mes).json().matchesSimple("{method:'A.bar',runs:3,running:0,errors:3,minTime:*,maxTime:*,avgTime:*,totalTime:*,exceptions:[{hash:'*',count:3,exceptionClass:*,message:*,stackTrace:*}]}");
}
@Test
@@ -84,7 +84,7 @@ public class MethodInvokerTest {
mi.invoke(a, 1, "x");
} catch (Exception e) {}
-
assertObjectMatches("{method:'A.baz',runs:3,running:0,errors:3,minTime:*,maxTime:*,avgTime:*,totalTime:*,exceptions:[{hash:'*',count:3,exceptionClass:*,message:*,stackTrace:*}]}",
mes);
+
assertObject(mes).json().matchesSimple("{method:'A.baz',runs:3,running:0,errors:3,minTime:*,maxTime:*,avgTime:*,totalTime:*,exceptions:[{hash:'*',count:3,exceptionClass:*,message:*,stackTrace:*}]}");
}
@Test
diff --git
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/utils/StackTraceDatabaseTest.java
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/utils/StackTraceDatabaseTest.java
index 86a1a39..5fe8a6a 100644
---
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/utils/StackTraceDatabaseTest.java
+++
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/utils/StackTraceDatabaseTest.java
@@ -14,8 +14,7 @@ package org.apache.juneau.utils;
import static org.junit.Assert.*;
import static org.junit.runners.MethodSorters.*;
-import static org.apache.juneau.testutils.TestUtils.*;
-
+import static org.apache.juneau.assertions.ObjectAssertion.*;
import java.util.*;
import org.junit.*;
@@ -62,7 +61,7 @@ public class StackTraceDatabaseTest {
List<StackTraceInfo> l = db.getClonedStackTraceInfos();
db.add(t1);
-
assertObjectMatches("[{exception:'Throwable',hash:'*',count:2},{exception:'Throwable',hash:'*',count:1}]",
l);
+
assertObject(l).json().matchesSimple("[{exception:'Throwable',hash:'*',count:2},{exception:'Throwable',hash:'*',count:1}]");
}
@Test
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
index e866f98..87556f9 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
@@ -12,6 +12,7 @@
//
***************************************************************************************************************************
package org.apache.juneau.internal;
+import static org.apache.juneau.internal.IOUtils.*;
import static org.apache.juneau.internal.ThrowableUtils.*;
import java.io.*;
@@ -25,6 +26,7 @@ import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.regex.*;
+import java.util.zip.*;
import javax.xml.bind.*;
@@ -2981,4 +2983,32 @@ public final class StringUtils {
count++;
return count;
}
+
+ /**
+ * Converts string into a GZipped input stream.
+ *
+ * @param contents The contents to compress.
+ * @return The input stream converted to GZip.
+ * @throws Exception Exception occurred.
+ */
+ public static final byte[] compress(String contents) throws Exception {
+ ByteArrayOutputStream baos = new
ByteArrayOutputStream(contents.length()>>1);
+ try (GZIPOutputStream gos = new GZIPOutputStream(baos)) {
+ gos.write(contents.getBytes());
+ gos.finish();
+ gos.flush();
+ }
+ return baos.toByteArray();
+ }
+
+ /**
+ * Converts a GZipped input stream into a string.
+ *
+ * @param is The contents to decompress.
+ * @return The string.
+ * @throws Exception Exception occurred.
+ */
+ public static final String decompress(byte[] is) throws Exception {
+ return read(new GZIPInputStream(new ByteArrayInputStream(is)));
+ }
}
diff --git
a/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/microservice/testutils/TestUtils.java
b/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/microservice/testutils/TestUtils.java
deleted file mode 100644
index 890028b..0000000
---
a/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/microservice/testutils/TestUtils.java
+++ /dev/null
@@ -1,41 +0,0 @@
-//
***************************************************************************************************************************
-// * 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.juneau.microservice.testutils;
-
-import static org.apache.juneau.internal.StringUtils.*;
-
-import org.apache.juneau.rest.client2.*;
-
-import junit.framework.*;
-
-public class TestUtils extends org.apache.juneau.rest.testutils.TestUtils {
-
- public static final void checkErrorResponse(boolean debug,
RestCallException e, int status, String...contains) throws AssertionFailedError
{
- String r = e.getResponseMessage();
- if (debug) {
- System.err.println(r); // NOT DEBUG
- e.printStackTrace();
- }
- if (status != e.getResponseCode()) {
- dumpResponse(r, "Response status code was not correct.
Expected: ''{0}''. Actual: ''{1}''", status, e.getResponseCode());
- throw new AssertionFailedError(format("Response status
code was not correct. Expected: ''{0}''. Actual: ''{1}''", status,
e.getResponseCode()));
- }
- for (String s : contains) {
- if (r == null || ! r.contains(s)) {
- if (! debug)
- dumpResponse(r, "Response did not have
the following expected text: ''{0}''", s);
- throw new AssertionFailedError(format("Response
did not have the following expected text: ''{0}''", s));
- }
- }
- }
-}
diff --git
a/juneau-rest/juneau-rest-mock-utest/src/test/java/org/apache/juneau/rest/testutils/TestUtils.java
b/juneau-rest/juneau-rest-mock-utest/src/test/java/org/apache/juneau/rest/testutils/TestUtils.java
index 445204d..0821e1f 100755
---
a/juneau-rest/juneau-rest-mock-utest/src/test/java/org/apache/juneau/rest/testutils/TestUtils.java
+++
b/juneau-rest/juneau-rest-mock-utest/src/test/java/org/apache/juneau/rest/testutils/TestUtils.java
@@ -12,12 +12,6 @@
//
***************************************************************************************************************************
package org.apache.juneau.rest.testutils;
-import static org.apache.juneau.internal.IOUtils.*;
-import static org.apache.juneau.internal.StringUtils.*;
-
-import java.io.*;
-import java.util.zip.*;
-
import org.apache.juneau.dto.swagger.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.mock2.*;
@@ -26,34 +20,6 @@ import org.apache.juneau.rest.mock2.*;
public class TestUtils extends org.apache.juneau.testutils.TestUtils {
/**
- * Converts string into a GZipped input stream.
- *
- * @param contents The contents to compress.
- * @return The input stream converted to GZip.
- * @throws Exception
- */
- public static final byte[] compress(String contents) throws Exception {
- ByteArrayOutputStream baos = new
ByteArrayOutputStream(contents.length()>>1);
- try (GZIPOutputStream gos = new GZIPOutputStream(baos)) {
- gos.write(contents.getBytes());
- gos.finish();
- gos.flush();
- }
- return baos.toByteArray();
- }
-
- /**
- * Converts a GZipped input stream into a string.
- *
- * @param is The contents to decompress.
- * @return The string.
- * @throws Exception
- */
- public static final String decompress(byte[] is) throws Exception {
- return read(new GZIPInputStream(new ByteArrayInputStream(is)));
- }
-
- /**
* Gets the swagger for the specified @Resource-annotated object.
* @param c
* @return
@@ -68,12 +34,4 @@ public class TestUtils extends
org.apache.juneau.testutils.TestUtils {
throw new RuntimeException(e);
}
}
-
- public static final void dumpResponse(String r, String msg,
Object...args) {
- System.err.println("*** Failure
****************************************************************************************");
// NOT DEBUG
- System.err.println(format(msg, args)); // NOT DEBUG
- System.err.println("*** Response-Start
*********************************************************************************");
// NOT DEBUG
- System.err.println(r); // NOT DEBUG
- System.err.println("*** Response-End
***********************************************************************************");
// NOT DEBUG
- }
}
diff --git
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/headers/AcceptEncodingTest.java
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/headers/AcceptEncodingTest.java
index 29c5f44..2963add 100644
---
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/headers/AcceptEncodingTest.java
+++
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/headers/AcceptEncodingTest.java
@@ -12,13 +12,13 @@
//
***************************************************************************************************************************
package org.apache.juneau.rest.headers;
-import static org.apache.juneau.rest.testutils.TestUtils.*;
import static org.junit.Assert.*;
import static org.junit.runners.MethodSorters.*;
import java.io.*;
import org.apache.juneau.encoders.*;
+import org.apache.juneau.internal.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.mock2.*;
@@ -134,15 +134,15 @@ public class AcceptEncodingTest {
}
@Test
public void b03_withCompression_gzip() throws Exception {
- assertEquals("foo",
decompress(b.get("/b01").acceptEncoding("*").run().getBody().asBytes()));
- assertEquals("foo",
decompress(b.get("/b01").acceptEncoding("mycoding").run().getBody().asBytes()));
+ assertEquals("foo",
StringUtils.decompress(b.get("/b01").acceptEncoding("*").run().getBody().asBytes()));
+ assertEquals("foo",
StringUtils.decompress(b.get("/b01").acceptEncoding("mycoding").run().getBody().asBytes()));
}
@Test
public void b04_withCompression_gzip_qValues() throws Exception {
- assertEquals("foo",
decompress(b.get("/b01").acceptEncoding("mycoding,identity;q=0").run().getBody().asBytes()));
- assertEquals("foo",
decompress(b.get("/b01").acceptEncoding("mycoding,*;q=0").run().getBody().asBytes()));
- assertEquals("foo",
decompress(b.get("/b01").acceptEncoding("mycoding;q=0.8,identity;q=0.6").run().getBody().asBytes()));
- assertEquals("foo",
decompress(b.get("/b01").acceptEncoding("mycoding;q=0.8,*;q=0.6").run().getBody().asBytes()));
+ assertEquals("foo",
StringUtils.decompress(b.get("/b01").acceptEncoding("mycoding,identity;q=0").run().getBody().asBytes()));
+ assertEquals("foo",
StringUtils.decompress(b.get("/b01").acceptEncoding("mycoding,*;q=0").run().getBody().asBytes()));
+ assertEquals("foo",
StringUtils.decompress(b.get("/b01").acceptEncoding("mycoding;q=0.8,identity;q=0.6").run().getBody().asBytes()));
+ assertEquals("foo",
StringUtils.decompress(b.get("/b01").acceptEncoding("mycoding;q=0.8,*;q=0.6").run().getBody().asBytes()));
}
@Test
public void b05_withCompression_nomatch() throws Exception {
@@ -251,13 +251,13 @@ public class AcceptEncodingTest {
.run()
.assertHeader("Content-Encoding").is("mycoding")
.getBody().asBytes();
- assertEquals("foo", decompress(body));
+ assertEquals("foo", StringUtils.decompress(body));
body = c.get("/c03")
.acceptEncoding("*")
.run()
.assertHeader("Content-Encoding").is("mycoding")
.getBody().asBytes();
- assertEquals("foo", decompress(body));
+ assertEquals("foo", StringUtils.decompress(body));
}
@Test
public void c04_direct4() throws Exception {
diff --git
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/headers/ContentEncodingTest.java
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/headers/ContentEncodingTest.java
index ecbb6ef..178236f 100644
---
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/headers/ContentEncodingTest.java
+++
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/headers/ContentEncodingTest.java
@@ -13,11 +13,11 @@
package org.apache.juneau.rest.headers;
import static org.apache.juneau.http.HttpMethodName.*;
-import static org.apache.juneau.rest.testutils.TestUtils.*;
import static org.junit.runners.MethodSorters.*;
import org.apache.juneau.encoders.*;
import org.apache.juneau.http.annotation.Body;
+import org.apache.juneau.internal.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.mock2.*;
import org.junit.*;
@@ -57,7 +57,7 @@ public class ContentEncodingTest {
}
@Test
public void a02_noCompression_invalid() throws Exception {
- a.put("?noTrace=true",
compress("foo")).contentEncoding("mycoding").run()
+ a.put("?noTrace=true",
StringUtils.compress("foo")).contentEncoding("mycoding").run()
.assertStatus().is(415)
.assertBody().contains(
"Unsupported encoding in request header
'Content-Encoding': 'mycoding'",
@@ -95,7 +95,7 @@ public class ContentEncodingTest {
@Test
@Ignore
public void b02_withCompression_gzip() throws Exception {
- b.put("/", compress("foo"))
+ b.put("/", StringUtils.compress("foo"))
.contentEncoding("mycoding")
.run()
.assertBody().is("foo");