2 * Copyright (c) 2015 Cisco Systems, 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
9 package org.opendaylight.groupbasedpolicy.renderer.restclient;
11 import javax.ws.rs.Consumes;
12 import javax.ws.rs.GET;
13 import javax.ws.rs.POST;
14 import javax.ws.rs.Path;
15 import javax.ws.rs.Produces;
16 import javax.ws.rs.core.MediaType;
17 import javax.ws.rs.core.Response;
18 import java.io.IOException;
20 import java.util.ArrayList;
21 import java.util.List;
23 import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory;
24 import com.sun.jersey.api.core.ClassNamesResourceConfig;
25 import com.sun.jersey.api.core.ResourceConfig;
26 import com.sun.jersey.test.framework.AppDescriptor;
27 import com.sun.jersey.test.framework.JerseyTest;
28 import com.sun.jersey.test.framework.WebAppDescriptor;
29 import org.glassfish.grizzly.http.server.HttpServer;
30 import org.junit.AfterClass;
31 import org.junit.Before;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.opendaylight.groupbasedpolicy.renderer.iovisor.restclient.RestClient;
36 public class RestClientTest extends JerseyTest {
38 private RestClient client;
40 private static String resolvedPolicy =
41 " { \"resolved-policy-uri\" : \"/restconf/operational/resolved-policy:resolved-policies/resolved-policy/tenant-red/client/tenant-red/webserver/\" } ";
43 private static final String BASE_URI = "http://localhost";
44 private static final int BASE_PORT = 1234;
45 private static HttpServer server;
47 private static HttpServer startServer() throws IOException {
48 final ResourceConfig resourceConfig = new ClassNamesResourceConfig(dumbServer.class);
49 HttpServer httpServer = null;
50 httpServer = GrizzlyServerFactory.createHttpServer(URI.create(BASE_URI + ":" + BASE_PORT), resourceConfig);
55 public static void setUpClass() throws IOException {
56 server = startServer();
60 public static void tearDownClass() {
61 if (server != null && server.isStarted())
67 client = new RestClient("http://localhost:1234");
71 public void testResolvedPoliciesJSON_coverage() {
72 client.new ResolvedPoliciesJSON("string");
74 List<String> uris = new ArrayList<>();
77 client.new ResolvedPoliciesJSON(uris);
81 public void testGet_coverage() {
83 client.get("/warning");
88 public void testPost_coverage() {
89 client.post("/", "json");
93 protected AppDescriptor configure() {
94 return new WebAppDescriptor.Builder().build();
98 public static class dumbServer {
101 @Produces(MediaType.APPLICATION_JSON)
102 public Response get200() {
103 return Response.status(Response.Status.OK).entity(resolvedPolicy).build();
107 @Consumes(MediaType.APPLICATION_JSON)
108 public Response post200(String json) {
109 return Response.status(Response.Status.OK).build();
114 public Response get202() {
115 return Response.status(Response.Status.ACCEPTED).build();
120 public Response get404() {
121 return Response.status(Response.Status.NOT_FOUND).build();