X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fservice%2FPathComputationServiceImplTest.java;h=4408d094ed0e3ff4f726888a2ba29f067a1e55b6;hb=2627d1efc45aaf7d30dc6b9b33a2e5a22728a531;hp=b7ccf9183314c6424413b45928483ba772d4d9dd;hpb=e631441244bd5437554d1f85ff4b591ed4a54e7a;p=transportpce.git diff --git a/pce/src/test/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImplTest.java b/pce/src/test/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImplTest.java index b7ccf9183..4408d094e 100644 --- a/pce/src/test/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImplTest.java +++ b/pce/src/test/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImplTest.java @@ -7,49 +7,74 @@ */ package org.opendaylight.transportpce.pce.service; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.transportpce.common.network.NetworkTransactionImpl; -import org.opendaylight.transportpce.common.network.RequestProcessor; -import org.opendaylight.transportpce.pce.gnpy.GnpyResult; -import org.opendaylight.transportpce.pce.gnpy.GnpyTopoImpl; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.util.Map; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.opendaylight.transportpce.common.network.NetworkTransactionService; import org.opendaylight.transportpce.pce.utils.PceTestData; import org.opendaylight.transportpce.test.AbstractTest; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.PathBandwidth; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.PathPropertiesBuilder; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathMetric; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathMetricBuilder; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.no.path.info.NoPathBuilder; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.Response; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.ResponseBuilder; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.ResponseKey; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.NoPathCaseBuilder; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.PathCaseBuilder; +import org.opendaylight.yangtools.yang.common.Decimal64; public class PathComputationServiceImplTest extends AbstractTest { private PathComputationServiceImpl pathComputationServiceImpl; + private static NetworkTransactionService networkTransactionService = null; - @Before - public void setUp() { + @BeforeEach + void setUp() { + networkTransactionService = Mockito.mock(NetworkTransactionService.class); pathComputationServiceImpl = new PathComputationServiceImpl( - new NetworkTransactionImpl(new RequestProcessor(this.getDataBroker())), - this.getNotificationPublishService()); - pathComputationServiceImpl.init(); + networkTransactionService, + this.getNotificationPublishService(), null, null); } @Test - public void pathComputationRequestTest() { - Assert.assertNotNull( - pathComputationServiceImpl.pathComputationRequest(PceTestData.getEmptyPCERequest())); - + void pathComputationRequestTest() { + pathComputationServiceImpl.generateGnpyResponse(null,"path"); + assertNotNull( + pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_simpletopology_test1_request())); } - @Test(expected = Exception.class) - public void generateGnpyResponse() throws Exception { + @Test + void testPathComputationRequestNoPath() { + Response response = new ResponseBuilder() + .withKey(new ResponseKey("responseId")).setResponseType(new NoPathCaseBuilder() + .setNoPath(new NoPathBuilder().setNoPath("no path").build()).build()).build(); - GnpyResult gnpyResult = - new GnpyResult("A-to-Z", - new GnpyTopoImpl(new NetworkTransactionImpl( - new RequestProcessor(this.getNewDataBroker())))); - pathComputationServiceImpl.generateGnpyResponse(gnpyResult.getResponse(), "A-to-Z"); + pathComputationServiceImpl.generateGnpyResponse(response,"path"); + assertNotNull(pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54())); } + @Test + void testPathComputationRequestPathCase() { + PathMetric pathMetric = new PathMetricBuilder() + .setAccumulativeValue(Decimal64.valueOf("21")) + .setMetricType(PathBandwidth.VALUE).build(); + Response response = new ResponseBuilder() + .withKey(new ResponseKey("responseId")).setResponseType(new PathCaseBuilder() + .setPathProperties(new PathPropertiesBuilder().setPathMetric(Map.of(pathMetric.key(),pathMetric)) + .build()).build()).build(); - @After - public void destroy() { - pathComputationServiceImpl.close(); + pathComputationServiceImpl.generateGnpyResponse(response,"path"); + assertNotNull(pathComputationServiceImpl.pathComputationRequest(PceTestData.getPCE_test3_request_54())); + } + + @Test + void pathComputationRerouteRequestTest() { + pathComputationServiceImpl.generateGnpyResponse(null,"path"); + assertNotNull(pathComputationServiceImpl.pathComputationRerouteRequest(PceTestData.getPCEReroute())); } }