Skip to content
Browse files

Add Arquillian Extension RestEasy

A Extension showing how you can combine RestEasy's Client Proxy Invoker with your own TestMethods. Making the TestClass a REST Client.
  • Loading branch information...
1 parent 74622ca commit 2c22c4e9e56ea0404119d1efb59c5c590ec24c45 @aslakknutsen aslakknutsen committed Nov 29, 2011
Showing with 940 additions and 0 deletions.
  1. +1 −0 extensions/pom.xml
  2. +158 −0 extensions/resteasy/pom.xml
  3. +38 −0 ...nsions/resteasy/src/main/java/org/jboss/arquillian/extension/rest/client/RestClientExtension.java
  4. +61 −0 extensions/resteasy/src/main/java/org/jboss/arquillian/extension/rest/client/RestEnricher.java
  5. +152 −0 extensions/resteasy/src/main/java/org/jboss/arquillian/extension/rest/client/RestInvoker.java
  6. +1 −0 ...ons/resteasy/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
  7. +83 −0 extensions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/RestClientTestCase.java
  8. +58 −0 extensions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/CustomerResource.java
  9. +70 −0 extensions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/model/Contact.java
  10. +75 −0 extensions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/model/Customer.java
  11. +55 −0 extensions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/model/LineItem.java
  12. +54 −0 extensions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/model/Product.java
  13. +70 −0 extensions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/model/SalesOrder.java
  14. +21 −0 ...easy/src/test/java/org/jboss/arquillian/extension/rest/app/persistence/EntityManagerProducer.java
  15. +8 −0 extensions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/rs/JaxRsActivator.java
  16. +12 −0 extensions/resteasy/src/test/resources/arquillian.xml
  17. +8 −0 extensions/resteasy/src/test/resources/import.sql
  18. +15 −0 extensions/resteasy/src/test/resources/test-persistence.xml
View
1 extensions/pom.xml
@@ -23,6 +23,7 @@
<module>lifecycle</module>
<module>deploymentscenario</module>
<module>systemproperties</module>
+ <module>resteasy</module>
<module>weld-servlet</module>
</modules>
View
158 extensions/resteasy/pom.xml
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <artifactId>arquillian-showcase-parent</artifactId>
+ <groupId>org.jboss.arquillian.showcase</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <artifactId>arquillian-showcase-extension-resteasy</artifactId>
+ <name>Arquillian Showcase Extension: RestEasy</name>
+ <description>Example that demonstrates how to integrate RestEasy Client Proxies into a Arquillian test</description>
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.resteasy>2.2.3.GA</version.resteasy>
+
+ <!-- test -->
+ <version.jboss_spec>1.0.0.Final</version.jboss_spec>
+
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxrs</artifactId>
+ <version>${version.resteasy}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxb-provider</artifactId>
+ <version>${version.resteasy}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <!-- Dependencies -->
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.arquillian.core</groupId>
+ <artifactId>arquillian-core-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.test</groupId>
+ <artifactId>arquillian-test-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-container-test-spi</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxrs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxb-provider</artifactId>
+ </dependency>
+
+ <!-- Test -->
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.protocol</groupId>
+ <artifactId>arquillian-protocol-servlet</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.spec</groupId>
+ <artifactId>jboss-javaee-6.0</artifactId>
+ <version>${version.jboss_spec}</version>
+ <scope>test</scope>
+ <type>pom</type>
+ </dependency>
+
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>arq-jbossas-managed-7</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-arquillian-container-managed</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <jboss.version>${version.jbossas_7}</jboss.version>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>unpack</id>
+ <phase>process-test-classes</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-dist</artifactId>
+ <version>${version.jbossas_7}</version>
+ <type>zip</type>
+ <overWrite>false</overWrite>
+ <outputDirectory>${project.build.directory}/</outputDirectory>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>arq-jbossas-remote-7</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-arquillian-container-remote</artifactId>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+</project>
View
38 ...esteasy/src/main/java/org/jboss/arquillian/extension/rest/client/RestClientExtension.java
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.extension.rest.client;
+
+import org.jboss.arquillian.core.spi.LoadableExtension;
+import org.jboss.arquillian.test.spi.TestEnricher;
+
+/**
+ * RestClientExtension
+ *
+ * @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class RestClientExtension implements LoadableExtension
+{
+ @Override
+ public void register(ExtensionBuilder builder)
+ {
+ builder.observer(RestInvoker.class);
+ builder.service(TestEnricher.class, RestEnricher.class);
+ }
+
+}
View
61 ...sions/resteasy/src/main/java/org/jboss/arquillian/extension/rest/client/RestEnricher.java
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.extension.rest.client;
+
+import java.lang.reflect.Method;
+
+import javax.ws.rs.core.Response;
+
+import org.jboss.arquillian.core.api.Instance;
+import org.jboss.arquillian.core.api.annotation.Inject;
+import org.jboss.arquillian.test.spi.TestEnricher;
+
+/**
+ * RestEnricher
+ *
+ * @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class RestEnricher implements TestEnricher
+{
+ @Inject
+ private Instance<Response> responseInst;
+
+ @Override
+ public void enrich(Object testCase)
+ {
+ }
+
+ @Override
+ public Object[] resolve(Method method)
+ {
+ Object[] values = new Object[method.getParameterTypes().length];
+ if(responseInst.get() != null)
+ {
+ Class<?>[] parameterTypes = method.getParameterTypes();
+ for(int i = 0; i < parameterTypes.length; i++)
+ {
+ if(Response.class.isAssignableFrom(parameterTypes[i]))
+ {
+ values[i] = responseInst.get();
+ }
+ }
+ }
+ return values;
+ }
+}
View
152 ...nsions/resteasy/src/main/java/org/jboss/arquillian/extension/rest/client/RestInvoker.java
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.extension.rest.client;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Providers;
+
+import org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext;
+import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData;
+import org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
+import org.jboss.arquillian.core.api.Instance;
+import org.jboss.arquillian.core.api.InstanceProducer;
+import org.jboss.arquillian.core.api.annotation.Inject;
+import org.jboss.arquillian.core.api.annotation.Observes;
+import org.jboss.arquillian.test.spi.annotation.TestScoped;
+import org.jboss.arquillian.test.spi.event.suite.Before;
+import org.jboss.resteasy.client.ClientExecutor;
+import org.jboss.resteasy.client.ClientRequest;
+import org.jboss.resteasy.client.core.ClientInvoker;
+import org.jboss.resteasy.client.core.ClientInvokerInterceptorFactory;
+import org.jboss.resteasy.client.core.extractors.DefaultEntityExtractorFactory;
+import org.jboss.resteasy.client.core.extractors.EntityExtractorFactory;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
+import org.jboss.resteasy.util.IsHttpMethod;
+
+/**
+ * RestInvoker
+ *
+ * @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class RestInvoker
+{
+ @Inject
+ private Instance<ProtocolMetaData> metaDataInst;
+
+ // Share the Response in the Arquillian scopes so it can be injected by the RestEnricher
+ @Inject @TestScoped
+ private InstanceProducer<Response> responseProducer;
+
+ public void call(@Observes Before event)
+ {
+ Set<String> httpMethods = IsHttpMethod.getHttpMethods(event.getTestMethod());
+ if (httpMethods != null && httpMethods.size() == 1)
+ {
+ Response response = doRestCall(event.getTestMethod(), httpMethods);
+ responseProducer.set(response);
+ }
+ }
+
+ /**
+ * Get the deployment URL, create the RestEasy Client Proxy Invoker for the given TestMethod and return the result.
+ *
+ * @param testMethod
+ * @param httpMethods
+ * @return
+ */
+ private Response doRestCall(Method testMethod, Set<String> httpMethods)
+ {
+ URI baseUri = getBaseURL();
+ ClientExecutor executor = ClientRequest.getDefaultExecutor();
+ ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
+ EntityExtractorFactory extractorFactory = new DefaultEntityExtractorFactory();
+
+ ArqClientInvoker invoker = new ArqClientInvoker(baseUri, testMethod.getDeclaringClass(), testMethod, providerFactory, executor, extractorFactory);
+ invoker.getAttributes().putAll(new HashMap<String, Object>());
+
+ ClientInvokerInterceptorFactory.applyDefaultInterceptors(invoker, providerFactory, testMethod.getDeclaringClass(), testMethod);
+ invoker.setHttpMethod(httpMethods.iterator().next());
+
+ return invoker.request(new Object[]{null});
+ }
+
+ // Currently no way to share @ArquillianResource URL (URLResourceProvider) logic internally, copied logic
+ private URI getBaseURL()
+ {
+ HTTPContext context = metaDataInst.get().getContext(HTTPContext.class);
+ if(allInSameContext(context.getServlets()))
+ {
+ return context.getServlets().get(0).getBaseURI();
+ }
+ throw new IllegalStateException("No baseURL found in HTTPContext");
+ }
+
+ private boolean allInSameContext(List<Servlet> servlets)
+ {
+ Set<String> context = new HashSet<String>();
+ for (Servlet servlet : servlets)
+ {
+ context.add(servlet.getContextRoot());
+ }
+ return context.size() == 1;
+ }
+
+ // Need to extend ClientInvoker to call createRequest
+ private static class ArqClientInvoker extends ClientInvoker
+ {
+ public ArqClientInvoker(URI baseUri, Class<?> declaring, Method method, ResteasyProviderFactory providerFactory, ClientExecutor executor, EntityExtractorFactory extractorFactory)
+ {
+ super(baseUri, declaring, method, providerFactory, executor, extractorFactory);
+ }
+
+ // As oppose to invoke(Object[]) which will return the Response Entity, we expose the raw Response object
+ public Response request(Object[] args)
+ {
+ boolean isProvidersSet = ResteasyProviderFactory.getContextData(Providers.class) != null;
+ if (!isProvidersSet) ResteasyProviderFactory.pushContext(Providers.class, providerFactory);
+
+ try
+ {
+ if (uri == null) throw new RuntimeException("You have not set a base URI for the client proxy");
+
+ ClientRequest request = createRequest(args);
+
+ try
+ {
+ return request.httpMethod(httpMethod);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ finally
+ {
+ if (!isProvidersSet) ResteasyProviderFactory.popContextData(Providers.class);
+ }
+ }
+ }
+}
View
1 ...easy/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
@@ -0,0 +1 @@
+org.jboss.arquillian.extension.rest.client.RestClientExtension
View
83 ...nsions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/RestClientTestCase.java
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.extension.rest;
+
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response.Status;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.extension.rest.app.CustomerResource;
+import org.jboss.arquillian.extension.rest.app.model.Customer;
+import org.jboss.arquillian.extension.rest.app.persistence.EntityManagerProducer;
+import org.jboss.arquillian.extension.rest.app.rs.JaxRsActivator;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.util.GenericType;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Arquillian Extension REST API Test Case
+ *
+ * Annotate the TestClass's TestMethods with JAX-RS Client annotations.
+ *
+ * Executes the REST request in the background for so to inject back the Response into the TestMethods arguments.
+ *
+ * * @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+@RunWith(Arquillian.class)
+public class RestClientTestCase
+{
+ @Deployment(testable = false)
+ public static WebArchive create() {
+ return ShrinkWrap.create(WebArchive.class)
+ .addPackage(Customer.class.getPackage())
+ .addClasses(EntityManagerProducer.class, CustomerResource.class, JaxRsActivator.class)
+ .addAsResource("import.sql")
+ .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+ @Test @GET @Path("rest/customer") @Consumes(MediaType.APPLICATION_XML)
+ public void shouldBeAbleToListAllCustomers(ClientResponse<List<Customer>> response)
+ {
+ Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ List<Customer> customers = response.getEntity(new GenericType<List<Customer>>(){});
+ Assert.assertEquals(2, customers.size());
+ }
+
+ @Test @GET @Path("rest/customer/1") @Consumes(MediaType.APPLICATION_XML)
+ public void shouldBeAbleToListACustomer(ClientResponse<Customer> response)
+ {
+ Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ Customer customer = response.getEntity(Customer.class);
+ Assert.assertEquals(1, customer.getId().intValue());
+ }
+}
View
58 ...ions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/CustomerResource.java
@@ -0,0 +1,58 @@
+package org.jboss.arquillian.extension.rest.app;
+
+import java.util.List;
+
+import javax.annotation.ManagedBean;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.jboss.arquillian.extension.rest.app.model.Customer;
+
+/**
+ * A REST service for retrieving Customer records
+ */
+@ManagedBean
+@Path("/customer")
+public class CustomerResource {
+ @Inject
+ private EntityManager em;
+
+ @GET @Produces(MediaType.APPLICATION_XML)
+ public List<Customer> getAllCustomers() {
+ return findAllCustomers();
+ }
+
+ /**
+ * This method responds to a GET request that supports the content type application/xml or application/json and returns the
+ * requested customer resource.
+ *
+ * <p>
+ * The customer is retrieved by id. A representation of the customer is then written into the response in the requested
+ * format. The id value is taken from the final path segment.
+ * </p>
+ *
+ * <a class="citation" href= "javacode://com.acme.jaxrs.CustomerResource#getCustomerById(java.lang.String)" />
+ */
+ @GET @Produces(MediaType.APPLICATION_XML)
+ @Path("/{id:[1-9][0-9]*}")
+ public Customer getCustomerById(@PathParam("id") long id) {
+ System.out.println("Handling resource request for /customer/" + id);
+ return findCustomerById(id);
+ }
+
+ private List<Customer> findAllCustomers() {
+ CriteriaQuery<Customer> criteria = em.getCriteriaBuilder().createQuery(Customer.class);
+ criteria.from(Customer.class);
+ return em.createQuery(criteria).getResultList();
+ }
+
+ private Customer findCustomerById(long id) {
+ return em.find(Customer.class, id);
+ }
+}
View
70 extensions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/model/Contact.java
@@ -0,0 +1,70 @@
+package org.jboss.arquillian.extension.rest.app.model;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+
+@Entity
+@Table(name = "contact")
+public class Contact implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private Long id;
+ private String address;
+ private String city;
+ private Customer customer;
+ private String phone;
+
+ @Id
+ @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @NotNull
+ @Size(min = 1, max = 50)
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ @NotNull
+ @Size(min = 2, max = 50)
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ @ManyToOne
+ public Customer getCustomer() {
+ return customer;
+ }
+
+ public void setCustomer(Customer customer) {
+ this.customer = customer;
+ }
+
+ @Pattern(regexp = "^\\d{3}-\\d{3}-\\d{4}")
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+}
View
75 ...nsions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/model/Customer.java
@@ -0,0 +1,75 @@
+package org.jboss.arquillian.extension.rest.app.model;
+
+import java.io.Serializable;
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.persistence.UniqueConstraint;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+/**
+ * A <strong>Customer</strong> is an entity for whom orders are created.
+ */
+@Entity
+@XmlRootElement
+@Table(name = "customer", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
+public class Customer implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private Long id;
+ private Set<Contact> contacts;
+ private String name;
+ private Set<SalesOrder> orders;
+
+ public Customer() {
+ }
+
+ public Customer(String name) {
+ this.name = name;
+ }
+
+ @Id
+ @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @XmlTransient
+ @OneToMany(mappedBy = "customer")
+ public Set<Contact> getContacts() {
+ return contacts;
+ }
+
+ public void setContacts(Set<Contact> contacts) {
+ this.contacts = contacts;
+ }
+
+ @NotNull
+ @Size(min = 3, max = 50)
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @XmlTransient
+ @OneToMany(mappedBy = "customer")
+ public Set<SalesOrder> getOrders() {
+ return orders;
+ }
+
+ public void setOrders(Set<SalesOrder> orders) {
+ this.orders = orders;
+ }
+}
View
55 ...nsions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/model/LineItem.java
@@ -0,0 +1,55 @@
+package org.jboss.arquillian.extension.rest.app.model;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "line_item")
+public class LineItem implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private Long id;
+ private SalesOrder order;
+ private Product product;
+ private BigDecimal quantity;
+
+ @Id
+ @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @ManyToOne
+ public SalesOrder getOrder() {
+ return order;
+ }
+
+ public void setOrder(SalesOrder order) {
+ this.order = order;
+ }
+
+ @ManyToOne
+ public Product getProduct() {
+ return product;
+ }
+
+ public void setProduct(Product product) {
+ this.product = product;
+ }
+
+ public BigDecimal getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(BigDecimal quantity) {
+ this.quantity = quantity;
+ }
+}
View
54 extensions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/model/Product.java
@@ -0,0 +1,54 @@
+package org.jboss.arquillian.extension.rest.app.model;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "product")
+public class Product implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private Long id;
+ private String code;
+ private String name;
+ private BigDecimal unitPrice;
+
+ @Id
+ @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Column(name = "unit_price")
+ public BigDecimal getUnitPrice() {
+ return unitPrice;
+ }
+
+ public void setUnitPrice(BigDecimal unitPrice) {
+ this.unitPrice = unitPrice;
+ }
+}
View
70 ...ions/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/model/SalesOrder.java
@@ -0,0 +1,70 @@
+package org.jboss.arquillian.extension.rest.app.model;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name = "sales_order")
+public class SalesOrder implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private Long id;
+ private BigDecimal amount;
+ private Date created;
+ private Customer customer;
+ private Set<LineItem> lineItems;
+
+ @Id
+ @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public BigDecimal getAmount() {
+ return amount;
+ }
+
+ public void setAmount(BigDecimal amount) {
+ this.amount = amount;
+ }
+
+ @Temporal(TemporalType.DATE)
+ public Date getCreated() {
+ return created;
+ }
+
+ public void setCreated(Date created) {
+ this.created = created;
+ }
+
+ @ManyToOne
+ public Customer getCustomer() {
+ return customer;
+ }
+
+ public void setCustomer(Customer customer) {
+ this.customer = customer;
+ }
+
+ @OneToMany(mappedBy = "order")
+ public Set<LineItem> getLineItems() {
+ return lineItems;
+ }
+
+ public void setLineItems(Set<LineItem> lineItems) {
+ this.lineItems = lineItems;
+ }
+}
View
21 .../test/java/org/jboss/arquillian/extension/rest/app/persistence/EntityManagerProducer.java
@@ -0,0 +1,21 @@
+package org.jboss.arquillian.extension.rest.app.persistence;
+
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.Disposes;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+public class EntityManagerProducer {
+ // NOTE cannot use producer field because Weld attempts to close EntityManager
+ // https://jira.jboss.org/jira/browse/WELD-341
+ @PersistenceContext
+ EntityManager em;
+
+ public @Produces
+ EntityManager retrieveEntityManager() {
+ return em;
+ }
+
+ public void disposeEntityManager(@Disposes EntityManager em) {
+ }
+}
View
8 ...ons/resteasy/src/test/java/org/jboss/arquillian/extension/rest/app/rs/JaxRsActivator.java
@@ -0,0 +1,8 @@
+package org.jboss.arquillian.extension.rest.app.rs;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@ApplicationPath("/rest")
+public class JaxRsActivator extends Application {
+}
View
12 extensions/resteasy/src/test/resources/arquillian.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://jboss.org/schema/arquillian"
+ xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+
+ <container qualifier="jbossas7" default="true">
+ <configuration>
+ <property name="jbossHome">target/jboss-as-${jboss.version:7.1.0.Beta1}</property>
+ </configuration>
+ </container>
+
+</arquillian>
View
8 extensions/resteasy/src/test/resources/import.sql
@@ -0,0 +1,8 @@
+insert into customer (id, name) values (1, 'Acme Corporation')
+insert into customer (id, name) values (2, 'Starbucks')
+insert into contact (id, address, city, phone, customer_id) values (1, '100 Broadway', 'New York', '212-555-1212', 1)
+insert into sales_order (id, created, amount, customer_id) values (1, '2010-05-25', 100.00, 1)
+insert into product (id, name, code, unit_price) values (1, 'Portable Hole', 'PHOLE', 20)
+insert into product (id, name, code, unit_price) values (2, 'Dynamite', 'DYN', 5)
+insert into line_item (id, order_id, product_id, quantity) values (1, 1, 1, 3)
+insert into line_item (id, order_id, product_id, quantity) values (2 ,1, 2, 8)
View
15 extensions/resteasy/src/test/resources/test-persistence.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence version="2.0"
+ xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://java.sun.com/xml/ns/persistence
+ http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
+ <persistence-unit name="sellmore">
+ <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+ <property name="hibernate.show_sql" value="true"/>
+ </properties>
+ </persistence-unit>
+</persistence>

0 comments on commit 2c22c4e

Please sign in to comment.
Something went wrong with that request. Please try again.