2 * # ============LICENSE_START=======================================================
3 * # Copyright (c) 2021 AT&T Intellectual Property. All rights reserved.
4 * # ================================================================================
5 * # Licensed under the Apache License, Version 2.0 (the "License");
6 * # you may not use this file except in compliance with the License.
7 * # You may obtain a copy of the License at
9 * # http://www.apache.org/licenses/LICENSE-2.0
11 * # Unless required by applicable law or agreed to in writing, software
12 * # distributed under the License is distributed on an "AS IS" BASIS,
13 * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * # See the License for the specific language governing permissions and
15 * # limitations under the License.
16 * # ============LICENSE_END=========================================================
19 package org.onap.dcaegen2.platform.helmchartgenerator;
21 import okhttp3.mockwebserver.MockResponse;
22 import okhttp3.mockwebserver.MockWebServer;
23 import org.apache.commons.io.FileUtils;
24 import org.junit.jupiter.api.AfterAll;
25 import org.junit.jupiter.api.BeforeAll;
26 import org.junit.jupiter.api.BeforeEach;
27 import org.junit.jupiter.api.Test;
28 import org.onap.dcaegen2.platform.helmchartgenerator.distribution.ChartMuseumDistributor;
31 import java.io.IOException;
33 public class ChartMuseumDistributorTest {
35 ChartMuseumDistributor distributor;
37 public static MockWebServer mockChartMuseumServer;
39 private static File mockChartFile;
42 static void init() throws IOException {
43 mockChartMuseumServer = new MockWebServer();
44 mockChartMuseumServer.start();
45 mockChartFile = File.createTempFile("dcae-ves-collector-1.8.0","tgz");
50 String baseUrl = String.format("http://localhost:%s",
51 mockChartMuseumServer.getPort());
52 distributor = new ChartMuseumDistributor(baseUrl, "mockUsername", "mockPassword");
56 void distribute() throws Exception{
57 mockChartMuseumServer.enqueue(getMock201Response());
58 distributor.distribute(mockChartFile);
61 private MockResponse getMock201Response() {
62 return new MockResponse()
64 .setBody("{\"saved\": true}");
69 static void tearDown() throws IOException {
70 mockChartMuseumServer.shutdown();
71 FileUtils.deleteQuietly(mockChartFile);