Created
March 14, 2018 17:04
-
-
Save ZiiSolutions/75c0cd30084eb8f31af793e781297a8e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@Test | |
public void testWiring() throws ExecutionException, TimeoutException, InterruptedException { | |
// stub elasticsearch responses | |
ResponseDefinitionBuilder dummyIndexResponse = aResponse() | |
.withBody("{\n" | |
+ " \"_shards\" : {\n" | |
+ " \"total\" : 2,\n" | |
+ " \"failed\" : 0,\n" | |
+ " \"successful\" : 2\n" | |
+ " },\n" | |
+ " \"_index\" : \"content-repository\",\n" | |
+ " \"_type\" : \"subject\",\n" | |
+ " \"_id\" : \"1\",\n" | |
+ " \"_version\" : 1,\n" | |
+ " \"_seq_no\" : 0,\n" | |
+ " \"_primary_term\" : 1,\n" | |
+ " \"result\" : \"created\"\n" | |
+ "}") | |
.withHeader("Content-Type", "application/json") | |
.withStatus(201); | |
stubFor(post(urlPathEqualTo("/content-repository/collections")).willReturn(dummyIndexResponse)); | |
stubFor(post(urlPathEqualTo("/content-repository/items")).willReturn(dummyIndexResponse)); | |
stubFor(post(urlPathEqualTo("/content-repository/subjects")).willReturn(dummyIndexResponse)); | |
// wire loaders and perform load against stub services (fongo + wiremock) | |
Guice.createInjector(override(dataLoaderModule).with(new AbstractModule() { | |
@Override | |
protected void configure() { | |
bind(MongoClient.class) | |
.toProvider(fongoRule::getMongoClient); | |
bind(HttpHost.class) | |
.toInstance(new HttpHost("localhost", wireMockRule.port())); | |
} | |
})).getInstance(DataLoader.class).load().get(10, TimeUnit.SECONDS); | |
// verify mongo | |
assertThat(fongoRule.getDatabase().getCollection("items").count()) | |
.isEqualTo(2); | |
// verify elasticsearch | |
verify(exactly(1), postRequestedFor(urlPathEqualTo("/content-repository/collections"))); | |
verify(exactly(2), postRequestedFor(urlPathEqualTo("/content-repository/items"))); | |
verify(exactly(1), postRequestedFor(urlPathEqualTo("/content-repository/subjects"))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment