2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Ericsson
6 * ================================================================================
7 * Modifications Copyright (C) 2019 AT&T Intellectual Property
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=========================================================
24 package org.onap.appc.dg.ssh.impl;
26 import java.util.HashMap;
28 import org.junit.Assert;
29 import org.junit.Rule;
30 import org.junit.Test;
31 import org.junit.rules.ExpectedException;
32 import org.mockito.Mockito;
33 import org.onap.appc.adapter.ssh.Constants;
34 import org.onap.appc.adapter.ssh.SshConnectionDetails;
35 import org.onap.appc.adapter.ssh.SshDataAccessException;
36 import org.onap.appc.adapter.ssh.SshDataAccessService;
37 import org.onap.appc.exceptions.APPCException;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
40 public class SshDBPluginImplTest {
43 public ExpectedException expectedEx = ExpectedException.none();
46 public void testRetrieveConnectionDetails() throws APPCException {
47 SshDBPluginImpl impl = new SshDBPluginImpl();
48 SshDataAccessService dataAccessServiceMock = Mockito.mock(SshDataAccessService.class);
49 Mockito.doReturn(true).when(dataAccessServiceMock)
50 .retrieveConnectionDetails(Mockito.anyString(), Mockito.any(SshConnectionDetails.class));
51 impl.setDataAccessService(dataAccessServiceMock);
52 Map<String, String> params = new HashMap<>();
53 SvcLogicContext ctx = new SvcLogicContext();
54 impl.retrieveConnectionDetails(params, ctx);
55 Assert.assertNotNull(ctx.getAttribute(Constants.CONNECTION_DETAILS_FIELD_NAME));
59 public void testRetrieveConnectionDetailsAppcException() throws APPCException {
60 SshDBPluginImpl impl = new SshDBPluginImpl();
61 SshDataAccessService dataAccessServiceMock = Mockito.mock(SshDataAccessService.class);
62 impl.setDataAccessService(dataAccessServiceMock);
63 Map<String, String> params = new HashMap<>();
64 SvcLogicContext ctx = new SvcLogicContext();
65 expectedEx.expect(APPCException.class);
66 impl.retrieveConnectionDetails(params, ctx);
70 public void testRetrieveConnectionDetailsSshDataAccessException() throws APPCException {
71 SshDBPluginImpl impl = new SshDBPluginImpl();
72 SshDataAccessService dataAccessServiceMock = Mockito.mock(SshDataAccessService.class);
73 Mockito.doThrow(new SshDataAccessException()).when(dataAccessServiceMock)
74 .retrieveConnectionDetails(Mockito.anyString(), Mockito.any(SshConnectionDetails.class));
75 impl.setDataAccessService(dataAccessServiceMock);
76 Map<String, String> params = new HashMap<>();
77 SvcLogicContext ctx = new SvcLogicContext();
78 expectedEx.expect(SshDataAccessException.class);
79 impl.retrieveConnectionDetails(params, ctx);