New API for GNPy
[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.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;
34
35 public class PathComputationServiceImplTest extends AbstractTest {
36
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();
43
44     @Before
45     public void setUp() {
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();
53     }
54
55     @Test
56     public void pathComputationRequestTest() {
57         pathComputationServiceImpl.generateGnpyResponse(null,"path");
58         Assert.assertNotNull(
59                 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_simpletopology_test1_request()));
60
61     }
62
63     @Test
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();
68
69         pathComputationServiceImpl.generateGnpyResponse(response,"path");
70         Assert.assertNotNull(
71                 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
72
73     }
74
75     @Test
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();
84
85         pathComputationServiceImpl.generateGnpyResponse(response,"path");
86         Assert.assertNotNull(
87                 pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54()));
88
89     }
90
91     @After
92     public void destroy() {
93         pathComputationServiceImpl.close();
94     }
95 }