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.Test;
16 import org.mockito.Mockito;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
19 import org.opendaylight.transportpce.pce.gnpy.GnpyResult;
20 import org.opendaylight.transportpce.pce.gnpy.GnpyTopoImpl;
21 import org.opendaylight.transportpce.pce.utils.PceTestData;
22 import org.opendaylight.transportpce.test.AbstractTest;
23 import org.opendaylight.transportpce.test.DataStoreContext;
24 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.PathBandwidth;
25 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.generic.path.properties.PathPropertiesBuilder;
26 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.generic.path.properties.path.properties.PathMetric;
27 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.generic.path.properties.path.properties.PathMetricBuilder;
28 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.no.path.info.NoPathBuilder;
29 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.Response;
30 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.ResponseBuilder;
31 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.ResponseKey;
32 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.NoPathCaseBuilder;
33 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.PathCaseBuilder;
35 public class PathComputationServiceImplTest extends AbstractTest {
37 private PathComputationServiceImpl pathComputationServiceImpl;
38 private static NetworkTransactionService networkTransactionService = null;
39 private static GnpyTopoImpl gnpyTopoImpl = null;
40 private static GnpyResult gnpyResult = null;
41 private DataStoreContext dataStoreContext = getDataStoreContextUtil();
42 private DataBroker dataBroker = getDataBroker();
46 networkTransactionService = Mockito.mock(NetworkTransactionService.class);
47 gnpyTopoImpl = Mockito.mock(GnpyTopoImpl.class);
48 gnpyResult = Mockito.mock(GnpyResult.class);
49 pathComputationServiceImpl = new PathComputationServiceImpl(
50 networkTransactionService,
51 this.getNotificationPublishService(), null, null);
52 pathComputationServiceImpl.init();
56 public void pathComputationRequestTest() {
57 pathComputationServiceImpl.generateGnpyResponse(null,"path");
59 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_simpletopology_test1_request()));
64 public void testPathComputationRequestNoPath() {
65 Response response = new ResponseBuilder()
66 .withKey(new ResponseKey("responseId")).setResponseType(new NoPathCaseBuilder()
67 .setNoPath(new NoPathBuilder().setNoPath("no path").build()).build()).build();
69 pathComputationServiceImpl.generateGnpyResponse(response,"path");
71 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
76 public void testPathComputationRequestPathCase() {
77 PathMetric pathMetric = new PathMetricBuilder()
78 .setAccumulativeValue(new BigDecimal(21))
79 .setMetricType(PathBandwidth.class).build();
80 Response response = new ResponseBuilder()
81 .withKey(new ResponseKey("responseId")).setResponseType(new PathCaseBuilder()
82 .setPathProperties(new PathPropertiesBuilder().setPathMetric(Map.of(pathMetric.key(),pathMetric))
83 .build()).build()).build();
85 pathComputationServiceImpl.generateGnpyResponse(response,"path");
87 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
92 public void destroy() {
93 pathComputationServiceImpl.close();