939ada805db8db3df4274efd5308f8420d7a3ac6
[sdnc/northbound.git] / generic-resource-api / provider / src / test / java / org / onap / sdnc / northbound / TestGenericResourceApi.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T 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
22 package org.onap.sdnc.northbound;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.fail;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import static org.mockito.Mockito.mock;
30
31 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
32 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
33 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
34 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
35 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutput;
36 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInputBuilder;
37 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationInputBuilder;
38 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationOutput;
39 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.information.NetworkInformationBuilder;
40 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation.RequestAction;
41 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformationBuilder;
42 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader.SvcAction;
43 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeaderBuilder;
44 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.information.ServiceInformationBuilder;
45 import org.opendaylight.yangtools.yang.common.RpcResult;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48
49 public class TestGenericResourceApi extends AbstractConcurrentDataBrokerTest {
50
51     private GenericResourceApiProvider genericResourceApiProvider;
52     private static final Logger LOG = LoggerFactory.getLogger(GenericResourceApiProvider.class);
53
54     @Before
55     public void setUp() throws Exception {
56         if (null == genericResourceApiProvider) {
57             DataBroker dataBroker = getDataBroker();
58             NotificationPublishService mockNotification = mock(NotificationPublishService.class);
59             RpcProviderRegistry mockRpcRegistry = mock(RpcProviderRegistry.class);
60             GenericResourceApiSvcLogicServiceClient client = mock(GenericResourceApiSvcLogicServiceClient.class);
61             try {
62                 genericResourceApiProvider = new GenericResourceApiProvider(dataBroker, mockNotification, mockRpcRegistry, client);
63             } catch (Exception e) {
64                         LOG.error("Caught exception on setUp", e);
65                         throw e;
66             }
67         }
68     }
69
70     @Test
71     public void testServiceTopologyOperation() {
72
73         ServiceTopologyOperationInputBuilder inputBuilder = new ServiceTopologyOperationInputBuilder();
74
75         SdncRequestHeaderBuilder sdncRequestHeaderBuilder = new SdncRequestHeaderBuilder();
76         sdncRequestHeaderBuilder.setSvcRequestId("1111");
77         sdncRequestHeaderBuilder.setSvcAction(SvcAction.Assign);
78         inputBuilder.setSdncRequestHeader(sdncRequestHeaderBuilder.build());
79
80         RequestInformationBuilder requestInformationBuilder = new RequestInformationBuilder();
81         requestInformationBuilder.setRequestId("1111");
82         requestInformationBuilder.setRequestAction(RequestAction.CreateServiceInstance);
83         inputBuilder.setRequestInformation(requestInformationBuilder.build());
84
85         ServiceInformationBuilder serviceInformationBuilder = new ServiceInformationBuilder();
86         serviceInformationBuilder.setServiceInstanceId("1111");
87         inputBuilder.setServiceInformation(serviceInformationBuilder.build());
88
89         // TODO: currently initialize GenericResourceApiSvcLogicServiceClient is failing, need to fix
90         java.util.concurrent.Future<RpcResult<ServiceTopologyOperationOutput>> future = genericResourceApiProvider
91         .serviceTopologyOperation(inputBuilder.build());
92         RpcResult<ServiceTopologyOperationOutput> rpcResult = null;
93         try {
94             rpcResult = future.get();
95         } catch (Exception e) {
96             fail("Error : " + e);
97         }
98         LOG.info("result: {}", rpcResult);
99         assertEquals("1111", rpcResult.getResult().getSvcRequestId());
100     }
101
102     @Test
103     public void testNetworkTopologyOperation() {
104
105         NetworkTopologyOperationInputBuilder inputBuilder = new NetworkTopologyOperationInputBuilder();
106
107         SdncRequestHeaderBuilder sdncRequestHeaderBuilder = new SdncRequestHeaderBuilder();
108         sdncRequestHeaderBuilder.setSvcRequestId("1111");
109         sdncRequestHeaderBuilder.setSvcAction(SvcAction.Create);
110         inputBuilder.setSdncRequestHeader(sdncRequestHeaderBuilder.build());
111
112         RequestInformationBuilder requestInformationBuilder = new RequestInformationBuilder();
113         requestInformationBuilder.setRequestId("1111");
114         requestInformationBuilder.setRequestAction(RequestAction.CreateNetworkInstance);
115         inputBuilder.setRequestInformation(requestInformationBuilder.build());
116
117         ServiceInformationBuilder serviceInformationBuilder = new ServiceInformationBuilder();
118         serviceInformationBuilder.setServiceInstanceId("1111");
119         inputBuilder.setServiceInformation(serviceInformationBuilder.build());
120
121         NetworkInformationBuilder networkInformationBuilder = new NetworkInformationBuilder();
122         inputBuilder.setNetworkInformation(networkInformationBuilder.build());
123
124         java.util.concurrent.Future<RpcResult<NetworkTopologyOperationOutput>> future = genericResourceApiProvider
125             .networkTopologyOperation(inputBuilder.build());
126         RpcResult<NetworkTopologyOperationOutput> rpcResult = null;
127         try {
128             rpcResult = future.get();
129         } catch (Exception e) {
130             fail("Error : " + e);
131         }
132         LOG.info("result: {}", rpcResult);
133         assertEquals("1111", rpcResult.getResult().getSvcRequestId());
134     }
135 }