Created
September 5, 2013 07:18
-
-
Save karangb/6446961 to your computer and use it in GitHub Desktop.
Dropwizard / Jersey returns 204 for a resource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.hypem.recommender</groupId> | |
<artifactId>service</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>org.mockito</groupId> | |
<artifactId>mockito-all</artifactId> | |
<version>1.9.5</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>com.yammer.dropwizard</groupId> | |
<artifactId>dropwizard-testing</artifactId> | |
<version>0.6.2</version> | |
</dependency> | |
<dependency> | |
<groupId>com.hypem.recommender</groupId> | |
<artifactId>api</artifactId> | |
<version>${project.version}</version> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | |
<component name="NewModuleRootManager" inherit-compiler-output="false"> | |
<output url="file://$MODULE_DIR$/target/classes" /> | |
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | |
<exclude-output /> | |
<content url="file://$MODULE_DIR$"> | |
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | |
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" /> | |
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | |
<excludeFolder url="file://$MODULE_DIR$/target" /> | |
</content> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
<orderEntry type="module-library" scope="TEST"> | |
<library> | |
<CLASSES> | |
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.10.jar!/" /> | |
</CLASSES> | |
<JAVADOC /> | |
<SOURCES /> | |
</library> | |
</orderEntry> | |
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-all:1.9.5" level="project" /> | |
<orderEntry type="library" name="Maven: com.yammer.dropwizard:dropwizard-testing:0.6.2" level="project" /> | |
<orderEntry type="library" name="Maven: com.yammer.dropwizard:dropwizard-core:0.6.2" level="project" /> | |
<orderEntry type="library" name="Maven: com.sun.jersey:jersey-core:1.17.1" level="project" /> | |
<orderEntry type="library" name="Maven: com.sun.jersey:jersey-server:1.17.1" level="project" /> | |
<orderEntry type="library" name="Maven: asm:asm:3.1" level="project" /> | |
<orderEntry type="library" name="Maven: com.sun.jersey:jersey-servlet:1.17.1" level="project" /> | |
<orderEntry type="library" name="Maven: com.yammer.metrics:metrics-core:2.2.0" level="project" /> | |
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.4" level="project" /> | |
<orderEntry type="library" name="Maven: com.yammer.metrics:metrics-servlet:2.2.0" level="project" /> | |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.1.4" level="project" /> | |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.1.4" level="project" /> | |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.1.4" level="project" /> | |
<orderEntry type="library" name="Maven: com.yammer.metrics:metrics-jetty:2.2.0" level="project" /> | |
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:8.1.10.v20130312" level="project" /> | |
<orderEntry type="library" name="Maven: org.eclipse.jetty.orbit:javax.servlet:3.0.0.v201112011016" level="project" /> | |
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-continuation:8.1.10.v20130312" level="project" /> | |
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:8.1.10.v20130312" level="project" /> | |
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:8.1.10.v20130312" level="project" /> | |
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:8.1.10.v20130312" level="project" /> | |
<orderEntry type="library" name="Maven: com.yammer.metrics:metrics-logback:2.2.0" level="project" /> | |
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.0.10" level="project" /> | |
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.0.10" level="project" /> | |
<orderEntry type="library" name="Maven: com.yammer.metrics:metrics-jersey:2.2.0" level="project" /> | |
<orderEntry type="library" name="Maven: com.yammer.metrics:metrics-annotation:2.2.0" level="project" /> | |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.1.4" level="project" /> | |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.1.4" level="project" /> | |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.1.4" level="project" /> | |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-guava:2.1.2" level="project" /> | |
<orderEntry type="library" name="Maven: com.google.guava:guava:14.0.1" level="project" /> | |
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:2.0.1" level="project" /> | |
<orderEntry type="library" name="Maven: net.sourceforge.argparse4j:argparse4j:0.4.0" level="project" /> | |
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.4" level="project" /> | |
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.4" level="project" /> | |
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-servlet:8.1.10.v20130312" level="project" /> | |
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-security:8.1.10.v20130312" level="project" /> | |
<orderEntry type="library" name="Maven: org.hibernate:hibernate-validator:4.3.1.Final" level="project" /> | |
<orderEntry type="library" name="Maven: javax.validation:validation-api:1.0.0.GA" level="project" /> | |
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.1.0.CR2" level="project" /> | |
<orderEntry type="library" name="Maven: joda-time:joda-time:2.2" level="project" /> | |
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.2" level="project" /> | |
<orderEntry type="library" name="Maven: com.sun.jersey.jersey-test-framework:jersey-test-framework-core:1.17.1" level="project" /> | |
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.0.1" level="project" /> | |
<orderEntry type="library" name="Maven: junit:junit:4.11" level="project" /> | |
<orderEntry type="library" name="Maven: com.sun.jersey:jersey-client:1.17.1" level="project" /> | |
<orderEntry type="library" name="Maven: com.sun.jersey.jersey-test-framework:jersey-test-framework-inmemory:1.17.1" level="project" /> | |
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> | |
<orderEntry type="library" name="Maven: org.easytesting:fest-assert-core:2.0M10" level="project" /> | |
<orderEntry type="library" name="Maven: org.easytesting:fest-util:1.2.5" level="project" /> | |
<orderEntry type="module" module-name="api" /> | |
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-all:1.3" level="project" /> | |
</component> | |
</module> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.yammer.dropwizard.config.Configuration; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: @karangb | |
* Date: 04/09/2013 | |
* Time: 22:51 | |
*/ | |
public class HypemRecommenderConfiguration extends Configuration { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.yammer.dropwizard.Service; | |
import com.yammer.dropwizard.config.Bootstrap; | |
import com.yammer.dropwizard.config.Environment; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: @karangb | |
* Date: 04/09/2013 | |
* Time: 22:51 | |
*/ | |
public class HypemRecommenderService extends Service<HypemRecommenderConfiguration> { | |
public static void main(String[] args) throws Exception { | |
new HypemRecommenderService().run(args); | |
} | |
@Override | |
public void initialize(Bootstrap<HypemRecommenderConfiguration> bootstrap) { | |
bootstrap.setName("hypem-recommender"); | |
} | |
@Override | |
public void run(HypemRecommenderConfiguration hypemRecommenderConfiguration, Environment environment) throws Exception { | |
environment.addResource(new RatingResource(new MongoRatingDao())); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created with IntelliJ IDEA. | |
* User: @karangb | |
* Date: 04/09/2013 | |
* Time: 23:01 | |
*/ | |
public class MongoRatingDao implements RatingDAO { | |
@Override | |
public Rating getRating(String username) { | |
return null; //To change body of implemented methods use File | Settings | File Templates. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created with IntelliJ IDEA. | |
* User: @karangb | |
* Date: 03/09/2013 | |
* Time: 23:25 | |
*/ | |
public interface RatingDAO { | |
public Rating getRating(String username); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.yammer.metrics.annotation.Timed; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.QueryParam; | |
import javax.ws.rs.core.MediaType; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: @karangb | |
* Date: 04/09/2013 | |
* Time: 22:35 | |
*/ | |
@Path("/ratings") | |
@Produces(MediaType.APPLICATION_JSON) | |
public class RatingResource { | |
private RatingDAO ratingDao; | |
public RatingResource(RatingDAO ratingDao) { | |
this.ratingDao = ratingDao; | |
} | |
@GET | |
@Timed | |
public Rating getRating(@QueryParam("username") String username) { | |
return ratingDao.getRating(username); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.sun.jersey.api.client.Client; | |
import com.yammer.dropwizard.testing.ResourceTest; | |
import org.junit.Test; | |
import org.junit.Before; | |
import java.util.ArrayList; | |
import java.util.List; | |
import static org.fest.assertions.api.Assertions.assertThat; | |
import static org.mockito.Mockito.mock; | |
import static org.mockito.Mockito.verify; | |
import static org.mockito.Mockito.when; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: @karangb | |
* Date: 03/09/2013 | |
* Time: 23:19 | |
*/ | |
public class RatingResourceTest extends ResourceTest { | |
private final Track track1 = new Track("track1", "artist1"); | |
private final Track track2 = new Track("track2", "artist2"); | |
private final RatingDAO ratingDao = mock(RatingDAO.class); | |
private List<Track> tracks; | |
private Rating rating; | |
@Before | |
public void setUp() | |
{ | |
tracks = new ArrayList<Track>(); | |
tracks.add(track1); | |
tracks.add(track2); | |
rating = new Rating(tracks); | |
} | |
@Override | |
protected void setUpResources() throws Exception { | |
when(ratingDao.getRating("karan")).thenReturn(rating); | |
addResource(new RatingResource(ratingDao)); | |
} | |
@Test | |
public void testRatingsGetsTracks() throws Exception{ | |
assertThat(client().resource("/ratings").queryParam("username", "karan").get(Rating.class)).isEqualTo(rating); | |
verify(ratingDao).getRating("karan"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
���� 2 | |