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