You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by ng...@apache.org on 2009/06/23 07:38:19 UTC
svn commit: r787553 [24/34] - in /incubator/wink/contrib/ibm-jaxrs/tests: ./
fvt/ fvt/demo/ fvt/demo/jaxrs/ fvt/demo/jaxrs/cache/
fvt/demo/jaxrs/cache/server/ fvt/demo/jaxrs/cache/test/
fvt/demo/jaxrs/datasource/ fvt/demo/jaxrs/datasource/server/ fvt/d...
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formparam/test/FormParamValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formparam/test/FormParamValidationTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formparam/test/FormParamValidationTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formparam/test/FormParamValidationTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,69 @@
+/*
+ * 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 jaxrs.tests.validation.param.formparam.test;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+
+import framework.defaults.test.Environment;
+import framework.defaults.test.FVTTestCase;
+
+public class FormParamValidationTest extends FVTTestCase {
+
+ public static Test suite() {
+ return FVTTestCase.getTestSuite(FormParamValidationTest.class,
+ jaxrs.tests.validation.param.formparam.server.Application.class
+ .getName());
+ }
+
+ public void testFormPropertyNoMultivaluedMapEntityValidation()
+ throws Exception {
+ HttpClient httpclient = new HttpClient();
+
+ PostMethod httpMethod = new PostMethod(getBaseURI()
+ + "/validate/paramnotmultivaluedmaparam");
+ try {
+ StringRequestEntity s = new StringRequestEntity(
+ "firstkey=somevalue&someothervalue=somethingelse",
+ "application/x-www-form-urlencoded", null);
+ httpMethod.setRequestEntity(s);
+ httpclient.executeMethod(httpMethod);
+ assertEquals(500, httpMethod.getStatusCode());
+ String resp = httpMethod.getResponseBodyAsString();
+ System.out.println(resp);
+ framework.defaults.test.FVTAssert
+ .assertInstallLogContainsException("ResourceValidationException");
+ if (Environment.getCurrentEnvironment() == Environment.GENERIC_WAS) {
+ framework.defaults.test.FVTAssert
+ .assertInstallLogContainsException("Uncaught exception created in one of the service methods "
+ + "of the servlet jaxrs.tests.validation.param.formparam in "
+ + "application jaxrs.tests.validation.param.formparam. "
+ + "Exception created : javax.servlet.ServletException: An error "
+ + "occurred validating JAX-RS artifacts in the application.");
+
+ }
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,24 @@
+<?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 name="jaxrs.tests.validation.param.formproperty" default="all">
+ <import file="../../../../../buildCommon.xml" />
+</project>
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/server/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/server/Application.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/server/Application.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/server/Application.java Tue Jun 23 05:37:57 2009
@@ -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 jaxrs.tests.validation.param.formproperty.server;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Application extends javax.ws.rs.core.Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> clazzes = new HashSet<Class<?>>();
+ clazzes.add(FormPropertyValidationResource.class);
+ return clazzes;
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/server/FormPropertyValidationResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/server/FormPropertyValidationResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/server/FormPropertyValidationResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/server/FormPropertyValidationResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,40 @@
+/*
+ * 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 jaxrs.tests.validation.param.formproperty.server;
+
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+@Path("params/form/validate/propertynotmultivaluedmaparam")
+public class FormPropertyValidationResource {
+
+ private String p1;
+
+ @POST
+ public String doSomething(String something) {
+ return "Should not see me" + p1;
+ }
+
+ @FormParam(value = "P1")
+ public void setP1(String p1) {
+ this.p1 = p1;
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/test/FormPropertyValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/test/FormPropertyValidationTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/test/FormPropertyValidationTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/validation/param/formproperty/test/FormPropertyValidationTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,78 @@
+/*
+ * 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 jaxrs.tests.validation.param.formproperty.test;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+
+import framework.defaults.test.DefaultURIInfo;
+import framework.defaults.test.Environment;
+import framework.defaults.test.FVTTestCase;
+
+public class FormPropertyValidationTest extends FVTTestCase {
+
+ public String getBaseURI() {
+ return DefaultURIInfo
+ .getClassDefaultBaseURI(FormPropertyValidationTest.class)
+ + "/params/form";
+ }
+
+ public static Test suite() {
+ return FVTTestCase
+ .getTestSuite(
+ FormPropertyValidationTest.class,
+ jaxrs.tests.validation.param.formproperty.server.Application.class
+ .getName());
+ }
+
+ public void testFormPropertyNoMultivaluedMapEntityValidation()
+ throws Exception {
+ HttpClient httpclient = new HttpClient();
+
+ PostMethod httpMethod = new PostMethod(getBaseURI()
+ + "/validate/propertynotmultivaluedmaparam");
+ try {
+ StringRequestEntity s = new StringRequestEntity(
+ "firstkey=somevalue&someothervalue=somethingelse",
+ "application/x-www-form-urlencoded", null);
+ httpMethod.setRequestEntity(s);
+ httpclient.executeMethod(httpMethod);
+ assertEquals(500, httpMethod.getStatusCode());
+ String resp = httpMethod.getResponseBodyAsString();
+ System.out.println(resp);
+ framework.defaults.test.FVTAssert
+ .assertInstallLogContainsException("ResourceValidationException");
+ if (Environment.getCurrentEnvironment() == Environment.GENERIC_WAS) {
+ framework.defaults.test.FVTAssert
+ .assertInstallLogContainsException("Uncaught exception created in one of the service methods "
+ + "of the servlet jaxrs.tests.validation.param.formproperty in "
+ + "application jaxrs.tests.validation.param.formproperty. "
+ + "Exception created : javax.servlet.ServletException: An error "
+ + "occurred validating JAX-RS artifacts in the application.");
+
+ }
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/addressbook/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/addressbook/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/addressbook/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/addressbook/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,109 @@
+<?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 name="jpa.demo" default="all">
+ <import file="../../buildCommon.xml" />
+<!--
+ <target name="compile">
+ <echo>===Compiling ${package.path}===</echo>
+ <echo>${fvt.base.dir}</echo>
+ <echo>${root.base.dir}</echo>
+ <echo>${package.path}</echo>
+ <javac srcdir="${root.base.dir}/samples/addressBook/src" destdir="${fvt.build.dir}" debug="true" failonerror="true">
+ <classpath refid="fvt.classpath" />
+ </javac>
+
+ <javac srcdir="${fvt.base.dir}/${package.path}" destdir="${fvt.build.dir}" debug="true" failonerror="true">
+ <classpath refid="fvt.classpath" />
+ <classpath location="${fvt.build.dir}/com/ibm/rest/sample" />
+ </javac>
+ <echo>===Done compiling ${package.path}===</echo>
+ </target>
+ -->
+
+ <!-- Generates the artifacts -->
+ <target name="dist">
+ <echo>===Distributing ${package.path}===</echo>
+
+ <pathconvert property="package.app.name" dirsep=".">
+ <path location="." />
+ <map from="${fvt.base.dir}${file.separator}" to="" />
+ </pathconvert>
+
+ <available file="${fvt.build.dir}/${package.path}/server" type="dir" property="package.server.dir.exists" />
+ <antcall target="internal.makeear" />
+ <echo>===Done distributing ${package.path}===</echo>
+ </target>
+
+ <target name="internal.makeear" if="package.server.dir.exists">
+ <copy todir="${fvt.work.dir}/${package.path}/server/" overwrite="true" failonerror="false">
+ <fileset dir="${fvt.base.dir}/${package.path}/server/">
+ <include name="**" />
+ </fileset>
+ </copy>
+ <copy todir="${fvt.work.dir}/${package.path}/server/" overwrite="false" failonerror="false">
+ <fileset dir="${fvt.base.dir}/framework/defaults/server/">
+ <include name="**" />
+ </fileset>
+ </copy>
+ <replace file="${fvt.work.dir}/${package.path}/server/WEB-INF/web.xml">
+ <replacefilter token="@REPLACE_SERVLET_NAME@" value="${package.app.name}" />
+ <replacefilter token="@REPLACE_APPLICATION_NAME@" value="${package.app.name}.server.Application" />
+ <replacefilter token="@REPLACE_PATH@" value="*" />
+ </replace>
+
+ <replace file="${fvt.work.dir}/${package.path}/server/META-INF/application.xml">
+ <replacefilter token="@REPLACE_APPLICATION_NAME@" value="${package.app.name}" />
+ <replacefilter token="@REPLACE_WAR_FILE_NAME@" value="${package.app.name}.war" />
+ <replacefilter token="@REPLACE_CONTEXT_ROOT@" value="${package.path}" />
+ </replace>
+
+
+ <war destfile="${fvt.apps.dir}/${package.app.name}.war" webxml="${fvt.work.dir}/${package.path}/server/WEB-INF/web.xml">
+ <classes dir="${fvt.build.dir}">
+ <include name="${package.path}/server/**" />
+ <exclude name="${package.path}/server/META-INF/application.xml" />
+ </classes>
+ <fileset dir="${fvt.work.dir}">
+ <include name="${package.path}/server/**/*.java" />
+ <exclude name="${package.path}/server/WEB-INF/web.xml" />
+ </fileset>
+ <lib dir="${root.base.dir}/build">
+ <include name="ibmjaxrs-snapshot.jar" />
+ </lib>
+ <lib dir="${root.base.dir}/lib">
+ <include name="abdera-core-0.4.0-incubating.jar" />
+ <include name="commons-codec-1.3.jar" />
+ <include name="commons-logging-1.1.1.jar" />
+ <include name="jsr311-api-0.11.jar" />
+ <include name="xmlbeans-2.3.0.jar" />
+ </lib>
+ </war>
+
+
+ <ear destfile="${fvt.apps.dir}/${package.app.name}.ear" appxml="${fvt.work.dir}/${package.path}/server/META-INF/application.xml">
+ <fileset dir="${fvt.apps.dir}">
+ <include name="${package.app.name}.war" />
+ </fileset>
+ </ear>
+ </target>
+
+</project>
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/addressbook/server/META-INF/application.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/addressbook/server/META-INF/application.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/addressbook/server/META-INF/application.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/addressbook/server/META-INF/application.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="ASCII"?>
+
+<!--
+ ~ 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.
+ -->
+
+<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
+ version="5">
+ <display-name>@REPLACE_APPLICATION_NAME@</display-name>
+ <module>
+ <web>
+ <web-uri>@REPLACE_WAR_FILE_NAME@</web-uri>
+ <context-root>@REPLACE_CONTEXT_ROOT@</context-root>
+ </web>
+ </module>
+</application>
\ No newline at end of file
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,73 @@
+<?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 name="samples.contentnegotiation" default="all">
+ <import file="../../buildCommon.xml" />
+
+ <target name="compile">
+ <echo>===Compiling ${fvt.package.path}===</echo>
+ <javac srcdir="${ibmjaxrs.base.dir}/samples/contentnegotiation/server/src" destdir="${fvt.build.classes.dir}" debug="true" failonerror="true">
+ <classpath refid="fvt.classpath" />
+ </javac>
+
+ <javac srcdir="${fvt.base.dir}/${fvt.package.path}" destdir="${fvt.build.classes.dir}" debug="true" failonerror="true">
+ <classpath refid="fvt.classpath" />
+ <classpath location="${fvt.build.classes.dir}/com/ibm/jaxrs/sample/contentnegotiation" />
+ </javac>
+ <echo>===Done compiling ${fvt.package.path}===</echo>
+ </target>
+
+ <!-- Generates the artifacts -->
+ <target name="dist">
+ <echo>===Distributing ${fvt.package.path}===</echo>
+ <antcall target="internal.makeear" />
+ <echo>===Done distributing ${fvt.package.path}===</echo>
+ </target>
+
+ <target name="internal.makeear">
+ <copy todir="${fvt.build.work.dir}/${fvt.package.path}/server/" overwrite="true" failonerror="false">
+ <fileset dir="${fvt.base.dir}/${fvt.package.path}/server/">
+ <include name="**" />
+ </fileset>
+ </copy>
+
+ <copy todir="${fvt.build.work.dir}/${fvt.package.path}/server/" overwrite="false" failonerror="false">
+ <fileset dir="${fvt.base.dir}/framework/defaults/server/">
+ <include name="**" />
+ </fileset>
+ </copy>
+
+ <replace file="${fvt.build.work.dir}/${fvt.package.path}/server/META-INF/application.xml">
+ <replacefilter token="@REPLACE_APPLICATION_NAME@" value="${fvt.package.app.name}" />
+ <replacefilter token="@REPLACE_WAR_FILE_NAME@" value="${fvt.package.app.name}.war" />
+ <replacefilter token="@REPLACE_CONTEXT_ROOT@" value="${fvt.package.path}" />
+ </replace>
+
+
+ <ear destfile="${fvt.build.apps.dir}/${fvt.package.app.name}.ear" appxml="${fvt.build.work.dir}/${fvt.package.path}/server/META-INF/application.xml">
+ <fileset dir="${ibmjaxrs.base.dir}/samples/contentnegotiation/dist">
+ <include name="contentnegotiation_server.war" />
+ </fileset>
+ </ear>
+
+ </target>
+</project>
+
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/server/META-INF/application.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/server/META-INF/application.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/server/META-INF/application.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/server/META-INF/application.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="ASCII"?>
+
+<!--
+ ~ 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.
+ -->
+
+<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
+ version="5">
+ <display-name>@REPLACE_APPLICATION_NAME@</display-name>
+ <module>
+ <web>
+ <web-uri>contentnegotiation_server.war</web-uri>
+ <context-root>@REPLACE_CONTEXT_ROOT@</context-root>
+ </web>
+ </module>
+</application>
\ No newline at end of file
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/test/ContentNegotiationTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/test/ContentNegotiationTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/test/ContentNegotiationTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/contentnegotiation/test/ContentNegotiationTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,258 @@
+/*
+ * 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 samples.contentnegotiation.test;
+
+import java.io.IOException;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+import com.ibm.jaxrs.sample.contentnegotiation.Score;
+
+import framework.defaults.test.FVTTestCase;
+
+public class ContentNegotiationTest extends FVTTestCase {
+
+ public static junit.framework.Test suite() {
+ return FVTTestCase
+ .getTestSuite(ContentNegotiationTest.class,
+ "com.ibm.jaxrs.sample.contentnegotiation.ScoreboardApplication");
+ }
+
+ /**
+ * Verifies that the method that specifically returns XML works.
+ *
+ * @throws HttpException
+ * @throws IOException
+ * @throws JAXBException
+ */
+ public void testGetXMLViaMultipleMethods() throws HttpException,
+ IOException, JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/scoreboard/multiplemethods/score/1.xml");
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("text/xml", getMethod.getResponseHeader("Content-Type")
+ .getValue());
+ JAXBContext context = JAXBContext.newInstance(Score.class.getPackage()
+ .getName());
+ Score s = (Score) context.createUnmarshaller().unmarshal(
+ getMethod.getResponseBodyAsStream());
+ assertEquals(s.getHomeTeam(), "Blue Team");
+ assertEquals(s.getHomeScore(), Integer.valueOf(1));
+
+ assertEquals(s.getVisitorTeam(), "Red Team");
+ assertEquals(s.getVisitorScore(), Integer.valueOf(2));
+ }
+
+ /**
+ * Verifies that the method that specifically returns plain text works.
+ *
+ * @throws HttpException
+ * @throws IOException
+ * @throws JAXBException
+ */
+ public void testGetTextViaMultipleMethods() throws HttpException,
+ IOException, JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/scoreboard/multiplemethods/score/1.text");
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("text/plain", getMethod.getResponseHeader("Content-Type")
+ .getValue());
+ assertEquals(
+ "Home Team: Blue Team ; Home Score: 1 ; Visitor Team: Red Team ; Visitor Score: 2",
+ getMethod.getResponseBodyAsString());
+ }
+
+
+ /**
+ * Verifies that the single method that can return different media types
+ * works with XML.
+ *
+ * @throws HttpException
+ * @throws IOException
+ * @throws JAXBException
+ */
+ public void testGetXMLViaSingleMethod() throws HttpException, IOException,
+ JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/scoreboard/singlemethod/score/1.xml");
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("text/xml", getMethod.getResponseHeader("Content-Type")
+ .getValue());
+ JAXBContext context = JAXBContext.newInstance(Score.class.getPackage()
+ .getName());
+ Score s = (Score) context.createUnmarshaller().unmarshal(
+ getMethod.getResponseBodyAsStream());
+ assertEquals(s.getHomeTeam(), "Blue Team");
+ assertEquals(s.getHomeScore(), Integer.valueOf(1));
+
+ assertEquals(s.getVisitorTeam(), "Red Team");
+ assertEquals(s.getVisitorScore(), Integer.valueOf(2));
+ }
+
+ /**
+ * Verifies that the single method that can return different media types
+ * works with plain text.
+ *
+ * @throws HttpException
+ * @throws IOException
+ * @throws JAXBException
+ */
+ public void testGetTextViaSingleMethod() throws HttpException, IOException,
+ JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/scoreboard/singlemethod/score/1.text");
+ client.executeMethod(getMethod);
+ assertEquals("text/plain", getMethod.getResponseHeader("Content-Type")
+ .getValue());
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals(
+ "Home Team: Blue Team ; Home Score: 1 ; Visitor Team: Red Team ; Visitor Score: 2",
+ getMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Verifies that the single method that uses the HTTP Accept header works
+ * with XML.
+ *
+ * @throws HttpException
+ * @throws IOException
+ * @throws JAXBException
+ */
+ public void testGetXMLViaHttpHeaderAcceptHeader() throws HttpException,
+ IOException, JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/scoreboard/httpheader/score/1");
+ getMethod.setRequestHeader("Accept", "text/xml");
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("text/xml", getMethod.getResponseHeader("Content-Type")
+ .getValue());
+ JAXBContext context = JAXBContext.newInstance(Score.class.getPackage()
+ .getName());
+ Score s = (Score) context.createUnmarshaller().unmarshal(
+ getMethod.getResponseBodyAsStream());
+ assertEquals(s.getHomeTeam(), "Blue Team");
+ assertEquals(s.getHomeScore(), Integer.valueOf(1));
+
+ assertEquals(s.getVisitorTeam(), "Red Team");
+ assertEquals(s.getVisitorScore(), Integer.valueOf(2));
+ }
+
+ /**
+ * Verifies that the single method that uses the HTTP Accept header works
+ * with plain text.
+ *
+ * @throws HttpException
+ * @throws IOException
+ * @throws JAXBException
+ */
+ public void testGetTextViaHttpHeaderAcceptHeader() throws HttpException,
+ IOException, JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/scoreboard/httpheader/score/1");
+ getMethod.setRequestHeader("Accept", "text/plain");
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("text/plain", getMethod.getResponseHeader("Content-Type")
+ .getValue());
+ assertEquals(
+ "Home Team: Blue Team ; Home Score: 1 ; Visitor Team: Red Team ; Visitor Score: 2",
+ getMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Verifies that the single method that uses the HTTP Accept header works
+ * with XML.
+ *
+ * @throws HttpException
+ * @throws IOException
+ * @throws JAXBException
+ */
+ public void testGetXMLViaRequestAcceptHeader() throws HttpException,
+ IOException, JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/scoreboard/request/score/1");
+ getMethod.setRequestHeader("Accept", "text/xml");
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("text/xml", getMethod.getResponseHeader("Content-Type")
+ .getValue());
+ JAXBContext context = JAXBContext.newInstance(Score.class.getPackage()
+ .getName());
+ Score s = (Score) context.createUnmarshaller().unmarshal(
+ getMethod.getResponseBodyAsStream());
+ assertEquals(s.getHomeTeam(), "Blue Team");
+ assertEquals(s.getHomeScore(), Integer.valueOf(1));
+
+ assertEquals(s.getVisitorTeam(), "Red Team");
+ assertEquals(s.getVisitorScore(), Integer.valueOf(2));
+ }
+
+ /**
+ * Verifies that the single method that uses the HTTP Accept header works
+ * with plain text.
+ *
+ * @throws HttpException
+ * @throws IOException
+ * @throws JAXBException
+ */
+ public void testGetTextViaRequestAcceptHeader() throws HttpException,
+ IOException, JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/scoreboard/request/score/1");
+ getMethod.setRequestHeader("Accept", "text/plain");
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("text/plain", getMethod.getResponseHeader("Content-Type")
+ .getValue());
+ assertEquals(
+ "Home Team: Blue Team ; Home Score: 1 ; Visitor Team: Red Team ; Visitor Score: 2",
+ getMethod.getResponseBodyAsString());
+ }
+
+ /*
+ * test without accept header ; test with unexpected types (in all methods)
+ * ; show with multiple quality factors
+ */
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,72 @@
+<?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 name="samples.guestbook" default="all">
+ <import file="../../buildCommon.xml" />
+
+ <target name="compile">
+ <echo>===Compiling ${fvt.package.path}===</echo>
+ <javac srcdir="${ibmjaxrs.base.dir}/samples/guestbook/server/src" destdir="${fvt.build.classes.dir}" debug="true" failonerror="true">
+ <classpath refid="fvt.classpath" />
+ </javac>
+
+ <javac srcdir="${fvt.base.dir}/${fvt.package.path}" destdir="${fvt.build.classes.dir}" debug="true" failonerror="true">
+ <classpath refid="fvt.classpath" />
+ <classpath location="${fvt.build.classes.dir}/com/ibm/rest/sample/guestbook" />
+ </javac>
+ <echo>===Done compiling ${fvt.package.path}===</echo>
+ </target>
+
+ <!-- Generates the artifacts -->
+ <target name="dist">
+ <echo>===Distributing ${fvt.package.path}===</echo>
+ <antcall target="internal.makeear" />
+ <echo>===Done distributing ${fvt.package.path}===</echo>
+ </target>
+
+ <target name="internal.makeear">
+ <copy todir="${fvt.build.work.dir}/${fvt.package.path}/server/" overwrite="true" failonerror="false">
+ <fileset dir="${fvt.base.dir}/${fvt.package.path}/server/">
+ <include name="**" />
+ </fileset>
+ </copy>
+
+ <copy todir="${fvt.build.work.dir}/${fvt.package.path}/server/" overwrite="false" failonerror="false">
+ <fileset dir="${fvt.base.dir}/framework/defaults/server/">
+ <include name="**" />
+ </fileset>
+ </copy>
+
+ <replace file="${fvt.build.work.dir}/${fvt.package.path}/server/META-INF/application.xml">
+ <replacefilter token="@REPLACE_APPLICATION_NAME@" value="${fvt.package.app.name}" />
+ <replacefilter token="@REPLACE_WAR_FILE_NAME@" value="${fvt.package.app.name}.war" />
+ <replacefilter token="@REPLACE_CONTEXT_ROOT@" value="${fvt.package.path}" />
+ </replace>
+
+ <ear destfile="${fvt.build.apps.dir}/${fvt.package.app.name}.ear" appxml="${fvt.build.work.dir}/${fvt.package.path}/server/META-INF/application.xml">
+ <fileset dir="${fvt.build.apps.dir}">
+ <include name="guestbook_server.war" />
+ <include name="guestbook_client.war" />
+ </fileset>
+ </ear>
+
+ </target>
+</project>
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/server/META-INF/application.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/server/META-INF/application.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/server/META-INF/application.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/server/META-INF/application.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="ASCII"?>
+
+<!--
+ ~ 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.
+ -->
+
+<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
+ version="5">
+ <display-name>@REPLACE_APPLICATION_NAME@</display-name>
+ <module>
+ <web>
+ <web-uri>guestbook_server.war</web-uri>
+ <context-root>@REPLACE_CONTEXT_ROOT@</context-root>
+ </web>
+ </module>
+ <module>
+ <web>
+ <web-uri>guestbook_client.war</web-uri>
+ <context-root>guestbookclient</context-root>
+ </web>
+ </module>
+</application>
\ No newline at end of file
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/test/GuestbookTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/test/GuestbookTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/test/GuestbookTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/test/GuestbookTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,172 @@
+/*
+ * 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 samples.guestbook.test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+
+import framework.defaults.test.FVTTestCase;
+
+/**
+ * Tests the Guestbook sample.
+ */
+public class GuestbookTests extends FVTTestCase {
+
+ public static junit.framework.Test suite() {
+ return FVTTestCase.getTestSuite(GuestbookTests.class,
+ "com.ibm.rest.sample.guestbook.GuestbookApplication");
+ }
+
+ public String getBaseURI() {
+ return super.getBaseURI() + "/guestbook";
+ }
+
+ /**
+ * Test the positive workflow where a comment with an id, a message and
+ * author is successfully posted to the Guestbook.
+ *
+ * @throws Exception
+ */
+ public void testRegularWorkflow() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><id>1</id><message>Hello World!</message><author>Anonymous</author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(201, postMethod.getStatusCode());
+ String newPostURILocation = postMethod.getResponseHeader("Location")
+ .getValue();
+ GetMethod getMethod = new GetMethod(newPostURILocation);
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><comment><author>Anonymous</author><id>1</id><message>Hello World!</message></comment>",
+ getMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Test the <code>Response.status()</code> sets the HTTP status code
+ * correctly.
+ *
+ * @throws Exception
+ */
+ public void testGETResponseStatus404Flow() throws Exception {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/987654321");
+ client.executeMethod(getMethod);
+ assertEquals(404, getMethod.getStatusCode());
+ assertEquals("", getMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Test the WebApplicationException sets the HTTP status code correctly.
+ *
+ * @throws Exception
+ */
+ public void testPOSTWebException400Flow() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod.setRequestEntity(new StringRequestEntity("", "text/xml",
+ null));
+ client.executeMethod(postMethod);
+ assertEquals(400, postMethod.getStatusCode());
+ assertEquals("", postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Test the WebApplicationException uses a given Response.
+ *
+ * @throws Exception
+ */
+ public void testPOSTWebExceptionWithResponse400Flow() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod.setRequestEntity(new StringRequestEntity(
+ "<comment><id>10000</id><author>Anonymous</author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(400, postMethod.getStatusCode());
+ assertEquals(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Please include a comment ID, a message, and your name.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Test a thrown RuntimeException.
+ *
+ * @throws Exception
+ */
+ public void testDELETERuntimeExceptionFlow() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/abcd");
+ client.executeMethod(deleteMethod);
+ assertEquals(500, deleteMethod.getStatusCode());
+ assertLogContainsException("java.lang.NumberFormatException: For input string: \"abcd\"");
+ }
+
+ /**
+ * Test a thrown CheckedException.
+ *
+ * @throws Exception
+ */
+ public void testPUTCheckedExceptionFlow() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/7");
+ putMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><id>7</id><message>Shaken, not stirred</message><author>James Bond</author></comment>",
+ "text/xml", null));
+ client.executeMethod(putMethod);
+ assertEquals(500, putMethod.getStatusCode());
+ assertLogContainsException("com.ibm.rest.sample.guestbook.GuestbookException: Cannot find existing comment to update.");
+ }
+
+ /**
+ * Test a thrown NullPointerException uses an application defined
+ * ExceptionMapper<NullPointerException>.
+ *
+ * @throws Exception
+ */
+ public void testPUTNullPointerExceptionExceptionMapperFlow()
+ throws Exception {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/7");
+ putMethod
+ .setRequestEntity(new StringRequestEntity("", "text/xml", null));
+ client.executeMethod(putMethod);
+ assertEquals(500, putMethod.getStatusCode());
+ assertEquals(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Someone forgot a null check.</message></commenterror>",
+ putMethod.getResponseBodyAsString());
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/wasceDeploymentPlan.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/wasceDeploymentPlan.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/wasceDeploymentPlan.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/guestbook/wasceDeploymentPlan.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,61 @@
+<?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.
+ -->
+
+<application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-2.0"
+ xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"
+ application-name="@REPLACE_APPLICATION_NAME@">
+ <sys:environment>
+ <sys:moduleId>
+ <sys:groupId>@REPLACE_GROUP_ID@</sys:groupId>
+ <sys:artifactId>@REPLACE_APPLICATION_NAME@</sys:artifactId>
+ <sys:version>@REPLACE_VERSION@</sys:version>
+ <sys:type>car</sys:type>
+ </sys:moduleId>
+ </sys:environment>
+ <module>
+ <web>guestbook_server.war</web>
+ <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1">
+ <sys:environment>
+ <sys:moduleId>
+ <sys:groupId>@REPLACE_GROUP_ID@</sys:groupId>
+ <sys:artifactId>@REPLACE_APPLICATION_NAME@</sys:artifactId>
+ <sys:version>2.5</sys:version>
+ <sys:type>war</sys:type>
+ </sys:moduleId>
+ </sys:environment>
+ <context-root>/@REPLACE_CONTEXT_ROOT@</context-root>
+ </web-app>
+ </module>
+ <module>
+ <web>guestbook_client.war</web>
+ <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1">
+ <sys:environment>
+ <sys:moduleId>
+ <sys:groupId>@REPLACE_GROUP_ID@</sys:groupId>
+ <sys:artifactId>@REPLACE_APPLICATION_NAME@Client</sys:artifactId>
+ <sys:version>2.5</sys:version>
+ <sys:type>war</sys:type>
+ </sys:moduleId>
+ </sys:environment>
+ <context-root>/guestbookclient</context-root>
+ </web-app>
+ </module>
+</application>
\ No newline at end of file
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,71 @@
+<?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 name="samples.helloworld" default="all">
+ <import file="../../buildCommon.xml" />
+
+ <target name="compile">
+ <echo>===Compiling ${fvt.package.path}===</echo>
+ <javac srcdir="${ibmjaxrs.base.dir}/samples/helloWorld/server/src" destdir="${fvt.build.classes.dir}" debug="true" failonerror="true">
+ <classpath refid="fvt.classpath" />
+ </javac>
+
+ <javac srcdir="${fvt.base.dir}/${fvt.package.path}" destdir="${fvt.build.classes.dir}" debug="true" failonerror="true">
+ <classpath refid="fvt.classpath" />
+ <classpath location="${fvt.build.classes.dir}/com/ibm/rest/sample/helloworld" />
+ </javac>
+ <echo>===Done compiling ${fvt.package.path}===</echo>
+ </target>
+
+ <!-- Generates the artifacts -->
+ <target name="dist">
+ <echo>===Distributing ${fvt.package.path}===</echo>
+ <antcall target="internal.makeear" />
+ <echo>===Done distributing ${fvt.package.path}===</echo>
+ </target>
+
+ <target name="internal.makeear">
+ <copy todir="${fvt.build.work.dir}/${fvt.package.path}/server/" overwrite="true" failonerror="false">
+ <fileset dir="${fvt.base.dir}/${fvt.package.path}/server/">
+ <include name="**" />
+ </fileset>
+ </copy>
+
+ <copy todir="${fvt.build.work.dir}/${fvt.package.path}/server/" overwrite="false" failonerror="false">
+ <fileset dir="${fvt.base.dir}/framework/defaults/server/">
+ <include name="**" />
+ </fileset>
+ </copy>
+
+ <replace file="${fvt.build.work.dir}/${fvt.package.path}/server/META-INF/application.xml">
+ <replacefilter token="@REPLACE_APPLICATION_NAME@" value="${fvt.package.app.name}" />
+ <replacefilter token="@REPLACE_WAR_FILE_NAME@" value="${fvt.package.app.name}.war" />
+ <replacefilter token="@REPLACE_CONTEXT_ROOT@" value="${fvt.package.path}" />
+ </replace>
+
+ <ear destfile="${fvt.build.apps.dir}/${package.app.name}.ear" appxml="${fvt.build.work.dir}/${fvt.package.path}/server/META-INF/application.xml">
+ <fileset dir="${fvt.build.apps.dir}">
+ <include name="helloworld_server.war" />
+ </fileset>
+ </ear>
+
+ </target>
+</project>
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/server/META-INF/application.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/server/META-INF/application.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/server/META-INF/application.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/server/META-INF/application.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="ASCII"?>
+
+<!--
+ ~ 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.
+ -->
+
+<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
+ version="5">
+ <display-name>@REPLACE_APPLICATION_NAME@</display-name>
+ <module>
+ <web>
+ <web-uri>helloworld_server.war</web-uri>
+ <context-root>@REPLACE_CONTEXT_ROOT@</context-root>
+ </web>
+ </module>
+</application>
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/test/HelloWorldTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/test/HelloWorldTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/test/HelloWorldTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/test/HelloWorldTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,56 @@
+/*
+ * 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 samples.helloworld.test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+import framework.defaults.test.FVTTestCase;
+
+/**
+ * Tests the HelloWorld sample.
+ */
+public class HelloWorldTests extends FVTTestCase {
+
+ public static junit.framework.Test suite() {
+ return FVTTestCase.getTestSuite(HelloWorldTests.class,
+ "com.ibm.jaxrs.sample.helloworld.HelloWorldApplication");
+ }
+
+ public String getBaseURI() {
+ return super.getBaseURI() + "/helloworld";
+ }
+
+ /**
+ * Test the <code>Response.status()</code> sets the HTTP status code
+ * correctly.
+ *
+ * @throws Exception
+ */
+ public void testGETResponseStatus200Flow() throws Exception {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI());
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("Hello, World!", getMethod.getResponseBodyAsString());
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/wasceDeploymentPlan.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/wasceDeploymentPlan.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/wasceDeploymentPlan.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/helloworld/wasceDeploymentPlan.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,47 @@
+<?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.
+ -->
+
+<application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-2.0"
+ xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"
+ application-name="@REPLACE_APPLICATION_NAME@">
+ <sys:environment>
+ <sys:moduleId>
+ <sys:groupId>@REPLACE_GROUP_ID@</sys:groupId>
+ <sys:artifactId>@REPLACE_APPLICATION_NAME@</sys:artifactId>
+ <sys:version>@REPLACE_VERSION@</sys:version>
+ <sys:type>car</sys:type>
+ </sys:moduleId>
+ </sys:environment>
+ <module>
+ <web>helloworld_server.war</web>
+ <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1">
+ <sys:environment>
+ <sys:moduleId>
+ <sys:groupId>@REPLACE_GROUP_ID@</sys:groupId>
+ <sys:artifactId>@REPLACE_APPLICATION_NAME@</sys:artifactId>
+ <sys:version>2.5</sys:version>
+ <sys:type>war</sys:type>
+ </sys:moduleId>
+ </sys:environment>
+ <context-root>/@REPLACE_CONTEXT_ROOT@</context-root>
+ </web-app>
+ </module>
+</application>
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,24 @@
+<?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 name="samples.provider" default="all">
+ <import file="../../buildCommon.xml" />
+</project>
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/Application.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/Application.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/Application.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,41 @@
+/*
+ * 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 samples.providers.server;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Application extends javax.ws.rs.core.Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> clazzes = new HashSet<Class<?>>();
+ clazzes.add(IntegerResource.class);
+ return clazzes;
+ }
+
+ @Override
+ public Set<Object> getSingletons() {
+ Set<Object> singletons = new HashSet<Object>();
+ singletons.add(new IntegerIntProvider());
+ singletons.add(new IntegerTextProvider());
+ return singletons;
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerIntProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerIntProvider.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerIntProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerIntProvider.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,96 @@
+/*
+ * 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 samples.providers.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+@Consumes(value = "integer/int")
+@Produces(value = "integer/int")
+public class IntegerIntProvider implements MessageBodyReader<Integer>, MessageBodyWriter<Integer> {
+
+ public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return type == Integer.class;
+ }
+
+ public Integer readFrom(Class<Integer> clazz, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, String> headers, InputStream is)
+ throws IOException {
+ System.out.println("Reading Integer as int.");
+ byte[] b = new byte[4];
+ is.read(b);
+ int[] i = new int[4];
+ i[0] = b[0];
+ i[1] = b[1];
+ i[2] = b[2];
+ i[3] = b[3];
+ if (i[0] < 0)
+ i[0] = i[0] + 256;
+ if (i[1] < 0)
+ i[1] = i[1] + 256;
+ if (i[2] < 0)
+ i[2] = i[2] + 256;
+ if (i[3] < 0)
+ i[3] = i[3] + 256;
+ int n = (i[0] + (i[1] << 8) + (i[2] << 16) + (i[3] << 24));
+ return new Integer(n);
+ }
+
+ public long getSize(Integer arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return 4;
+ }
+
+ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return type == Integer.class;
+ }
+
+ public void writeTo(Integer obj, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os)
+ throws IOException {
+ System.out.println("Writing Integer as int.");
+ System.out.println(m.toString());
+
+ List<Object> list = new ArrayList<Object>();
+ list.add(m.toString());
+ headers.put("Content-Type", list);
+
+ int n = obj;
+ byte[] b = new byte[4];
+ b[0] = (byte) (n & 255);
+ b[1] = (byte) ((n >> 8) & 255);
+ b[2] = (byte) ((n >> 16) & 255);
+ b[3] = (byte) ((n >> 24) & 255);
+ os.write(b);
+ os.close();
+
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,69 @@
+/*
+ * 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 samples.providers.server;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+@Path(value = "/integer")
+public class IntegerResource {
+
+ static Integer integer = new Integer(-1);
+
+ @POST
+ @Consumes(value = { "integer/int", "integer/text" })
+ public void setInteger(Integer integer) {
+ IntegerResource.integer = integer;
+ }
+
+ @POST
+ @Path(value = "/wrapper")
+ public void acceptWrapper(IntegerWrapper wrapper) {
+ return;
+ }
+
+ @GET
+ @Produces(value = { "integer/int", "integer/text" })
+ public Response getInteger() {
+ return Response.ok(IntegerResource.integer).build();
+ }
+
+ @POST
+ @Path(value = "/reset")
+ public void reset() {
+ IntegerResource.integer = new Integer(-1);
+ }
+
+ public class IntegerWrapper {
+ private Integer integer;
+
+ public IntegerWrapper(Integer integer) {
+ this.integer = integer;
+ }
+
+ public Integer getInteger() {
+ return this.integer;
+ }
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerTextProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerTextProvider.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerTextProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/server/IntegerTextProvider.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,96 @@
+/*
+ * 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 samples.providers.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+@Consumes(value = "integer/text")
+@Produces(value = "integer/text")
+public class IntegerTextProvider implements MessageBodyReader<Integer>, MessageBodyWriter<Integer> {
+
+ public static final Charset UTF8_CHARSET = Charset.forName("utf-8");
+
+ public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return type == Integer.class;
+ }
+
+ public Integer readFrom(Class<Integer> clazz, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, String> headers, InputStream is)
+ throws IOException {
+ System.out.println("Reading Integer as text.");
+ return Integer.parseInt(toString(is));
+ }
+
+ public long getSize(Integer arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return arg0.toString().length();
+ }
+
+ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return type == Integer.class;
+ }
+
+ public void writeTo(Integer obj, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os)
+ throws IOException {
+ System.out.println("Writing Integer as text.");
+ System.out.println(m.toString());
+
+ List<Object> list = new ArrayList<Object>();
+ list.add(m.toString());
+ headers.put("Content-Type", list);
+
+ String s = obj.toString();
+ byte[] b = new byte[s.length()];
+ char[] c = s.toCharArray();
+ for (int i = 0; i < b.length; ++i)
+ b[i] = (byte) c[i];
+ os.write(b);
+ os.close();
+ }
+
+ protected String toString(InputStream is) throws IOException {
+ int avail = is.available();
+
+ StringBuilder buf = new StringBuilder();
+ final byte[] buffer = new byte[avail];
+ int n = 0;
+ n = is.read(buffer);
+ while (-1 != n) {
+ buf.append(new String(buffer, 0, n, UTF8_CHARSET.name()));
+ n = is.read(buffer);
+ }
+ is.close();
+ return buf.toString();
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/test/ProvidersSampleTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/test/ProvidersSampleTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/test/ProvidersSampleTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/samples/providers/test/ProvidersSampleTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,216 @@
+/*
+ * 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 samples.providers.test;
+
+import java.nio.charset.Charset;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+
+import framework.defaults.test.DefaultURIInfo;
+import framework.defaults.test.FVTTestCase;
+
+public class ProvidersSampleTest extends FVTTestCase {
+
+ final private static String BASE_URI = DefaultURIInfo
+ .getClassDefaultBaseURI(ProvidersSampleTest.class)
+ + "/integer";
+ public static final Charset UTF8_CHARSET = Charset.forName("utf-8");
+
+ protected HttpClient httpclient = new HttpClient();
+
+ public static junit.framework.Test suite() {
+ return FVTTestCase.getTestSuite(ProvidersSampleTest.class,
+ "samples.providers.server.Application");
+ }
+
+ public void testUnsupportedContentType() throws Exception {
+ PostMethod post = new PostMethod(getBaseURI() + "/integer/wrapper");
+ post.setRequestEntity(new ByteArrayRequestEntity(intToBytes(324324322),
+ "contentType/unsupported"));
+ try {
+ int returnCode = httpclient.executeMethod(post);
+ assertEquals(
+ "Did not receive the unsupported media type return code 415.",
+ 415, returnCode);
+ } finally {
+ post.releaseConnection();
+ }
+ }
+
+ public void testUnsupportedAcceptType() throws Exception {
+ GetMethod get = new GetMethod(getBaseURI() + "/integer");
+ get.setRequestHeader("Accept", "contentType/unsupported");
+ try {
+ int returnCode = httpclient.executeMethod(get);
+ assertEquals(
+ "The not acceptable return code, 406, was not returned.",
+ 406, returnCode);
+ } finally {
+ get.releaseConnection();
+ }
+ }
+
+ public void testDefaultText() throws Exception {
+ resetInteger();
+ GetMethod get = new GetMethod(getBaseURI() + "/integer");
+ get.setRequestHeader("Accept", "integer/text");
+ try {
+ httpclient.executeMethod(get);
+ String integer = get.getResponseBodyAsString();
+ System.out.println("Default integer value is: " + integer);
+ assertEquals("Did not receive the default value of \"-1\".", "-1",
+ integer);
+ } finally {
+ get.releaseConnection();
+ }
+ }
+
+ public void testDefaultInt() throws Exception {
+ resetInteger();
+ GetMethod get = new GetMethod(BASE_URI);
+ get.setRequestHeader("Accept", "integer/int");
+ try {
+ httpclient.executeMethod(get);
+ int integer = bytesToInt(get.getResponseBody());
+ System.out.println("Default integer value is: " + integer);
+ assertEquals("Did not receive the default value of -1.", -1,
+ integer);
+ } finally {
+ get.releaseConnection();
+ }
+ }
+
+ public void testIntegerTextProvider() throws Exception {
+ resetInteger();
+ PostMethod post = new PostMethod(BASE_URI);
+ post.setRequestEntity(new StringRequestEntity("100", "integer/text",
+ UTF8_CHARSET.name()));
+ try {
+ httpclient.executeMethod(post);
+ } finally {
+ post.releaseConnection();
+ }
+ GetMethod get = new GetMethod(BASE_URI);
+ get.setRequestHeader("Accept", "integer/text");
+ try {
+ httpclient.executeMethod(get);
+ String response = get.getResponseBodyAsString();
+ assertEquals("Did not receive the posted value of \"100\".", "100",
+ response);
+ } finally {
+ get.releaseConnection();
+ }
+ }
+
+ public void testIntegerIntProvider() throws Exception {
+ resetInteger();
+ PostMethod post = new PostMethod(BASE_URI);
+ post.setRequestEntity(new ByteArrayRequestEntity(intToBytes(100),
+ "integer/int"));
+ try {
+ httpclient.executeMethod(post);
+ } finally {
+ post.releaseConnection();
+ }
+ GetMethod get = new GetMethod(BASE_URI);
+ get.setRequestHeader("Accept", "integer/int");
+ try {
+ httpclient.executeMethod(get);
+ int integer = bytesToInt(get.getResponseBody());
+ assertEquals("Did not receive the posted value of 100.", 100,
+ integer);
+ } finally {
+ get.releaseConnection();
+ }
+ }
+
+ public void testPreferTextMediaType() throws Exception {
+ resetInteger();
+ GetMethod get = new GetMethod(getBaseURI() + "/integer");
+ get.setRequestHeader("Accept",
+ "integer/text; q=0.8, integer/int; q=0.2");
+ try {
+ httpclient.executeMethod(get);
+ Header h = get.getResponseHeaders("Content-Type")[0];
+ assertEquals(
+ "Response ContentType did not match the prefered quality of service, integer/text.",
+ "integer/text;q=0.8", h.getValue());
+ } finally {
+ get.releaseConnection();
+ }
+ }
+
+ public void testFallbackToSupportedMediaType() throws Exception {
+ resetInteger();
+ GetMethod get = new GetMethod(getBaseURI() + "/integer");
+ get.setRequestHeader("Accept",
+ "contentType/unsupported; q=0.8, integer/int; q=0.2");
+ try {
+ httpclient.executeMethod(get);
+ Header h = get.getResponseHeaders("Content-Type")[0];
+ assertEquals(
+ "Response ContentType did not match the supported type, integer/int.",
+ "integer/int;q=0.2", h.getValue());
+ } finally {
+ get.releaseConnection();
+ }
+ }
+
+ protected void resetInteger() throws Exception {
+ PostMethod post = new PostMethod(BASE_URI + "/reset");
+ try {
+ httpclient.executeMethod(post);
+ } finally {
+ post.releaseConnection();
+ }
+ }
+
+ protected int bytesToInt(byte[] b) {
+ int[] i = new int[4];
+ i[0] = b[0];
+ i[1] = b[1];
+ i[2] = b[2];
+ i[3] = b[3];
+ if (i[0] < 0)
+ i[0] = i[0] + 256;
+ if (i[1] < 0)
+ i[1] = i[1] + 256;
+ if (i[2] < 0)
+ i[2] = i[2] + 256;
+ if (i[3] < 0)
+ i[3] = i[3] + 256;
+ int n = (i[0] + (i[1] << 8) + (i[2] << 16) + (i[3] << 24));
+ return n;
+ }
+
+ protected byte[] intToBytes(int n) {
+ byte[] b = new byte[4];
+ b[0] = (byte) (n & 255);
+ b[1] = (byte) ((n >> 8) & 255);
+ b[2] = (byte) ((n >> 16) & 255);
+ b[3] = (byte) ((n >> 24) & 255);
+ return b;
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/template/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/template/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/template/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/template/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,24 @@
+<?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 name="template" default="all">
+ <import file="../buildCommon.xml" />
+</project>
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/template/server/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/template/server/Application.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/template/server/Application.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/template/server/Application.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,33 @@
+/*
+ * 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 template.server;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Application extends javax.ws.rs.core.Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> clazzes = new HashSet<Class<?>>();
+ return clazzes;
+ }
+
+}