Add unit tests PCE RPC path-computation-reroute
[transportpce.git] / pce / src / test / java / org / opendaylight / transportpce / pce / service / PathComputationServiceImplTest.java
1 /*
2  * Copyright © 2020 Orange Labs, 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.service;
9
10 import java.util.Map;
11 import org.junit.After;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
17 import org.opendaylight.transportpce.pce.utils.PceTestData;
18 import org.opendaylight.transportpce.test.AbstractTest;
19 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.PathBandwidth;
20 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.PathPropertiesBuilder;
21 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathMetric;
22 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathMetricBuilder;
23 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.no.path.info.NoPathBuilder;
24 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.Response;
25 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.ResponseBuilder;
26 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.ResponseKey;
27 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.NoPathCaseBuilder;
28 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.PathCaseBuilder;
29 import org.opendaylight.yangtools.yang.common.Decimal64;
30
31 public class PathComputationServiceImplTest extends AbstractTest {
32
33     private PathComputationServiceImpl pathComputationServiceImpl;
34     private static NetworkTransactionService networkTransactionService = null;
35
36     @Before
37     public void setUp() {
38         networkTransactionService = Mockito.mock(NetworkTransactionService.class);
39         pathComputationServiceImpl = new PathComputationServiceImpl(
40                 networkTransactionService,
41                 this.getNotificationPublishService(), null, null);
42         pathComputationServiceImpl.init();
43     }
44
45     @Test
46     public void pathComputationRequestTest() {
47         pathComputationServiceImpl.generateGnpyResponse(null,"path");
48         Assert.assertNotNull(
49                 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_simpletopology_test1_request()));
50
51     }
52
53     @Test
54     public void testPathComputationRequestNoPath() {
55         Response response = new ResponseBuilder()
56                 .withKey(new ResponseKey("responseId")).setResponseType(new NoPathCaseBuilder()
57                 .setNoPath(new NoPathBuilder().setNoPath("no path").build()).build()).build();
58
59         pathComputationServiceImpl.generateGnpyResponse(response,"path");
60         Assert.assertNotNull(
61                 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
62
63     }
64
65     @Test
66     public void testPathComputationRequestPathCase() {
67         PathMetric pathMetric = new PathMetricBuilder()
68                 .setAccumulativeValue(Decimal64.valueOf("21"))
69                 .setMetricType(PathBandwidth.VALUE).build();
70         Response response = new ResponseBuilder()
71                 .withKey(new ResponseKey("responseId")).setResponseType(new PathCaseBuilder()
72                 .setPathProperties(new PathPropertiesBuilder().setPathMetric(Map.of(pathMetric.key(),pathMetric))
73                 .build()).build()).build();
74
75         pathComputationServiceImpl.generateGnpyResponse(response,"path");
76         Assert.assertNotNull(
77                 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
78
79     }
80
81     @Test
82     public void pathComputationRerouteRequestTest() {
83         pathComputationServiceImpl.generateGnpyResponse(null,"path");
84         Assert.assertNotNull(pathComputationServiceImpl
85                 .pathComputationRerouteRequest(PceTestData.getPCEReroute()));
86
87     }
88
89     @After
90     public void destroy() {
91         pathComputationServiceImpl.close();
92     }
93 }