blob: 4b95844d22158ae7773221940f5421d2746c2850 [file] [log] [blame]
Bharat saraswalf38e2262015-11-18 22:57:05 +05301/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.vtnweb.resources;
17
18import java.io.IOException;
19import java.net.ServerSocket;
20
21import com.sun.jersey.test.framework.AppDescriptor;
22import com.sun.jersey.test.framework.JerseyTest;
23import com.sun.jersey.test.framework.WebAppDescriptor;
24
25/**
26 * Base class for VTN REST API tests. Performs common configuration operations.
27 */
28public class VtnResourceTest extends JerseyTest {
29
30 /**
31 * Assigns an available port for the test.
32 *
33 * @param defaultPort If a port cannot be determined, this one is used.
34 * @return free port
35 */
36 @Override
37 public int getPort(int defaultPort) {
38 try {
39 ServerSocket socket = new ServerSocket(0);
40 socket.setReuseAddress(true);
41 int port = socket.getLocalPort();
42 socket.close();
43 return port;
44 } catch (IOException ioe) {
45 return defaultPort;
46 }
47 }
48
49 @Override
50 public AppDescriptor configure() {
51 return new WebAppDescriptor.Builder("org.onosproject.vtnweb.resources").build();
52 }
53
54}