diff options
author | micdzied <michal.1.dziedzic@nokia.com> | 2019-01-08 09:38:12 +0100 |
---|---|---|
committer | micdzied <michal.1.dziedzic@nokia.com> | 2019-01-08 09:40:22 +0100 |
commit | a224b4adbe65b476cdbd74efb3169aacbf292382 (patch) | |
tree | 17386959d44d82eb9c65ee3da24c5b862d62eb98 /datafile-app-server/src/test/java | |
parent | f5791850232005aaf47c639f89f76007c67beff7 (diff) |
use sdk-cbs
Change-Id: I615d57927c163d022683ad3cae2703adda48cf88
Issue-ID: DCAEGEN2-1064
Signed-off-by: micdzied <michal.1.dziedzic@nokia.com>
Diffstat (limited to 'datafile-app-server/src/test/java')
2 files changed, 0 insertions, 165 deletions
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DatafileConfigurationProviderTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DatafileConfigurationProviderTest.java deleted file mode 100644 index efd89837..00000000 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DatafileConfigurationProviderTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.collectors.datafile.service; - - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.collectors.datafile.model.EnvProperties; -import org.onap.dcaegen2.collectors.datafile.model.ImmutableEnvProperties; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -class DatafileConfigurationProviderTest { - private static final Gson gson = new Gson(); - private static final String configBindingService = "[{\"ID\":\"9c8dd674-34ce-7049-d318-e98d93a64303\",\"Node\"" - + ":\"dcae-bootstrap\",\"Address\":\"10.42.52.82\",\"Datacenter\":\"dc1\",\"TaggedAddresses\":" - + "{\"lan\":\"10.42.52.82\",\"wan\":\"10.42.52.82\"},\"NodeMeta\":{\"consul-network-segment\":\"\"}," - + "\"ServiceID\":\"dcae-cbs1\",\"ServiceName\":\"config-binding-service\",\"ServiceTags\":[]," - + "\"ServiceAddress\":\"config-binding-service\",\"ServicePort\":10000,\"ServiceEnableTagOverride\":false," - + "\"CreateIndex\":14352,\"ModifyIndex\":14352},{\"ID\":\"35c6f540-a29c-1a92-23b0-1305bd8c81f5\",\"Node\":" - + "\"dev-consul-server-1\",\"Address\":\"10.42.165.51\",\"Datacenter\":\"dc1\",\"TaggedAddresses\":" - + "{\"lan\":\"10.42.165.51\",\"wan\":\"10.42.165.51\"},\"NodeMeta\":{\"consul-network-segment\":\"\"}," - + "\"ServiceID\":\"dcae-cbs1\",\"ServiceName\":\"config-binding-service\",\"ServiceTags\":[]," - + "\"ServiceAddress\":\"config-binding-service\",\"ServicePort\":10000,\"ServiceEnableTagOverride\":false," - + "\"CreateIndex\":803,\"ModifyIndex\":803}]"; - private static final JsonArray configBindingServiceJson = gson.fromJson(configBindingService, JsonArray.class); - private static final JsonArray emptyConfigBindingServiceJson = gson.fromJson("[]", JsonArray.class); - private static final String datafileCollectorMockConfiguration = "{\"test\":1}"; - private static final JsonObject datafileCollectorMockConfigurationJson = gson.fromJson(datafileCollectorMockConfiguration, JsonObject.class); - - private EnvProperties envProperties = ImmutableEnvProperties.builder() - .appName("dcae-datafile-collector") - .cbsName("config-binding-service") - .consulHost("consul") - .consulPort(8500) - .build(); - - @Test - void shouldReturnDatafileCollectorConfiguration() { - // given - HttpGetClient webClient = mock(HttpGetClient.class); - when( - webClient.callHttpGet("http://consul:8500/v1/catalog/service/config-binding-service", JsonArray.class)) - .thenReturn(Mono.just(configBindingServiceJson)); - when(webClient.callHttpGet("http://config-binding-service:10000/service_component/dcae-datafile-collector", JsonObject.class)) - .thenReturn(Mono.just(datafileCollectorMockConfigurationJson)); - - DatafileConfigurationProvider provider = new DatafileConfigurationProvider(webClient); - - //when/then - StepVerifier.create(provider.callForDataFileCollectorConfiguration(envProperties)).expectSubscription() - .expectNext(datafileCollectorMockConfigurationJson).verifyComplete(); - } - - @Test - void shouldReturnMonoErrorWhenConsuleDoesntHaveConfigBindingServiceEntry() { - // given - HttpGetClient webClient = mock(HttpGetClient.class); - when( - webClient.callHttpGet("http://consul:8500/v1/catalog/service/config-binding-service", JsonArray.class)) - .thenReturn(Mono.just(emptyConfigBindingServiceJson)); - - DatafileConfigurationProvider provider = new DatafileConfigurationProvider(webClient); - - //when/then - StepVerifier.create(provider.callForDataFileCollectorConfiguration(envProperties)).expectSubscription() - .expectError(IllegalStateException.class).verify(); - } -}
\ No newline at end of file diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/HttpGetClientTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/HttpGetClientTest.java deleted file mode 100644 index d95e3417..00000000 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/HttpGetClientTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.collectors.datafile.service; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; -import org.junit.jupiter.api.Test; -import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -class HttpGetClientTest { - - private static final String SOMEURL = "http://someurl"; - private static final String DATA = "{}"; - private Gson gson = new Gson(); - private WebClient webClient = mock(WebClient.class); - private WebClient.RequestHeadersUriSpec requestBodyUriSpec = mock(WebClient.RequestBodyUriSpec.class); - private WebClient.ResponseSpec responseSpec = mock(WebClient.ResponseSpec.class); - - @Test - void shouldReturnJsonObjectOnGetCall() { - //given - mockWebClientDependantObject(); - HttpGetClient httpGetClient = new HttpGetClient(webClient); - when(responseSpec.bodyToMono(String.class)).thenReturn(Mono.just(DATA)); - - //when/then - StepVerifier.create(httpGetClient.callHttpGet(SOMEURL, JsonObject.class)).expectSubscription() - .expectNext(gson.fromJson(DATA, JsonObject.class)).verifyComplete(); - } - - @Test - void shouldReturnMonoErrorOnGetCall() { - //given - mockWebClientDependantObject(); - HttpGetClient httpGetClient = new HttpGetClient(webClient); - when(responseSpec.bodyToMono(String.class)).thenReturn(Mono.just("some wrong data")); - - //when/then - StepVerifier.create(httpGetClient.callHttpGet(SOMEURL, JsonObject.class)).expectSubscription() - .expectError(JsonSyntaxException.class).verify(); - } - - - private void mockWebClientDependantObject() { - doReturn(requestBodyUriSpec).when(webClient).get(); - when(requestBodyUriSpec.uri(SOMEURL)).thenReturn(requestBodyUriSpec); - doReturn(responseSpec).when(requestBodyUriSpec).retrieve(); - doReturn(responseSpec).when(responseSpec).onStatus(any(), any()); - doReturn(responseSpec).when(responseSpec).onStatus(any(), any()); - } -}
\ No newline at end of file |