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 @GET
@Path("/getinfo") @Path("/getinfo")
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
Movie movieByImdbID(@QueryParam("imdbID") String imdbID); Movie movieByImdbId(@QueryParam("imdbId") String imdbId);
@GET @GET
@ -37,7 +37,7 @@ public interface ServicesInterface {
@DELETE @DELETE
@Path("/deletemovie") @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", "country",
"director", "director",
"genre", "genre",
"imdbID", "imdbId",
"imdbRating", "imdbRating",
"imdbVotes", "imdbVotes",
"language", "language",
@ -36,7 +36,7 @@ public class Movie {
protected String country; protected String country;
protected String director; protected String director;
protected String genre; protected String genre;
protected String imdbID; protected String imdbId;
protected String imdbRating; protected String imdbRating;
protected String imdbVotes; protected String imdbVotes;
protected String language; 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 * @return
* possible object is * possible object is
* {@link String } * {@link String }
* *
*/ */
public String getImdbID() { public String getImdbId() {
return imdbID; return imdbId;
} }
/** /**
* Imposta il valore della propriet<EFBFBD> imdbID. * Imposta il valore della propriet<EFBFBD> imdbId.
* *
* @param value * @param value
* allowed object is * allowed object is
* {@link String } * {@link String }
* *
*/ */
public void setImdbID(String value) { public void setImdbId(String value) {
this.imdbID = value; this.imdbId = value;
} }
/** /**
@ -540,7 +540,7 @@ public class Movie {
", country='" + country + '\'' + ", country='" + country + '\'' +
", director='" + director + '\'' + ", director='" + director + '\'' +
", genre='" + genre + '\'' + ", genre='" + genre + '\'' +
", imdbID='" + imdbID + '\'' + ", imdbId='" + imdbId + '\'' +
", imdbRating='" + imdbRating + '\'' + ", imdbRating='" + imdbRating + '\'' +
", imdbVotes='" + imdbVotes + '\'' + ", imdbVotes='" + imdbVotes + '\'' +
", language='" + language + '\'' + ", language='" + language + '\'' +
@ -564,14 +564,14 @@ public class Movie {
Movie movie = (Movie) o; 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; return title != null ? title.equals(movie.title) : movie.title == null;
} }
@Override @Override
public int hashCode() { 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); result = 31 * result + (title != null ? title.hashCode() : 0);
return result; return result;
} }

View File

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

View File

@ -5,47 +5,12 @@
<display-name>RestEasy Example</display-name> <display-name>RestEasy Example</display-name>
<listener> <!-- needed only if you want prepend a relative path to your services -->
<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 -->
<context-param> <context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name> <param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value> <param-value>/rest</param-value>
</context-param> </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> </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; package com.baeldung.server;
import com.baeldung.model.Movie;
import com.baeldung.client.ServicesInterface; import com.baeldung.client.ServicesInterface;
import com.baeldung.model.Movie;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper; 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.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import javax.naming.NamingException; import javax.naming.NamingException;
@ -23,22 +22,13 @@ import java.util.Locale;
public class RestEasyClientTest { public class RestEasyClientTest {
Movie transformerMovie=null; Movie transformerMovie=null;
Movie batmanMovie=null; Movie batmanMovie=null;
ObjectMapper jsonMapper=null; ObjectMapper jsonMapper=null;
@BeforeClass
public static void loadMovieInventory(){
}
@Before @Before
public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException {
jsonMapper=new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); jsonMapper=new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
jsonMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); jsonMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
@ -57,19 +47,15 @@ public class RestEasyClientTest {
batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Test is going to die ...", e); throw new RuntimeException("Test is going to die ...", e);
} }
} }
@Test @Test
public void testListAllMovies() { public void testListAllMovies() {
try {
ResteasyClient client = new ResteasyClientBuilder().build(); ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class); ServicesInterface simple = target.proxy(ServicesInterface.class);
Response moviesResponse = simple.addMovie(transformerMovie); Response moviesResponse = simple.addMovie(transformerMovie);
@ -77,43 +63,32 @@ public class RestEasyClientTest {
moviesResponse = simple.addMovie(batmanMovie); moviesResponse = simple.addMovie(batmanMovie);
moviesResponse.close(); moviesResponse.close();
final List<Movie> movies = simple.listMovies(); List<Movie> movies = simple.listMovies();
System.out.println(movies); System.out.println(movies);
} catch (Exception e) {
e.printStackTrace();
} }
}
@Test @Test
public void testMovieByImdbID() { public void testMovieByImdbId() {
String transformerImdbId="tt0418279"; String transformerImdbId="tt0418279";
try {
ResteasyClient client = new ResteasyClientBuilder().build(); ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class); ServicesInterface simple = target.proxy(ServicesInterface.class);
Response moviesResponse = simple.addMovie(transformerMovie); Response moviesResponse = simple.addMovie(transformerMovie);
moviesResponse.close(); moviesResponse.close();
final Movie movies = simple.movieByImdbID(transformerImdbId); Movie movies = simple.movieByImdbId(transformerImdbId);
System.out.println(movies); System.out.println(movies);
} catch (Exception e) {
e.printStackTrace();
}
} }
@Test @Test
public void testAddMovie() { public void testAddMovie() {
try {
ResteasyClient client = new ResteasyClientBuilder().build(); ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class); ServicesInterface simple = target.proxy(ServicesInterface.class);
Response moviesResponse = simple.addMovie(batmanMovie); Response moviesResponse = simple.addMovie(batmanMovie);
@ -121,31 +96,24 @@ public class RestEasyClientTest {
moviesResponse = simple.addMovie(transformerMovie); moviesResponse = simple.addMovie(transformerMovie);
if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
//System.out.println(moviesResponse.readEntity(String.class));
System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus());
} }
moviesResponse.close();
} catch (Exception e) { moviesResponse.close();
e.printStackTrace(); System.out.println("Response Code: "+Response.Status.OK.getStatusCode());
}
} }
@Test @Test
public void testDeleteMovie() { public void testDeleteMovi1e() {
String transformerImdbId="tt0418279";
try {
ResteasyClient client = new ResteasyClientBuilder().build(); ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class); ServicesInterface simple = target.proxy(ServicesInterface.class);
Response moviesResponse = simple.addMovie(batmanMovie); Response moviesResponse = simple.addMovie(batmanMovie);
moviesResponse.close(); moviesResponse.close();
moviesResponse = simple.deleteMovie(transformerImdbId); moviesResponse = simple.deleteMovie(batmanMovie.getImdbId());
moviesResponse.close();
if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) {
System.out.println(moviesResponse.readEntity(String.class)); System.out.println(moviesResponse.readEntity(String.class));
@ -153,20 +121,15 @@ public class RestEasyClientTest {
} }
moviesResponse.close(); moviesResponse.close();
System.out.println("Response Code: "+Response.Status.OK.getStatusCode());
} catch (Exception e) {
e.printStackTrace();
}
} }
@Test @Test
public void testUpdateMovie() { public void testUpdateMovie() {
try {
ResteasyClient client = new ResteasyClientBuilder().build(); ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest"));
ServicesInterface simple = target.proxy(ServicesInterface.class); ServicesInterface simple = target.proxy(ServicesInterface.class);
Response moviesResponse = simple.addMovie(batmanMovie); Response moviesResponse = simple.addMovie(batmanMovie);
@ -175,15 +138,11 @@ public class RestEasyClientTest {
moviesResponse = simple.updateMovie(batmanMovie); moviesResponse = simple.updateMovie(batmanMovie);
if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) {
//System.out.println(moviesResponse.readEntity(String.class));
System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus());
} }
moviesResponse.close(); moviesResponse.close();
System.out.println("Response Code: "+Response.Status.OK.getStatusCode());
} catch (Exception e) {
e.printStackTrace();
}
} }
} }