CleanUp and reformatting Code; dependency fix in pom.xml

This commit is contained in:
giuseppe.bueti 2016-02-08 14:00:11 +01:00
parent 03b6cbf3e5
commit c3ef41a10d
9 changed files with 125 additions and 205 deletions

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -9,16 +8,8 @@
<version>1.0</version> <version>1.0</version>
<packaging>war</packaging> <packaging>war</packaging>
<repositories>
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<properties> <properties>
<resteasy.version>3.0.14.Final</resteasy.version> <resteasy.version>3.0.14.Final</resteasy.version>
<resteasy.scope>runtime</resteasy.scope>
</properties> </properties>
<build> <build>
@ -37,52 +28,33 @@
<dependencies> <dependencies>
<dependency> <!-- core library -->
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>3.0.12.Final</version>
<scope>${resteasy.scope}</scope>
</dependency>
<dependency> <dependency>
<groupId>org.jboss.resteasy</groupId> <groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId> <artifactId>resteasy-servlet-initializer</artifactId>
<version>${resteasy.version}</version> <version>${resteasy.version}</version>
<scope>${resteasy.scope}</scope>
<exclusions>
<exclusion>
<artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jboss.resteasy</groupId> <groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId> <artifactId>resteasy-client</artifactId>
<version>${resteasy.version}</version> <version>${resteasy.version}</version>
<scope>${resteasy.scope}</scope>
</dependency> </dependency>
<!-- Optional library -->
<dependency> <dependency>
<groupId>javax.ws.rs</groupId> <groupId>org.jboss.resteasy</groupId>
<artifactId>javax.ws.rs-api</artifactId> <artifactId>resteasy-jaxb-provider</artifactId>
<version>2.0.1</version> <version>${resteasy.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jboss.resteasy</groupId> <groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId> <artifactId>resteasy-jackson-provider</artifactId>
<version>${resteasy.version}</version> <version>${resteasy.version}</version>
<scope>${resteasy.scope}</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>${resteasy.version}</version>
<scope>${resteasy.scope}</scope>
</dependency> </dependency>
<!-- Junit Library --> <!-- Junit Library -->
@ -101,4 +73,5 @@
</dependencies> </dependencies>
</project> </project>

View File

@ -9,35 +9,28 @@ import java.util.List;
@Path("/movies") @Path("/movies")
public interface ServicesInterface { 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
@Path("/listmovies") @Path("/listmovies")
@Produces({ "application/json" }) @Produces({ "application/json" })
List<Movie> listMovies(); List<Movie> listMovies();
@POST @POST
@Path("/addmovie") @Path("/addmovie")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
Response addMovie(Movie movie); Response addMovie(Movie movie);
@PUT @PUT
@Path("/updatemovie") @Path("/updatemovie")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
Response updateMovie(Movie movie); Response updateMovie(Movie movie);
@DELETE @DELETE
@Path("/deletemovie") @Path("/deletemovie")
Response deleteMovie(@QueryParam("imdbId") String imdbID); Response deleteMovie(@QueryParam("imdbId") String imdbID);
} }

View File

@ -5,28 +5,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "movie", propOrder = { @XmlType(name = "movie", propOrder = { "actors", "awards", "country", "director", "genre", "imdbId", "imdbRating", "imdbVotes", "language", "metascore", "plot", "poster", "rated", "released", "response", "runtime", "title", "type", "writer", "year" })
"actors",
"awards",
"country",
"director",
"genre",
"imdbId",
"imdbRating",
"imdbVotes",
"language",
"metascore",
"plot",
"poster",
"rated",
"released",
"response",
"runtime",
"title",
"type",
"writer",
"year"
})
public class Movie { public class Movie {
protected String actors; protected String actors;
@ -212,37 +191,22 @@ public class Movie {
@Override @Override
public String toString() { public String toString() {
return "Movie{" + return "Movie{" + "actors='" + actors + '\'' + ", awards='" + awards + '\'' + ", country='" + country + '\'' + ", director='" + director + '\'' + ", genre='" + genre + '\'' + ", imdbId='" + imdbId + '\'' + ", imdbRating='" + imdbRating + '\''
"actors='" + actors + '\'' + + ", imdbVotes='" + imdbVotes + '\'' + ", language='" + language + '\'' + ", metascore='" + metascore + '\'' + ", poster='" + poster + '\'' + ", rated='" + rated + '\'' + ", released='" + released + '\'' + ", response='" + response + '\''
", awards='" + awards + '\'' + + ", runtime='" + runtime + '\'' + ", title='" + title + '\'' + ", type='" + type + '\'' + ", writer='" + writer + '\'' + ", year='" + year + '\'' + '}';
", country='" + country + '\'' +
", director='" + director + '\'' +
", genre='" + genre + '\'' +
", imdbId='" + imdbId + '\'' +
", imdbRating='" + imdbRating + '\'' +
", imdbVotes='" + imdbVotes + '\'' +
", language='" + language + '\'' +
", metascore='" + metascore + '\'' +
", poster='" + poster + '\'' +
", rated='" + rated + '\'' +
", released='" + released + '\'' +
", response='" + response + '\'' +
", runtime='" + runtime + '\'' +
", title='" + title + '\'' +
", type='" + type + '\'' +
", writer='" + writer + '\'' +
", year='" + year + '\'' +
'}';
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o)
if (o == null || getClass() != o.getClass()) return false; return true;
if (o == null || getClass() != o.getClass())
return false;
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;
} }

View File

@ -15,7 +15,6 @@ public class MovieCrudService {
private Map<String, Movie> inventory = new HashMap<String, Movie>(); private Map<String, Movie> inventory = new HashMap<String, Movie>();
@GET @GET
@Path("/getinfo") @Path("/getinfo")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ -25,11 +24,11 @@ public class MovieCrudService {
if (inventory.containsKey(imdbId)) { if (inventory.containsKey(imdbId)) {
return inventory.get(imdbId); return inventory.get(imdbId);
}else return null; } else
return null;
} }
@POST @POST
@Path("/addmovie") @Path("/addmovie")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ -38,8 +37,7 @@ 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);
@ -47,7 +45,6 @@ public class MovieCrudService {
return Response.status(Response.Status.CREATED).build(); return Response.status(Response.Status.CREATED).build();
} }
@PUT @PUT
@Path("/updatemovie") @Path("/updatemovie")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ -56,15 +53,13 @@ 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();
} }
@DELETE @DELETE
@Path("/deletemovie") @Path("/deletemovie")
public Response deleteMovie(@QueryParam("imdbId") String imdbId) { public Response deleteMovie(@QueryParam("imdbId") String imdbId) {
@ -72,15 +67,13 @@ public class MovieCrudService {
System.out.println("*** Calling deleteMovie ***"); System.out.println("*** Calling deleteMovie ***");
if (null == inventory.get(imdbId)) { if (null == inventory.get(imdbId)) {
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND).entity("Movie is not in the database.\nUnable to Delete").build();
.entity("Movie is not in the database.\nUnable to Delete").build();
} }
inventory.remove(imdbId); inventory.remove(imdbId);
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} }
@GET @GET
@Path("/listmovies") @Path("/listmovies")
@Produces({ "application/json" }) @Produces({ "application/json" })

View File

@ -82,7 +82,6 @@ public class RestEasyClientTest {
System.out.println(movies); System.out.println(movies);
} }
@Test @Test
public void testAddMovie() { public void testAddMovie() {
@ -102,7 +101,6 @@ public class RestEasyClientTest {
System.out.println("Response Code: " + Response.Status.OK.getStatusCode()); System.out.println("Response Code: " + Response.Status.OK.getStatusCode());
} }
@Test @Test
public void testDeleteMovi1e() { public void testDeleteMovi1e() {
@ -123,7 +121,6 @@ public class RestEasyClientTest {
System.out.println("Response Code: " + Response.Status.OK.getStatusCode()); System.out.println("Response Code: " + Response.Status.OK.getStatusCode());
} }
@Test @Test
public void testUpdateMovie() { public void testUpdateMovie() {

View File

@ -16,7 +16,7 @@
"metascore": "66", "metascore": "66",
"imdbRating": "7.6", "imdbRating": "7.6",
"imdbVotes": "256,000", "imdbVotes": "256,000",
"imdbID": "tt0096895", "imdbId": "tt0096895",
"type": "movie", "type": "movie",
"response": "True" "response": "True"
} }

View File

@ -16,7 +16,7 @@
"metascore": "61", "metascore": "61",
"imdbRating": "7.1", "imdbRating": "7.1",
"imdbVotes": "492,225", "imdbVotes": "492,225",
"imdbID": "tt0418279", "imdbId": "tt0418279",
"type": "movie", "type": "movie",
"response": "True" "response": "True"
} }