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;
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.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import java.io.ByteArrayOutputStream;
30 import java.io.IOException;
31 import java.io.PrintStream;
32 import java.net.URISyntaxException;
33 import java.nio.file.Files;
34 import java.nio.file.Paths;
36 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
37 import static com.github.tomakehurst.wiremock.client.WireMock.get;
38 import static com.github.tomakehurst.wiremock.client.WireMock.put;
39 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
40 import static org.hamcrest.MatcherAssert.assertThat;
42 public class DataMigrationInternalTest {
45 public WireMockRule source = new WireMockRule(8081);
47 public WireMockRule target = new WireMockRule(8082);
49 private static final Logger LOG = LoggerFactory.getLogger(DataMigrationInternal.class);
50 DataMigrationInternal dataMigrationInternal = new DataMigrationInternal(LOG);
51 private ClassLoader classLoader = getClass().getClassLoader();
52 private String preloadVnfResponseJson = new String(Files.readAllBytes(Paths.get(classLoader.getResource("wiremock/preloadVnfResponse.json").toURI())));
53 private String preloadInformationRequestJson = new String(Files.readAllBytes(Paths.get(classLoader.getResource("wiremock/preloadInformationRequest.json").toURI())));
55 public DataMigrationInternalTest() throws IOException, URISyntaxException {
59 public void runPositiveTest() {
60 String [] args = {"-c","migration/props"};
61 PrintStream oldOutputStream = System.out;
62 final ByteArrayOutputStream myOut = new ByteArrayOutputStream();
63 System.setOut(new PrintStream(myOut));
64 source.stubFor(get(urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-vnfs")).willReturn(
67 .withBody(preloadVnfResponseJson)));
68 target.stubFor(put(urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-information")).withRequestBody(WireMock.equalTo(preloadInformationRequestJson)).willReturn(
71 dataMigrationInternal.run(args);
72 String content = myOut.toString();
73 assertThat("Migration failed", content.contains("MIGRATE operation completed Successfully."));
74 System.setOut(oldOutputStream);
78 public void runTestWithNoData() {
79 String [] args = {"-c","migration/props"};
80 PrintStream oldOutputStream = System.out;
81 final ByteArrayOutputStream myOut = new ByteArrayOutputStream();
82 System.setOut(new PrintStream(myOut));
83 source.stubFor(get(urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-vnfs"))
84 .willReturn(aResponse().withStatus(404)));
85 target.stubFor(put(urlEqualTo("/restconf/config/GENERIC-RESOURCE-API:preload-information"))
86 .withRequestBody(WireMock.equalTo(preloadInformationRequestJson)).willReturn(aResponse().withStatus(200)));
87 dataMigrationInternal.run(args);
88 String content = myOut.toString();
89 assertThat("Migration failed", content.contains("MIGRATE operation completed Successfully."));
90 System.setOut(oldOutputStream);