Commit d945a7ec by dblevins

Reworked service and documentation

parent ea3acb90
......@@ -19,11 +19,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- Change: groupId, artifactId, version -->
<groupId>org.superbiz</groupId>
<artifactId>tomee-rest-arquillian</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Maven Project with Arquillian and TomEE JAX-RS</name>
<dependencies>
<dependency>
......@@ -54,6 +55,7 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
......@@ -62,12 +64,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<version>3.1</version>
<configuration>
<optimize>true</optimize>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<version>2.17</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......@@ -77,6 +84,16 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.openejb.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<version>1.6.0.2</version>
<configuration>
<tomeeVersion>1.6.0.2</tomeeVersion>
<tomeeClassifier>jaxrs</tomeeClassifier>
</configuration>
</plugin>
</plugins>
</build>
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.superbiz;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Color {
private String name;
private int r;
private int g;
private int b;
public Color() {
}
public Color(String name, int r, int g, int b) {
this.name = name;
this.r = r;
this.g = g;
this.b = b;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getR() {
return r;
}
public void setR(int r) {
this.r = r;
}
public int getG() {
return g;
}
public void setG(int g) {
this.g = g;
}
public int getB() {
return b;
}
public void setB(int b) {
this.b = b;
}
}
......@@ -21,14 +21,17 @@ import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@Path("/color")
@Singleton
public class ColorBean {
public class ColorService {
private String color;
public ColorBean() {
public ColorService() {
this.color = "white";
}
......@@ -37,15 +40,16 @@ public class ColorBean {
return color;
}
@Path("favorite")
@GET
public String getFavoriteColor() {
return "orange";
}
@Path("{color}")
@POST
public void setColor(@PathParam("color") String color) {
this.color = color;
}
@Path("object")
@GET
@Produces({ APPLICATION_JSON })
public Color getColorObject() {
return new Color("orange", 0xE7, 0x71, 0x00);
}
}
......@@ -26,6 +26,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
......@@ -44,7 +45,7 @@ import java.net.URL;
*
*/
@RunWith(Arquillian.class)
public class ColorBeanTest extends Assert {
public class ColorServiceTest extends Assert {
/**
* ShrinkWrap is used to create a war file on the fly.
......@@ -57,7 +58,7 @@ public class ColorBeanTest extends Assert {
*/
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class).addClass(ColorBean.class);
return ShrinkWrap.create(WebArchive.class).addClasses(ColorService.class, Color.class);
}
/**
......@@ -99,15 +100,18 @@ public class ColorBeanTest extends Assert {
}
@Test
public void getFavorite() throws Exception {
final WebClient webClient = WebClient.create(webappUrl.toURI());
final Response response = webClient.path("color/favorite").get();
public void getColorObject() throws Exception {
assertEquals(200, response.getStatus());
final WebClient webClient = WebClient.create(webappUrl.toURI());
webClient.accept(MediaType.APPLICATION_JSON);
final String content = slurp((InputStream) response.getEntity());
final Color color = webClient.path("color/object").get(Color.class);
assertEquals("orange", content);
assertNotNull(color);
assertEquals("orange", color.getName());
assertEquals(0xE7, color.getR());
assertEquals(0x71, color.getG());
assertEquals(0x00, color.getB());
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment