2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Ericsson
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.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.design.services.util;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26 import java.io.IOException;
27 import java.security.KeyManagementException;
28 import java.security.NoSuchAlgorithmException;
29 import java.security.SecureRandom;
30 import java.util.Properties;
31 import javax.net.ssl.KeyManager;
32 import javax.net.ssl.SSLContext;
33 import javax.net.ssl.TrustManager;
34 import org.junit.Before;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.rules.ExpectedException;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mockito;
40 import org.powermock.api.mockito.PowerMockito;
41 import org.powermock.core.classloader.annotations.PrepareForTest;
42 import org.powermock.modules.junit4.PowerMockRunner;
43 import org.powermock.reflect.Whitebox;
45 @RunWith(PowerMockRunner.class)
46 @PrepareForTest({DesignServiceConstants.class})
47 public class ArtifactHandlerClientTest {
50 public ExpectedException expectedEx = ExpectedException.none();
53 public void setup() throws NoSuchAlgorithmException, KeyManagementException {
54 PowerMockito.mockStatic(DesignServiceConstants.class);
58 public void testConstructorException() throws IOException {
59 expectedEx.expect(IOException.class);
60 new ArtifactHandlerClient();
64 public void testConstructor() throws IOException {
65 PowerMockito.when(DesignServiceConstants.getEnvironmentVariable(ArtifactHandlerClient.SDNC_CONFIG_DIR_VAR))
66 .thenReturn("src/test/resources");
67 ArtifactHandlerClient client = new ArtifactHandlerClient();
68 assertTrue(client instanceof ArtifactHandlerClient);
69 Properties props = Whitebox.getInternalState(client, "props");
70 assertTrue(props.containsKey("appc.upload.provider.url"));
74 public void testCreateArtifactData() throws IOException {
75 PowerMockito.when(DesignServiceConstants.getEnvironmentVariable(ArtifactHandlerClient.SDNC_CONFIG_DIR_VAR))
76 .thenReturn("src/test/resources");
77 ArtifactHandlerClient client = new ArtifactHandlerClient();
78 assertEquals("{\"input\": {\"request-information\":{\"request-id\":\"\",\"request-action\":"
79 + "\"StoreSdcDocumentRequest\",\"source\":\"Design-tool\"},\"document-parameters\":"
80 + "{\"artifact-version\":\"TEST\",\"artifact-name\":\"TEST\",\"artifact-contents\":"
81 + "\"TEST\"}}}", client.createArtifactData("{\"" + DesignServiceConstants.ARTIFACT_NAME
82 + "\":\"TEST\", \"" + DesignServiceConstants.ARTIFACT_VERSOIN + "\":\"TEST\", \"" +
83 DesignServiceConstants.ARTIFACT_CONTENTS + "\":\"TEST\"}", ""));