blob: 9ccf53f8c8283cf6836decd70c79e9be4e52fa75 [file] [log] [blame]
Ray Milkey9c3d3362015-01-28 10:39:56 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkey9c3d3362015-01-28 10:39:56 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jian Li8ae91202016-03-24 14:36:16 -070016package org.onosproject.rest.resources;
Ray Milkey9c3d3362015-01-28 10:39:56 -080017
Jian Li9d616492016-03-09 10:52:49 -080018import org.glassfish.jersey.server.ResourceConfig;
19import org.glassfish.jersey.test.JerseyTest;
HIGUCHI Yuta6827dc32016-05-28 10:34:28 -070020import org.glassfish.jersey.test.TestProperties;
Jian Li4fb71772016-04-20 09:41:56 -070021import org.glassfish.jersey.test.jetty.JettyTestContainerFactory;
22import org.glassfish.jersey.test.spi.TestContainerException;
23import org.glassfish.jersey.test.spi.TestContainerFactory;
Ray Milkey094a1352018-01-22 14:03:54 -080024import org.onlab.junit.TestUtils;
25import org.onlab.osgi.ServiceDirectory;
Thomas Vachuska67484d92018-07-17 11:51:54 -070026import org.onlab.rest.AuthorizationFilter;
arjunek1992f6353d42018-11-20 08:56:29 -050027import org.onlab.rest.AuditFilter;
Ray Milkey094a1352018-01-22 14:03:54 -080028import org.onlab.rest.BaseResource;
Ray Milkey9c3d3362015-01-28 10:39:56 -080029
30/**
Jian Li4fb71772016-04-20 09:41:56 -070031 * Base class for REST API tests.
32 * Performs common configuration operations.
Ray Milkey9c3d3362015-01-28 10:39:56 -080033 */
34public class ResourceTest extends JerseyTest {
35
36 /**
Thomas Vachuskaa026be72015-12-07 16:00:37 -080037 * Creates a new web-resource test.
38 */
39 public ResourceTest() {
Jian Li9d616492016-03-09 10:52:49 -080040 super(ResourceConfig.forApplicationClass(CoreWebApplication.class));
HIGUCHI Yuta6827dc32016-05-28 10:34:28 -070041 configureProperties();
Jian Li7ff79782016-03-28 10:27:22 -070042 }
43
44 /**
Ray Milkey7c251822016-04-06 17:38:25 -070045 * Creates a new web-resource test.
46 */
47 public ResourceTest(ResourceConfig config) {
48 super(config);
HIGUCHI Yuta6827dc32016-05-28 10:34:28 -070049 configureProperties();
Ray Milkey7c251822016-04-06 17:38:25 -070050 }
51
HIGUCHI Yuta6827dc32016-05-28 10:34:28 -070052 private void configureProperties() {
53 set(TestProperties.CONTAINER_PORT, 0);
Thomas Vachuska67484d92018-07-17 11:51:54 -070054 AuthorizationFilter.disableForTests();
arjunek1992f6353d42018-11-20 08:56:29 -050055 AuditFilter.disableForTests();
Thomas Vachuskaa026be72015-12-07 16:00:37 -080056 }
Jian Li4fb71772016-04-20 09:41:56 -070057
58 /**
59 * Configures the jetty test container as default test container.
60 *
61 * @return test container factory
62 * @throws TestContainerException
63 */
64 @Override
65 protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
66 return new JettyTestContainerFactory();
67 }
Ray Milkey094a1352018-01-22 14:03:54 -080068
69 /**
70 * Sets up the test services directory in the base resource environment.
71 *
72 * @param testDirectory new test directory
73 */
74 protected void setServiceDirectory(ServiceDirectory testDirectory) {
75 TestUtils.setField(BaseResource.class, "services", testDirectory);
76 }
Ray Milkey9c3d3362015-01-28 10:39:56 -080077}