Test coverage in appc-dg-ssh
[appc.git] / appc-dg / appc-dg-shared / appc-dg-ssh / src / test / java / org / onap / appc / dg / ssh / impl / SshDBPluginImplTest.java
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.dg.ssh.impl;
23
24 import java.util.HashMap;
25 import java.util.Map;
26 import org.junit.Assert;
27 import org.junit.Rule;
28 import org.junit.Test;
29 import org.junit.rules.ExpectedException;
30 import org.mockito.Mockito;
31 import org.onap.appc.adapter.ssh.Constants;
32 import org.onap.appc.adapter.ssh.SshConnectionDetails;
33 import org.onap.appc.adapter.ssh.SshDataAccessException;
34 import org.onap.appc.adapter.ssh.SshDataAccessService;
35 import org.onap.appc.exceptions.APPCException;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
37
38 public class SshDBPluginImplTest {
39
40     @Rule
41     public ExpectedException expectedEx = ExpectedException.none();
42
43     @Test
44     public void testRetrieveConnectionDetails() throws APPCException {
45         SshDBPluginImpl impl = new SshDBPluginImpl();
46         SshDataAccessService dataAccessServiceMock = Mockito.mock(SshDataAccessService.class);
47         Mockito.doReturn(true).when(dataAccessServiceMock).retrieveConnectionDetails(Mockito.anyString(),
48                 Mockito.any(SshConnectionDetails.class));
49         impl.setDataAccessService(dataAccessServiceMock);
50         Map<String, String> params = new HashMap<>();
51         SvcLogicContext ctx = new SvcLogicContext();
52         impl.retrieveConnectionDetails(params, ctx);
53         Assert.assertNotNull(ctx.getAttribute(Constants.CONNECTION_DETAILS_FIELD_NAME));
54     }
55
56     @Test
57     public void testRetrieveConnectionDetailsAppcException() throws APPCException {
58         SshDBPluginImpl impl = new SshDBPluginImpl();
59         SshDataAccessService dataAccessServiceMock = Mockito.mock(SshDataAccessService.class);
60         impl.setDataAccessService(dataAccessServiceMock);
61         Map<String, String> params = new HashMap<>();
62         SvcLogicContext ctx = new SvcLogicContext();
63         expectedEx.expect(APPCException.class);
64         impl.retrieveConnectionDetails(params, ctx);
65     }
66
67     @Test
68     public void testRetrieveConnectionDetailsSshDataAccessException() throws APPCException {
69         SshDBPluginImpl impl = new SshDBPluginImpl();
70         SshDataAccessService dataAccessServiceMock = Mockito.mock(SshDataAccessService.class);
71         Mockito.doThrow(new SshDataAccessException()).when(dataAccessServiceMock).retrieveConnectionDetails(Mockito.anyString(),
72                 Mockito.any(SshConnectionDetails.class));
73         impl.setDataAccessService(dataAccessServiceMock);
74         Map<String, String> params = new HashMap<>();
75         SvcLogicContext ctx = new SvcLogicContext();
76         expectedEx.expect(SshDataAccessException.class);
77         impl.retrieveConnectionDetails(params, ctx);
78     }
79
80 }