aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/test/java/org/onap/dcaegen2/services
diff options
context:
space:
mode:
Diffstat (limited to 'prh-app-server/src/test/java/org/onap/dcaegen2/services')
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ScheduledXmlContextITest.java7
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/HttpGetClientTest.java79
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProviderTest.java93
3 files changed, 2 insertions, 177 deletions
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ScheduledXmlContextITest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ScheduledXmlContextITest.java
index 3d1d79fe..934f572f 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ScheduledXmlContextITest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ScheduledXmlContextITest.java
@@ -40,11 +40,10 @@ import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18
*/
-
@Configuration
-@ComponentScan
+@ComponentScan("org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers")
@ExtendWith({MockitoExtension.class, SpringExtension.class})
-@ContextConfiguration(locations = {"classpath:scheduled-context.xml"})
+@ContextConfiguration(locations = "classpath:scheduled-context.xml")
class ScheduledXmlContextITest extends AbstractTestNGSpringContextTests {
private static final int WAIT_FOR_SCHEDULING = 1;
@@ -62,5 +61,3 @@ class ScheduledXmlContextITest extends AbstractTestNGSpringContextTests {
verify(scheduledTask, atLeast(1)).scheduleMainPrhEventTask();
}
}
-
-
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/HttpGetClientTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/HttpGetClientTest.java
deleted file mode 100644
index ab789a00..00000000
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/HttpGetClientTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * 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.services.prh.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
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProviderTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProviderTest.java
deleted file mode 100644
index e99389f5..00000000
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/PrhConfigurationProviderTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * 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.services.prh.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.services.prh.model.EnvProperties;
-import org.onap.dcaegen2.services.prh.model.ImmutableEnvProperties;
-import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
-
-
-class PrhConfigurationProviderTest {
-
- 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 prhMockConfiguration = "{\"test\":1}";
- private static final JsonObject prhMockConfigurationJson = gson.fromJson(prhMockConfiguration, JsonObject.class);
-
- private EnvProperties envProperties = ImmutableEnvProperties.builder()
- .appName("dcae-prh")
- .cbsName("config-binding-service")
- .consulHost("consul")
- .consulPort(8500)
- .build();
-
- @Test
- void shouldReturnPrhConfiguration() {
- // 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-prh", JsonObject.class))
- .thenReturn(Mono.just(prhMockConfigurationJson));
-
- PrhConfigurationProvider provider = new PrhConfigurationProvider(webClient);
-
- //when/then
- StepVerifier.create(provider.callForPrhConfiguration(envProperties)).expectSubscription()
- .expectNext(prhMockConfigurationJson).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));
-
- PrhConfigurationProvider provider = new PrhConfigurationProvider(webClient);
-
- //when/then
- StepVerifier.create(provider.callForPrhConfiguration(envProperties)).expectSubscription()
- .expectError(IllegalStateException.class).verify();
- }
-} \ No newline at end of file