From b25393a821da7f97415448600788c4422bde0927 Mon Sep 17 00:00:00 2001 From: joshua bauer Date: Fri, 21 Sep 2018 10:58:59 -0700 Subject: [PATCH] Cleanup Refactored test package names. Added yaml to swagger. Better text handling. --- pom.xml | 323 +++++++++--------- .../sinistral/proteus/server/MediaType.java | 2 + .../proteus/server/ServerResponse.java | 5 + .../server/predicates/ServerPredicates.java | 5 +- .../proteus/services/SwaggerService.java | 61 +++- .../proteus/{ => test}/controllers/Tests.java | 6 +- .../proteus/{ => test}/models/User.java | 2 +- .../{ => test}/server/DefaultServer.java | 4 +- .../server/TestControllerEndpoints.java | 6 +- 9 files changed, 234 insertions(+), 180 deletions(-) rename src/test/java/io/sinistral/proteus/{ => test}/controllers/Tests.java (98%) rename src/test/java/io/sinistral/proteus/{ => test}/models/User.java (95%) rename src/test/java/io/sinistral/proteus/{ => test}/server/DefaultServer.java (96%) rename src/test/java/io/sinistral/proteus/{ => test}/server/TestControllerEndpoints.java (98%) diff --git a/pom.xml b/pom.xml index 9c9112a..28a54fa 100644 --- a/pom.xml +++ b/pom.xml @@ -2,63 +2,63 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 io.sinistral - proteus-core - 0.3.3-SNAPSHOT + proteus-core + 0.3.3-SNAPSHOT proteus core - Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow. - http://github.com/noboomu/proteus - jar + Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow. + http://github.com/noboomu/proteus + jar - - - MIT License - http://www.opensource.org/licenses/mit-license.php - - + + + MIT License + http://www.opensource.org/licenses/mit-license.php + + - - - Joshua Lee Bauer - bauer.j@gmail.com - - + + + Joshua Lee Bauer + bauer.j@gmail.com + + - - scm:git:git://github.com/noboomu/proteus.git - scm:git:ssh://github.com:noboomu/proteus.git - http://github.com/noboomu/proteus/tree/master - + + scm:git:git://github.com/noboomu/proteus.git + scm:git:ssh://github.com:noboomu/proteus.git + http://github.com/noboomu/proteus/tree/master + + + + 1.8 + 1.8 + UTF-8 + 3.0.0 + 2.0.13.Final + 2.9.6 + - - 1.8 - 1.8 - UTF-8 - 3.0.0 - 2.0.13.Final - 2.9.6 - - - - - src/main/resources - false - - - - - src/test/resources - - - src/test/java - - **/*.java - - - + + + src/main/resources + false + + + + + src/test/resources + + + src/test/java + + **/*.java + + + - + org.eclipse.m2e lifecycle-mapping @@ -87,125 +87,125 @@ - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - -Xdoclint:none - - - - - - maven-surefire-plugin - 2.20.1 - - - - org.apache.maven.surefire - surefire-junit47 - 2.20.1 - - - - -Dconfig.file=src/test/resources/application.conf - + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + -Xdoclint:none + + + + + + maven-surefire-plugin + 2.20.1 + + + + org.apache.maven.surefire + surefire-junit47 + 2.20.1 + + + + -Dconfig.file=src/test/resources/application.conf + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + gpg + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-release-plugin + 2.5.3 + + true + false + ossrh + deploy + - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - gpg - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://oss.sonatype.org/ - true - - - - org.apache.maven.plugins - maven-release-plugin - 2.5.3 - - true - false - ossrh - deploy - - - + maven-compiler-plugin 3.5.1 1.8 1.8 - UTF-8 - -parameters + UTF-8 + -parameters - + io.rest-assured rest-assured 3.0.2 test - + junit junit 4.12 test - - - - + + + + io.undertow undertow-core ${version.undertow} - + org.glassfish.jersey jax-rs-ri @@ -232,7 +232,7 @@ - + com.google.guava guava @@ -255,12 +255,19 @@ jackson-core ${version.jackson} - + com.fasterxml.jackson.dataformat jackson-dataformat-xml ${version.jackson} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + ${version.jackson} + + com.fasterxml.jackson.module jackson-module-afterburner @@ -303,8 +310,8 @@ slf4j-api - - + + io.swagger swagger-parser @@ -340,23 +347,23 @@ org.fusesource.jansi jansi 1.15 - + org.reactivestreams reactive-streams 1.0.0.final - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - https://oss.sonatype.org/content/groups/public/io/sinistral/proteus-core - - + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + https://oss.sonatype.org/content/groups/public/io/sinistral/proteus-core + + diff --git a/src/main/java/io/sinistral/proteus/server/MediaType.java b/src/main/java/io/sinistral/proteus/server/MediaType.java index 1f57b15..338d033 100644 --- a/src/main/java/io/sinistral/proteus/server/MediaType.java +++ b/src/main/java/io/sinistral/proteus/server/MediaType.java @@ -31,6 +31,8 @@ public class MediaType { /*******************************************************/ + public static final MediaType TEXT_YAML = create("text/yaml","yaml"); + public static final MediaType APPLICATION_ANDREW_INSET = create("application/andrew-inset", "ez"); public static final MediaType APPLICATION_ANNODEX = create("application/annodex", "anx"); public static final MediaType APPLICATION_APPLIXWARE = create("application/applixware", "aw"); diff --git a/src/main/java/io/sinistral/proteus/server/ServerResponse.java b/src/main/java/io/sinistral/proteus/server/ServerResponse.java index ed62c55..a1542a7 100644 --- a/src/main/java/io/sinistral/proteus/server/ServerResponse.java +++ b/src/main/java/io/sinistral/proteus/server/ServerResponse.java @@ -602,6 +602,11 @@ else if (ServerPredicates.ACCEPT_XML_PREDICATE.resolve(exchange)) this.applicationXml(); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, this.contentType); } + else if (ServerPredicates.ACCEPT_TEXT_PREDICATE.resolve(exchange)) + { + this.textPlain(); + exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, this.contentType); + } } diff --git a/src/main/java/io/sinistral/proteus/server/predicates/ServerPredicates.java b/src/main/java/io/sinistral/proteus/server/predicates/ServerPredicates.java index e7da28c..c559274 100644 --- a/src/main/java/io/sinistral/proteus/server/predicates/ServerPredicates.java +++ b/src/main/java/io/sinistral/proteus/server/predicates/ServerPredicates.java @@ -24,6 +24,8 @@ public class ServerPredicates public static final String XML_REGEX = "^(application\\/(xml|xhtml\\+xml)|text\\/xml)(;.*)?$"; + public static final String TEXT_REGEX = "^(text\\/plain)(;.*)?$"; + public static final Predicate JSON_PREDICATE = Predicates.regex(ExchangeAttributes.requestHeader(Headers.CONTENT_TYPE), JSON_REGEX); public static final Predicate XML_PREDICATE = Predicates.regex(ExchangeAttributes.requestHeader(Headers.CONTENT_TYPE), XML_REGEX); @@ -35,7 +37,8 @@ public class ServerPredicates //public static final Predicate ACCEPT_JSON_PREDICATE = Predicates.contains(ExchangeAttributes.requestHeader(Headers.ACCEPT), MediaType.APPLICATION_JSON.contentType(),MediaType.APPLICATION_JSON.withCharset("UTF-8").toString()); public static final Predicate ACCEPT_JSON_PREDICATE = Predicates.regex(ExchangeAttributes.requestHeader(Headers.ACCEPT), JSON_REGEX); public static final Predicate ACCEPT_XML_PREDICATE = Predicates.regex(ExchangeAttributes.requestHeader(Headers.ACCEPT), XML_REGEX);; - //public static final Predicate ACCEPT_XML_PREDICATE = Predicates.contains(ExchangeAttributes.requestHeader(Headers.ACCEPT), MediaType.APPLICATION_XML.contentType(),MediaType.APPLICATION_XML.withCharset("UTF-8").toString()); + public static final Predicate ACCEPT_TEXT_PREDICATE = Predicates.regex(ExchangeAttributes.requestHeader(Headers.ACCEPT), TEXT_REGEX);; +//public static final Predicate ACCEPT_XML_PREDICATE = Predicates.contains(ExchangeAttributes.requestHeader(Headers.ACCEPT), MediaType.APPLICATION_XML.contentType(),MediaType.APPLICATION_XML.withCharset("UTF-8").toString()); public static final Predicate ACCEPT_XML_EXCLUSIVE_PREDICATE = Predicates.and(ACCEPT_XML_PREDICATE, NO_WILDCARD_PREDICATE ); public static final Predicate MAX_CONTENT_SIZE_PREDICATE = new MaxRequestContentLengthPredicate.Builder().build(Collections.singletonMap("value", 0L)); public static final Predicate STRING_BODY_PREDICATE = Predicates.and(Predicates.or(JSON_PREDICATE,XML_PREDICATE), MAX_CONTENT_SIZE_PREDICATE ); diff --git a/src/main/java/io/sinistral/proteus/services/SwaggerService.java b/src/main/java/io/sinistral/proteus/services/SwaggerService.java index 3146af6..054ae59 100644 --- a/src/main/java/io/sinistral/proteus/services/SwaggerService.java +++ b/src/main/java/io/sinistral/proteus/services/SwaggerService.java @@ -32,7 +32,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -148,6 +148,8 @@ public class SwaggerService extends BaseService implements Supplier>> responseFu @POST @Path("/response/file/path") @Produces(MediaType.APPLICATION_OCTET_STREAM) - @Consumes("*/*") + @Consumes(MediaType.MULTIPART_FORM_DATA) @ApiOperation(value = "Upload file path endpoint", httpMethod = "POST" ) public ServerResponse responseUploadFilePath(ServerRequest request, @FormParam("file") java.nio.file.Path file ) throws Exception { diff --git a/src/test/java/io/sinistral/proteus/models/User.java b/src/test/java/io/sinistral/proteus/test/models/User.java similarity index 95% rename from src/test/java/io/sinistral/proteus/models/User.java rename to src/test/java/io/sinistral/proteus/test/models/User.java index 1a2b66d..a2fd5c0 100644 --- a/src/test/java/io/sinistral/proteus/models/User.java +++ b/src/test/java/io/sinistral/proteus/test/models/User.java @@ -1,7 +1,7 @@ /** * */ -package io.sinistral.proteus.models; +package io.sinistral.proteus.test.models; /** diff --git a/src/test/java/io/sinistral/proteus/server/DefaultServer.java b/src/test/java/io/sinistral/proteus/test/server/DefaultServer.java similarity index 96% rename from src/test/java/io/sinistral/proteus/server/DefaultServer.java rename to src/test/java/io/sinistral/proteus/test/server/DefaultServer.java index 5d34af9..a58e992 100644 --- a/src/test/java/io/sinistral/proteus/server/DefaultServer.java +++ b/src/test/java/io/sinistral/proteus/test/server/DefaultServer.java @@ -1,7 +1,7 @@ /** * */ -package io.sinistral.proteus.server; +package io.sinistral.proteus.test.server; import java.util.List; @@ -16,9 +16,9 @@ import io.restassured.RestAssured; import io.sinistral.proteus.ProteusApplication; -import io.sinistral.proteus.controllers.Tests; import io.sinistral.proteus.services.AssetsService; import io.sinistral.proteus.services.SwaggerService; +import io.sinistral.proteus.test.controllers.Tests; /** * @author jbauer diff --git a/src/test/java/io/sinistral/proteus/server/TestControllerEndpoints.java b/src/test/java/io/sinistral/proteus/test/server/TestControllerEndpoints.java similarity index 98% rename from src/test/java/io/sinistral/proteus/server/TestControllerEndpoints.java rename to src/test/java/io/sinistral/proteus/test/server/TestControllerEndpoints.java index 73a22fa..88c985a 100644 --- a/src/test/java/io/sinistral/proteus/server/TestControllerEndpoints.java +++ b/src/test/java/io/sinistral/proteus/test/server/TestControllerEndpoints.java @@ -1,7 +1,7 @@ /** * */ -package io.sinistral.proteus.server; +package io.sinistral.proteus.test.server; import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.containsString; @@ -32,8 +32,8 @@ import org.junit.runner.RunWith; import io.restassured.http.ContentType; -import io.sinistral.proteus.models.User; -import io.sinistral.proteus.models.User.UserType; +import io.sinistral.proteus.test.models.User; +import io.sinistral.proteus.test.models.User.UserType; /* * import static io.restassured.RestAssured.*; import static io.restassured.matcher.RestAssuredMatchers.*; import static org.hamcrest.Matchers.*;