GNPy client refactor
[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.math.BigDecimal;
11 import java.util.Map;
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.rev200909.PathBandwidth;
25 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.generic.path.properties.PathPropertiesBuilder;
26 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.generic.path.properties.path.properties.PathMetric;
27 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.generic.path.properties.path.properties.PathMetricBuilder;
28 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.no.path.info.NoPathBuilder;
29 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.Response;
30 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.ResponseBuilder;
31 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.ResponseKey;
32 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.response.response.type.NoPathCaseBuilder;
33 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.result.response.response.type.PathCaseBuilder;
34 import org.opendaylight.yangtools.yang.common.Uint32;
35
36 public class PathComputationServiceImplTest extends AbstractTest {
37
38     private PathComputationServiceImpl pathComputationServiceImpl;
39     private static NetworkTransactionService networkTransactionService = null;
40     private static GnpyTopoImpl gnpyTopoImpl = null;
41     private static GnpyResult gnpyResult = null;
42     private DataStoreContext dataStoreContext = this.getDataStoreContextUtil();
43     private DataBroker dataBroker = this.getDataBroker();
44
45     @Before
46     public void setUp() {
47         networkTransactionService = Mockito.mock(NetworkTransactionService.class);
48         gnpyTopoImpl = Mockito.mock(GnpyTopoImpl.class);
49         gnpyResult = Mockito.mock(GnpyResult.class);
50         pathComputationServiceImpl = new PathComputationServiceImpl(
51                 networkTransactionService,
52                 this.getNotificationPublishService(), null);
53         pathComputationServiceImpl.init();
54     }
55
56     @Test
57     public void pathComputationRequestTest() {
58         pathComputationServiceImpl.generateGnpyResponse(null,"path");
59         Assert.assertNotNull(
60                 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_simpletopology_test1_request()));
61
62     }
63
64     @Test
65     public void testPathComputationRequestNoPath() {
66         Response response = new ResponseBuilder()
67                 .withKey(new ResponseKey(Uint32.valueOf(1))).setResponseType(new NoPathCaseBuilder()
68                 .setNoPath(new NoPathBuilder().setNoPath("no path").build()).build()).build();
69
70         pathComputationServiceImpl.generateGnpyResponse(response,"path");
71         Assert.assertNotNull(
72                 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
73
74     }
75
76     @Test
77     public void testPathComputationRequestPathCase() {
78         PathMetric pathMetric = new PathMetricBuilder()
79                 .setAccumulativeValue(new BigDecimal(21))
80                 .setMetricType(PathBandwidth.class).build();
81         Response response = new ResponseBuilder()
82                 .withKey(new ResponseKey(Uint32.valueOf(1))).setResponseType(new PathCaseBuilder()
83                 .setPathProperties(new PathPropertiesBuilder().setPathMetric(Map.of(pathMetric.key(),pathMetric))
84                 .build()).build()).build();
85
86         pathComputationServiceImpl.generateGnpyResponse(response,"path");
87         Assert.assertNotNull(
88                 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
89
90     }
91
92     @After
93     public void destroy() {
94         pathComputationServiceImpl.close();
95     }
96 }