a23956f18f10edeef30341342605c07d4aa0e4f9
[appc.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
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  *
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.appc.design.services.util;
23
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;
44
45 @RunWith(PowerMockRunner.class)
46 @PrepareForTest({DesignServiceConstants.class})
47 public class ArtifactHandlerClientTest {
48
49     @Rule
50     public ExpectedException expectedEx = ExpectedException.none();
51
52     @Before
53     public void setup() throws NoSuchAlgorithmException, KeyManagementException {
54         PowerMockito.mockStatic(DesignServiceConstants.class);
55     }
56
57     @Test
58     public void testConstructorException() throws IOException {
59         expectedEx.expect(IOException.class);
60         new ArtifactHandlerClient();
61     }
62
63     @Test
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"));
71     }
72
73     @Test
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\"}", ""));
84     }
85 }