GNPy stub for PCE
[transportpce.git] / pce / src / test / java / org / opendaylight / transportpce / pce / gnpy / ConnectToGnpyServerTest.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.gnpy;
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.charset.StandardCharsets;
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.Test;
21
22 public class ConnectToGnpyServerTest extends JerseyTest {
23     static {
24         //we must hardcode port because it's hardcoded in ConnectToGnpyServer
25         System.setProperty("jersey.config.test.container.port", "8008");
26     }
27
28     @Override
29     protected Application configure() {
30         return new ResourceConfig(GnpyStub.class);
31     }
32
33     @Test
34     public void isGnpyURLExistTest() throws GnpyException, IOException {
35         ConnectToGnpyServer connectToGnpy = new ConnectToGnpyServer();
36         assertTrue(connectToGnpy.isGnpyURLExist());
37     }
38
39     @Test
40     public void returnGnpyResponseTest() throws GnpyException, IOException {
41         ConnectToGnpyServer connectToGnpy = new ConnectToGnpyServer();
42         String result = connectToGnpy.returnGnpyResponse(Files.readString(
43                 Paths.get("src", "test", "resources", "gnpy", "gnpy_request.json"), StandardCharsets.US_ASCII));
44         assertNotNull("result should not be null", result);
45         assertTrue("Result should not be empty", !result.isEmpty());
46     }
47
48 }