You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2016/11/29 16:49:18 UTC
cxf git commit: [CXF-6836] Starting converting the tests to use
SwaggerUtils
Repository: cxf
Updated Branches:
refs/heads/master 5226685d6 -> 5954d4ce3
[CXF-6836] Starting converting the tests to use SwaggerUtils
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/5954d4ce
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/5954d4ce
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/5954d4ce
Branch: refs/heads/master
Commit: 5954d4ce3c9713c17c3bbb8b730fad210aebfb3a
Parents: 5226685
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Tue Nov 29 16:49:03 2016 +0000
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Tue Nov 29 16:49:03 2016 +0000
----------------------------------------------------------------------
.../apache/cxf/jaxrs/swagger/SwaggerUtils.java | 7 ++-
systests/jaxrs/pom.xml | 5 ++
.../AbstractSwagger2ServiceDescriptionTest.java | 49 ++++++++++++++------
.../Swagger2FilterServiceDescriptionTest.java | 11 +++--
...gger2NonAnnotatedServiceDescriptionTest.java | 9 ++--
.../Swagger2RegularServiceDescriptionTest.java | 11 +++--
.../jaxrs/description/group1/BookStore.java | 37 ++++-----------
7 files changed, 72 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/5954d4ce/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUtils.java b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUtils.java
index 2438458..c0d7c6b 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUtils.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUtils.java
@@ -18,6 +18,7 @@
*/
package org.apache.cxf.jaxrs.swagger;
+import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
@@ -69,12 +70,15 @@ public final class SwaggerUtils {
if (is == null) {
return null;
}
- return getUserResourceFromJson(IOUtils.readStringFromStream(is));
+ return getUserResourceFromStream(is);
} catch (Exception ex) {
LOG.warning("Problem with processing a user model at " + loc);
}
return null;
}
+ public static UserResource getUserResourceFromStream(InputStream is) throws IOException {
+ return getUserResourceFromJson(IOUtils.readStringFromStream(is));
+ }
public static List<UserResource> getUserResourcesFromResourceObjects(List<String> jsonObjects) {
List<UserResource> resources = new ArrayList<UserResource>();
for (String json : jsonObjects) {
@@ -137,7 +141,6 @@ public final class SwaggerUtils {
Parameter userParam = new Parameter(pType, name);
setJavaType(userParam, (String)param.get("type"));
-
userOpParams.add(userParam);
}
if (!userOpParams.isEmpty()) {
http://git-wip-us.apache.org/repos/asf/cxf/blob/5954d4ce/systests/jaxrs/pom.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/pom.xml b/systests/jaxrs/pom.xml
index fe9bc56..7dbb2f7 100644
--- a/systests/jaxrs/pom.xml
+++ b/systests/jaxrs/pom.xml
@@ -328,6 +328,11 @@
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-json-basic</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-rx</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/5954d4ce/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
index c4bfd95..bf758a7 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
@@ -21,7 +21,10 @@ package org.apache.cxf.systest.jaxrs.description;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -35,17 +38,20 @@ import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.jaxrs.model.Parameter;
+import org.apache.cxf.jaxrs.model.ParameterType;
+import org.apache.cxf.jaxrs.model.UserOperation;
+import org.apache.cxf.jaxrs.model.UserResource;
import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
+import org.apache.cxf.jaxrs.swagger.SwaggerUtils;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
import org.junit.Ignore;
import org.junit.Test;
-import org.skyscreamer.jsonassert.JSONAssert;
import org.yaml.snakeyaml.Yaml;
-
public abstract class AbstractSwagger2ServiceDescriptionTest extends AbstractBusClientServerTestBase {
@Ignore
@@ -93,21 +99,36 @@ public abstract class AbstractSwagger2ServiceDescriptionTest extends AbstractBus
protected abstract String getPort();
- protected abstract String getExpectedFileJson();
-
protected abstract String getExpectedFileYaml();
- @Test
- @Ignore
- public void testApiListingIsProperlyReturnedJSON() throws Exception {
+ protected void doTestApiListingIsProperlyReturnedJSON() throws Exception {
final WebClient client = createWebClient("/swagger.json");
try {
- final Response r = client.get();
- assertEquals(Status.OK.getStatusCode(), r.getStatus());
- JSONAssert.assertEquals(
- getExpectedValue(getExpectedFileJson(), getPort()),
- IOUtils.readStringFromStream((InputStream)r.getEntity()),
- false);
+ String swaggerJson = client.get(String.class);
+ UserResource r = SwaggerUtils.getUserResourceFromJson(swaggerJson);
+ Map<String, UserOperation> map = r.getOperationsAsMap();
+ assertEquals(3, map.size());
+ UserOperation getBooksOp = map.get("getBooks");
+ assertEquals(HttpMethod.GET, getBooksOp.getVerb());
+ assertEquals("/bookstore", getBooksOp.getPath());
+ assertEquals(MediaType.APPLICATION_JSON, getBooksOp.getProduces());
+ List<Parameter> getBooksOpParams = getBooksOp.getParameters();
+ assertEquals(1, getBooksOpParams.size());
+ assertEquals(ParameterType.QUERY, getBooksOpParams.get(0).getType());
+ UserOperation getBookOp = map.get("getBook");
+ assertEquals(HttpMethod.GET, getBookOp.getVerb());
+ assertEquals("/bookstore/{id}", getBookOp.getPath());
+ assertEquals(MediaType.APPLICATION_JSON, getBookOp.getProduces());
+ List<Parameter> getBookOpParams = getBookOp.getParameters();
+ assertEquals(1, getBookOpParams.size());
+ assertEquals(ParameterType.PATH, getBookOpParams.get(0).getType());
+ UserOperation deleteOp = map.get("delete");
+ assertEquals(HttpMethod.DELETE, deleteOp.getVerb());
+ assertEquals("/bookstore/{id}", deleteOp.getPath());
+ List<Parameter> delOpParams = deleteOp.getParameters();
+ assertEquals(1, delOpParams.size());
+ assertEquals(ParameterType.PATH, delOpParams.get(0).getType());
+
} finally {
client.close();
}
@@ -134,7 +155,7 @@ public abstract class AbstractSwagger2ServiceDescriptionTest extends AbstractBus
}
}
- private WebClient createWebClient(final String url) {
+ protected WebClient createWebClient(final String url) {
return WebClient
.create("http://localhost:" + getPort() + url,
Arrays.< Object >asList(new JacksonJsonProvider()),
http://git-wip-us.apache.org/repos/asf/cxf/blob/5954d4ce/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2FilterServiceDescriptionTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2FilterServiceDescriptionTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2FilterServiceDescriptionTest.java
index 2ca5455..699c7d0 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2FilterServiceDescriptionTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2FilterServiceDescriptionTest.java
@@ -19,6 +19,7 @@
package org.apache.cxf.systest.jaxrs.description;
import org.junit.BeforeClass;
+import org.junit.Test;
public class Swagger2FilterServiceDescriptionTest extends AbstractSwagger2ServiceDescriptionTest {
private static final String PORT = allocatePort(Swagger2FilterServiceDescriptionTest.class);
@@ -44,12 +45,12 @@ public class Swagger2FilterServiceDescriptionTest extends AbstractSwagger2Servic
}
@Override
- protected String getExpectedFileJson() {
- return "swagger2-json.txt";
- }
-
- @Override
protected String getExpectedFileYaml() {
return "swagger2-yaml.txt";
}
+
+ @Test
+ public void testApiListingIsProperlyReturnedJSON() throws Exception {
+ doTestApiListingIsProperlyReturnedJSON();
+ }
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/5954d4ce/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2NonAnnotatedServiceDescriptionTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2NonAnnotatedServiceDescriptionTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2NonAnnotatedServiceDescriptionTest.java
index dd56fe2..f3cb800 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2NonAnnotatedServiceDescriptionTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2NonAnnotatedServiceDescriptionTest.java
@@ -28,6 +28,7 @@ import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
import org.apache.cxf.systest.jaxrs.description.group1.BookStore;
import org.junit.BeforeClass;
+import org.junit.Test;
public class Swagger2NonAnnotatedServiceDescriptionTest extends AbstractSwagger2ServiceDescriptionTest {
private static final String PORT = allocatePort(Swagger2NonAnnotatedServiceDescriptionTest.class);
@@ -70,11 +71,11 @@ public class Swagger2NonAnnotatedServiceDescriptionTest extends AbstractSwagger2
return PORT;
}
- @Override
- protected String getExpectedFileJson() {
- return "swagger2-noano-json.txt";
+ @Test
+ public void testApiListingIsProperlyReturnedJSON() throws Exception {
+ doTestApiListingIsProperlyReturnedJSON();
}
-
+
@Override
protected String getExpectedFileYaml() {
return "swagger2-noano-yaml.txt";
http://git-wip-us.apache.org/repos/asf/cxf/blob/5954d4ce/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2RegularServiceDescriptionTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2RegularServiceDescriptionTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2RegularServiceDescriptionTest.java
index a95bfd6..23d5cfb 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2RegularServiceDescriptionTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2RegularServiceDescriptionTest.java
@@ -19,6 +19,7 @@
package org.apache.cxf.systest.jaxrs.description;
import org.junit.BeforeClass;
+import org.junit.Test;
public class Swagger2RegularServiceDescriptionTest extends AbstractSwagger2ServiceDescriptionTest {
private static final String PORT = allocatePort(Swagger2RegularServiceDescriptionTest.class);
@@ -44,12 +45,12 @@ public class Swagger2RegularServiceDescriptionTest extends AbstractSwagger2Servi
}
@Override
- protected String getExpectedFileJson() {
- return "swagger2-json.txt";
- }
-
- @Override
protected String getExpectedFileYaml() {
return "swagger2-yaml.txt";
}
+
+ @Test
+ public void testApiListingIsProperlyReturnedJSON() throws Exception {
+ doTestApiListingIsProperlyReturnedJSON();
+ }
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/5954d4ce/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/group1/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/group1/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/group1/BookStore.java
index f9bf4d7..492036b 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/group1/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/group1/BookStore.java
@@ -31,47 +31,30 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.apache.cxf.systest.jaxrs.Book;
+
//FIXME swagger-jaxrs 1.5.3 can't handle a self-recursive sub resource like Book. so hide Book for now
//import org.apache.cxf.systest.jaxrs.Book;
@Path("/bookstore")
public class BookStore {
-// @Produces({ MediaType.APPLICATION_JSON })
-// @GET
-// public Response getBooks(
-// @QueryParam("page") @DefaultValue("1") int page) {
-// return Response.ok(
-// Arrays.asList(
-// new Book("Book 1", 1),
-// new Book("Book 2", 2)
-// )
-// ).build();
-// }
-//
-// @Produces({ MediaType.APPLICATION_JSON })
-// @Path("/{id}")
-// @GET
-// public Book getBook(@PathParam("id") Long id) {
-// return new Book("Book", id);
-// }
-
@Produces({ MediaType.APPLICATION_JSON })
@GET
- @Path("/names")
- public Response getBookNames(
+ public Response getBooks(
@QueryParam("page") @DefaultValue("1") int page) {
return Response.ok(
Arrays.asList(
- "Book 1",
- "Book 2"
+ new Book("Book 1", 1),
+ new Book("Book 2", 2)
)
).build();
}
-
- @Path("/name/{id}")
+
+ @Produces({ MediaType.APPLICATION_JSON })
+ @Path("/{id}")
@GET
- public String getBookName(@PathParam("id") String id) {
- return "Book of " + id;
+ public Book getBook(@PathParam("id") Long id) {
+ return new Book("Book", id);
}
@Path("/{id}")