Unit tests
[vid.git] / vid-app-common / src / test / java / org / onap / vid / asdc / RestfulClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID ASDC Client
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.asdc;
22
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.net.URI;
26 import java.net.URISyntaxException;
27 import java.util.Properties;
28
29 import javax.net.ssl.HostnameVerifier;
30 import javax.net.ssl.SSLSession;
31 import javax.ws.rs.client.Client;
32 import javax.ws.rs.client.ClientBuilder;
33
34 import org.junit.Before;
35 import org.junit.Ignore;
36 import org.junit.Test;
37 import org.onap.vid.asdc.rest.RestfulAsdcClient;
38
39 /**
40  * The Class RestfulClientTest.
41  */
42 @Ignore
43 public class RestfulClientTest extends BaseClientTest {
44
45         /** The rest client. */
46         private Client restClient;
47         
48         /** The uri. */
49         private URI uri;
50         
51         /** The properties. */
52         private Properties properties;
53         
54         /** The auth. */
55         private String auth;
56         
57         /**
58          * Sets the up.
59          *
60          * @throws URISyntaxException the URI syntax exception
61          * @throws IOException Signals that an I/O exception has occurred.
62          */
63         @Before
64         public void setUp() throws URISyntaxException, IOException {
65                 final InputStream propertiesFile = getClass().getClassLoader().getResourceAsStream("asdc.properties");          
66                 
67                 properties = new Properties();
68                 properties.load(propertiesFile);
69                 
70                 final String protocol = properties.getProperty("protocol", "http");
71                 
72                 restClient = ClientBuilder.newBuilder()
73                                                 .hostnameVerifier(new HostnameVerifier() {
74
75                                                         @Override
76                                                         public boolean verify(String arg0, SSLSession arg1) {
77                                                                 return true;
78                                                         }
79                                                 })
80                                                 .build();
81                 uri = new URI(protocol + "://" + properties.getProperty("host", "localhost") + ":" + properties.getProperty("port", "80") + "/");
82                 auth = properties.getProperty("auth");
83         }
84
85         /**
86          * Test resources.
87          *
88          * @throws AsdcCatalogException the asdc catalog exception
89          */
90         @Test
91         public void testResources() throws AsdcCatalogException {
92                 
93                 runResourceTests(new RestfulAsdcClient.Builder(restClient, uri).auth(auth).build());
94         }
95         
96         /**
97          * Test services.
98          *
99          * @throws AsdcCatalogException the asdc catalog exception
100          * @throws URISyntaxException the URI syntax exception
101          */
102         @Test
103         public void testServices() throws AsdcCatalogException, URISyntaxException {
104
105                 runServiceTests(new RestfulAsdcClient.Builder(restClient, uri).auth(auth).build());
106         }
107 }