2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2019 AMDOCS
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=========================================================
20 package org.onap.sdnc.oam.datamigrator.datamigrator;
22 import com.github.tomakehurst.wiremock.client.WireMock;
23 import com.github.tomakehurst.wiremock.junit.WireMockRule;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.onap.sdnc.oam.datamigrator.common.Operation;
27 import org.onap.sdnc.oam.datamigrator.common.RestconfClient;
28 import org.onap.sdnc.oam.datamigrator.migrators.PreloadInformationMigrator;
30 import java.io.IOException;
31 import java.net.URISyntaxException;
32 import java.nio.file.Files;
33 import java.nio.file.Paths;
35 public class PreloadInformationMigratorTest {
38 public WireMockRule service1 = new WireMockRule(8081);
41 public WireMockRule service2 = new WireMockRule(8082);
42 PreloadInformationMigrator migrator = new PreloadInformationMigrator();
43 private ClassLoader classLoader = getClass().getClassLoader();
44 private String preloadVnfResponseJson = new String(Files.readAllBytes(Paths.get(classLoader.getResource("wiremock/preloadVnfResponse.json").toURI())));
45 private String preloadInformationRequestJson = new String(Files.readAllBytes(Paths.get(classLoader.getResource("wiremock/preloadInformationRequest.json").toURI())));
47 public PreloadInformationMigratorTest() throws IOException, URISyntaxException {
51 public void testRun (){
52 service1.stubFor(WireMock.get(WireMock.urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-vnfs")).willReturn(
55 .withBody(preloadVnfResponseJson)));
56 service2.stubFor(WireMock.put(WireMock.urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-information")).withRequestBody(WireMock.equalTo(preloadInformationRequestJson)).willReturn(
59 RestconfClient sourceClient = new RestconfClient("http://localhost:8081","admin","Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U");
60 migrator.setSourceClient(sourceClient);
61 RestconfClient targetClient = new RestconfClient("http://localhost:8082","admin","Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U");
62 migrator.setTargetClient(targetClient);
63 migrator.run(Operation.MIGRATE);
67 public void testRunNoData (){
68 service1.stubFor(WireMock.get(WireMock.urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-vnfs")).willReturn(
71 service2.stubFor(WireMock.put(WireMock.urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-information")).withRequestBody(WireMock.equalTo(preloadInformationRequestJson)).willReturn(
74 RestconfClient sourceClient = new RestconfClient("http://localhost:8081","admin","Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U");
75 migrator.setSourceClient(sourceClient);
76 RestconfClient targetClient = new RestconfClient("http://localhost:8082","admin","Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U");
77 migrator.setTargetClient(targetClient);
78 migrator.run(Operation.MIGRATE);