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:11 UTC

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

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) {