2 * ============LICENSE_START==========================================
\r
4 * ===================================================================
\r
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright © 2017-2018 Amdocs
\r
7 * ===================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END============================================
\r
21 package org.onap.aai.modelloader.entity.catalog;
\r
23 import static org.junit.Assert.fail;
\r
25 import com.sun.jersey.api.client.ClientResponse;
\r
26 import java.io.IOException;
\r
27 import java.util.Properties;
\r
28 import javax.ws.rs.core.MediaType;
\r
29 import javax.ws.rs.core.Response;
\r
30 import org.junit.Test;
\r
31 import org.junit.runner.RunWith;
\r
32 import org.mockito.Mockito;
\r
33 import org.onap.aai.modelloader.config.ModelLoaderConfig;
\r
34 import org.onap.aai.modelloader.restclient.AaiRestClient;
\r
35 import org.onap.aai.restclient.client.OperationResult;
\r
36 import org.powermock.api.mockito.PowerMockito;
\r
37 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
38 import org.powermock.modules.junit4.PowerMockRunner;
\r
40 @RunWith(PowerMockRunner.class)
\r
41 @PrepareForTest({VnfCatalogArtifactHandler.class, ClientResponse.class, AaiRestClient.class})
\r
42 public class VnfCatalogArtifactHandlerTest {
\r
44 protected static String CONFIG_FILE = "model-loader.properties";
\r
47 public void testWithMocks() throws Exception {
\r
49 Properties configProperties = new Properties();
\r
51 configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
\r
52 } catch (IOException e) {
\r
55 ModelLoaderConfig config = new ModelLoaderConfig(configProperties, null);
\r
56 config.setModelVersion("11");
\r
58 AaiRestClient mockRestClient = PowerMockito.mock(AaiRestClient.class);
\r
59 PowerMockito.whenNew(AaiRestClient.class).withAnyArguments().thenReturn(mockRestClient);
\r
62 OperationResult mockGetResp = PowerMockito.mock(OperationResult.class);
\r
65 PowerMockito.when(mockGetResp.getResultCode())
\r
66 .thenReturn(Response.Status.OK.getStatusCode())
\r
67 .thenReturn(Response.Status.NOT_FOUND.getStatusCode())
\r
68 .thenReturn(Response.Status.NOT_FOUND.getStatusCode())
\r
69 .thenReturn(Response.Status.OK.getStatusCode());
\r
72 mockRestClient.getResource(Mockito.anyString(), Mockito.anyString(), Mockito.any(MediaType.class)))
\r
73 .thenReturn(mockGetResp);
\r
76 OperationResult mockPutResp = PowerMockito.mock(OperationResult.class);
\r
78 PowerMockito.when(mockPutResp.getResultCode()).thenReturn(Response.Status.CREATED.getStatusCode());
\r
79 PowerMockito.when(mockRestClient.putResource(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
\r
80 Mockito.any(MediaType.class))).thenReturn(mockPutResp);
\r
82 // Example VNF Catalog with
\r
83 VnfCatalogArtifactHandler vnfCAH = new VnfCatalogArtifactHandler(config);
\r
84 String examplePath = "src/test/resources/imagedataexample.json";
\r
86 * byte[] encoded = Files.readAllBytes(Paths.get(examplePath)); List<Artifact> artifacts = new
\r
87 * ArrayList<Artifact>(); artifacts.add(new VnfCatalogArtifact(new String(encoded, "utf-8")));
\r
89 * assertTrue(vnfCAH.pushArtifacts(artifacts, "test", new ArrayList<Artifact>(), mockRestClient));
\r
91 * // Only two of the VNF images should be pushed ArgumentCaptor<String> argument =
\r
92 * ArgumentCaptor.forClass(String.class); AaiRestClient r = Mockito.verify(mockRestClient, Mockito.times(2));
\r
93 * r.putResource(Mockito.anyString(), argument.capture(), Mockito.anyString(), Mockito.any(MediaType.class));
\r
94 * assertTrue(argument.getAllValues().get(0).contains("3.16.9"));
\r
95 * assertTrue(argument.getAllValues().get(0).contains("VM00"));
\r
96 * assertTrue(argument.getAllValues().get(1).contains("3.16.1"));
\r
97 * assertTrue(argument.getAllValues().get(1).contains("VM01"));
\r