Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
santanusinha committed Dec 17, 2024
1 parent 31d6176 commit 14e41b7
Showing 1 changed file with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,68 @@
class HttpServiceDataSourceTest {

private static final ObjectMapper MAPPER = new ObjectMapper();

@Test
void testServiceDataSource(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException {
val responseObj = ServiceDataSourceResponse.builder()
val responseObjReplicated = ServiceDataSourceResponse.builder()
.data(Sets.newHashSet(
RangerTestUtils.getService("test-n", "test-s"),
RangerTestUtils.getService("test-n", "test-s1"),
RangerTestUtils.getService("test-n", "test-s2")
))
.build();
val response = MAPPER.writeValueAsBytes(responseObj);
stubFor(get(urlPathEqualTo("/ranger/services/v1"))
stubFor(get(urlEqualTo("/ranger/services/v1?skipReplicationSources=false"))
.willReturn(aResponse()
.withBody(response)
.withBody(MAPPER.writeValueAsBytes(responseObjReplicated))
.withStatus(200)));
val clientConfig = HttpClientConfig.builder()
.host("127.0.0.1")
.port(wireMockRuntimeInfo.getHttpPort())
.connectionTimeoutMs(30_000)
.operationTimeoutMs(30_000)
val responseObjReplicationSkipped = ServiceDataSourceResponse.builder()
.data(Sets.newHashSet(
RangerTestUtils.getService("test-n", "test-s"),
RangerTestUtils.getService("test-n", "test-s1")))
.build();
val httpServiceDataSource = new HttpServiceDataSource<>(clientConfig, RangerHttpUtils.httpClient(clientConfig, MAPPER));
val services = httpServiceDataSource.services();
Assertions.assertNotNull(services);
Assertions.assertFalse(services.isEmpty());
Assertions.assertEquals(3, services.size());
Assertions.assertFalse(services.stream().noneMatch(each -> each.getServiceName().equalsIgnoreCase("test-s")));
Assertions.assertFalse(services.stream().noneMatch(each -> each.getServiceName().equalsIgnoreCase("test-s1")));
Assertions.assertFalse(services.stream().noneMatch(each -> each.getServiceName().equalsIgnoreCase("test-s2")));
stubFor(get(urlEqualTo("/ranger/services/v1?skipReplicationSources=true"))
.willReturn(aResponse()
.withBody(MAPPER.writeValueAsBytes(responseObjReplicationSkipped))
.withStatus(200)));
{
val clientConfig = HttpClientConfig.builder()
.host("127.0.0.1")
.port(wireMockRuntimeInfo.getHttpPort())
.connectionTimeoutMs(30_000)
.operationTimeoutMs(30_000)
.build();
val httpServiceDataSource = new HttpServiceDataSource<>(clientConfig,
RangerHttpUtils.httpClient(clientConfig, MAPPER));
val services = httpServiceDataSource.services();
Assertions.assertNotNull(services);
Assertions.assertFalse(services.isEmpty());
Assertions.assertEquals(3, services.size());
Assertions.assertFalse(services.stream()
.noneMatch(each -> each.getServiceName().equalsIgnoreCase("test-s")));
Assertions.assertFalse(services.stream()
.noneMatch(each -> each.getServiceName().equalsIgnoreCase("test-s1")));
Assertions.assertFalse(services.stream()
.noneMatch(each -> each.getServiceName().equalsIgnoreCase("test-s2")));
}
{ //Here we set skip replication data to false. so query param is set
val clientConfig = HttpClientConfig.builder()
.host("127.0.0.1")
.port(wireMockRuntimeInfo.getHttpPort())
.connectionTimeoutMs(30_000)
.operationTimeoutMs(30_000)
.skipReplicatedData(true)
.build();
val httpServiceDataSource = new HttpServiceDataSource<>(clientConfig,
RangerHttpUtils.httpClient(clientConfig, MAPPER));
val services = httpServiceDataSource.services();
Assertions.assertNotNull(services);
Assertions.assertFalse(services.isEmpty());
Assertions.assertEquals(2, services.size());
Assertions.assertFalse(services.stream()
.noneMatch(each -> each.getServiceName().equalsIgnoreCase("test-s")));
Assertions.assertFalse(services.stream()
.noneMatch(each -> each.getServiceName().equalsIgnoreCase("test-s1")));
}
}

}

0 comments on commit 14e41b7

Please sign in to comment.