Skip to content

Commit

Permalink
updated the project to DropWizard version 0.7.0 and migrated package …
Browse files Browse the repository at this point in the history
…structure from yammer to codahale
  • Loading branch information
Drane committed Jul 18, 2013
1 parent c302564 commit 6e13edc
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.iml
*.ipr
*.iws
target/
target/
.idea/
16 changes: 12 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@

<groupId>com.federecio</groupId>
<artifactId>dropwizard-junit</artifactId>
<version>0.1-SNAPSHOT</version>
<version>0.2-SNAPSHOT</version>

<properties>
<dropwizard.version>0.7.0-SNAPSHOT</dropwizard.version>
</properties>

<developers>
<developer>
<name>Federico Recio</name>
<url>http://about.me/federecio</url>
</developer>
<developer>
<name>Jochen Szostek</name>
<url>http://prefabsoft.com</url>
</developer>
</developers>

<scm>
Expand All @@ -20,11 +28,11 @@
</scm>

<dependencies>
<!-- DropWizard -->
<dependency>
<groupId>com.yammer.dropwizard</groupId>
<groupId>com.codahale.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.6.2</version>
<scope>provided</scope>
<version>${dropwizard.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.federecio.dropwizard.junitrunner;

import java.lang.annotation.Annotation;
import java.net.URL;

import com.codahale.dropwizard.Application;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;

import com.yammer.dropwizard.Service;
import java.lang.annotation.Annotation;
import java.net.URL;

/**
* @author Federico Recio
*/
public class DropwizardJunitRunner extends BlockJUnit4ClassRunner {

private Service<?> service;
private Application<?> application;

public DropwizardJunitRunner(Class<?> testClass) throws InitializationError {
super(testClass);
Expand All @@ -26,20 +25,20 @@ protected Statement classBlock(final RunNotifier notifier) {
DropwizardTestConfig dropwizardTestConfig = getTestConfigOrFail();
URL resource = getYamlConfigFileOrFail(dropwizardTestConfig);
try {
service = dropwizardTestConfig.serviceClass().newInstance();
service.run(new String[]{"server", resource.getFile()});
application = dropwizardTestConfig.applicationClass().newInstance();
application.run(new String[]{"server", resource.getFile()});
} catch (IllegalAccessException e) {
throw new DropwizardJunitRunnerException("Could not access class or class' constructor on " + dropwizardTestConfig.serviceClass(), e);
throw new DropwizardJunitRunnerException("Could not access class or class' constructor on " + dropwizardTestConfig.applicationClass(), e);
} catch (InstantiationException e) {
throw new DropwizardJunitRunnerException("Could not instantiate class " + dropwizardTestConfig.serviceClass(), e);
throw new DropwizardJunitRunnerException("Could not instantiate class " + dropwizardTestConfig.applicationClass(), e);
} catch (Exception e) {
throw new DropwizardJunitRunnerException(e);
}
return super.classBlock(notifier);
}

protected Service<?> getService() {
return service;
protected Application<?> getApplication() {
return application;
}

private DropwizardTestConfig getTestConfigOrFail() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.federecio.dropwizard.junitrunner;

import com.codahale.dropwizard.Application;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.yammer.dropwizard.Service;

/**
* @author Federico Recio
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface DropwizardTestConfig {

Class<? extends Service<?>> serviceClass();
Class<? extends Application<?>> applicationClass();

String yamlFile();
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.federecio.dropwizard.junitrunner;

import com.jayway.restassured.RestAssured;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.jayway.restassured.RestAssured;

/**
* @author Federico Recio
*/
@RunWith(DropwizardJunitRunner.class)
@DropwizardTestConfig(serviceClass = TestService.class, yamlFile = "/test.yaml")
@DropwizardTestConfig(applicationClass = TestApplication.class, yamlFile = "/test.yaml")
public class DropwizardJunitRunnerTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.federecio.dropwizard.junitrunner;

import com.yammer.dropwizard.Service;
import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Environment;
import com.codahale.dropwizard.Application;
import com.codahale.dropwizard.setup.Bootstrap;
import com.codahale.dropwizard.setup.Environment;

/**
* @author Federico Recio
*/
public class TestService extends Service<TestConfig> {
public class TestApplication extends Application<TestConfig> {

@Override
public void initialize(Bootstrap<TestConfig> bootstrap) {
Expand All @@ -16,6 +16,6 @@ public void initialize(Bootstrap<TestConfig> bootstrap) {

@Override
public void run(TestConfig configuration, Environment environment) throws Exception {
environment.addResource(new TestResource());
environment.jersey().register(new TestResource());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.federecio.dropwizard.junitrunner;

import com.yammer.dropwizard.config.Configuration;
import com.codahale.dropwizard.Configuration;

/**
* @author Federico Recio
Expand Down

0 comments on commit 6e13edc

Please sign in to comment.