Minor Bugfix

This commit is contained in:
giuseppe.bueti 2016-02-07 20:29:30 +01:00 committed by Giuseppe Bueti
parent b39ec7d76e
commit 5cdf7185a4
6 changed files with 81 additions and 150 deletions

View File

@ -14,7 +14,7 @@ public interface ServicesInterface {
@GET
@Path("/getinfo")
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
Movie movieByImdbID(@QueryParam("imdbID") String imdbID);
Movie movieByImdbId(@QueryParam("imdbId") String imdbId);
@GET
@ -37,7 +37,7 @@ public interface ServicesInterface {
@DELETE
@Path("/deletemovie")
Response deleteMovie(@QueryParam("imdbID") String imdbID);
Response deleteMovie(@QueryParam("imdbId") String imdbID);

View File

@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlType;
"country",
"director",
"genre",
"imdbID",
"imdbId",
"imdbRating",
"imdbVotes",
"language",
@ -36,7 +36,7 @@ public class Movie {
protected String country;
protected String director;
protected String genre;
protected String imdbID;
protected String imdbId;
protected String imdbRating;
protected String imdbVotes;
protected String language;
@ -173,27 +173,27 @@ public class Movie {
}
/**
* Recupera il valore della propriet<EFBFBD> imdbID.
* Recupera il valore della propriet<EFBFBD> imdbId.
*
* @return
* possible object is
* {@link String }
*
*/
public String getImdbID() {
return imdbID;
public String getImdbId() {
return imdbId;
}
/**
* Imposta il valore della propriet<EFBFBD> imdbID.
* Imposta il valore della propriet<EFBFBD> imdbId.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setImdbID(String value) {
this.imdbID = value;
public void setImdbId(String value) {
this.imdbId = value;
}
/**
@ -540,7 +540,7 @@ public class Movie {
", country='" + country + '\'' +
", director='" + director + '\'' +
", genre='" + genre + '\'' +
", imdbID='" + imdbID + '\'' +
", imdbId='" + imdbId + '\'' +
", imdbRating='" + imdbRating + '\'' +
", imdbVotes='" + imdbVotes + '\'' +
", language='" + language + '\'' +
@ -564,14 +564,14 @@ public class Movie {
Movie movie = (Movie) o;
if (imdbID != null ? !imdbID.equals(movie.imdbID) : movie.imdbID != null) return false;
if (imdbId != null ? !imdbId.equals(movie.imdbId) : movie.imdbId != null) return false;
return title != null ? title.equals(movie.title) : movie.title == null;
}
@Override
public int hashCode() {
int result = imdbID != null ? imdbID.hashCode() : 0;
int result = imdbId != null ? imdbId.hashCode() : 0;
result = 31 * result + (title != null ? title.hashCode() : 0);
return result;
}

View File

@ -22,7 +22,7 @@ public class MovieCrudService {
@GET
@Path("/getinfo")
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){
public Movie movieByImdbID(@QueryParam("imdbId") String imdbID){
System.out.println("*** Calling getinfo for a given ImdbID***");
@ -40,12 +40,12 @@ public class MovieCrudService {
System.out.println("*** Calling addMovie ***");
if (null!=inventory.get(movie.getImdbID())){
if (null!=inventory.get(movie.getImdbId())){
return Response.status(Response.Status.NOT_MODIFIED)
.entity("Movie is Already in the database.").build();
}
inventory.put(movie.getImdbID(),movie);
inventory.put(movie.getImdbId(),movie);
return Response.status(Response.Status.CREATED).build();
}
@ -58,11 +58,11 @@ public class MovieCrudService {
System.out.println("*** Calling updateMovie ***");
if (null==inventory.get(movie.getImdbID())){
if (null==inventory.get(movie.getImdbId())){
return Response.status(Response.Status.NOT_MODIFIED)
.entity("Movie is not in the database.\nUnable to Update").build();
}
inventory.put(movie.getImdbID(),movie);
inventory.put(movie.getImdbId(),movie);
return Response.status(Response.Status.OK).build();
}
@ -70,7 +70,7 @@ public class MovieCrudService {
@DELETE
@Path("/deletemovie")
public Response deleteMovie(@QueryParam("imdbID") String imdbID){
public Response deleteMovie(@QueryParam("imdbId") String imdbID){
System.out.println("*** Calling deleteMovie ***");

View File

@ -5,47 +5,12 @@
<display-name>RestEasy Example</display-name>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<description>RestEasy Example</description>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>RestEasyExample</param-value>
</context-param>
<!-- this need same with resteasy servlet url-pattern -->
<!-- needed only if you want prepend a relative path to your services -->
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.baeldung.server.RestEasyServices</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

View File

@ -0,0 +1,7 @@
package baeldung.client;
/**
* Created by Admin on 29/01/2016.
*/
public class RestEasyClient {
}

View File

@ -1,7 +1,7 @@
package com.baeldung.server;
import com.baeldung.model.Movie;
import com.baeldung.client.ServicesInterface;
import com.baeldung.model.Movie;
import org.apache.commons.io.IOUtils;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
@ -9,7 +9,6 @@ import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import javax.naming.NamingException;
@ -23,22 +22,13 @@ import java.util.Locale;
public class RestEasyClientTest {
Movie transformerMovie=null;
Movie batmanMovie=null;
ObjectMapper jsonMapper=null;
@BeforeClass
public static void loadMovieInventory(){
}
@Before
public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException {
jsonMapper=new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
jsonMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
@ -57,133 +47,102 @@ public class RestEasyClientTest {
batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Test is going to die ...", e);
}
}
@Test
public void testListAllMovies() {
try {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class);
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class);
Response moviesResponse = simple.addMovie(transformerMovie);
moviesResponse.close();
moviesResponse = simple.addMovie(batmanMovie);
moviesResponse.close();
Response moviesResponse = simple.addMovie(transformerMovie);
moviesResponse.close();
moviesResponse = simple.addMovie(batmanMovie);
moviesResponse.close();
final List<Movie> movies = simple.listMovies();
System.out.println(movies);
} catch (Exception e) {
e.printStackTrace();
}
List<Movie> movies = simple.listMovies();
System.out.println(movies);
}
@Test
public void testMovieByImdbID() {
public void testMovieByImdbId() {
String transformerImdbId="tt0418279";
try {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class);
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class);
Response moviesResponse = simple.addMovie(transformerMovie);
moviesResponse.close();
Response moviesResponse = simple.addMovie(transformerMovie);
moviesResponse.close();
final Movie movies = simple.movieByImdbID(transformerImdbId);
System.out.println(movies);
} catch (Exception e) {
e.printStackTrace();
}
Movie movies = simple.movieByImdbId(transformerImdbId);
System.out.println(movies);
}
@Test
public void testAddMovie() {
try {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class);
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class);
Response moviesResponse = simple.addMovie(batmanMovie);
moviesResponse.close();
moviesResponse = simple.addMovie(transformerMovie);
Response moviesResponse = simple.addMovie(batmanMovie);
moviesResponse.close();
moviesResponse = simple.addMovie(transformerMovie);
if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
//System.out.println(moviesResponse.readEntity(String.class));
System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus());
}
moviesResponse.close();
} catch (Exception e) {
e.printStackTrace();
if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus());
}
moviesResponse.close();
System.out.println("Response Code: "+Response.Status.OK.getStatusCode());
}
@Test
public void testDeleteMovie() {
public void testDeleteMovi1e() {
String transformerImdbId="tt0418279";
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class);
try {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class);
Response moviesResponse = simple.addMovie(batmanMovie);
moviesResponse.close();
moviesResponse = simple.deleteMovie(batmanMovie.getImdbId());
Response moviesResponse = simple.addMovie(batmanMovie);
moviesResponse.close();
moviesResponse = simple.deleteMovie(transformerImdbId);
moviesResponse.close();
if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) {
System.out.println(moviesResponse.readEntity(String.class));
throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus());
}
moviesResponse.close();
} catch (Exception e) {
e.printStackTrace();
if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) {
System.out.println(moviesResponse.readEntity(String.class));
throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus());
}
moviesResponse.close();
System.out.println("Response Code: "+Response.Status.OK.getStatusCode());
}
@Test
public void testUpdateMovie() {
try {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class);
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class);
Response moviesResponse = simple.addMovie(batmanMovie);
moviesResponse.close();
batmanMovie.setImdbVotes("300,000");
moviesResponse = simple.updateMovie(batmanMovie);
Response moviesResponse = simple.addMovie(batmanMovie);
moviesResponse.close();
batmanMovie.setImdbVotes("300,000");
moviesResponse = simple.updateMovie(batmanMovie);
if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) {
//System.out.println(moviesResponse.readEntity(String.class));
System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus());
}
moviesResponse.close();
} catch (Exception e) {
e.printStackTrace();
if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) {
System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus());
}
moviesResponse.close();
System.out.println("Response Code: "+Response.Status.OK.getStatusCode());
}
}