2 * Copyright © 2020 Orange Labs, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.pce.service;
10 import java.math.BigDecimal;
12 import org.junit.After;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Ignore;
16 import org.junit.Test;
17 import org.mockito.Mockito;
18 import org.opendaylight.mdsal.binding.api.DataBroker;
19 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
20 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
21 import org.opendaylight.transportpce.common.network.RequestProcessor;
22 import org.opendaylight.transportpce.pce.gnpy.GnpyResult;
23 import org.opendaylight.transportpce.pce.gnpy.GnpyTopoImpl;
24 import org.opendaylight.transportpce.pce.utils.PceTestData;
25 import org.opendaylight.transportpce.pce.utils.PceTestUtils;
26 import org.opendaylight.transportpce.pce.utils.TransactionUtils;
27 import org.opendaylight.transportpce.test.AbstractTest;
28 import org.opendaylight.transportpce.test.DataStoreContext;
29 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.PathBandwidth;
30 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.generic.path.properties.PathPropertiesBuilder;
31 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.generic.path.properties.path.properties.PathMetric;
32 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.generic.path.properties.path.properties.PathMetricBuilder;
33 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.no.path.info.NoPathBuilder;
34 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.Response;
35 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.ResponseBuilder;
36 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.response.response.type.NoPathCaseBuilder;
37 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.response.response.type.PathCaseBuilder;
40 public class PathComputationServiceImplTest extends AbstractTest {
42 private PathComputationServiceImpl pathComputationServiceImpl;
43 private static NetworkTransactionService networkTransactionService = null;
44 private static GnpyTopoImpl gnpyTopoImpl = null;
45 private static GnpyResult gnpyResult = null;
46 private DataStoreContext dataStoreContext = this.getDataStoreContextUtil();
47 private DataBroker dataBroker = this.getDataBroker();
51 networkTransactionService = Mockito.mock(NetworkTransactionService.class);
52 gnpyTopoImpl = Mockito.mock(GnpyTopoImpl.class);
53 gnpyResult = Mockito.mock(GnpyResult.class);
54 pathComputationServiceImpl = new PathComputationServiceImpl(
55 networkTransactionService,
56 this.getNotificationPublishService(), null);
57 pathComputationServiceImpl.init();
61 public void pathComputationRequestTest() {
62 pathComputationServiceImpl.generateGnpyResponse(null,"path");
64 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_simpletopology_test1_request()));
69 public void testPathComputationRequestNoPath() {
70 Response response = new ResponseBuilder().setResponseType(new NoPathCaseBuilder()
71 .setNoPath(new NoPathBuilder().setNoPath("no path").build()).build()).build();
73 pathComputationServiceImpl.generateGnpyResponse(response,"path");
75 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
80 public void testPathComputationRequestPathCase() {
81 PathMetric pathMetric = new PathMetricBuilder()
82 .setAccumulativeValue(new BigDecimal(21))
83 .setMetricType(PathBandwidth.class).build();
84 Response response = new ResponseBuilder().setResponseType(new PathCaseBuilder()
85 .setPathProperties(new PathPropertiesBuilder().setPathMetric(Map.of(pathMetric.key(),pathMetric))
86 .build()).build()).build();
88 pathComputationServiceImpl.generateGnpyResponse(response,"path");
90 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
94 @Test(expected = Exception.class)
95 public void generateGnpyResponse() throws Exception {
96 PceTestUtils.writeNetworkIntoDataStore(dataBroker, dataStoreContext, TransactionUtils.getNetworkForSpanLoss());
97 GnpyResult gnpyResult2 =
98 new GnpyResult("A-to-Z",
99 new GnpyTopoImpl(new NetworkTransactionImpl(
100 new RequestProcessor(dataBroker))), null);
101 pathComputationServiceImpl.generateGnpyResponse(gnpyResult2.getResponse(), "A-to-Z");
106 public void destroy() {
107 pathComputationServiceImpl.close();