Migrate pce module to JUnit5
[transportpce.git] / pce / src / test / java / org / opendaylight / transportpce / pce / gnpy / consumer / GnpyConsumerTest.java
1 /*
2  * Copyright © 2021 Orange, 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.gnpy.consumer;
9
10
11 import static org.junit.jupiter.api.Assertions.assertNotNull;
12 import static org.junit.jupiter.api.Assertions.assertTrue;
13
14 import java.io.IOException;
15 import java.nio.file.Files;
16 import java.nio.file.Paths;
17 import javax.ws.rs.core.Application;
18 import org.glassfish.jersey.server.ResourceConfig;
19 import org.glassfish.jersey.test.JerseyTest;
20 import org.junit.jupiter.api.Test;
21 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
22 import org.opendaylight.transportpce.test.AbstractTest;
23 import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.Request;
24 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.Result;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class GnpyConsumerTest extends JerseyTest {
32     private static final Logger LOG = LoggerFactory.getLogger(GnpyConsumerTest.class);
33     private JsonStringConverter<Request> gnpyApiConverter;
34
35     @Override
36     protected Application configure() {
37         gnpyApiConverter = new JsonStringConverter<>(
38                 AbstractTest.getDataStoreContextUtil().getBindingDOMCodecServices());
39         return new ResourceConfig(GnpyStub.class);
40     }
41
42     @Test
43     void isAvailableTest() {
44         GnpyConsumer gnpyConsumer = new GnpyConsumerImpl("http://localhost:9998",
45                 "mylogin",
46                 "mypassword",
47                 AbstractTest.getDataStoreContextUtil().getBindingDOMCodecServices());
48         assertTrue(gnpyConsumer.isAvailable(), "Gnpy should be available");
49     }
50
51     @Test
52     void computePathsTest() throws IOException {
53         GnpyConsumer gnpyConsumer = new GnpyConsumerImpl("http://localhost:9998",
54                 "mylogin",
55                 "mypassword",
56                 AbstractTest.getDataStoreContextUtil().getBindingDOMCodecServices());
57         QName pathQname = Request.QNAME;
58         YangInstanceIdentifier yangId = YangInstanceIdentifier.of(pathQname);
59         Request request = gnpyApiConverter
60                 .createDataObjectFromJsonString(yangId,
61                         Files.readString(Paths.get("src/test/resources/gnpy/gnpy_request.json")),
62                         JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02);
63         Result result = gnpyConsumer.computePaths(request);
64         LOG.info("Response received {}", result);
65         assertNotNull(result, "Result should not be null");
66     }
67 }