2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Samsung
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=========================================================
21 package org.onap.ccsdk.adapter.ansible.impl;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.onap.ccsdk.sli.adaptors.ansible.impl.ConnectionBuilder;
26 import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
29 import javax.net.ssl.SSLException;
30 import java.io.FileNotFoundException;
31 import java.io.IOException;
32 import java.security.KeyManagementException;
33 import java.security.KeyStoreException;
34 import java.security.NoSuchAlgorithmException;
35 import java.security.cert.CertificateException;
37 import static org.junit.Assert.assertEquals;
39 public class TestConnectionBuilder {
40 ConnectionBuilder builder;
43 throws SSLException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
44 builder = new ConnectionBuilder(1);
49 public void testSetHttpContext() throws IllegalStateException, IllegalArgumentException {
50 String user = "testUser";
51 String pass = "testPassword";
53 builder.setHttpContext(user, pass);
57 public void testPost() throws IllegalStateException, IllegalArgumentException {
58 String user = "testUser";
59 String pass = "testPassword";
60 String agentUrl = "test/server.com";
61 String payload = "testPayload";
63 builder.setHttpContext(user, pass);
64 AnsibleResult result = builder.post(agentUrl, payload);
66 assertEquals(611, result.getStatusCode());
67 assertEquals(null, result.getStatusMessage());
68 assertEquals("UNKNOWN", result.getResults());
72 public void testGet() throws IllegalStateException, IllegalArgumentException {
73 String user = "testUser";
74 String pass = "testPassword";
75 String agentUrl = "test/server.com";
77 builder.setHttpContext(user, pass);
78 AnsibleResult result = builder.get(agentUrl);
80 assertEquals(611, result.getStatusCode());
81 assertEquals(null, result.getStatusMessage());
82 assertEquals("UNKNOWN", result.getResults());
86 public void testGetMode()
87 throws SSLException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
88 String user = "testUser";
89 String pass = "testPassword";
90 String agentUrl = "test/server.com";
92 builder = new ConnectionBuilder(2);
93 builder.setHttpContext(user, pass);
94 AnsibleResult result = builder.get(agentUrl);
96 assertEquals(611, result.getStatusCode());
97 assertEquals(null, result.getStatusMessage());
98 assertEquals("UNKNOWN", result.getResults());
101 @Test (expected = FileNotFoundException.class)
102 public void testGetModeCert()
103 throws KeyStoreException, CertificateException, IOException,
104 KeyManagementException, NoSuchAlgorithmException, SvcLogicException {
105 String user = "testUser";
106 String pass = "testPassword";
107 String agentUrl = "test/server.com";
108 String certFile = "testCert";
110 builder = new ConnectionBuilder(certFile);
111 builder.setHttpContext(user, pass);
112 AnsibleResult result = builder.get(agentUrl);
114 assertEquals(611, result.getStatusCode());
115 assertEquals(null, result.getStatusMessage());
116 assertEquals("UNKNOWN", result.getResults());