Thomas Vachuska
Committed by Gerrit Code Review

Restructuring the form of REST API deployment to provide

for security of app's REST APIs and for consistency of
exception mappers and JSON writer.

Change-Id: Id318372bf62f82ed974355c05e7fe64e0fbfc0c5
Showing 25 changed files with 399 additions and 151 deletions
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -13,23 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.rest.exceptions;
import org.junit.Test;
package org.onosproject.acl;
import static org.junit.Assert.*;
import org.onlab.rest.AbstractWebApplication;
import java.util.Set;
/**
* Set of tests for the various exception mappers.
* ACL REST API web application.
*/
public class ExceptionMapperTest {
@Test
public void emptyMessage() {
RuntimeException exception = new NullPointerException();
ServerErrorMapper mapper = new ServerErrorMapper();
Object response = mapper.toResponse(exception).getEntity();
assertTrue("incorrect response",
response.toString().contains("ExceptionMapperTest.emptyMessage("));
public class AclWebApplication extends AbstractWebApplication {
@Override
public Set<Class<?>> getClasses() {
return getClasses(AclWebResource.class);
}
}
......
......@@ -22,20 +22,35 @@
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="ONOS" version="2.5">
<display-name>ACL application</display-name>
<display-name>ACL application REST API</display-name>
<security-constraint>
<web-resource-collection>
<web-resource-name>Secured</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>admin</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>karaf</realm-name>
</login-config>
<servlet>
<servlet-name>JAX-RS Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.classnames</param-name>
<param-value>org.onosproject.acl.AclWebResource</param-value>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.onosproject.acl.AclWebApplication</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
......
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.dhcp.rest;
import org.onlab.rest.AbstractWebApplication;
import java.util.Set;
/**
* DHCP Web application.
*/
public class DhcpWebApplication extends AbstractWebApplication {
@Override
public Set<Class<?>> getClasses() {
return getClasses(DhcpWebResource.class);
}
}
......@@ -44,7 +44,7 @@ import java.util.Map;
@Path("dhcp")
public class DhcpWebResource extends AbstractWebResource {
final DhcpService service = get(DhcpService.class);
private final DhcpService service = get(DhcpService.class);
/**
* Get DHCP server configuration data.
......@@ -56,12 +56,11 @@ public class DhcpWebResource extends AbstractWebResource {
@GET
@Path("config")
public Response getConfigs() {
DhcpService service = get(DhcpService.class);
ObjectNode node = mapper().createObjectNode()
.put("leaseTime", service.getLeaseTime())
.put("renewalTime", service.getRenewalTime())
.put("rebindingTime", service.getRebindingTime());
return ok(node.toString()).build();
return ok(node).build();
}
/**
......@@ -76,13 +75,13 @@ public class DhcpWebResource extends AbstractWebResource {
public Response listMappings() {
ObjectNode root = mapper().createObjectNode();
final Map<HostId, IpAssignment> intents = service.listMapping();
Map<HostId, IpAssignment> intents = service.listMapping();
ArrayNode arrayNode = root.putArray("mappings");
intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
.put("host", i.getKey().toString())
.put("ip", i.getValue().ipAddress().toString())));
return ok(root.toString()).build();
return ok(root).build();
}
......@@ -96,12 +95,11 @@ public class DhcpWebResource extends AbstractWebResource {
@GET
@Path("available")
public Response listAvailableIPs() {
final Iterable<Ip4Address> availableIPList = service.getAvailableIPs();
final ObjectNode root = mapper().createObjectNode();
Iterable<Ip4Address> availableIPList = service.getAvailableIPs();
ObjectNode root = mapper().createObjectNode();
ArrayNode arrayNode = root.putArray("availableIP");
availableIPList.forEach(i -> arrayNode.add(i.toString()));
return ok(root.toString()).build();
return ok(root).build();
}
/**
......@@ -139,7 +137,7 @@ public class DhcpWebResource extends AbstractWebResource {
} catch (IOException e) {
throw new IllegalArgumentException(e.getMessage());
}
return ok(root.toString()).build();
return ok(root).build();
}
/**
......@@ -152,7 +150,6 @@ public class DhcpWebResource extends AbstractWebResource {
@DELETE
@Path("mappings/{macID}")
public Response deleteMapping(@PathParam("macID") String macID) {
ObjectNode root = mapper().createObjectNode();
if (!service.removeStaticMapping(MacAddress.valueOf(macID))) {
......@@ -164,6 +161,6 @@ public class DhcpWebResource extends AbstractWebResource {
.put("host", i.getKey().toString())
.put("ip", i.getValue().ipAddress().toString())));
return ok(root.toString()).build();
return ok(root).build();
}
}
......
......@@ -14,24 +14,38 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="ONOS" version="2.5">
<display-name>DHCP Server REST API v1.0</display-name>
<security-constraint>
<web-resource-collection>
<web-resource-name>Secured</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>admin</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>karaf</realm-name>
</login-config>
<servlet>
<servlet-name>JAX-RS Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.classnames</param-name>
<param-value>
org.onosproject.dhcp.rest.DhcpWebResource
</param-value>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.onosproject.dhcp.rest.DhcpWebApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
......
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.vtnweb.resources;
import org.onlab.rest.AbstractWebApplication;
import java.util.Set;
/**
* VTN REST API web application.
*/
public class VtnWebApplication extends AbstractWebApplication {
@Override
public Set<Class<?>> getClasses() {
return getClasses(TenantNetworkWebResource.class,
SubnetWebResource.class,
VirtualPortWebResource.class,
FlowClassifierWebResource.class,
PortChainWebResource.class,
PortPairGroupWebResource.class,
PortPairWebResource.class,
FloatingIpWebResource.class,
RouterWebResource.class);
}
}
......@@ -42,41 +42,17 @@
-->
<servlet>
<servlet-name>VTNRSC JAX-RS Service</servlet-name>
<servlet-name>JAX-RS Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.classnames</param-name>
<param-value>
org.onosproject.rest.exceptions.EntityNotFoundMapper,
org.onosproject.rest.exceptions.ServiceNotFoundMapper,
org.onosproject.rest.exceptions.NotFoundMapper,
org.onosproject.rest.exceptions.ServerErrorMapper,
org.onosproject.rest.exceptions.BadRequestMapper,
org.onosproject.rest.exceptions.WebApplicationExceptionMapper,
org.onosproject.rest.exceptions.IllegalArgumentExceptionMapper,
org.onosproject.rest.exceptions.IllegalStateExceptionMapper,
org.onosproject.rest.resources.JsonBodyWriter,
org.onosproject.vtnweb.resources.TenantNetworkWebResource,
org.onosproject.vtnweb.resources.SubnetWebResource,
org.onosproject.vtnweb.resources.VirtualPortWebResource,
org.onosproject.vtnweb.resources.FlowClassifierWebResource,
org.onosproject.vtnweb.resources.PortChainWebResource,
org.onosproject.vtnweb.resources.PortPairGroupWebResource,
org.onosproject.vtnweb.resources.PortPairWebResource,
org.onosproject.vtnweb.resources.FloatingIpWebResource,
org.onosproject.vtnweb.resources.RouterWebResource
</param-value>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.onosproject.vtnweb.resources.VtnWebApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>VTNRSC JAX-RS Service</servlet-name>
<servlet-name>JAX-RS Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
......
......@@ -33,6 +33,25 @@
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-misc</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-osgi</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<scope>test</scope>
......@@ -42,12 +61,6 @@
<artifactId>jersey-test-framework-grizzly2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-osgi</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
......
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onlab.rest;
import com.google.common.collect.ImmutableSet;
import org.onlab.rest.exceptions.BadRequestMapper;
import org.onlab.rest.exceptions.EntityNotFoundMapper;
import org.onlab.rest.exceptions.IllegalArgumentExceptionMapper;
import org.onlab.rest.exceptions.IllegalStateExceptionMapper;
import org.onlab.rest.exceptions.NotFoundMapper;
import org.onlab.rest.exceptions.ServerErrorMapper;
import org.onlab.rest.exceptions.ServiceNotFoundMapper;
import org.onlab.rest.exceptions.WebApplicationExceptionMapper;
import javax.ws.rs.core.Application;
import java.util.Set;
/**
* Base web application.
*/
public abstract class AbstractWebApplication extends Application {
/**
* Returns the aggregate set of resources, writers and mappers combined
* with a default set of such web entities.
*
* @param classes set of resources, writers and mappers
* @return combined set of web entities
*/
protected Set<Class<?>> getClasses(Class<?>... classes) {
ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder();
builder.add(ServiceNotFoundMapper.class,
EntityNotFoundMapper.class,
NotFoundMapper.class,
ServerErrorMapper.class,
BadRequestMapper.class,
WebApplicationExceptionMapper.class,
IllegalArgumentExceptionMapper.class,
IllegalStateExceptionMapper.class,
JsonBodyWriter.class);
builder.add(classes);
return builder.build();
}
@Override
public abstract Set<Class<?>> getClasses();
}
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onlab.rest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
/**
* JAX-RS Response message body writer.
*/
@Provider
@Produces("application/json")
public class JsonBodyWriter implements MessageBodyWriter<ObjectNode> {
private ObjectMapper mapper = new ObjectMapper();
@Override
public boolean isWriteable(Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
return type == ObjectNode.class;
}
@Override
public long getSize(ObjectNode node, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
return -1;
}
@Override
public void writeTo(ObjectNode node, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException {
mapper.writer().writeValue(entityStream, node);
entityStream.flush();
}
}
......@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.rest.exceptions;
package org.onlab.rest.exceptions;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
......
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.rest.exceptions;
package org.onlab.rest.exceptions;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
/**
......
......@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.rest.exceptions;
package org.onlab.rest.exceptions;
import org.onlab.util.ItemNotFoundException;
......
......@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.rest.exceptions;
package org.onlab.rest.exceptions;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
......
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.rest.exceptions;
package org.onlab.rest.exceptions;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
......
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.rest.exceptions;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
package org.onlab.rest.exceptions;
import com.sun.jersey.api.NotFoundException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
/**
* Mapper for api not found exceptions to the NOT_FOUND response code.
*/
......
......@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.rest.exceptions;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
package org.onlab.rest.exceptions;
import org.slf4j.Logger;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
import static org.slf4j.LoggerFactory.getLogger;
/**
......
......@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.rest.exceptions;
package org.onlab.rest.exceptions;
import org.onlab.osgi.ServiceNotFoundException;
......
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.rest.exceptions;
package org.onlab.rest.exceptions;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
......
/*
* Copyright 2014 Open Networking Laboratory
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,4 +17,4 @@
/**
* Various exception mappers to map errors to proper response status codes.
*/
package org.onosproject.rest.exceptions;
package org.onlab.rest.exceptions;
......
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.rest.resources;
import org.onlab.rest.AbstractWebApplication;
import java.util.Set;
/**
* Core REST APIs web application.
*/
public class CoreWebApplication extends AbstractWebApplication {
@Override
public Set<Class<?>> getClasses() {
return getClasses(ApiDocResource.class,
ApplicationsWebResource.class,
ComponentConfigWebResource.class,
NetworkConfigWebResource.class,
ClusterWebResource.class,
DevicesWebResource.class,
LinksWebResource.class,
HostsWebResource.class,
IntentsWebResource.class,
FlowsWebResource.class,
TopologyWebResource.class,
ConfigWebResource.class,
PathsWebResource.class,
StatisticsWebResource.class
);
}
}
......@@ -45,37 +45,8 @@
<servlet-name>JAX-RS Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.classnames</param-name>
<param-value>
org.onosproject.rest.exceptions.EntityNotFoundMapper,
org.onosproject.rest.exceptions.ServiceNotFoundMapper,
org.onosproject.rest.exceptions.NotFoundMapper,
org.onosproject.rest.exceptions.ServerErrorMapper,
org.onosproject.rest.exceptions.BadRequestMapper,
org.onosproject.rest.exceptions.WebApplicationExceptionMapper,
org.onosproject.rest.exceptions.IllegalArgumentExceptionMapper,
org.onosproject.rest.exceptions.IllegalStateExceptionMapper,
org.onosproject.rest.resources.JsonBodyWriter,
org.onosproject.rest.resources.ApiDocResource,
org.onosproject.rest.resources.ApplicationsWebResource,
org.onosproject.rest.resources.ComponentConfigWebResource,
org.onosproject.rest.resources.NetworkConfigWebResource,
org.onosproject.rest.resources.ClusterWebResource,
org.onosproject.rest.resources.DevicesWebResource,
org.onosproject.rest.resources.LinksWebResource,
org.onosproject.rest.resources.HostsWebResource,
org.onosproject.rest.resources.IntentsWebResource,
org.onosproject.rest.resources.FlowsWebResource,
org.onosproject.rest.resources.TopologyWebResource,
org.onosproject.rest.resources.ConfigWebResource,
org.onosproject.rest.resources.PathsWebResource,
org.onosproject.rest.resources.StatisticsWebResource
</param-value>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.onosproject.rest.resources.CoreWebApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
......
......@@ -15,13 +15,12 @@
*/
package org.onosproject.rest;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.util.Collections;
import java.util.HashSet;
import javax.ws.rs.core.MediaType;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonValue;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
import org.hamcrest.Description;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
......@@ -44,24 +43,16 @@ import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.rest.resources.CoreWebApplication;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonValue;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
import javax.ws.rs.core.MediaType;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.util.Collections;
import java.util.HashSet;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.easymock.EasyMock.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.onosproject.net.intent.IntentTestsMocks.MockIntent;
......@@ -76,6 +67,10 @@ public class IntentsResourceTest extends ResourceTest {
private static final ApplicationId APP_ID = new DefaultApplicationId(1, "test");
private IdGenerator mockGenerator;
public IntentsResourceTest() {
super(CoreWebApplication.class);
}
private class MockResource implements NetworkResource {
int id;
......
......@@ -18,6 +18,7 @@ package org.onosproject.rest;
import java.io.IOException;
import java.net.ServerSocket;
import com.sun.jersey.spi.container.servlet.ServletContainer;
import com.sun.jersey.test.framework.AppDescriptor;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.WebAppDescriptor;
......@@ -28,6 +29,23 @@ import com.sun.jersey.test.framework.WebAppDescriptor;
public class ResourceTest extends JerseyTest {
/**
* Creates a new web-resource test.
*/
public ResourceTest() {
super();
}
/**
* Creates a new web-resource test initialized according to the specified
* web application class.
*/
protected ResourceTest(Class<?> webAppClass) {
super(new WebAppDescriptor.Builder("javax.ws.rs.Application",
webAppClass.getCanonicalName())
.servletClass(ServletContainer.class).build());
}
/**
* Assigns an available port for the test.
*
* @param defaultPort If a port cannot be determined, this one is used.
......
......@@ -189,6 +189,10 @@ public class NetworkConfigWebResourceTest extends ResourceTest {
}
}
public NetworkConfigWebResourceTest() {
super(CoreWebApplication.class);
}
/**
* Sets up mocked config service.
*/
......