Merge "DG changes for the closed loop and async support in MDONS"
[sdnc/oam.git] / data-migrator / src / test / java / org / onap / sdnc / oam / datamigrator / datamigrator / PreloadInformationMigratorTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : SDNC
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.sdnc.oam.datamigrator.datamigrator;
21
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;
29
30 import java.io.IOException;
31 import java.net.URISyntaxException;
32 import java.nio.file.Files;
33 import java.nio.file.Paths;
34
35 public class PreloadInformationMigratorTest {
36
37     @Rule
38     public WireMockRule service1 = new WireMockRule(8081);
39
40     @Rule
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())));
46
47     public PreloadInformationMigratorTest() throws IOException, URISyntaxException {
48     }
49
50     @Test
51     public void testRun (){
52         service1.stubFor(WireMock.get(WireMock.urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-vnfs")).willReturn(
53                 WireMock.aResponse()
54                         .withStatus(200)
55                         .withBody(preloadVnfResponseJson)));
56         service2.stubFor(WireMock.put(WireMock.urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-information")).withRequestBody(WireMock.equalTo(preloadInformationRequestJson)).willReturn(
57                 WireMock.aResponse()
58                         .withStatus(200)));
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);
64     }
65
66     @Test
67     public void testRunNoData (){
68         service1.stubFor(WireMock.get(WireMock.urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-vnfs")).willReturn(
69                 WireMock.aResponse()
70                         .withStatus(404)));
71         service2.stubFor(WireMock.put(WireMock.urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-information")).withRequestBody(WireMock.equalTo(preloadInformationRequestJson)).willReturn(
72                 WireMock.aResponse()
73                         .withStatus(200)));
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);
79     }
80 }