5738aabba4c9ce0f40142460d3c95bfbb359dcc8
[sdnc/northbound.git] / optical-service / provider / src / test / java / org / onap / sdnc / northbound / TestOpticalServiceProvider.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 org.junit.Before;
24 import org.junit.Test;
25 import org.onap.sdnc.northbound.OpticalServiceProvider;
26 import org.onap.sdnc.northbound.OpticalServiceClient;
27 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
28 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
29 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
30 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
31 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.optical.service.rev191206.OpticalServiceCreateInput;
32 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.optical.service.rev191206.OpticalServiceCreateInputBuilder;
33 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.optical.service.rev191206.OpticalServiceCreateOutput;
34 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.optical.service.rev191206.optical.service.create.request.PayloadBuilder;
35 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.optical.service.rev191206.OpticalServiceDeleteInput;
36 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.optical.service.rev191206.OpticalServiceDeleteInputBuilder;
37 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.optical.service.rev191206.OpticalServiceDeleteOutput;
38
39 import org.opendaylight.yangtools.yang.common.RpcResult;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 import static org.junit.Assert.*;
44 import static org.mockito.Mockito.mock;
45 import static org.mockito.Mockito.when;
46
47 public class TestOpticalServiceProvider extends AbstractConcurrentDataBrokerTest {
48
49     private OpticalServiceProvider opticalServiceProvider;
50     private static final Logger LOG = LoggerFactory.getLogger(OpticalServiceProvider.class);
51     String module = "OpticalService"; 
52     String rpc = "optical-service-create"; 
53     String version = null; 
54     String mode = "sync"; 
55
56     @Before
57     public void setUp() throws Exception {
58         if (null == opticalServiceProvider) {
59             DataBroker dataBroker = getDataBroker();
60             NotificationPublishService mockNotification = mock(NotificationPublishService.class);
61             RpcProviderRegistry mockRpcRegistry = mock(RpcProviderRegistry.class);
62             OpticalServiceClient mockSliClient = mock(OpticalServiceClient.class);
63             when(mockSliClient.hasGraph(module, rpc, version, mode)).thenReturn(false); 
64             opticalServiceProvider = new OpticalServiceProvider(dataBroker, mockNotification, mockRpcRegistry, mockSliClient);
65         }
66     }
67
68     //Should return error 503 when No service logic active for optical-service.
69     @Test
70     public void testOpticalServiceCreate() {
71
72         OpticalServiceCreateInputBuilder inputBuilder = new OpticalServiceCreateInputBuilder();
73
74         java.util.concurrent.Future<RpcResult<OpticalServiceCreateOutput>> future = opticalServiceProvider
75                                                                           .opticalServiceCreate(inputBuilder.build());
76         RpcResult<OpticalServiceCreateOutput> rpcResult = null;
77         try {
78             rpcResult = future.get();
79         } catch (Exception e) {
80             fail("Error : " + e);
81         }
82         assertEquals("503", rpcResult.getResult().getResponseCode());
83     }
84     
85     @Test
86     public void testOpticalServiceDelete() {
87
88         OpticalServiceDeleteInputBuilder inputBuilder = new OpticalServiceDeleteInputBuilder();
89         java.util.concurrent.Future<RpcResult<OpticalServiceDeleteOutput>> future = opticalServiceProvider
90                                                                           .opticalServiceDelete(inputBuilder.build());
91         RpcResult<OpticalServiceDeleteOutput> rpcResult = null;
92         try {
93             rpcResult = future.get();
94         } catch (Exception e) {
95             fail("Error : " + e);
96         }
97         assertEquals("503", rpcResult.getResult().getResponseCode());
98     }
99     
100     
101     
102
103     //Input parameter validation
104     @Test
105     public void testOpticalServiceCreateInputValidation() {
106
107         java.util.concurrent.Future<RpcResult<OpticalServiceCreateOutput>> future = opticalServiceProvider
108                                                                                       .opticalServiceCreate(null);
109         RpcResult<OpticalServiceCreateOutput> rpcResult = null;
110         try {
111             rpcResult = future.get();
112         } catch (Exception e) {
113             fail("Error : " + e);
114         }
115         assertEquals("403", rpcResult.getResult().getResponseCode());
116     }
117     
118 }