2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2018 Nokia Solutions and Networks
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
23 package org.onap.appc.listener.LCM.operation;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
30 import static org.mockito.Matchers.anyString;
32 import com.att.aft.dme2.internal.jersey.core.util.Base64;
33 import java.io.IOException;
34 import java.net.Socket;
35 import java.net.SocketException;
36 import java.security.KeyManagementException;
37 import java.security.KeyStore;
38 import java.security.KeyStoreException;
39 import java.security.NoSuchAlgorithmException;
40 import java.security.UnrecoverableKeyException;
41 import org.junit.Before;
42 import org.junit.Test;
43 import org.mockito.Mock;
44 import org.onap.appc.exceptions.APPCException;
45 import org.onap.appc.listener.LCM.operation.ProviderOperations.MySSLSocketFactory;
47 public class ProviderOperationsTest {
49 private ProviderOperations providerOperations;
50 private MySSLSocketFactory socketFactory;
53 private KeyStore mockKeyStore;
58 throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
61 new ProviderOperations("http://127.0.0.1", "test_user", "test_password");
62 socketFactory = new MySSLSocketFactory(mockKeyStore);
66 public void setAuthentication_should_return_null_given_null_arguments() {
67 String newAuthentication = providerOperations.setAuthentication(null, null);
68 assertNull(newAuthentication);
72 public void should_set_properties() {
73 providerOperations.setUrl("hp://123.1.2.3");
74 assertEquals("http://127.0.0.1", providerOperations.getUrl());
75 providerOperations.setUrl("http://123.1.2.3");
76 assertEquals("http://123.1.2.3", providerOperations.getUrl());
78 String newAuthentication = providerOperations.setAuthentication("new_user", "new_password");
79 assertEquals("new_user:new_password", Base64.base64Decode(newAuthentication));
83 public void isSucceeded_should_resolve_status_codes() {
85 assertFalse(ProviderOperations.isSucceeded(null));
86 assertFalse(ProviderOperations.isSucceeded(200));
87 assertTrue(ProviderOperations.isSucceeded(100));
88 assertTrue(ProviderOperations.isSucceeded(400));
91 @Test(expected = APPCException.class)
92 public void topologyDG_should_throw_given_null_message() throws APPCException {
94 providerOperations.topologyDG("test-rpc-name", null);
97 @Test(expected = SocketException.class)
98 public void sslSocketFactory_should_throw_when_socket_not_connected() throws IOException {
99 Socket socket = socketFactory.createSocket();
100 assertNotNull(socket);
102 socketFactory.createSocket(socket, "127.0.0.1", 123, true);
105 //TODO write some test cases for topologyDG method