2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
24 package org.onap.appc.listener.LCM.operation;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertNull;
30 import static org.junit.Assert.assertTrue;
31 import static org.mockito.Matchers.anyString;
33 import com.att.aft.dme2.internal.jersey.core.util.Base64;
34 import com.fasterxml.jackson.databind.JsonNode;
35 import java.io.IOException;
36 import java.net.Socket;
37 import java.net.SocketException;
38 import java.security.KeyManagementException;
39 import java.security.KeyStore;
40 import java.security.KeyStoreException;
41 import java.security.NoSuchAlgorithmException;
42 import java.security.UnrecoverableKeyException;
43 import org.junit.Before;
44 import org.junit.Test;
45 import org.mockito.Mock;
46 import org.onap.appc.exceptions.APPCException;
47 import org.onap.appc.listener.LCM.operation.ProviderOperations.MySSLSocketFactory;
48 import org.onap.appc.listener.util.Mapper;
50 public class ProviderOperationsTest {
52 private static final String jsonInputBodyStr =
53 "{\"input\":{ \"common-header\": { \"timestamp\": \"2016-08-03T08:50:18.97Z\", "
54 + "\"api-ver\": \"1\", \"originator-id\": \"1\", \"request-id\": \"123\", \"sub-request-id\": \"1\", "
55 + "\"flags\": { \"force\":\"TRUE\", \"ttl\":\"9900\" } }, \"action\": \"Stop\", "
56 + "\"action-identifiers\": { \"vnf-id\": \"TEST\" } }}";
57 private final JsonNode jsonNode = Mapper.toJsonNodeFromJsonString(jsonInputBodyStr);
59 private ProviderOperations providerOperations;
60 private MySSLSocketFactory socketFactory;
63 private KeyStore mockKeyStore;
68 throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
71 new ProviderOperations("http://127.0.0.1", "test_user", "test_password");
72 socketFactory = new MySSLSocketFactory(mockKeyStore);
76 public void setAuthentication_should_return_null_given_null_arguments() {
77 String newAuthentication = providerOperations.setAuthentication(null, null);
78 assertNull(newAuthentication);
82 public void should_set_properties() {
83 providerOperations.setUrl("hp://123.1.2.3");
84 assertEquals("http://127.0.0.1", providerOperations.getUrl());
85 providerOperations.setUrl("http://123.1.2.3");
86 assertEquals("http://123.1.2.3", providerOperations.getUrl());
88 String newAuthentication = providerOperations.setAuthentication("new_user", "new_password");
89 assertEquals("new_user:new_password", Base64.base64Decode(newAuthentication));
93 public void isSucceeded_should_resolve_status_codes() {
95 assertFalse(ProviderOperations.isSucceeded(null));
96 assertFalse(ProviderOperations.isSucceeded(200));
97 assertTrue(ProviderOperations.isSucceeded(100));
98 assertTrue(ProviderOperations.isSucceeded(400));
101 @Test(expected = APPCException.class)
102 public void topologyDG_should_throw_given_null_message() throws APPCException {
104 providerOperations.topologyDG("test-rpc-name", null);
108 public void todo() throws APPCException {
109 //TODO write some test cases for topologyDG method
110 // JsonNode result = providerOperations.topologyDG("test", jsonNode);
113 @Test(expected = SocketException.class)
114 public void sslSocketFactory_should_throw_when_socket_not_connected() throws IOException {
115 Socket socket = socketFactory.createSocket();
116 assertNotNull(socket);
118 socketFactory.createSocket(socket, "127.0.0.1", 123, true);