2 * Copyright © 2020 Orange Labs, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.pce.gnpy;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
13 import java.io.ByteArrayInputStream;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.InputStreamReader;
17 import java.nio.charset.StandardCharsets;
18 import java.nio.file.Files;
19 import java.nio.file.Paths;
20 import javax.ws.rs.core.Application;
21 import org.glassfish.jersey.server.ResourceConfig;
22 import org.glassfish.jersey.test.JerseyTest;
23 import org.junit.Assert;
24 import org.junit.Test;
26 public class ConnectToGnpyServerTest extends JerseyTest {
28 //we must hardcode port because it's hardcoded in ConnectToGnpyServer
29 System.setProperty("jersey.config.test.container.port", "8008");
33 protected Application configure() {
34 return new ResourceConfig(GnpyStub.class);
38 public void isGnpyURLExistTest() throws GnpyException, IOException {
39 ConnectToGnpyServer connectToGnpy = new ConnectToGnpyServer();
40 assertTrue(connectToGnpy.isGnpyURLExist());
44 public void returnGnpyResponseTest() throws GnpyException, IOException {
45 ConnectToGnpyServer connectToGnpy = new ConnectToGnpyServer();
46 String result = connectToGnpy.returnGnpyResponse(Files.readString(
47 Paths.get("src", "test", "resources", "gnpy", "gnpy_request.json"), StandardCharsets.US_ASCII));
48 assertNotNull("result should not be null", result);
49 assertTrue("Result should not be empty", !result.isEmpty());
53 public void readResponseTest() throws GnpyException {
54 InputStream anyInputStream = new ByteArrayInputStream("test data".getBytes());
55 ConnectToGnpyServer connectToGnpy = new ConnectToGnpyServer();
56 String result = connectToGnpy.readResponse(new InputStreamReader(anyInputStream));
57 Assert.assertNotNull(result);