Service-notification handling for PCE
[transportpce.git] / pce / src / test / java / org / opendaylight / transportpce / pce / PceManyTests.java
1 /*
2  * Copyright © 2017 AT&T, 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 package org.opendaylight.transportpce.pce;
9
10 import java.util.Arrays;
11 import java.util.Collection;
12
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.junit.runners.Parameterized;
16 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
17 import org.opendaylight.transportpce.common.ResponseCodes;
18 import org.opendaylight.transportpce.pce.service.PathComputationService;
19 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
20 import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock;
21 import org.opendaylight.transportpce.pce.utils.PceTestData;
22 import org.opendaylight.transportpce.pce.utils.PceTestUtils;
23 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
24 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthServiceImpl;
25 import org.opendaylight.transportpce.test.AbstractTest;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestInput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 @RunWith(value = Parameterized.class)
32 public class PceManyTests extends AbstractTest {
33
34     private static final Logger LOG = LoggerFactory.getLogger(PceManyTests.class);
35
36     private PathComputationRequestInput input;
37     private PathComputationRequestOutput expectedOutput;
38     private NetworkModelWavelengthService networkModelWavelengthService;
39     private NotificationPublishService notificationPublishService;
40
41     /**
42      * Input parameters for testPathCalculation.
43      *
44      * @param input
45      *   input path computation request
46      * @param expectedOutput
47      *   expected path computation result
48      * @param topologyDataPath
49      *   path to topology data file to be used for DataStore population
50      *
51      * @throws Exception exception throws by the function
52      */
53     public PceManyTests(PathComputationRequestInput input,
54                         PathComputationRequestOutput expectedOutput, String topologyDataPath) throws Exception {
55         this.input = input;
56         this.expectedOutput = expectedOutput;
57         this.networkModelWavelengthService = new NetworkModelWavelengthServiceImpl(getDataBroker());
58         this.notificationPublishService = new NotificationPublishServiceMock();
59         PceTestUtils.writeTopologyIntoDataStore(getDataBroker(), getDataStoreContextUtil(), topologyDataPath);
60     }
61
62     @Parameterized.Parameters(name = "parameters")
63     public static Collection<Object[]> data() {
64         return Arrays.asList(new Object[][]{
65                 { PceTestData.getPCE_simpletopology_test1_request(),
66                     PceTestData.getPCE_simpletopology_test1_result((long)5),  "topologyData/NW-simple-topology.xml" }
67         });
68     }
69
70    /**
71     * This test runs single PCE calculation on the top one openroadm-topology.
72     * @throws Exception exception throws by the function
73     */
74     @Test
75     public void testPathCalculations() throws Exception {
76         LOG.info("testPathCalculations");
77
78         PathComputationService pathComputationService =
79             new PathComputationServiceImpl(getDataBroker(), notificationPublishService);
80         PathComputationRequestOutput output = pathComputationService.pathComputationRequest(input).get();
81
82         PceTestUtils.checkConfigurationResponse(output, expectedOutput);
83
84         if (ResponseCodes.RESPONSE_OK.equals(output.getConfigurationResponseCommon().getResponseCode())) {
85             //networkModelWavelengthService.useWavelengths(output.getResponseParameters().getPathDescription());
86             PceTestUtils.checkCalculatedPath(output, expectedOutput);
87         }
88     }
89
90 }