Ray Milkey | 9c3d336 | 2015-01-28 10:39:56 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Ray Milkey | 9c3d336 | 2015-01-28 10:39:56 -0800 | [diff] [blame] | 3 | * |
| 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 Li | 8ae9120 | 2016-03-24 14:36:16 -0700 | [diff] [blame] | 16 | package org.onosproject.rest.resources; |
Ray Milkey | 9c3d336 | 2015-01-28 10:39:56 -0800 | [diff] [blame] | 17 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 18 | import org.glassfish.jersey.server.ResourceConfig; |
| 19 | import org.glassfish.jersey.test.JerseyTest; |
HIGUCHI Yuta | 6827dc3 | 2016-05-28 10:34:28 -0700 | [diff] [blame] | 20 | import org.glassfish.jersey.test.TestProperties; |
Jian Li | 4fb7177 | 2016-04-20 09:41:56 -0700 | [diff] [blame] | 21 | import org.glassfish.jersey.test.jetty.JettyTestContainerFactory; |
| 22 | import org.glassfish.jersey.test.spi.TestContainerException; |
| 23 | import org.glassfish.jersey.test.spi.TestContainerFactory; |
Ray Milkey | 094a135 | 2018-01-22 14:03:54 -0800 | [diff] [blame] | 24 | import org.onlab.junit.TestUtils; |
| 25 | import org.onlab.osgi.ServiceDirectory; |
| 26 | import org.onlab.rest.BaseResource; |
Ray Milkey | 9c3d336 | 2015-01-28 10:39:56 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
Jian Li | 4fb7177 | 2016-04-20 09:41:56 -0700 | [diff] [blame] | 29 | * Base class for REST API tests. |
| 30 | * Performs common configuration operations. |
Ray Milkey | 9c3d336 | 2015-01-28 10:39:56 -0800 | [diff] [blame] | 31 | */ |
| 32 | public class ResourceTest extends JerseyTest { |
| 33 | |
| 34 | /** |
Thomas Vachuska | a026be7 | 2015-12-07 16:00:37 -0800 | [diff] [blame] | 35 | * Creates a new web-resource test. |
| 36 | */ |
| 37 | public ResourceTest() { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 38 | super(ResourceConfig.forApplicationClass(CoreWebApplication.class)); |
HIGUCHI Yuta | 6827dc3 | 2016-05-28 10:34:28 -0700 | [diff] [blame] | 39 | configureProperties(); |
Jian Li | 7ff7978 | 2016-03-28 10:27:22 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /** |
Ray Milkey | 7c25182 | 2016-04-06 17:38:25 -0700 | [diff] [blame] | 43 | * Creates a new web-resource test. |
| 44 | */ |
| 45 | public ResourceTest(ResourceConfig config) { |
| 46 | super(config); |
HIGUCHI Yuta | 6827dc3 | 2016-05-28 10:34:28 -0700 | [diff] [blame] | 47 | configureProperties(); |
Ray Milkey | 7c25182 | 2016-04-06 17:38:25 -0700 | [diff] [blame] | 48 | } |
| 49 | |
HIGUCHI Yuta | 6827dc3 | 2016-05-28 10:34:28 -0700 | [diff] [blame] | 50 | private void configureProperties() { |
| 51 | set(TestProperties.CONTAINER_PORT, 0); |
Thomas Vachuska | a026be7 | 2015-12-07 16:00:37 -0800 | [diff] [blame] | 52 | } |
Jian Li | 4fb7177 | 2016-04-20 09:41:56 -0700 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Configures the jetty test container as default test container. |
| 56 | * |
| 57 | * @return test container factory |
| 58 | * @throws TestContainerException |
| 59 | */ |
| 60 | @Override |
| 61 | protected TestContainerFactory getTestContainerFactory() throws TestContainerException { |
| 62 | return new JettyTestContainerFactory(); |
| 63 | } |
Ray Milkey | 094a135 | 2018-01-22 14:03:54 -0800 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Sets up the test services directory in the base resource environment. |
| 67 | * |
| 68 | * @param testDirectory new test directory |
| 69 | */ |
| 70 | protected void setServiceDirectory(ServiceDirectory testDirectory) { |
| 71 | TestUtils.setField(BaseResource.class, "services", testDirectory); |
| 72 | } |
Ray Milkey | 9c3d336 | 2015-01-28 10:39:56 -0800 | [diff] [blame] | 73 | } |