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/pojos/SwappedPojoSwap.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/SwappedPojoSwap.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/SwappedPojoSwap.java new file mode 100644 index 0000000..53c3e93 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/SwappedPojoSwap.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.pojos; + +import static org.apache.juneau.rest.test.pojos.Constants.*; + +import org.apache.juneau.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.serializer.*; +import org.apache.juneau.transform.*; + +public class SwappedPojoSwap extends PojoSwap<SwappedPojo,String> { + @Override + public String swap(BeanSession session, SwappedPojo c) throws SerializeException { + return SWAP; + } + + @Override + public SwappedPojo unswap(BeanSession session, String f, ClassMeta<?> hint) throws ParseException { + SwappedPojo c = new SwappedPojo(); + if (f.equals(SWAP)) + c.wasUnswapped = true; + return c; + } +} \ No newline at end of file
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/pojos/TestEnum.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/TestEnum.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/TestEnum.java new file mode 100644 index 0000000..06facf7 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/TestEnum.java @@ -0,0 +1,17 @@ +// *************************************************************************************************************************** +// * 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.pojos; + +public enum TestEnum { + ONE,TWO,THREE +} \ No newline at end of file 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/pojos/TypedBean.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/TypedBean.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/TypedBean.java new file mode 100644 index 0000000..0e13279 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/TypedBean.java @@ -0,0 +1,17 @@ +// *************************************************************************************************************************** +// * 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.pojos; + [email protected](beanDictionary={TypedBeanImpl.class}) +public interface TypedBean { +} \ No newline at end of file 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/pojos/TypedBeanImpl.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/TypedBeanImpl.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/TypedBeanImpl.java new file mode 100644 index 0000000..a381475 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/pojos/TypedBeanImpl.java @@ -0,0 +1,25 @@ +// *************************************************************************************************************************** +// * 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.pojos; + [email protected](typeName="TypedBeanImpl", sort=true) +public class TypedBeanImpl implements TypedBean { + public int a; + public String b; + + public TypedBeanImpl init() { + this.a = 1; + this.b = "foo"; + return this; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/HtmlPropertiesResource.properties ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/HtmlPropertiesResource.properties b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/HtmlPropertiesResource.properties new file mode 100644 index 0000000..a35bfe7 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/HtmlPropertiesResource.properties @@ -0,0 +1,31 @@ +# *************************************************************************************************************************** +# * 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. * +# * * +# *************************************************************************************************************************** + +LocalizedExplicit.pageTitle = LocalizedExplicit.nls.pageTitle +LocalizedExplicit.pageText = LocalizedExplicit.nls.pageText + +LocalizedExplicit.test2.pageTitle = LocalizedExplicit.test2.nls.pageTitle +LocalizedExplicit.test2.pageText = LocalizedExplicit.test2.nls.pageText + +LocalizedExplicit.test3.pageTitle = LocalizedExplicit.test3.nls.pageTitle +LocalizedExplicit.test3.pageText = LocalizedExplicit.test3.nls.pageText + +LocalizedExplicit.test4.pageTitle = LocalizedExplicit.test4.nls.pageTitle +LocalizedExplicit.test4.pageText = LocalizedExplicit.test4.nls.pageText + +LocalizedImplicit.pageTitle = LocalizedImplicit.nls.pageTitle +LocalizedImplicit.pageText = LocalizedImplicit.nls.pageText + +LocalizedImplicit.test2.pageTitle = LocalizedImplicit.test2.nls.pageTitle +LocalizedImplicit.test2.pageText = LocalizedImplicit.test2.nls.pageText http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/Messages2Resource.properties ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/Messages2Resource.properties b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/Messages2Resource.properties new file mode 100644 index 0000000..9a5fe73 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/Messages2Resource.properties @@ -0,0 +1,16 @@ +# *************************************************************************************************************************** +# * 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. * +# * * +# *************************************************************************************************************************** + +key2 = value2b +key3 = value3b \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/MessagesResource.properties ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/MessagesResource.properties b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/MessagesResource.properties new file mode 100644 index 0000000..d107ee8 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/MessagesResource.properties @@ -0,0 +1,16 @@ +# *************************************************************************************************************************** +# * 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. * +# * * +# *************************************************************************************************************************** + +key1 = value1a +key2 = value2a \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsPropertyResource.properties ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsPropertyResource.properties b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsPropertyResource.properties new file mode 100644 index 0000000..a833256 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsPropertyResource.properties @@ -0,0 +1,16 @@ +# *************************************************************************************************************************** +# * 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. * +# * * +# *************************************************************************************************************************** + +key1 = value1 +key2 = value2 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties new file mode 100644 index 0000000..d461923 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties @@ -0,0 +1,71 @@ +# *************************************************************************************************************************** +# * 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. * +# * * +# *************************************************************************************************************************** + +title = Test2.a +description = Test2.b +test2.summary = Test2.c +test2.req.path.a.description = Test2.d +test2.req.query.b.description = Test2.e +test2.req.body.description = Test2.f +test2.req.header.D.description = Test2.g +test2.req.path.a2.description = Test2.h +test2.req.query.b2.description = Test2.i +test2.req.header.D2.description = Test2.j +test2.res.200.description = OK2 +test2.res.201.description = Test2.l + +Test3.title = Test3.a +Test3.description = Test3.b +Test3.test3.summary = Test3.c +Test3.test3.req.path.a.description = Test3.d +Test3.test3.req.query.b.description = Test3.e +Test3.test3.req.body.description = Test3.f +Test3.test3.req.header.D.description = Test3.g +Test3.test3.req.path.a2.description = Test3.h +Test3.test3.req.query.b2.description = Test3.i +Test3.test3.req.header.D2.description = Test3.j +Test3.test3.res.200.description = OK3 +Test3.test3.res.201.description = Test3.l + +Test4.title = $L{foo} +Test4.description = $L{foo} +Test4.test4.summary = $L{foo} +Test4.test4.req.path.a.description = $L{foo} +Test4.test4.req.query.b.description = $L{foo} +Test4.test4.req.body.description = $L{foo} +Test4.test4.req.header.D.description = $L{foo} +Test4.test4.req.path.a2.description = $L{foo} +Test4.test4.req.query.b2.description = $L{foo} +Test4.test4.req.header.D2.description = $L{foo} +Test4.test4.res.200.description = foo$L{foo}foo$L{foo}foo +Test4.test4.res.201.description = $L{foo} + +foo = $L{bar} +bar = baz + +Test5.title = $L{foo2} +Test5.description = $R{servletTitle} +Test5.test5.summary = $R{servletTitle} +Test5.test5.req.path.a.description = $R{servletTitle} +Test5.test5.req.query.b.description = $R{servletTitle} +Test5.test5.req.body.description = $R{servletTitle} +Test5.test5.req.header.D.description = $R{servletTitle} +Test5.test5.req.path.a2.description = $R{servletTitle} +Test5.test5.req.query.b2.description = $R{servletTitle} +Test5.test5.req.header.D2.description = $R{servletTitle} +Test5.test5.res.200.description = foo$R{servletTitle}foo$R{servletTitle}foo +Test5.test5.res.201.description = $R{servletTitle} +Test5.foo2 = $L{bar2} +Test5.bar2 = baz2 + http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource.properties ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource.properties b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource.properties new file mode 100644 index 0000000..73add61 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource.properties @@ -0,0 +1,15 @@ +# *************************************************************************************************************************** +# * 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. * +# * * +# *************************************************************************************************************************** + +foo = bar \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource_ja_JP.properties ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource_ja_JP.properties b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource_ja_JP.properties new file mode 100644 index 0000000..336741e --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/ParamsResource_ja_JP.properties @@ -0,0 +1,15 @@ +# *************************************************************************************************************************** +# * 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. * +# * * +# *************************************************************************************************************************** + +foo = baz \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/test.txt ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/test.txt b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/test.txt new file mode 100644 index 0000000..b4ea91c --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/test.txt @@ -0,0 +1,13 @@ + *************************************************************************************************************************** + * 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. * + *************************************************************************************************************************** + OK-1 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/xdocs/test.txt ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/xdocs/test.txt b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/xdocs/test.txt new file mode 100644 index 0000000..e3db156 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/main/resources/org/apache/juneau/rest/test/xdocs/xdocs/test.txt @@ -0,0 +1,13 @@ + *************************************************************************************************************************** + * 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. * + *************************************************************************************************************************** + OK-2 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/AcceptCharsetTest.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/AcceptCharsetTest.java b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/AcceptCharsetTest.java new file mode 100644 index 0000000..84bbd9a --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/AcceptCharsetTest.java @@ -0,0 +1,125 @@ +// *************************************************************************************************************************** +// * 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 javax.servlet.http.HttpServletResponse.*; +import static org.apache.juneau.internal.IOUtils.*; +import static org.apache.juneau.rest.test.TestUtils.*; +import static org.junit.Assert.*; + +import java.io.*; + +import org.apache.juneau.rest.client.*; +import org.junit.*; + +public class AcceptCharsetTest extends RestTestcase { + + boolean debug = false; + + //==================================================================================================== + // Test that Q-values are being resolved correctly. + //==================================================================================================== + @Test + public void testQValues() throws Exception { + RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT; + + check1(client, "utf-8", "utf-8"); + check1(client, "iso-8859-1", "iso-8859-1"); + check1(client, "bad,utf-8", "utf-8"); + check1(client, "utf-8,bad", "utf-8"); + check1(client, "bad;q=0.9,utf-8;q=0.1", "utf-8"); + check1(client, "bad;q=0.1,utf-8;q=0.9", "utf-8"); +// check1(client, "utf-8,iso-8859-1", "utf-8"); +// check1(client, "iso-8859-1,utf-8", "utf-8"); + check1(client, "utf-8;q=0.9,iso-8859-1;q=0.1", "utf-8"); + check1(client, "utf-8;q=0.1,iso-8859-1;q=0.9", "iso-8859-1"); + check1(client, "*", "utf-8"); + check1(client, "bad,iso-8859-1;q=0.5,*;q=0.1", "iso-8859-1"); + check1(client, "bad,iso-8859-1;q=0.1,*;q=0.5", "utf-8"); + } + + private void check1(RestClient client, String requestCharset, String responseCharset) throws Exception { + RestCall r; + debug=true; + InputStream is; + String url = "/testAcceptCharset/testQValues"; + r = client.doGet(url).acceptCharset(requestCharset).connect(); + + if (! r.getResponse().getFirstHeader("Content-Type").getValue().toLowerCase().contains(responseCharset)) + System.err.println("Expected '"+responseCharset+"', actual '"+r.getResponse().getFirstHeader("Content-Type").getValue().toLowerCase()+"'"); + assertTrue(r.getResponse().getFirstHeader("Content-Type").getValue().toLowerCase().contains(responseCharset)); + is = r.getInputStream(); + assertEquals("foo", read(new InputStreamReader(is, responseCharset))); + } + + //==================================================================================================== + // Validate various Accept-Charset variations. + //==================================================================================================== + @Test + public void testCharsetOnResponse() throws Exception { + RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT; + String url = "/testAcceptCharset/testCharsetOnResponse"; + String r; + + r = client.doPut(url, new StringReader("")).getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).acceptCharset("Shift_JIS").getResponseAsString(); + assertEquals("utf-8/shift_jis", r.toLowerCase()); + + try { + r = client.doPut(url+"?noTrace=true", new StringReader("")).acceptCharset("BAD").getResponseAsString(); + fail("Exception expected"); + } catch (RestCallException e) { + checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, "No supported charsets in header 'Accept-Charset': 'BAD'"); + } + + r = client.doPut(url, new StringReader("")).acceptCharset("UTF-8").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).acceptCharset("bad,iso-8859-1").getResponseAsString(); + assertEquals("utf-8/iso-8859-1", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).acceptCharset("bad;q=0.9,iso-8859-1;q=0.1").getResponseAsString(); + assertEquals("utf-8/iso-8859-1", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).acceptCharset("bad;q=0.1,iso-8859-1;q=0.9").getResponseAsString(); + assertEquals("utf-8/iso-8859-1", r.toLowerCase()); + + client = TestMicroservice.client().accept("text/plain").contentType("text/plain").acceptCharset("utf-8").build(); + + r = client.doPut(url, new StringReader("")).contentType("text/plain").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).contentType("text/plain;charset=utf-8").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).contentType("text/plain;charset=UTF-8").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).contentType("text/plain;charset=iso-8859-1").getResponseAsString(); + assertEquals("iso-8859-1/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).contentType("text/plain;charset=Shift_JIS").getResponseAsString(); + assertEquals("shift_jis/utf-8", r.toLowerCase()); + + try { + r = client.doPut(url + "?noTrace=true&Content-Type=text/plain;charset=BAD", new StringReader("")).getResponseAsString(); + fail("Exception expected"); + } catch (RestCallException e) { + checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported charset in header 'Content-Type': 'text/plain;charset=BAD'"); + } + + client.closeQuietly(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/BeanContextPropertiesTest.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/BeanContextPropertiesTest.java b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/BeanContextPropertiesTest.java new file mode 100644 index 0000000..1e583a5 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/BeanContextPropertiesTest.java @@ -0,0 +1,34 @@ +// *************************************************************************************************************************** +// * 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.junit.Assert.*; + +import org.apache.juneau.rest.client.*; +import org.junit.*; + +public class BeanContextPropertiesTest extends RestTestcase { + + boolean debug = false; + + //==================================================================================================== + // Validate that filters defined on class filter to underlying bean context. + //==================================================================================================== + @Test + public void testClassTransforms() throws Exception { + RestClient client = TestMicroservice.DEFAULT_CLIENT; + String r; + r = client.doGet("/testBeanContext/testClassTransforms/2001-07-04T15:30:45Z?d2=2001-07-05T15:30:45Z").header("X-D3", "2001-07-06T15:30:45Z").getResponseAsString(); + assertEquals("d1=2001-07-04T15:30:45Z,d2=2001-07-05T15:30:45Z,d3=2001-07-06T15:30:45Z", r); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/BpiTest.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/BpiTest.java b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/BpiTest.java new file mode 100644 index 0000000..d78f59e --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/BpiTest.java @@ -0,0 +1,253 @@ +// *************************************************************************************************************************** +// * 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.junit.Assert.*; + +import java.util.*; + +import org.apache.juneau.*; +import org.apache.juneau.msgpack.*; +import org.apache.juneau.rest.client.*; +import org.junit.*; +import org.junit.runner.*; +import org.junit.runners.*; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(Parameterized.class) +public class BpiTest extends RestTestcase { + + @Parameterized.Parameters + public static Collection<Object[]> getParameters() { + return Arrays.asList(new Object[][] { + { /* 0 */ + "a1", + "{a:1,_b:'foo'}", + "<?xml version='1.0' encoding='UTF-8'?><object><a>1</a><_b>foo</_b></object>", + "<table><tr><td>a</td><td>1</td></tr><tr><td>_b</td><td>foo</td></tr></table>", + "(a=1,_b=foo)", + "a=1&_b=foo", + "{a:1,_b:'foo'}", + "<rdf:RDF>\n<rdf:Description>\n<jp:a>1</jp:a>\n<jp:_b>foo</jp:_b>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 1 */ + "a2", + "{a:1}", + "<?xml version='1.0' encoding='UTF-8'?><object><a>1</a></object>", + "<table><tr><td>a</td><td>1</td></tr></table>", + "(a=1)", + "a=1", + "{a:1}", + "<rdf:RDF>\n<rdf:Description>\n<jp:a>1</jp:a>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 2 */ + "a3", + "{_b:'foo'}", + "<?xml version='1.0' encoding='UTF-8'?><object><_b>foo</_b></object>", + "<table><tr><td>_b</td><td>foo</td></tr></table>", + "(_b=foo)", + "_b=foo", + "{_b:'foo'}", + "<rdf:RDF>\n<rdf:Description>\n<jp:_b>foo</jp:_b>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 3 */ + "a4", + "{_b:'foo'}", + "<?xml version='1.0' encoding='UTF-8'?><object><_b>foo</_b></object>", + "<table><tr><td>_b</td><td>foo</td></tr></table>", + "(_b=foo)", + "_b=foo", + "{_b:'foo'}", + "<rdf:RDF>\n<rdf:Description>\n<jp:_b>foo</jp:_b>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 4 */ + "a5", + "{a:1}", + "<?xml version='1.0' encoding='UTF-8'?><object><a>1</a></object>", + "<table><tr><td>a</td><td>1</td></tr></table>", + "(a=1)", + "a=1", + "{a:1}", + "<rdf:RDF>\n<rdf:Description>\n<jp:a>1</jp:a>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 5 */ + "a6", + "{}", + "<?xml version='1.0' encoding='UTF-8'?><object/>", + "<table></table>", + "()", + "", + "{}", + "<rdf:RDF>\n</rdf:RDF>" + }, + { /* 6 */ + "b1", + "{_b:'foo',a:1}", + "<?xml version='1.0' encoding='UTF-8'?><object><_b>foo</_b><a>1</a></object>", + "<table><tr><td>_b</td><td>foo</td></tr><tr><td>a</td><td>1</td></tr></table>", + "(_b=foo,a=1)", + "_b=foo&a=1", + "{_b:'foo',a:1}", + "<rdf:RDF>\n<rdf:Description>\n<jp:a>1</jp:a>\n<jp:_b>foo</jp:_b>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 7 */ + "b2", + "{a:1}", + "<?xml version='1.0' encoding='UTF-8'?><object><a>1</a></object>", + "<table><tr><td>a</td><td>1</td></tr></table>", + "(a=1)", + "a=1", + "{a:1}", + "<rdf:RDF>\n<rdf:Description>\n<jp:a>1</jp:a>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 8 */ + "b3", + "{_b:'foo'}", + "<?xml version='1.0' encoding='UTF-8'?><object><_b>foo</_b></object>", + "<table><tr><td>_b</td><td>foo</td></tr></table>", + "(_b=foo)", + "_b=foo", + "{_b:'foo'}", + "<rdf:RDF>\n<rdf:Description>\n<jp:_b>foo</jp:_b>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 9 */ + "b4", + "{_b:'foo'}", + "<?xml version='1.0' encoding='UTF-8'?><object><_b>foo</_b></object>", + "<table><tr><td>_b</td><td>foo</td></tr></table>", + "(_b=foo)", + "_b=foo", + "{_b:'foo'}", + "<rdf:RDF>\n<rdf:Description>\n<jp:_b>foo</jp:_b>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 10 */ + "b5", + "{a:1}", + "<?xml version='1.0' encoding='UTF-8'?><object><a>1</a></object>", + "<table><tr><td>a</td><td>1</td></tr></table>", + "(a=1)", + "a=1", + "{a:1}", + "<rdf:RDF>\n<rdf:Description>\n<jp:a>1</jp:a>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 11 */ + "b6", + "{}", + "<?xml version='1.0' encoding='UTF-8'?><object/>", + "<table></table>", + "()", + "", + "{}", + "<rdf:RDF>\n</rdf:RDF>" + }, + { /* 12 */ + "c1", + "{a:1}", + "<?xml version='1.0' encoding='UTF-8'?><object><a>1</a></object>", + "<table><tr><td>a</td><td>1</td></tr></table>", + "(a=1)", + "a=1", + "{a:1}", + "<rdf:RDF>\n<rdf:Description>\n<jp:a>1</jp:a>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 13 */ + "c2", + "{a:1}", + "<?xml version='1.0' encoding='UTF-8'?><object><a>1</a></object>", + "<table><tr><td>a</td><td>1</td></tr></table>", + "(a=1)", + "a=1", + "{a:1}", + "<rdf:RDF>\n<rdf:Description>\n<jp:a>1</jp:a>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 14 */ + "d1", + "{a:1,_b:'foo'}", + "<?xml version='1.0' encoding='UTF-8'?><object><a>1</a><_b>foo</_b></object>", + "<table><tr><td>a</td><td>1</td></tr><tr><td>_b</td><td>foo</td></tr></table>", + "(a=1,_b=foo)", + "a=1&_b=foo", + "{a:1,_b:'foo'}", + "<rdf:RDF>\n<rdf:Description>\n<jp:a>1</jp:a>\n<jp:_b>foo</jp:_b>\n</rdf:Description>\n</rdf:RDF>" + }, + { /* 15 */ + "d2", + "{a:1,_b:'foo'}", + "<?xml version='1.0' encoding='UTF-8'?><object><a>1</a><_b>foo</_b></object>", + "<table><tr><td>a</td><td>1</td></tr><tr><td>_b</td><td>foo</td></tr></table>", + "(a=1,_b=foo)", + "a=1&_b=foo", + "{a:1,_b:'foo'}", + "<rdf:RDF>\n<rdf:Description>\n<jp:a>1</jp:a>\n<jp:_b>foo</jp:_b>\n</rdf:Description>\n</rdf:RDF>" + } + }); + } + + private String label; + private String json, xml, html, uon, urlEnc, msgPack, rdfXml; + private RestClient client = TestMicroservice.DEFAULT_CLIENT; + + public BpiTest(String label, String json, String xml, String html, String uon, String urlEnc, String msgPack, String rdfXml) { + this.label = label; + this.json = json; + this.xml = xml; + this.html = html; + this.uon = uon; + this.urlEnc = urlEnc; + this.msgPack = msgPack; + this.rdfXml = rdfXml; + } + + @Test + public void a01_json() throws Exception { + String r = client.doGet("/testBpi/test/" + label).accept("text/json+simple").getResponseAsString(); + assertEquals(json, r); + } + + @Test + public void a02_xml() throws Exception { + String r = client.doGet("/testBpi/test/" + label).accept("text/xml").getResponseAsString().replace('"', '\''); + assertEquals(xml, r); + } + + @Test + public void a03_html() throws Exception { + String r = client.doGet("/testBpi/test/" + label).accept("text/html+stripped").getResponseAsString(); + assertEquals(html, r); + } + + @Test + public void a04_uon() throws Exception { + String r = client.doGet("/testBpi/test/" + label).accept("text/uon").getResponseAsString(); + assertEquals(uon, r); + } + + @Test + public void a05_urlEnc() throws Exception { + String r = client.doGet("/testBpi/test/" + label).accept("application/x-www-form-urlencoded").getResponseAsString(); + assertEquals(urlEnc, r); + } + + @Test + public void a06_msgPack() throws Exception { + String r = client.doGet("/testBpi/test/" + label).accept("octal/msgpack").parser(MsgPackParser.DEFAULT).getResponse(ObjectMap.class).toString(); + assertEquals(msgPack, r); + } + + @Test + public void a07_rdfXml() throws Exception { + String r = client.doGet("/testBpi/test/" + label).accept("text/xml+rdf+abbrev").getResponseAsString(); + r = r.replaceAll("<rdf:RDF[^>]*>", "<rdf:RDF>").replace('"', '\''); + TestUtils.assertEqualsAfterSort(rdfXml, r, "a07_rdfXml failed"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/CallbackStringsTest.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/CallbackStringsTest.java b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/CallbackStringsTest.java new file mode 100644 index 0000000..36a6961 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/CallbackStringsTest.java @@ -0,0 +1,50 @@ +// *************************************************************************************************************************** +// * 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.junit.Assert.*; + +import org.apache.juneau.rest.client.*; +import org.junit.*; + +public class CallbackStringsTest extends RestTestcase { + + //==================================================================================================== + // Basic tests using @Body parameter + //==================================================================================================== + @Test + public void test() throws Exception { + RestClient c = TestMicroservice.client().accept("text/json+simple").build(); + String r; + + r = c.doCallback("GET /testCallback").getResponseAsString(); + assertEquals("{method:'GET',headers:{},content:''}", r); + + r = c.doCallback("GET /testCallback some sample content").getResponseAsString(); + assertEquals("{method:'GET',headers:{},content:'some sample content'}", r); + + r = c.doCallback("GET {Foo-X:123,Foo-Y:'abc'} /testCallback").getResponseAsString(); + assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:''}", r); + + r = c.doCallback("GET { Foo-X : 123, Foo-Y : 'abc' } /testCallback").getResponseAsString(); + assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:''}", r); + + r = c.doCallback("GET {Foo-X:123,Foo-Y:'abc'} /testCallback some sample content ").getResponseAsString(); + assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:'some sample content'}", r); + + r = c.doCallback("PUT {Foo-X:123,Foo-Y:'abc'} /testCallback some sample content ").getResponseAsString(); + assertEquals("{method:'PUT',headers:{'Foo-X':'123','Foo-Y':'abc'},content:'some sample content'}", r); + + c.closeQuietly(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/CharsetEncodingsTest.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/CharsetEncodingsTest.java b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/CharsetEncodingsTest.java new file mode 100644 index 0000000..fa0a242 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/CharsetEncodingsTest.java @@ -0,0 +1,110 @@ +// *************************************************************************************************************************** +// * 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 javax.servlet.http.HttpServletResponse.*; +import static org.apache.juneau.internal.IOUtils.*; +import static org.apache.juneau.rest.test.TestUtils.*; +import static org.junit.Assert.*; + +import java.io.*; + +import org.apache.juneau.rest.client.*; +import org.junit.*; + + +public class CharsetEncodingsTest extends RestTestcase { + + private static boolean debug = false; + + /** + * Basic tests to ensure that the correct charsets are found and used + * under a variety of scenarios. + */ + @Test + public void test() throws Exception { + String url = "/testCharsetEncodings"; + RestClientBuilder cb = TestMicroservice.client().accept("text/s").contentType("text/p"); + RestClient client = cb.build(); + InputStream is; + String r; + + r = client.doPut(url, new StringReader("foo")).getResponseAsString(); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + + is = client.doPut(url, new StringReader("foo")).getInputStream(); + r = read(new InputStreamReader(is, "utf-8")); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + + client.closeQuietly(); + + client = cb.acceptCharset("utf-8").contentType("text/p;charset=utf-8").build(); + is = client.doPut(url, new StringReader("foo")).acceptCharset("utf-8").contentType("text/p;charset=utf-8").getInputStream(); + r = read(new InputStreamReader(is, "utf-8")); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + + client.closeQuietly(); + + client = cb.acceptCharset("Shift_JIS").contentType("text/p;charset=shift_jis").build(); + is = client.doPut(url, new StringReader("foo")).getInputStream(); + r = read(new InputStreamReader(is, "Shift_JIS")); + if (debug) System.err.println(r); + assertEquals("shift_jis/foo/shift_jis", r); + + client.closeQuietly(); + + try { + client = cb.acceptCharset("BAD").contentType("text/p;charset=sjis").build(); + is = client.doPut(url + "?noTrace=true", new StringReader("foo")).getInputStream(); + r = read(new InputStreamReader(is, "sjis")); + if (debug) System.err.println(r); + fail("Exception expected"); + } catch (RestCallException e) { + checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, "No supported charsets in header 'Accept-Charset': 'BAD'"); + } + + client.closeQuietly(); + + client = cb.accept("text/s").acceptCharset("utf-8").contentType("text/p").build(); + is = client.doPut(url+"?Content-Type=text/p", new StringReader("foo")).getInputStream(); + r = read(new InputStreamReader(is, "utf-8")); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + + client.closeQuietly(); + + client = cb.accept("text/s").contentType("text/bad").acceptCharset("utf-8").build(); + is = client.doPut(url+"?Content-Type=text/p;charset=utf-8", new StringReader("foo")).getInputStream(); + r = read(new InputStreamReader(is, "utf-8")); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + + client.closeQuietly(); + + try { + client = cb.accept("text/s").contentType("text/p").acceptCharset("utf-8").build(); + is = client.doPut(url+"?Content-Type=text/p;charset=BAD&noTrace=true", new StringReader("foo")).getInputStream(); + r = read(new InputStreamReader(is, "utf-8")); + if (debug) System.err.println(r); + assertEquals("utf-8/foo/utf-8", r); + fail("Exception expected"); + } catch (RestCallException e) { + checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported charset in header 'Content-Type': 'text/p;charset=BAD'"); + } + + client.closeQuietly(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ClientFuturesTest.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ClientFuturesTest.java b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ClientFuturesTest.java new file mode 100644 index 0000000..d89d9de --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ClientFuturesTest.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 static org.apache.juneau.rest.test.TestUtils.*; +import static org.junit.Assert.*; + +import java.util.concurrent.*; + +import org.apache.juneau.*; +import org.apache.juneau.rest.client.*; +import org.junit.*; + +public class ClientFuturesTest extends RestTestcase { + + private static String URL = "/testClientFutures"; + + //==================================================================================================== + // Basic tests + //==================================================================================================== + @Test + public void test() throws Exception { + RestClient client = TestMicroservice.DEFAULT_CLIENT; + + Future<Integer> f = client.doGet(URL).runFuture(); + assertEquals(200, f.get().intValue()); + + Future<ObjectMap> f2 = client.doGet(URL).getResponseFuture(ObjectMap.class); + assertObjectEquals("{foo:'bar'}", f2.get()); + + Future<String> f3 = client.doGet(URL).getResponseAsStringFuture(); + assertObjectEquals("'{\"foo\":\"bar\"}'", f3.get()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ClientVersionTest.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ClientVersionTest.java b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ClientVersionTest.java new file mode 100644 index 0000000..3eda27b --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ClientVersionTest.java @@ -0,0 +1,77 @@ +// *************************************************************************************************************************** +// * 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.junit.Assert.*; + +import org.apache.juneau.rest.client.*; +import org.junit.*; + +public class ClientVersionTest extends RestTestcase { + + private static String URL = "/testClientVersion"; + + //==================================================================================================== + // Basic tests - default X-Client-Version header. + //==================================================================================================== + @Test + public void testDefaultHeader() throws Exception { + RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT; + String url = URL + "/defaultHeader"; + + assertEquals("no-version", client.doGet(url).getResponseAsString()); + +// for (String s : "0, 0.0, 0.1, .1, .9, .99".split("\\s*,\\s*")) { +// assertEquals(s, "[0.0,1.0)", client.doGet(url).clientVersion(s).getResponseAsString()); +// } + + for (String s : "1, 1.0, 1.0.0, 1.0.1".split("\\s*,\\s*")) { + assertEquals(s, "[1.0,1.0]", client.doGet(url).clientVersion(s).getResponseAsString()); + } + + for (String s : "1.1, 1.1.1, 1.2, 1.9.9".split("\\s*,\\s*")) { + assertEquals(s, "[1.1,2)", client.doGet(url).clientVersion(s).getResponseAsString()); + } + + for (String s : "2, 2.0, 2.1, 9, 9.9".split("\\s*,\\s*")) { + assertEquals(s, "2", client.doGet(url).clientVersion(s).getResponseAsString()); + } + } + + //==================================================================================================== + // Basic tests - Custom-Client-Version header. + //==================================================================================================== + @Test + public void testCustomHeader() throws Exception { + RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT; + String url = URL + "/customHeader"; + + assertEquals("no-version", client.doGet(url).getResponseAsString()); + + for (String s : "0, 0.0, 0.1, .1, .9, .99".split("\\s*,\\s*")) { + assertEquals("[0.0,1.0)", client.doGet(url).header("Custom-Client-Version", s).getResponseAsString()); + } + + for (String s : "1, 1.0, 1.0.0, 1.0.1".split("\\s*,\\s*")) { + assertEquals("[1.0,1.0]", client.doGet(url).header("Custom-Client-Version", s).getResponseAsString()); + } + + for (String s : "1.1, 1.1.1, 1.2, 1.9.9".split("\\s*,\\s*")) { + assertEquals("[1.1,2)", client.doGet(url).header("Custom-Client-Version", s).getResponseAsString()); + } + + for (String s : "2, 2.0, 2.1, 9, 9.9".split("\\s*,\\s*")) { + assertEquals("2", client.doGet(url).header("Custom-Client-Version", s).getResponseAsString()); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ConfigTest.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ConfigTest.java b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ConfigTest.java new file mode 100644 index 0000000..9c186f3 --- /dev/null +++ b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ConfigTest.java @@ -0,0 +1,57 @@ +// *************************************************************************************************************************** +// * 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.StringUtils.*; +import static org.apache.juneau.rest.test.TestUtils.*; +import static org.junit.Assert.*; + +import org.apache.juneau.ini.*; +import org.apache.juneau.rest.client.*; +import org.junit.*; + +public class ConfigTest extends RestTestcase { + + private static String URL = "/testConfig"; + + //==================================================================================================== + // Basic tests + //==================================================================================================== + @Test + public void test() throws Exception { + RestClient c = TestMicroservice.client().accept("text/json+simple").build(); + + ConfigFile cf = c.doGet(URL).getResponse(ConfigFileImpl.class); + + assertObjectEquals("{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}'}", cf.get("Test")); + + assertEquals("'1'", c.doGet(URL + "/Test%2Fint1/" + getName(String.class)).getResponseAsString()); + assertEquals("'[1,2,3]'", c.doGet(URL + "/Test%2Fint2/" + getName(String.class)).getResponseAsString()); + assertEquals("['1','2','3']", c.doGet(URL + "/Test%2Fint2/" + getName(String[].class)).getResponseAsString()); + assertEquals("[1,2,3]", c.doGet(URL + "/Test%2Fint2/" + getName(int[].class)).getResponseAsString()); + assertEquals("[1,2,3]", c.doGet(URL + "/Test%2Fint2/" + getName(Integer[].class)).getResponseAsString()); + assertEquals("1", c.doGet(URL + "/Test%2Fint3/" + getName(Integer.class)).getResponseAsString()); + assertEquals("1", c.doGet(URL + "/Test%2Fint4/" + getName(Integer.class)).getResponseAsString()); + assertEquals("-1", c.doGet(URL + "/Test%2Fint5/" + getName(Integer.class)).getResponseAsString()); + assertEquals("true", c.doGet(URL + "/Test%2Fboolean1/" + getName(Boolean.class)).getResponseAsString()); + assertEquals("[true,true]", c.doGet(URL + "/Test%2Fboolean2/" + getName(Boolean[].class)).getResponseAsString()); + assertTrue(c.doGet(URL + "/Test%2Fpath/" + getName(String.class)).getResponseAsString().length() > 10); + assertEquals("'test-value'", c.doGet(URL + "/Test%2FtestManifestEntry/" + getName(String.class)).getResponseAsString()); + + c.closeQuietly(); + } + + private String getName(Class<?> c) { + return urlEncode(c.getName()); + } +}
