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