2 * ============LICENSE_START=======================================================
3 * PNF-REGISTRATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2019-2021 NOKIA Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.dcaegen2.services.prh.integration;
23 import com.github.tomakehurst.wiremock.client.WireMock;
24 import com.google.gson.Gson;
25 import com.google.gson.JsonObject;
26 import com.jayway.jsonpath.JsonPath;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29 import org.onap.dcaegen2.services.prh.MainApp;
30 import org.onap.dcaegen2.services.prh.configuration.CbsConfiguration;
31 import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks;
32 import org.onap.dcaegen2.services.prh.tasks.ScheduledTasksRunner;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.beans.factory.annotation.Value;
35 import org.springframework.boot.test.context.SpringBootTest;
36 import org.springframework.boot.test.mock.mockito.MockBean;
37 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
38 import org.springframework.context.annotation.Bean;
39 import org.springframework.context.annotation.Configuration;
40 import org.springframework.context.annotation.Import;
42 import java.nio.file.Files;
43 import java.nio.file.Paths;
45 import static com.github.tomakehurst.wiremock.client.WireMock.*;
46 import static java.lang.ClassLoader.getSystemResource;
47 import static java.util.Collections.singletonList;
51 @AutoConfigureWireMock(port = 0)
52 class PrhWorkflowIntegrationTest {
55 private ScheduledTasks scheduledTasks;
58 private ScheduledTasksRunner scheduledTasksRunner; // just to disable scheduling - some configurability in ScheduledTaskRunner not to start tasks at app startup would be welcome
62 @Import(MainApp.class)
63 static class CbsConfigTestConfig {
65 @Value("http://localhost:${wiremock.server.port}")
66 private String wiremockServerAddress;
69 public CbsConfiguration cbsConfiguration() {
70 JsonObject cbsConfigJson = new Gson().fromJson(getResourceContent("configurationFromCbs.json")
71 .replaceAll("https?://dmaap-mr[\\w.]*:\\d+", wiremockServerAddress)
72 .replaceAll("https?://aai[\\w.]*:\\d+", wiremockServerAddress),
75 CbsConfiguration cbsConfiguration = new CbsConfiguration();
76 cbsConfiguration.parseCBSConfig(cbsConfigJson);
77 return cbsConfiguration;
82 void resetWireMock() {
88 void whenThereAreNoEventsInDmaap_WorkflowShouldFinish() {
89 stubFor(get(urlEqualTo("/events/unauthenticated.VES_PNFREG_OUTPUT/OpenDCAE-c12/c12"))
90 .willReturn(aResponse().withBody("[]")));
92 scheduledTasks.scheduleMainPrhEventTask();
94 verify(0, anyRequestedFor(urlPathMatching("/aai.*")));
95 verify(0, postRequestedFor(urlPathMatching("/events.*")));
100 void whenThereIsAnEventsInDmaap_ShouldSendPnfReadyNotification() {
101 String event = getResourceContent("integration/event.json");
102 String pnfName = JsonPath.read(event, "$.event.commonEventHeader.sourceName");
104 stubFor(get(urlEqualTo("/events/unauthenticated.VES_PNFREG_OUTPUT/OpenDCAE-c12/c12"))
105 .willReturn(ok().withBody(new Gson().toJson(singletonList(event)))));
106 stubFor(get(urlEqualTo("/aai/v23/network/pnfs/pnf/" + pnfName)).willReturn(ok().withBody("{}")));
107 stubFor(patch(urlEqualTo("/aai/v23/network/pnfs/pnf/" + pnfName)));
108 stubFor(post(urlEqualTo("/events/unauthenticated.PNF_READY")));
110 scheduledTasks.scheduleMainPrhEventTask();
112 verify(1, postRequestedFor(urlEqualTo("/events/unauthenticated.PNF_READY"))
113 .withRequestBody(matchingJsonPath("$[0].correlationId", equalTo(pnfName))));
117 private static String getResourceContent(String resourceName) {
119 return new String(Files.readAllBytes(Paths.get(getSystemResource(resourceName).toURI())));
120 } catch (Exception e) {
121 throw new RuntimeException("failed loading content of '" + resourceName + "'", e);