006a002bf1023e8d4308ccc7c675b6a3b2b9e869
[transportpce.git] / renderer / src / test / java / org / opendaylight / transportpce / renderer / provisiondevice / RendererServiceOperationsImplTest.java
1 /*
2  * Copyright © 2018 Orange Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.renderer.provisiondevice;
10
11 import com.google.common.util.concurrent.ListeningExecutorService;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import java.util.concurrent.Executors;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
18 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
19 import org.opendaylight.transportpce.common.ResponseCodes;
20 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
21 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
22 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
23 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
24 import org.opendaylight.transportpce.common.mapping.PortMapping;
25 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
26 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
27 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
28 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
29 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthServiceImpl;
30 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
31 import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub;
32 import org.opendaylight.transportpce.renderer.stub.MountPointStub;
33 import org.opendaylight.transportpce.renderer.stub.OlmServiceStub;
34 import org.opendaylight.transportpce.renderer.utils.MountPointUtils;
35 import org.opendaylight.transportpce.renderer.utils.ServiceDataUtils;
36 import org.opendaylight.transportpce.test.AbstractTest;
37 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput;
38 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.OlmService;
40
41
42
43 public class RendererServiceOperationsImplTest extends AbstractTest {
44
45     private static final int NUMBER_OF_THREADS = 4;
46     private MountPointService mountPointService;
47     private DeviceTransactionManager deviceTransactionManager;
48     private RendererServiceOperationsImpl rendererServiceOperations;
49     private OpenRoadmInterfaces openRoadmInterfaces;
50     private DeviceRendererService deviceRenderer;
51     private PortMapping portMapping;
52     private OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
53     private CrossConnect crossConnect;
54     private OlmService olmService;
55     private ListeningExecutorService executor;
56     private NetworkModelWavelengthService networkModelWavelengthService;
57
58     private void setMountPoint(MountPoint mountPoint) {
59         this.mountPointService = new MountPointServiceStub(mountPoint);
60         this.deviceTransactionManager = new DeviceTransactionManagerImpl(this.mountPointService, 3000);
61         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(this.deviceTransactionManager);
62         this.portMapping = new PortMappingImpl(this.getDataBroker(), this.deviceTransactionManager,
63             openRoadmInterfaces);
64         this.openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(portMapping,
65             openRoadmInterfaces);
66         this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager);
67         this.deviceRenderer = new DeviceRendererServiceImpl(this.getDataBroker(),
68             this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect, portMapping);
69     }
70
71     @Before
72     public void setUp() {
73         setMountPoint(new MountPointStub(getDataBroker()));
74         this.olmService = new OlmServiceStub();
75         this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
76         this.networkModelWavelengthService = new NetworkModelWavelengthServiceImpl(getDataBroker());
77         this.rendererServiceOperations =  new RendererServiceOperationsImpl(this.deviceRenderer, this.olmService,
78             getDataBroker(), this.networkModelWavelengthService);
79
80     }
81
82
83     @Test
84     public void serviceImplementationTerminationPointAsResourceTtp() {
85
86         ServiceImplementationRequestInput input = ServiceDataUtils
87             .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.TTP_TOKEN);
88         writePortMapping(input, OpenRoadmInterfacesImpl.TTP_TOKEN);
89         ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
90         Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
91
92     }
93
94     @Test
95     public void serviceImplementationTerminationPointAsResourcePp() {
96
97         ServiceImplementationRequestInput input = ServiceDataUtils
98             .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.PP_TOKEN);
99         writePortMapping(input, OpenRoadmInterfacesImpl.PP_TOKEN);
100         ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
101         Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
102
103     }
104
105 //    @Test
106 //    public void serviceImplementationTerminationPointAsResourceNetwork() {
107 //
108 //        ServiceImplementationRequestInput input = ServiceDataUtils
109 //            .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
110 //        writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
111 //        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
112 //        Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
113 //
114 //    }
115 //
116 //    @Test
117 //    public void serviceImplementationTerminationPointAsResourceClient() {
118 //        ServiceImplementationRequestInput input = ServiceDataUtils
119 //            .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.CLIENT_TOKEN);
120 //        writePortMapping(input, OpenRoadmInterfacesImpl.CLIENT_TOKEN);
121 //        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
122 //        Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
123 //    }
124 //
125 //    @Test
126 //    public void serviceImplementationTerminationPointAsResourceNoMapping() {
127 //        String[] interfaceTokens = {
128 //            OpenRoadmInterfacesImpl.NETWORK_TOKEN,
129 //            OpenRoadmInterfacesImpl.CLIENT_TOKEN,
130 //            OpenRoadmInterfacesImpl.TTP_TOKEN,
131 //            OpenRoadmInterfacesImpl.PP_TOKEN
132 //        };
133 //        for (String tpToken : interfaceTokens) {
134 //            ServiceImplementationRequestInput input = ServiceDataUtils
135 //                .buildServiceImplementationRequestInputTerminationPointResource(tpToken);
136 //            ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
137 //            Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
138 //                result.getConfigurationResponseCommon().getResponseCode());
139 //        }
140 //    }
141
142     private void writePortMapping(ServiceImplementationRequestInput input, String tpToken) {
143         MountPointUtils.writeMapping(
144             input.getServiceAEnd().getNodeId(),
145             input.getServiceAEnd().getNodeId() + "-" + tpToken,
146             this.deviceTransactionManager
147         );
148         MountPointUtils.writeMapping(
149             input.getServiceZEnd().getNodeId(),
150             input.getServiceZEnd().getNodeId() + "-" + tpToken,
151             this.deviceTransactionManager
152         );
153     }
154
155     /*@Test
156     public void serviceImplementationLinkAsResource() {
157         ServiceImplementationRequestInput input = ServiceDataUtils.buildServiceImplementationRequestInputLinkResource();
158         ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
159         Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
160     }*/
161
162     /*@Test
163     public void serviceImplementtionInvalidResource() {
164
165         ServiceImplementationRequestInput input = ServiceDataUtils
166         .buildServiceImplementationRequestInputInvalidResource();
167         ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input);
168         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
169
170     }*/
171
172 }