optical-service package added for service create
[sdnc/northbound.git] / optical-service / provider / src / test / java / org / onap / sdnc / northbound / OpticalServiceClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2019-2020 Fujitsu Limited Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.sdnc.northbound;
22
23 import static org.junit.Assert.*;
24 import static org.mockito.Mockito.*;
25
26 import java.util.Properties;
27
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
31 import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper;
32 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
33 import org.onap.sdnc.northbound.OpticalServiceClient;
34 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.optical.service.rev191206.OpticalServiceCreateOutputBuilder;
35 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.optical.service.rev191206.OpticalServiceDeleteOutputBuilder;
36
37 public class OpticalServiceClientTest {
38
39         SvcLogicService mockSvcLogicService;
40         String module = "test-module";
41         String rpc = "test-rpc";
42         String version = "test-version";
43         String mode = "test-mode";
44         Properties localProp = new Properties();
45
46         @Before
47         public void setUp() throws Exception {
48                 mockSvcLogicService = mock(SvcLogicService.class);
49                 when(mockSvcLogicService.hasGraph(module, rpc, version, mode)).thenReturn(true);
50         }
51
52         @Test
53         public void testOpticalServiceClientConstructor() {
54                 OpticalServiceClient opticalServiceClient = new OpticalServiceClient(mockSvcLogicService);
55                 assertNotNull(opticalServiceClient);
56         }
57
58         @Test
59         public void testHasGraph() throws SvcLogicException {
60                 OpticalServiceClient opticalServiceClient = new OpticalServiceClient(mockSvcLogicService);
61                 boolean result = opticalServiceClient.hasGraph(module, rpc, version, mode);
62                 assertTrue(result);
63         }
64
65         @Test
66         public void testExecuteSvcLogicStatusFailureCreate() throws SvcLogicException {
67                 OpticalServiceCreateOutputBuilder serviceData = mock(OpticalServiceCreateOutputBuilder.class);
68                 Properties parms = mock(Properties.class);
69                 SvcLogicService svcLogicService = mock(SvcLogicService.class);
70                 Properties properties = new Properties();
71                 properties.setProperty("SvcLogic.status", "failure");
72                 when(svcLogicService.execute(module, rpc, version, mode, properties)).thenReturn(properties);
73                 OpticalServiceClient sliClient = new OpticalServiceClient(svcLogicService);
74                 Properties prop = sliClient.execute(module, rpc, version, mode, serviceData, properties);
75                 assertTrue(prop != null);
76         }
77
78         @Test
79         public void testExecuteSvcLogicStatusFailureDelete() throws SvcLogicException {
80                 OpticalServiceDeleteOutputBuilder serviceData = mock(OpticalServiceDeleteOutputBuilder.class);
81                 Properties parms = mock(Properties.class);
82                 SvcLogicService svcLogicService = mock(SvcLogicService.class);
83                 Properties properties = new Properties();
84                 properties.setProperty("SvcLogic.status", "failure");
85                 when(svcLogicService.execute(module, rpc, version, mode, properties)).thenReturn(properties);
86                 OpticalServiceClient sliClient = new OpticalServiceClient(svcLogicService);
87                 Properties prop = sliClient.execute(module, rpc, version, mode, serviceData, properties);
88                 assertTrue(prop != null);
89         }
90 }