2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 Fujitsu Limited Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.sdnc.northbound;
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;
39 import org.opendaylight.yangtools.yang.common.RpcResult;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
43 import static org.junit.Assert.*;
44 import static org.mockito.Mockito.mock;
45 import static org.mockito.Mockito.when;
47 public class TestOpticalServiceProvider extends AbstractConcurrentDataBrokerTest {
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;
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);
68 //Should return error 503 when No service logic active for optical-service.
70 public void testOpticalServiceCreate() {
72 OpticalServiceCreateInputBuilder inputBuilder = new OpticalServiceCreateInputBuilder();
74 java.util.concurrent.Future<RpcResult<OpticalServiceCreateOutput>> future = opticalServiceProvider
75 .opticalServiceCreate(inputBuilder.build());
76 RpcResult<OpticalServiceCreateOutput> rpcResult = null;
78 rpcResult = future.get();
79 } catch (Exception e) {
82 assertEquals("503", rpcResult.getResult().getResponseCode());
86 public void testOpticalServiceDelete() {
88 OpticalServiceDeleteInputBuilder inputBuilder = new OpticalServiceDeleteInputBuilder();
89 java.util.concurrent.Future<RpcResult<OpticalServiceDeleteOutput>> future = opticalServiceProvider
90 .opticalServiceDelete(inputBuilder.build());
91 RpcResult<OpticalServiceDeleteOutput> rpcResult = null;
93 rpcResult = future.get();
94 } catch (Exception e) {
97 assertEquals("503", rpcResult.getResult().getResponseCode());
103 //Input parameter validation
105 public void testOpticalServiceCreateInputValidation() {
107 java.util.concurrent.Future<RpcResult<OpticalServiceCreateOutput>> future = opticalServiceProvider
108 .opticalServiceCreate(null);
109 RpcResult<OpticalServiceCreateOutput> rpcResult = null;
111 rpcResult = future.get();
112 } catch (Exception e) {
113 fail("Error : " + e);
115 assertEquals("403", rpcResult.getResult().getResponseCode());