You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bu...@apache.org on 2019/06/10 13:18:09 UTC

[cxf] branch master updated (cc4e90a -> edf9b20)

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

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


    from cc4e90a  update cxf.hazelcast.version
     new 2d60e61  cxf-rt-rs-security-oauth2: add test for OAuthClientUtils
     new 8ddd7e7  cxf-systests-jaxrs: minor test changes
     new edf9b20  cxf-rt-rs-extension-providers: add test for JsonMapObjectProvider

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../provider/json/JsonMapObjectProviderTest.java}  | 36 ++++++++++---------
 .../oauth2/client/OAuthClientUtilsTest.java        | 24 ++++++++++++-
 .../java/org/apache/cxf/systest/jaxrs/Book.java    | 40 +++++++++-------------
 .../jaxrs/JAXRSContinuationsServlet3Test.java      |  6 ++--
 .../jaxrs/failover/AbstractFailoverTest.java       | 32 +++++++----------
 5 files changed, 75 insertions(+), 63 deletions(-)
 copy rt/{frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/JaxWsImplementorInfoTest.java => rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectProviderTest.java} (52%)


[cxf] 02/03: cxf-systests-jaxrs: minor test changes

Posted by bu...@apache.org.
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

commit 8ddd7e775417ee0fcecb7b36c8cf605a3b94bcca
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Mon Jun 10 14:54:02 2019 +0300

    cxf-systests-jaxrs: minor test changes
---
 .../java/org/apache/cxf/systest/jaxrs/Book.java    | 40 +++++++++-------------
 .../jaxrs/JAXRSContinuationsServlet3Test.java      |  6 ++--
 .../jaxrs/failover/AbstractFailoverTest.java       | 32 +++++++----------
 3 files changed, 33 insertions(+), 45 deletions(-)

diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
index 0fcf04f..19d694d 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
@@ -43,8 +43,14 @@ public class Book {
     private Map<Long, Chapter> chapters = new HashMap<>();
 
     public Book() {
-        init();
-        //System.out.println("----chapters: " + chapters.size());
+        Chapter c1 = new Chapter();
+        c1.setId(1L);
+        c1.setTitle("chapter 1");
+        chapters.put(c1.getId(), c1);
+        Chapter c2 = new Chapter();
+        c2.setId(2L);
+        c2.setTitle("chapter 2");
+        chapters.put(c2.getId(), c2);
     }
 
     public Book(String name, long id) {
@@ -81,44 +87,32 @@ public class Book {
     @GET
     @Path("chapters/{chapterid}/")
     @Produces("application/xml;charset=ISO-8859-1")
-    public Chapter getChapter(@PathParam("chapterid")int chapterid) {
-        return chapters.get(Long.valueOf(chapterid));
+    public Chapter getChapter(@PathParam("chapterid") long chapterid) {
+        return chapters.get(chapterid);
     }
 
     @GET
     @Path("chapters/acceptencoding/{chapterid}/")
     @Produces("application/xml")
-    public Chapter getChapterAcceptEncoding(@PathParam("chapterid")int chapterid) {
-        return chapters.get(Long.valueOf(chapterid));
+    public Chapter getChapterAcceptEncoding(@PathParam("chapterid") long chapterid) {
+        return chapters.get(chapterid);
     }
 
     @GET
     @Path("chapters/badencoding/{chapterid}/")
     @Produces("application/xml;charset=UTF-48")
-    public Chapter getChapterBadEncoding(@PathParam("chapterid")int chapterid) {
-        return chapters.get(Long.valueOf(chapterid));
+    public Chapter getChapterBadEncoding(@PathParam("chapterid") long chapterid) {
+        return chapters.get(chapterid);
     }
 
     @Path("chapters/sub/{chapterid}/")
-    public Chapter getSubChapter(@PathParam("chapterid")int chapterid) {
-        return chapters.get(Long.valueOf(chapterid));
+    public Chapter getSubChapter(@PathParam("chapterid") long chapterid) {
+        return chapters.get(chapterid);
     }
 
     @Path("chaptersobject/sub/{chapterid}/")
-    public Object getSubChapterObject(@PathParam("chapterid")int chapterid) {
+    public Object getSubChapterObject(@PathParam("chapterid") long chapterid) {
         return getSubChapter(chapterid);
     }
 
-
-    final void init() {
-        Chapter c1 = new Chapter();
-        c1.setId(1);
-        c1.setTitle("chapter 1");
-        chapters.put(c1.getId(), c1);
-        Chapter c2 = new Chapter();
-        c2.setId(2);
-        c2.setTitle("chapter 2");
-        chapters.put(c2.getId(), c2);
-    }
-
 }
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsServlet3Test.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsServlet3Test.java
index 959b2c3..bcf36cb 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsServlet3Test.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsServlet3Test.java
@@ -114,17 +114,17 @@ public class JAXRSContinuationsServlet3Test extends AbstractJAXRSContinuationsTe
         assertEquals(check, content);
     }
 
-    private <T> Future<Response> invokeRequest(String resource, T entity) {
+    private static <T> Future<Response> invokeRequest(String resource, T entity) {
         AsyncInvoker async = createAsyncInvoker(resource);
         return async.post(Entity.entity(entity, MediaType.TEXT_PLAIN_TYPE));
     }
 
-    private Future<Response> invokeRequest(String resource) {
+    private static Future<Response> invokeRequest(String resource) {
         AsyncInvoker async = createAsyncInvoker(resource);
         return async.get();
     }
 
-    private AsyncInvoker createAsyncInvoker(String resource) {
+    private static AsyncInvoker createAsyncInvoker(String resource) {
         WebTarget target = ClientBuilder.newClient().target(resource);
         return target.request().async();
     }
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
index 904d603..dc1a4d7 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
@@ -19,7 +19,7 @@
 
 package org.apache.cxf.systest.jaxrs.failover;
 
-import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -34,7 +34,6 @@ import org.apache.cxf.clustering.RandomStrategy;
 import org.apache.cxf.clustering.RetryStrategy;
 import org.apache.cxf.clustering.SequentialStrategy;
 import org.apache.cxf.endpoint.ConduitSelector;
-import org.apache.cxf.feature.Feature;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.systest.jaxrs.Book;
@@ -62,7 +61,7 @@ public abstract class AbstractFailoverTest extends AbstractBusClientServerTestBa
                    launchServer(Server.class, true));
         boolean activeReplica1Started = false;
         boolean activeReplica2Started = false;
-        for (int i = 0; i < 60; i++) {
+        for (int i = 0; i < 10; i++) {
             if (!activeReplica1Started) {
                 activeReplica1Started = checkReplica(Server.ADDRESS2);
             }
@@ -72,13 +71,13 @@ public abstract class AbstractFailoverTest extends AbstractBusClientServerTestBa
             if (activeReplica1Started && activeReplica2Started) {
                 break;
             }
-            Thread.sleep(1000);
+            Thread.sleep(100L);
         }
     }
+
     private static boolean checkReplica(String address) {
         try {
-            Response r = WebClient.create(address).query("_wadl").get();
-            return r.getStatus() == 200;
+            return WebClient.create(address).query("_wadl").get().getStatus() == 200;
         } catch (Exception ex) {
             return false;
         }
@@ -171,13 +170,11 @@ public abstract class AbstractFailoverTest extends AbstractBusClientServerTestBa
         String address = "http://localhost:" + NON_PORT + "/non-existent";
         String address2 = "http://localhost:" + NON_PORT + "/non-existent2";
 
-        FailoverFeature feature = new FailoverFeature();
-        List<String> alternateAddresses = new ArrayList<>();
-        alternateAddresses.add(address);
-        alternateAddresses.add(address2);
         CustomRetryStrategy strategy = new CustomRetryStrategy();
         strategy.setMaxNumberOfRetries(5);
-        strategy.setAlternateAddresses(alternateAddresses);
+        strategy.setAlternateAddresses(Arrays.asList(address, address2));
+
+        FailoverFeature feature = new FailoverFeature();
         feature.setStrategy(strategy);
 
         BookStore store = getBookStore(address, feature);
@@ -205,18 +202,14 @@ public abstract class AbstractFailoverTest extends AbstractBusClientServerTestBa
     protected WebClient getWebClient(String address,
                                      FailoverFeature feature) throws Exception {
         JAXRSClientFactoryBean bean = createBean(address, feature);
-
         return bean.createWebClient();
     }
 
-    protected JAXRSClientFactoryBean createBean(String address,
+    private static JAXRSClientFactoryBean createBean(String address,
                                                 FailoverFeature feature) {
         JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
         bean.setAddress(address);
-        List<Feature> features = new ArrayList<>();
-        features.add(feature);
-        bean.setFeatures(features);
-
+        bean.setFeatures(Arrays.asList(feature));
         return bean;
     }
 
@@ -249,9 +242,10 @@ public abstract class AbstractFailoverTest extends AbstractBusClientServerTestBa
                     bookStore.getBook("9999");
                     fail("Exception expected");
                 } else {
-                    Book book = bookStore.echoBookElementJson(new Book("CXF", 123));
+                    final long bookId = 123L;
+                    Book book = bookStore.echoBookElementJson(new Book("CXF", bookId));
                     assertNotNull("expected non-null response", book);
-                    assertEquals("unexpected id", 123L, book.getId());
+                    assertEquals("unexpected id", bookId, book.getId());
                 }
             } catch (Exception error) {
                 if (!expectServerException) {


[cxf] 03/03: cxf-rt-rs-extension-providers: add test for JsonMapObjectProvider

Posted by bu...@apache.org.
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

commit edf9b208e984806daf073de6defa90ec42c40234
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Mon Jun 10 14:54:36 2019 +0300

    cxf-rt-rs-extension-providers: add test for JsonMapObjectProvider
---
 .../provider/json/JsonMapObjectProviderTest.java   | 51 ++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectProviderTest.java b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectProviderTest.java
new file mode 100644
index 0000000..950c9bc
--- /dev/null
+++ b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectProviderTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.cxf.jaxrs.provider.json;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.apache.cxf.jaxrs.json.basic.JsonMapObject;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class JsonMapObjectProviderTest {
+
+    @Test
+    public void testReadWrite() throws Exception {
+        JsonMapObjectProvider p = new JsonMapObjectProvider();
+
+        JsonMapObject object = new JsonMapObject();
+        object.setProperty("p", "v");
+
+        assertTrue(p.isWriteable(JsonMapObject.class, null, null, null));
+
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        p.writeTo(object, JsonMapObject.class, JsonMapObject.class, null, null, null, os);
+
+        JsonMapObject result = p.readFrom(JsonMapObject.class, null, null,
+                                       null, null, new ByteArrayInputStream(os.toByteArray()));
+        assertEquals(object, result);
+    }
+
+}


[cxf] 01/03: cxf-rt-rs-security-oauth2: add test for OAuthClientUtils

Posted by bu...@apache.org.
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

commit 2d60e6189b93471372de66a63e4e0ed580d059a9
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Mon Jun 10 12:57:15 2019 +0300

    cxf-rt-rs-security-oauth2: add test for OAuthClientUtils
---
 .../oauth2/client/OAuthClientUtilsTest.java        | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/rt/rs/security/oauth-parent/oauth2/src/test/java/org/apache/cxf/rs/security/oauth2/client/OAuthClientUtilsTest.java b/rt/rs/security/oauth-parent/oauth2/src/test/java/org/apache/cxf/rs/security/oauth2/client/OAuthClientUtilsTest.java
index a50c057..c0622bb 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/test/java/org/apache/cxf/rs/security/oauth2/client/OAuthClientUtilsTest.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/test/java/org/apache/cxf/rs/security/oauth2/client/OAuthClientUtilsTest.java
@@ -19,6 +19,8 @@
 package org.apache.cxf.rs.security.oauth2.client;
 
 import java.io.ByteArrayInputStream;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.ws.rs.core.Form;
 import javax.ws.rs.core.MediaType;
@@ -75,4 +77,24 @@ public class OAuthClientUtilsTest {
             verify(accessTokenService);
         }
     }
-}
\ No newline at end of file
+
+    @Test
+    public void fromMapToClientToken() {
+        final Map<String, String> map = new HashMap<>();
+        final String accessToken = "SlAV32hkKG";
+        map.put(OAuthConstants.ACCESS_TOKEN, accessToken);
+        final String tokenType = "Bearer";
+        map.put(OAuthConstants.ACCESS_TOKEN_TYPE, tokenType);
+        final String refreshToken = "8xLOxBtZp8";
+        map.put(OAuthConstants.REFRESH_TOKEN, refreshToken);
+        final String expiresIn = "3600";
+        map.put(OAuthConstants.ACCESS_TOKEN_EXPIRES_IN, expiresIn);
+
+        final ClientAccessToken token = OAuthClientUtils.fromMapToClientToken(map);
+        assertEquals(accessToken, token.getTokenKey());
+        assertEquals(tokenType, token.getTokenType());
+        assertEquals(refreshToken, token.getRefreshToken());
+        assertEquals(Long.parseLong(expiresIn), token.getExpiresIn());
+    }
+
+}