PCE module init
[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.rev170426.PathComputationRequestInput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.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     public PceManyTests(PathComputationRequestInput input,
52                         PathComputationRequestOutput expectedOutput, String topologyDataPath) throws Exception {
53         this.input = input;
54         this.expectedOutput = expectedOutput;
55         this.networkModelWavelengthService = new NetworkModelWavelengthServiceImpl(getDataBroker());
56         this.notificationPublishService = new NotificationPublishServiceMock();
57         PceTestUtils.writeTopologyIntoDataStore(getDataBroker(), getDataStoreContextUtil(), topologyDataPath);
58     }
59
60     @Parameterized.Parameters(name = "parameters")
61     public static Collection<Object[]> data() {
62         return Arrays.asList(new Object[][]{
63                 { PceTestData.getPCE_simpletopology_test1_request(),
64                     PceTestData.getPCE_simpletopology_test1_result((long)5),  "topologyData/NW-simple-topology.xml" }
65         });
66     }
67
68    /**
69     * This test runs single PCE calculation on the top one openroadm-topology.
70     * @throws Exception exception throws by the function
71     */
72     @Test
73     public void testPathCalculations() throws Exception {
74         LOG.info("testPathCalculations");
75
76         PathComputationService pathComputationService =
77             new PathComputationServiceImpl(getDataBroker(), notificationPublishService);
78         PathComputationRequestOutput output = pathComputationService.pathComputationRequest(input);
79
80         PceTestUtils.checkConfigurationResponse(output, expectedOutput);
81
82         if (ResponseCodes.RESPONSE_OK.equals(output.getConfigurationResponseCommon().getResponseCode())) {
83             networkModelWavelengthService.useWavelengths(output.getResponseParameters().getPathDescription());
84             PceTestUtils.checkCalculatedPath(output, expectedOutput);
85         }
86     }
87
88 }