http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/nls/Messages.properties ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/nls/Messages.properties b/juneau-microservice/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/nls/Messages.properties new file mode 100755 index 0000000..d4a7d06 --- /dev/null +++ b/juneau-microservice/juneau-microservice-template/src/main/java/org/apache/juneau/microservice/sample/nls/Messages.properties @@ -0,0 +1,19 @@ +# *************************************************************************************************************************** +# * 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. +# * +# *************************************************************************************************************************** + +#-------------------------------------------------------------------------------- +# RootResources +#-------------------------------------------------------------------------------- +RootResources.title = Juneau Microservice Template +RootResources.description = Template for creating REST microservices
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-template/src/test/java/.gitignore ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-template/src/test/java/.gitignore b/juneau-microservice/juneau-microservice-template/src/test/java/.gitignore new file mode 100644 index 0000000..8a0051a --- /dev/null +++ b/juneau-microservice/juneau-microservice-template/src/test/java/.gitignore @@ -0,0 +1,12 @@ + *************************************************************************************************************************** + * 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. * + *************************************************************************************************************************** http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/.classpath ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/.classpath b/juneau-microservice/juneau-microservice-test/.classpath new file mode 100644 index 0000000..0060db7 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/.classpath @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" output="target/test-classes" path="src/test/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" output="target/classes" path="src/main/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="output" path="target/classes"/> +</classpath> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/.gitignore ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/.gitignore b/juneau-microservice/juneau-microservice-test/.gitignore new file mode 100644 index 0000000..d274d47 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/.gitignore @@ -0,0 +1,3 @@ +/target/ +/.settings/ +/.DS_Store http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/.project ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/.project b/juneau-microservice/juneau-microservice-test/.project new file mode 100644 index 0000000..5fb0d4c --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/.project @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>juneau-microservice-test</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.m2e.core.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.m2e.core.maven2Nature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/jetty.xml ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/jetty.xml b/juneau-microservice/juneau-microservice-test/jetty.xml new file mode 100644 index 0000000..76d9e2d --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/jetty.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> +<!-- + *************************************************************************************************************************** + * 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. * + *************************************************************************************************************************** +--> + +<Configure id="ExampleServer" class="org.eclipse.jetty.server.Server"> + + <Set name="connectors"> + <Array type="org.eclipse.jetty.server.Connector"> + <Item> + <New class="org.eclipse.jetty.server.ServerConnector"> + <Arg> + <Ref refid="ExampleServer" /> + </Arg> + <Set name="port">10001</Set> + </New> + </Item> + </Array> + </Set> + + <New id="context" class="org.eclipse.jetty.servlet.ServletContextHandler"> + <Set name="contextPath">/</Set> + <Call name="addServlet"> + <Arg>org.apache.juneau.rest.test.Root</Arg> + <Arg>/*</Arg> + </Call> + <Set name="sessionHandler"> + <New class="org.eclipse.jetty.server.session.SessionHandler" /> + </Set> + </New> + + <Set name="handler"> + <New class="org.eclipse.jetty.server.handler.HandlerCollection"> + <Set name="handlers"> + <Array type="org.eclipse.jetty.server.Handler"> + <Item> + <Ref refid="context" /> + </Item> + <Item> + <New class="org.eclipse.jetty.server.handler.DefaultHandler" /> + </Item> + </Array> + </Set> + </New> + </Set> +</Configure> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/juneau-microservice-test.cfg ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/juneau-microservice-test.cfg b/juneau-microservice/juneau-microservice-test/juneau-microservice-test.cfg new file mode 100644 index 0000000..5009719 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/juneau-microservice-test.cfg @@ -0,0 +1,58 @@ +# *************************************************************************************************************************** +# * 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. * +# *************************************************************************************************************************** + +#================================================================================ +# Basic configuration file for SaaS microservices +# Subprojects can use this as a starting point. +#================================================================================ + +#================================================================================ +# REST settings +#================================================================================ +[REST] + +jettyXml = jetty.xml + +# What to do when the config file is saved. +# Possible values: +# NOTHING - Don't do anything. +# RESTART_SERVER - Restart the Jetty server. +# RESTART_SERVICE - Shutdown and exit with code '3'. +saveConfigAction = RESTART_SERVER + +#================================================================================ +# Logger settings +# See FileHandler Java class for details. +#================================================================================ +[Logging] +logDir = $S{user.dir}/target/logs +logFile = test.%g.log +dateFormat = yyyy.MM.dd hh:mm:ss +format = [{date} {level}] {msg}%n +append = false +limit = 10M +count = 5 +levels = { com.foo.team:'INFO' } +useStackTraceHashes = true +consoleLevel = WARNING + +[Test] +int1 = 1 +int2 = [1,2,3] +int3 = $C{Test/int1, -1} +int4 = $C{Test/int3, -1} +int5 = $C{XXX, -1} +boolean1 = true +boolean2 = [true,true] +path = $E{PATH} +testManifestEntry = $MF{Test-Entry} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/juneau-microservice-test.launch ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/juneau-microservice-test.launch b/juneau-microservice/juneau-microservice-test/juneau-microservice-test.launch new file mode 100644 index 0000000..4af27b6 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/juneau-microservice-test.launch @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication"> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/juneau-microservice-test"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="4"/> +</listAttribute> +<booleanAttribute key="org.eclipse.jdt.debug.ui.CONSIDER_INHERITED_MAIN" value="true"/> +<booleanAttribute key="org.eclipse.jdt.debug.ui.INCLUDE_EXTERNAL_JARS" value="true"/> +<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> +<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/> +<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.apache.juneau.microservice.RestMicroservice"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="juneau-microservice-test.cfg"/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="juneau-microservice-test"/> +<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/> +</launchConfiguration> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/pom.xml b/juneau-microservice/juneau-microservice-test/pom.xml new file mode 100644 index 0000000..4f45be0 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/pom.xml @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + *************************************************************************************************************************** + * 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. * + *************************************************************************************************************************** +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-rest</artifactId> + <version>6.3.2-incubating-SNAPSHOT</version> + </parent> + + <artifactId>juneau-microservice-test</artifactId> + <name>Apache Juneau Microservice Tests</name> + <description>Tests for Juneau Client/Server/Microservice.</description> + + <properties> + <maven.javadoc.skip>true</maven.javadoc.skip> + + <!-- Java 8 required because Jetty requires it. --> + <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>1.8</maven.compiler.target> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-examples-rest</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-rest-server-jaxrs</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-marshall-rdf</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>javax.ws.rs</groupId> + <artifactId>jsr311-api</artifactId> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <includes> + <include> + **/_TestSuite.java + </include> + </includes> + </configuration> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/AcceptCharsetResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/AcceptCharsetResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/AcceptCharsetResource.java new file mode 100644 index 0000000..2281896 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/AcceptCharsetResource.java @@ -0,0 +1,94 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.apache.juneau.rest.RestContext.*; + +import java.io.*; + +import org.apache.juneau.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.plaintext.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.serializer.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testAcceptCharset", + serializers={PlainTextSerializer.class}, + properties={ + // Some versions of Jetty default to ISO8601, so specify UTF-8 for test consistency. + @Property(name=REST_defaultCharset,value="utf-8") + } +) +public class AcceptCharsetResource extends RestServlet { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Test that Q-values are being resolved correctly. + //==================================================================================================== + @RestMethod(name="GET", path="/testQValues") + public String testQValues() { + return "foo"; + } + + //==================================================================================================== + // Validate various Accept-Charset variations. + //==================================================================================================== + @RestMethod(name="PUT", path="/testCharsetOnResponse", parsers=TestParser.class, serializers=TestSerializer.class) + public String testCharsetOnResponse(@Body String in) { + return in; + } + + public static class TestParser extends InputStreamParser { + + public TestParser(PropertyStore propertyStore) { + super(propertyStore, "text/plain"); + } + + @Override /* Parser */ + public InputStreamParserSession createSession(ParserSessionArgs args) { + return new InputStreamParserSession(args) { + + @Override /* ParserSession */ + @SuppressWarnings("unchecked") + protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception { + return (T)getStringProperty("characterEncoding"); + } + }; + } + } + + public static class TestSerializer extends OutputStreamSerializer { + + public TestSerializer(PropertyStore propertyStore) { + super(propertyStore, "text/plain"); + } + + @Override /* Serializer */ + public OutputStreamSerializerSession createSession(SerializerSessionArgs args) { + return new OutputStreamSerializerSession(args) { + + @Override /* SerializerSession */ + protected void doSerialize(SerializerPipe out, Object o) throws Exception { + Writer w = new OutputStreamWriter(out.getOutputStream()); + w.append(o.toString()).append('/').append(getStringProperty("characterEncoding")); + w.flush(); + } + }; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/BeanContextPropertiesResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/BeanContextPropertiesResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/BeanContextPropertiesResource.java new file mode 100644 index 0000000..f5479b8 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/BeanContextPropertiesResource.java @@ -0,0 +1,44 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import java.io.*; +import java.util.*; + +import org.apache.juneau.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.transforms.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testBeanContext", + pojoSwaps=DateSwap.ISO8601DTZ.class +) +public class BeanContextPropertiesResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Validate that transforms defined on class transform to underlying bean context. + //==================================================================================================== + @RestMethod(name="GET", path="/testClassTransforms/{d1}") + public Reader testClassTransforms(@Path("d1") Date d1, @Query("d2") Date d2, @Header("X-D3") Date d3) throws Exception { + DateSwap df = DateSwap.ISO8601DTZ.class.newInstance(); + BeanSession session = BeanContext.DEFAULT.createSession(); + return new StringReader( + "d1="+df.swap(session, d1)+",d2="+df.swap(session, d2)+",d3="+df.swap(session, d3)+"" + ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/BpiResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/BpiResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/BpiResource.java new file mode 100644 index 0000000..4c6373e --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/BpiResource.java @@ -0,0 +1,140 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.annotation.*; +import org.apache.juneau.microservice.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testBpi" +) +public class BpiResource extends ResourceJena { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Validates that the @RestMethod(bpIncludes,bpExcludes) properties work. + //==================================================================================================== + + @RestMethod(name="GET", path="/test/a1", bpi="MyBeanA: a,_b") + public Object testA1() throws Exception { + return new MyBeanA().init(); + } + + @RestMethod(name="GET", path="/test/a2", bpi="MyBeanA: a") + public Object testA2() throws Exception { + return new MyBeanA().init(); + } + + @RestMethod(name="GET", path="/test/a3", bpi="MyBeanA: _b") + public Object testA3() throws Exception { + return new MyBeanA().init(); + } + + @RestMethod(name="GET", path="/test/a4", bpi="MyBeanA: a") + public Object testA4() throws Exception { + return new MyBeanA().init(); + } + + @RestMethod(name="GET", path="/test/a5", bpi="MyBeanA: _b") + public Object testA5() throws Exception { + return new MyBeanA().init(); + } + + @RestMethod(name="GET", path="/test/a6", bpi="MyBeanA: a,_b") + public Object testA6() throws Exception { + return new MyBeanA().init(); + } + + @RestMethod(name="GET", path="/test/b1", bpi="MyBeanB: a,_b") + public Object testB1() throws Exception { + return new MyBeanB().init(); + } + + @RestMethod(name="GET", path="/test/b2", bpi="MyBeanB: a") + public Object testB2() throws Exception { + return new MyBeanB().init(); + } + + @RestMethod(name="GET", path="/test/b3", bpi="MyBeanB: _b") + public Object testB3() throws Exception { + return new MyBeanB().init(); + } + + @RestMethod(name="GET", path="/test/b4", bpi="MyBeanB: a") + public Object testB4() throws Exception { + return new MyBeanB().init(); + } + + @RestMethod(name="GET", path="/test/b5", bpi="MyBeanB: _b'") + public Object testB5() throws Exception { + return new MyBeanB().init(); + } + + @RestMethod(name="GET", path="/test/b6", bpi="MyBeanB: a,_b") + public Object testB6() throws Exception { + return new MyBeanB().init(); + } + + @RestMethod(name="GET", path="/test/c1", bpi="*: a") + public Object testC1() throws Exception { + return new MyBeanA().init(); + } + + @RestMethod(name="GET", path="/test/c2", bpi="org.apache.juneau.rest.test.BpIncludesResource$MyBeanA: a") + public Object testC2() throws Exception { + return new MyBeanA().init(); + } + + // Should not match. + @RestMethod(name="GET", path="/test/d1", bpi="MyBean: a") + public Object testD1() throws Exception { + return new MyBeanA().init(); + } + + // Should not match. + @RestMethod(name="GET", path="/test/d2", bpi="MyBean*: a") + public Object testD2() throws Exception { + return new MyBeanA().init(); + } + + //------------------------------------------------------------------------------------------------------------------- + // Beans + //------------------------------------------------------------------------------------------------------------------- + + public static class MyBeanA { + public int a; + @BeanProperty("_b") public String b; + + MyBeanA init() { + a = 1; + b = "foo"; + return this; + } + } + + @Bean(properties="_b,a") + public static class MyBeanB { + public int a; + @BeanProperty("_b") public String b; + + MyBeanB init() { + a = 1; + b = "foo"; + return this; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/CallbackStringsResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/CallbackStringsResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/CallbackStringsResource.java new file mode 100644 index 0000000..74038b3 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/CallbackStringsResource.java @@ -0,0 +1,53 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import java.util.*; + +import org.apache.juneau.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testCallback" +) +public class CallbackStringsResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Test GET + //==================================================================================================== + @RestMethod(name="GET", path="/") + public ObjectMap test1(RestRequest req) throws Exception { + return new ObjectMap().append("method","GET").append("headers", getFooHeaders(req)).append("content", req.getBody().asString()); + } + + //==================================================================================================== + // Test PUT + //==================================================================================================== + @RestMethod(name="PUT", path="/") + public ObjectMap testCharsetOnResponse(RestRequest req) throws Exception { + return new ObjectMap().append("method","PUT").append("headers", getFooHeaders(req)).append("content", req.getBody().asString()); + } + + private Map<String,Object> getFooHeaders(RestRequest req) { + Map<String,Object> m = new TreeMap<String,Object>(); + for (Map.Entry<String,String[]> e : req.getHeaders().entrySet()) + if (e.getKey().startsWith("Foo-")) + m.put(e.getKey(), e.getValue()[0]); + return m; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/CharsetEncodingsResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/CharsetEncodingsResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/CharsetEncodingsResource.java new file mode 100644 index 0000000..d9906f4 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/CharsetEncodingsResource.java @@ -0,0 +1,75 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.apache.juneau.internal.IOUtils.*; + +import org.apache.juneau.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.serializer.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testCharsetEncodings", + defaultRequestHeaders={"Accept: text/s", "Content-Type: text/p"}, + parsers={CharsetEncodingsResource.CtParser.class}, serializers={CharsetEncodingsResource.ASerializer.class} +) +public class CharsetEncodingsResource extends RestServlet { + private static final long serialVersionUID = 1L; + + public static class CtParser extends ReaderParser { + + public CtParser(PropertyStore propertyStore) { + super(propertyStore, "text/p"); + } + + @Override /* Parser */ + public ReaderParserSession createSession(ParserSessionArgs args) { + return new ReaderParserSession(args) { + + @Override /* ParserSession */ + @SuppressWarnings("unchecked") + protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception { + return (T)read(pipe.getReader()); + } + }; + } + } + + public static class ASerializer extends WriterSerializer { + + public ASerializer(PropertyStore propertyStore) { + super(propertyStore, "text/s"); + } + + @Override /* Serializer */ + public WriterSerializerSession createSession(SerializerSessionArgs args) { + return new WriterSerializerSession(args) { + + @Override /* SerializerSession */ + protected void doSerialize(SerializerPipe out, Object o) throws Exception { + out.getWriter().write(o.toString()); + } + }; + } + } + + @RestMethod(name="PUT", path="/") + public String test1(RestRequest req, @Body String in) { + return req.getCharacterEncoding() + "/" + in + "/" + req.getCharacterEncoding(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ClientFuturesResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ClientFuturesResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ClientFuturesResource.java new file mode 100644 index 0000000..0a4202a --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ClientFuturesResource.java @@ -0,0 +1,35 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testClientFutures" +) +public class ClientFuturesResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Test GET + //==================================================================================================== + @RestMethod(name="GET", path="/") + public ObjectMap test1(RestRequest req) throws Exception { + return new ObjectMap().append("foo","bar"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ClientVersionResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ClientVersionResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ClientVersionResource.java new file mode 100644 index 0000000..231304c --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ClientVersionResource.java @@ -0,0 +1,93 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.microservice.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testClientVersion", + children={ + ClientVersionResource.DefaultHeader.class, + ClientVersionResource.CustomHeader.class + } +) +@SuppressWarnings("serial") +public class ClientVersionResource extends Resource { + + @RestResource( + path="/defaultHeader" + ) + public static class DefaultHeader extends Resource { + + @RestMethod(name="GET", path="/") + public String test0() { + return "no-version"; + } + + @RestMethod(name="GET", path="/", clientVersion="[0.0,1.0)") + public String test1() { + return "[0.0,1.0)"; + } + + @RestMethod(name="GET", path="/", clientVersion="[1.0,1.0]") + public String test2() { + return "[1.0,1.0]"; + } + + @RestMethod(name="GET", path="/", clientVersion="[1.1,2)") + public String test3() { + return "[1.1,2)"; + } + + @RestMethod(name="GET", path="/", clientVersion="2") + public String test4() { + return "2"; + } + } + + @RestResource( + path="/customHeader", + clientVersionHeader="Custom-Client-Version" + ) + public static class CustomHeader extends Resource { + + @RestMethod(name="GET", path="/") + public String test0() { + return "no-version"; + } + + @RestMethod(name="GET", path="/", clientVersion="[0.0,1.0)") + public String test1() { + return "[0.0,1.0)"; + } + + @RestMethod(name="GET", path="/", clientVersion="[1.0,1.0]") + public String test2() { + return "[1.0,1.0]"; + } + + @RestMethod(name="GET", path="/", clientVersion="[1.1,2)") + public String test3() { + return "[1.1,2)"; + } + + @RestMethod(name="GET", path="/", clientVersion="2") + public String test4() { + return "2"; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ConfigResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ConfigResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ConfigResource.java new file mode 100644 index 0000000..d766290 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ConfigResource.java @@ -0,0 +1,38 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.ini.*; +import org.apache.juneau.microservice.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testConfig" +) +@SuppressWarnings("serial") +public class ConfigResource extends Resource { + + @RestMethod(name="GET", path="/") + public ConfigFile test1(RestRequest req) { + return req.getConfigFile(); + } + + @RestMethod(name="GET", path="/{key}/{class}") + public Object test2(RestRequest req, @Path("key") String key, @Path("class") Class<?> c) throws Exception { + return req.getConfigFile().getObject(key, c); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ContentResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ContentResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ContentResource.java new file mode 100644 index 0000000..6575ec9 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ContentResource.java @@ -0,0 +1,81 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.apache.juneau.rest.RestContext.*; + +import java.util.*; + +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testContent", + properties={ + @Property(name=REST_allowMethodParam, value="*") + } +) +public class ContentResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Basic tests + //==================================================================================================== + @RestMethod(name="POST", path="/boolean") + public boolean testBool(@Body boolean b) { + return b; + } + + @RestMethod(name="POST", path="/Boolean") + public Boolean testBoolean(@Body Boolean b) { + return b; + } + + @RestMethod(name="POST", path="/int") + public int testInt(@Body int i) { + return i; + } + + @RestMethod(name="POST", path="/Integer") + public Integer testInteger(@Body Integer i) { + return i; + } + + @RestMethod(name="POST", path="/float") + public float testFloat(@Body float f) { + return f; + } + + @RestMethod(name="POST", path="/Float") + public Float testFloat2(@Body Float f) { + return f; + } + + @RestMethod(name="POST", path="/Map") + public TreeMap<String,String> testMap(@Body TreeMap<String,String> m) { + return m; + } + + @RestMethod(name="POST", path="/B") + public DTO2s.B testPojo1(@Body DTO2s.B b) { + return b; + } + + @RestMethod(name="POST", path="/C") + public DTO2s.C testPojo2(@Body DTO2s.C c) { + return c; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/DTO2s.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/DTO2s.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/DTO2s.java new file mode 100644 index 0000000..262d34c --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/DTO2s.java @@ -0,0 +1,138 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import java.util.*; + +import org.apache.juneau.annotation.*; +import org.apache.juneau.urlencoding.annotation.*; +import org.apache.juneau.utils.*; + +public class DTO2s { + + @Bean(sort=true) + public static class A { + public String a; + public int b; + public boolean c; + + public static A create() { + A t = new A(); + t.a = "a"; + t.b = 1; + t.c = true; + return t; + } + + } + + @Bean(sort=true) + public static class B { + public String[] f01; + public List<String> f02; + public int[] f03; + public List<Integer> f04; + public String[][] f05; + public List<String[]> f06; + public A[] f07; + public List<A> f08; + public A[][] f09; + public List<List<A>> f10; + + private String[] f11; + private List<String> f12; + private int[] f13; + private List<Integer> f14; + private String[][] f15; + private List<String[]> f16; + private A[] f17; + private List<A> f18; + private A[][] f19; + private List<List<A>> f20; + + public String[] getF11() { return f11; } + public List<String> getF12() { return f12; } + public int[] getF13() { return f13; } + public List<Integer> getF14() { return f14; } + public String[][] getF15() { return f15; } + public List<String[]> getF16() { return f16; } + public A[] getF17() { return f17; } + public List<A> getF18() { return f18; } + public A[][] getF19() { return f19; } + public List<List<A>> getF20() { return f20; } + + public void setF11(String[] f11) { this.f11 = f11; } + public void setF12(List<String> f12) { this.f12 = f12; } + public void setF13(int[] f13) { this.f13 = f13; } + public void setF14(List<Integer> f14) { this.f14 = f14; } + public void setF15(String[][] f15) { this.f15 = f15; } + public void setF16(List<String[]> f16) { this.f16 = f16; } + public void setF17(A[] f17) { this.f17 = f17; } + public void setF18(List<A> f18) { this.f18 = f18; } + public void setF19(A[][] f19) { this.f19 = f19; } + public void setF20(List<List<A>> f20) { this.f20 = f20; } + + static B create() { + B t = new B(); + t.f01 = new String[]{"a","b"}; + t.f02 = new AList<String>().append("c").append("d"); + t.f03 = new int[]{1,2}; + t.f04 = new AList<Integer>().append(3).append(4); + t.f05 = new String[][]{{"e","f"},{"g","h"}}; + t.f06 = new AList<String[]>().append(new String[]{"i","j"}).append(new String[]{"k","l"}); + t.f07 = new A[]{A.create(),A.create()}; + t.f08 = new AList<A>().append(A.create()).append(A.create()); + t.f09 = new A[][]{{A.create()},{A.create()}}; + t.f10 = new AList<List<A>>().append(Arrays.asList(A.create())).append(Arrays.asList(A.create())); + t.setF11(new String[]{"a","b"}); + t.setF12(new AList<String>().append("c").append("d")); + t.setF13(new int[]{1,2}); + t.setF14(new AList<Integer>().append(3).append(4)); + t.setF15(new String[][]{{"e","f"},{"g","h"}}); + t.setF16(new AList<String[]>().append(new String[]{"i","j"}).append(new String[]{"k","l"})); + t.setF17(new A[]{A.create(),A.create()}); + t.setF18(new AList<A>().append(A.create()).append(A.create())); + t.setF19(new A[][]{{A.create()},{A.create()}}); + t.setF20(new AList<List<A>>().append(Arrays.asList(A.create())).append(Arrays.asList(A.create()))); + return t; + } + } + + @UrlEncoding(expandedParams=true) + public static class C extends B { + static C create() { + C t = new C(); + t.f01 = new String[]{"a","b"}; + t.f02 = new AList<String>().append("c").append("d"); + t.f03 = new int[]{1,2}; + t.f04 = new AList<Integer>().append(3).append(4); + t.f05 = new String[][]{{"e","f"},{"g","h"}}; + t.f06 = new AList<String[]>().append(new String[]{"i","j"}).append(new String[]{"k","l"}); + t.f07 = new A[]{A.create(),A.create()}; + t.f08 = new AList<A>().append(A.create()).append(A.create()); + t.f09 = new A[][]{{A.create()},{A.create()}}; + t.f10 = new AList<List<A>>().append(Arrays.asList(A.create())).append(Arrays.asList(A.create())); + t.setF11(new String[]{"a","b"}); + t.setF12(new AList<String>().append("c").append("d")); + t.setF13(new int[]{1,2}); + t.setF14(new AList<Integer>().append(3).append(4)); + t.setF15(new String[][]{{"e","f"},{"g","h"}}); + t.setF16(new AList<String[]>().append(new String[]{"i","j"}).append(new String[]{"k","l"})); + t.setF17(new A[]{A.create(),A.create()}); + t.setF18(new AList<A>().append(A.create()).append(A.create())); + t.setF19(new A[][]{{A.create()},{A.create()}}); + t.setF20(new AList<List<A>>().append(Arrays.asList(A.create())).append(Arrays.asList(A.create()))); + return t; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/DefaultContentTypesResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/DefaultContentTypesResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/DefaultContentTypesResource.java new file mode 100644 index 0000000..dbd3d05 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/DefaultContentTypesResource.java @@ -0,0 +1,141 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.apache.juneau.rest.annotation.Inherit.*; + +import org.apache.juneau.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.serializer.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testDefaultContentTypes", + defaultRequestHeaders={" Accept : text/s2 "," Content-Type : text/p2 "}, + parsers={DefaultContentTypesResource.P1.class,DefaultContentTypesResource.P2.class}, serializers={DefaultContentTypesResource.S1.class,DefaultContentTypesResource.S2.class} +) +@SuppressWarnings("synthetic-access") +public class DefaultContentTypesResource extends RestServlet { + private static final long serialVersionUID = 1L; + + public static class P1 extends DummyParser { public P1(PropertyStore ps) {super(ps, "p1", "text/p1");}} + + public static class P2 extends DummyParser { public P2(PropertyStore ps) {super(ps, "p2", "text/p2");}} + + public static class P3 extends DummyParser { public P3(PropertyStore ps) {super(ps, "p3", "text/p3");}} + + public static class S1 extends DummySerializer { public S1(PropertyStore ps) {super(ps, "s1", "text/s1");}} + + public static class S2 extends DummySerializer { public S2(PropertyStore ps) {super(ps, "s2", "text/s2");}} + + public static class S3 extends DummySerializer { public S3(PropertyStore ps) {super(ps, "s3", "text/s3");}} + + /** + * Test that default Accept and Content-Type headers on servlet annotation are picked up. + */ + @RestMethod(name="PUT", path="/testDefaultHeadersOnServletAnnotation") + public String testDefaultHeadersOnServletAnnotation(@Body String in) { + return in; + } + + //==================================================================================================== + // Test that default Accept and Content-Type headers on servlet annotation are picked up + // when @RestMethod.parsers/serializers annotations are used. + //==================================================================================================== + @RestMethod(name="PUT", path="/testRestMethodParsersSerializers", parsers=P3.class, serializers=S3.class) + public String testRestMethodParsersSerializers(@Body String in) { + return in; + } + + //==================================================================================================== + // Test that default Accept and Content-Type headers on servlet annotation are picked up + // when @RestMethod.addParsers/addSerializers annotations are used. + //==================================================================================================== + @RestMethod(name="PUT", path="/testRestMethodAddParsersSerializers", parsers=P3.class, parsersInherit=PARSERS, serializers=S3.class, serializersInherit=SERIALIZERS) + public String testRestMethodAddParsersSerializers(@Body String in) { + return in; + } + + //==================================================================================================== + // Various Accept incantations. + //==================================================================================================== + @RestMethod(name="PUT", path="/testAccept") + public String testAccept(@Body String in) { + return in; + } + + //==================================================================================================== + // Test that default Accept and Content-Type headers on method annotation are picked up + // when @RestMethod.parsers/serializers annotations are used. + //==================================================================================================== + @RestMethod(name="PUT", path="/testRestMethodParserSerializerAnnotations", defaultRequestHeaders={"Accept: text/s3","Content-Type: text/p3"}, parsers=P3.class, serializers=S3.class) + public String testRestMethodParserSerializerAnnotations(@Body String in) { + return in; + } + + //==================================================================================================== + // Test that default Accept and Content-Type headers on method annotation are picked up + // when @RestMethod.addParsers/addSerializers annotations are used. + //==================================================================================================== + @RestMethod(name="PUT", path="/testRestMethodAddParsersSerializersAnnotations", defaultRequestHeaders={"Accept: text/s3","Content-Type: text/p3"}, parsers=P3.class, parsersInherit=PARSERS, serializers=S3.class, serializersInherit=SERIALIZERS) + public String testRestMethodAddParsersSerializersAnnotations(@Body String in) { + return in; + } + + public static class DummyParser extends ReaderParser { + + private String name; + + private DummyParser(PropertyStore propertyStore, String name, String...consumes) { + super(propertyStore, consumes); + this.name = name; + } + + @Override /* Parser */ + public ReaderParserSession createSession(ParserSessionArgs args) { + return new ReaderParserSession(args) { + + @Override /* ParserSession */ + @SuppressWarnings("unchecked") + protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception { + return (T)name; + } + }; + } + } + + public static class DummySerializer extends WriterSerializer { + + private String name; + + private DummySerializer(PropertyStore propertyStore, String name, String produces) { + super(propertyStore, produces); + this.name = name; + } + + @Override /* Serializer */ + public WriterSerializerSession createSession(SerializerSessionArgs args) { + return new WriterSerializerSession(args) { + + @Override /* SerializerSession */ + protected void doSerialize(SerializerPipe out, Object o) throws Exception { + out.getWriter().write(name + "/" + o); + } + }; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ErrorConditionsResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ErrorConditionsResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ErrorConditionsResource.java new file mode 100644 index 0000000..8cb0890 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ErrorConditionsResource.java @@ -0,0 +1,135 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + * Validates correct parser is used. + */ +@RestResource( + path="/testErrorConditions" +) +public class ErrorConditionsResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Test non-existent properties + //==================================================================================================== + @RestMethod(name="PUT", path="/testNonExistentBeanProperties") + public String testNonExistentBeanProperties(@Body Test1 in) { + return "OK"; + } + + public static class Test1 { + public String f1; + } + + //==================================================================================================== + // Test trying to set properties to wrong data type + //==================================================================================================== + @RestMethod(name="PUT", path="/testWrongDataType") + public String testWrongDataType(@Body Test2 in) { + return "OK"; + } + + public static class Test2 { + public int f1; + } + + //==================================================================================================== + // Test trying to parse into class with non-public no-arg constructor. + //==================================================================================================== + @RestMethod(name="PUT", path="/testParseIntoNonConstructableBean") + public String testParseIntoNonConstructableBean(@Body Test3a in) { + return "OK"; + } + + public static class Test3a { + public int f1; + private Test3a(){} + } + + //==================================================================================================== + // Test trying to parse into non-static inner class + //==================================================================================================== + @RestMethod(name="PUT", path="/testParseIntoNonStaticInnerClass") + public String testParseIntoNonStaticInnerClass(@Body Test3b in) { + return "OK"; + } + + public class Test3b { + public Test3b(){} + } + + //==================================================================================================== + // Test trying to parse into non-public inner class + //==================================================================================================== + @RestMethod(name="PUT", path="/testParseIntoNonPublicInnerClass") + public String testParseIntoNonPublicInnerClass(@Body Test3b1 in) { + return "OK"; + } + + static class Test3b1 { + public Test3b1(){} + } + + //==================================================================================================== + // Test exception thrown during bean construction. + //==================================================================================================== + @RestMethod(name="PUT", path="/testThrownConstructorException") + public String testThrownConstructorException(@Body Test3c in) { + return "OK"; + } + + public static class Test3c { + public int f1; + private Test3c(){} + public static Test3c valueOf(String s) { + throw new RuntimeException("Test error"); + } + } + + //==================================================================================================== + // Test trying to set parameters to invalid types. + //==================================================================================================== + @RestMethod(name="PUT", path="/testSetParameterToInvalidTypes/{a1}") + public String testSetParameterToInvalidTypes(@Query("p1") int t1, @Path int a1, @Header("h1") int h1) { + return "OK"; + } + + //==================================================================================================== + // Test SC_NOT_FOUND & SC_METHOD_NOT_ALLOWED + //==================================================================================================== + @RestMethod(name="GET", path="/test404and405") + public String test404and405() { + return "OK"; + } + + //==================================================================================================== + // Test SC_PRECONDITION_FAILED + //==================================================================================================== + @RestMethod(name="GET", path="/test412", matchers=NeverMatcher.class) + public String test412() { + return "OK"; + } + + public static class NeverMatcher extends RestMatcher { + @Override /* RestMatcher */ + public boolean matches(RestRequest req) { + return false; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/FormDataResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/FormDataResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/FormDataResource.java new file mode 100644 index 0000000..34936b7 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/FormDataResource.java @@ -0,0 +1,75 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.apache.juneau.internal.IOUtils.*; + +import java.io.*; + +import org.apache.juneau.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testFormData" +) +public class FormDataResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Basic tests + //==================================================================================================== + @RestMethod(name="POST", path="/*") + public Reader test(RestRequest req) throws IOException { + return new StringReader("Content-Type=["+req.getContentType()+"], contents=["+read(req.getReader())+"]"); + } + + //==================================================================================================== + // Default values. + //==================================================================================================== + + @RestMethod(name="POST", path="/defaultFormData", defaultFormData={"f1:1","f2=2"," f3 : 3 "}) + public ObjectMap defaultFormData(RequestFormData formData) { + return new ObjectMap() + .append("f1", formData.getString("f1")) + .append("f2", formData.getString("f2")) + .append("f3", formData.getString("f3")); + } + + @RestMethod(name="POST", path="/annotatedFormData") + public ObjectMap annotatedFormData(@FormData("f1") String f1, @FormData("f2") String f2, @FormData("f3") String f3) { + return new ObjectMap() + .append("f1", f1) + .append("f2", f2) + .append("f3", f3); + } + + @RestMethod(name="POST", path="/annotatedFormDataDefault") + public ObjectMap annotatedFormDataDefault(@FormData(value="f1",def="1") String f1, @FormData(value="f2",def="2") String f2, @FormData(value="f3",def="3") String f3) { + return new ObjectMap() + .append("f1", f1) + .append("f2", f2) + .append("f3", f3); + } + + @RestMethod(name="POST", path="/annotatedAndDefaultFormData", defaultFormData={"f1:1","f2=2"," f3 : 3 "}) + public ObjectMap annotatedAndDefaultFormData(@FormData(value="f1",def="4") String f1, @FormData(value="f2",def="5") String f2, @FormData(value="f3",def="6") String f3) { + return new ObjectMap() + .append("f1", f1) + .append("f2", f2) + .append("f3", f3); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/GroupsResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/GroupsResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/GroupsResource.java new file mode 100644 index 0000000..6bd6454 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/GroupsResource.java @@ -0,0 +1,87 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.apache.juneau.internal.IOUtils.*; +import static org.apache.juneau.rest.annotation.HookEvent.*; + +import org.apache.juneau.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.serializer.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testGroups" +) +public class GroupsResource extends RestServlet { + private static final long serialVersionUID = 1L; + + @RestHook(INIT) + public void init(RestConfig config) throws Exception { + config.addSerializers(SSerializer.class).addParsers(PParser.class); + } + + public static class SSerializer extends WriterSerializer { + + public SSerializer(PropertyStore propertyStore) { + super(propertyStore, "text/s1", "text/s1", "text/s2"); + } + + @Override /* Serializer */ + public WriterSerializerSession createSession(SerializerSessionArgs args) { + return new WriterSerializerSession(args) { + + @Override /* SerializerSession */ + protected void doSerialize(SerializerPipe out, Object o) throws Exception { + out.getWriter().write("text/s," + o); + } + }; + } + } + + public static class PParser extends ReaderParser { + + public PParser(PropertyStore propertyStore) { + super(propertyStore, "text/p1", "text/p2"); + } + + @Override /* Parser */ + public ReaderParserSession createSession(ParserSessionArgs args) { + return new ReaderParserSession(args) { + + @Override /* ParserSession */ + @SuppressWarnings("unchecked") + protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception { + return (T)read(pipe.getReader()); + } + }; + } + } + + //==================================================================================================== + // Serializer defined on class. + //==================================================================================================== + @RestMethod(name="GET", path="/testSerializerDefinedOnClass") + public String testSerializerDefinedOnClass_get() { + return "GET"; + } + + @RestMethod(name="PUT", path="/testSerializerDefinedOnClass") + public String testSerializerDefinedOnClass_put(@Body String in) { + return in; + } +}