Skip to content

Instantly share code, notes, and snippets.

@dherges
Created September 25, 2016 12:49
Show Gist options
  • Save dherges/3ac82646ec76632a36542fa2e6be73ed to your computer and use it in GitHub Desktop.
Save dherges/3ac82646ec76632a36542fa2e6be73ed to your computer and use it in GitHub Desktop.
ok-testing-reloaded-medium
public class SparkRunner extends BlockJUnit4ClassRunner {
private Class<? extends SparkApplicationContainer> applicationContainer;
/* ... */
private void scanAnnotation() {
SparkApplicationTest annotation = getTestClass().getAnnotation(SparkApplicationTest.class);
applicationContainer = annotation.value();
/* ... */
}
private void sparkBootstrap() throws IllegalAccessException, InstantiationException {
/* ... */
applicationContainer.newInstance().sparkApplication().init();
/* ... */
}
/* ... */
}
@RunWith(SparkRunner.class)
@SparkApplicationTest(value = TestApplicationContainer.class, port = 4444)
public class TwitterAppTest {
@Test
public void testAgain() throws IOException {
final Request request = new Request.Builder()
.get()
.url("http://localhost:4444/statuses/retweets/200")
.build();
final Response response = okHttpClient.newCall(request).execute();
assertThat(response)
.isOk()
.hasContentType("application/json")
.jsonPath("$.length()", Integer.class, 100)
.jsonPath("$[0].id", Integer.class, 200)
.jsonPath("$[0].user.name", String.class, "Maria Moccachino");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment