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 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;
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;
42 public class TestOpticalServiceProvider extends AbstractConcurrentDataBrokerTest {
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;
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);
63 //Should return error 503 when No service logic active for optical-service.
65 public void testOpticalServiceCreate() {
67 OpticalServiceCreateInputBuilder inputBuilder = new OpticalServiceCreateInputBuilder();
69 java.util.concurrent.Future<RpcResult<OpticalServiceCreateOutput>> future = opticalServiceProvider
70 .opticalServiceCreate(inputBuilder.build());
71 RpcResult<OpticalServiceCreateOutput> rpcResult = null;
73 rpcResult = future.get();
74 } catch (Exception e) {
77 assertEquals("503", rpcResult.getResult().getResponseCode());
81 public void testOpticalServiceDelete() {
83 OpticalServiceDeleteInputBuilder inputBuilder = new OpticalServiceDeleteInputBuilder();
84 java.util.concurrent.Future<RpcResult<OpticalServiceDeleteOutput>> future = opticalServiceProvider
85 .opticalServiceDelete(inputBuilder.build());
86 RpcResult<OpticalServiceDeleteOutput> rpcResult = null;
88 rpcResult = future.get();
89 } catch (Exception e) {
92 assertEquals("503", rpcResult.getResult().getResponseCode());
98 //Input parameter validation
100 public void testOpticalServiceCreateInputValidation() {
102 java.util.concurrent.Future<RpcResult<OpticalServiceCreateOutput>> future = opticalServiceProvider
103 .opticalServiceCreate(null);
104 RpcResult<OpticalServiceCreateOutput> rpcResult = null;
106 rpcResult = future.get();
107 } catch (Exception e) {
108 fail("Error : " + e);
110 assertEquals("403", rpcResult.getResult().getResponseCode());