Migrate pce module to JUnit5
[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 static org.junit.jupiter.api.Assertions.assertNotNull;
11
12 import java.util.Map;
13 import org.junit.jupiter.api.AfterEach;
14 import org.junit.jupiter.api.BeforeEach;
15 import org.junit.jupiter.api.Test;
16 import org.mockito.Mockito;
17 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
18 import org.opendaylight.transportpce.pce.utils.PceTestData;
19 import org.opendaylight.transportpce.test.AbstractTest;
20 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.PathBandwidth;
21 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.PathPropertiesBuilder;
22 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathMetric;
23 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathMetricBuilder;
24 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.no.path.info.NoPathBuilder;
25 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.Response;
26 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.ResponseBuilder;
27 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.ResponseKey;
28 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.NoPathCaseBuilder;
29 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.PathCaseBuilder;
30 import org.opendaylight.yangtools.yang.common.Decimal64;
31
32 public class PathComputationServiceImplTest extends AbstractTest {
33
34     private PathComputationServiceImpl pathComputationServiceImpl;
35     private static NetworkTransactionService networkTransactionService = null;
36
37     @BeforeEach
38     void setUp() {
39         networkTransactionService = Mockito.mock(NetworkTransactionService.class);
40         pathComputationServiceImpl = new PathComputationServiceImpl(
41                 networkTransactionService,
42                 this.getNotificationPublishService(), null, null);
43         pathComputationServiceImpl.init();
44     }
45
46     @Test
47     void pathComputationRequestTest() {
48         pathComputationServiceImpl.generateGnpyResponse(null,"path");
49         assertNotNull(
50             pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_simpletopology_test1_request()));
51     }
52
53     @Test
54     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         assertNotNull(pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
61     }
62
63     @Test
64     void testPathComputationRequestPathCase() {
65         PathMetric pathMetric = new PathMetricBuilder()
66                 .setAccumulativeValue(Decimal64.valueOf("21"))
67                 .setMetricType(PathBandwidth.VALUE).build();
68         Response response = new ResponseBuilder()
69                 .withKey(new ResponseKey("responseId")).setResponseType(new PathCaseBuilder()
70                 .setPathProperties(new PathPropertiesBuilder().setPathMetric(Map.of(pathMetric.key(),pathMetric))
71                 .build()).build()).build();
72
73         pathComputationServiceImpl.generateGnpyResponse(response,"path");
74         assertNotNull(pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
75     }
76
77     @Test
78     void pathComputationRerouteRequestTest() {
79         pathComputationServiceImpl.generateGnpyResponse(null,"path");
80         assertNotNull(pathComputationServiceImpl.pathComputationRerouteRequest(PceTestData.getPCEReroute()));
81     }
82
83     @AfterEach
84     void destroy() {
85         pathComputationServiceImpl.close();
86     }
87 }