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.Ignore;
25 import org.junit.Test;
28 public class ConnectToGnpyServerTest extends JerseyTest {
30 //we must hardcode port because it's hardcoded in ConnectToGnpyServer
31 System.setProperty("jersey.config.test.container.port", "8008");
35 protected Application configure() {
36 return new ResourceConfig(GnpyStub.class);
40 public void isGnpyURLExistTest() throws GnpyException, IOException {
41 ConnectToGnpyServer connectToGnpy = new ConnectToGnpyServer();
42 assertTrue(connectToGnpy.isGnpyURLExist());
46 public void returnGnpyResponseTest() throws GnpyException, IOException {
47 ConnectToGnpyServer connectToGnpy = new ConnectToGnpyServer();
48 String result = connectToGnpy.returnGnpyResponse(Files.readString(
49 Paths.get("src", "test", "resources", "gnpy", "gnpy_request.json"), StandardCharsets.US_ASCII));
50 assertNotNull("result should not be null", result);
51 assertTrue("Result should not be empty", !result.isEmpty());
55 public void readResponseTest() throws GnpyException {
56 InputStream anyInputStream = new ByteArrayInputStream("test data".getBytes());
57 ConnectToGnpyServer connectToGnpy = new ConnectToGnpyServer();
58 String result = connectToGnpy.readResponse(new InputStreamReader(anyInputStream));
59 Assert.assertNotNull(result);