1 package org.onap.vid.asdc.rest;
3 import java.io.IOException;
4 import java.io.InputStream;
6 import java.net.URISyntaxException;
7 import java.util.Collection;
9 import java.util.Properties;
10 import java.util.UUID;
12 import javax.net.ssl.HostnameVerifier;
13 import javax.net.ssl.SSLSession;
14 import javax.ws.rs.client.Client;
15 import javax.ws.rs.client.ClientBuilder;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.onap.vid.asdc.AsdcCatalogException;
20 import org.onap.vid.asdc.beans.Artifact;
21 import org.onap.vid.asdc.beans.Resource;
22 import org.onap.vid.asdc.beans.Service;
24 import nu.xom.Builder;
26 public class RestfulAsdcClientTest {
28 private RestfulAsdcClient createTestSubject() {
29 return new RestfulAsdcClient.Builder(restClient, uri).auth(auth)
33 /** The rest client. */
34 private Client restClient;
39 /** The properties. */
40 private Properties properties;
48 * @throws URISyntaxException
49 * the URI syntax exception
51 * Signals that an I/O exception has occurred.
54 public void setUp() throws URISyntaxException, IOException {
55 final InputStream propertiesFile = getClass().getClassLoader()
56 .getResourceAsStream("asdc.properties");
58 properties = new Properties();
59 properties.load(propertiesFile);
61 final String protocol = properties.getProperty("protocol", "http");
63 restClient = ClientBuilder.newBuilder()
64 .hostnameVerifier(new HostnameVerifier() {
67 public boolean verify(String arg0, SSLSession arg1) {
72 uri = new URI(protocol + "://" + properties.getProperty("host", "localhost") + ":"
73 + properties.getProperty("port", "80") + "/");
74 auth = properties.getProperty("auth");
78 public void testGetResource() throws Exception {
79 RestfulAsdcClient testSubject;
80 UUID uuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
84 testSubject = createTestSubject();
86 result = testSubject.getResource(uuid);
87 } catch (Exception e) {
93 public void testGetResourceArtifact() throws Exception {
94 RestfulAsdcClient testSubject;
95 UUID resourceUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
96 UUID artifactUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
100 testSubject = createTestSubject();
102 result = testSubject.getResourceArtifact(resourceUuid, artifactUuid);
103 } catch (Exception e) {
109 public void testGetResources() throws Exception {
110 RestfulAsdcClient testSubject;
111 Collection<Resource> result;
114 testSubject = createTestSubject();
116 result = testSubject.getResources();
117 } catch (Exception e) {
123 public void testGetResources_1() throws Exception {
124 RestfulAsdcClient testSubject;
125 Map<String, String[]> filter = null;
126 Collection<Resource> result;
129 testSubject = createTestSubject();
131 result = testSubject.getResources(filter);
132 } catch (Exception e) {
138 public void testGetResourceToscaModel() throws Exception {
139 RestfulAsdcClient testSubject;
140 UUID resourceUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
143 testSubject = createTestSubject();
145 testSubject.getResourceToscaModel(resourceUuid);
146 } catch (Exception e) {
152 public void testGetService() throws Exception {
153 RestfulAsdcClient testSubject;
154 UUID uuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
158 testSubject = createTestSubject();
160 result = testSubject.getService(uuid);
161 } catch (Exception e) {
167 public void testGetServiceArtifact() throws Exception {
168 RestfulAsdcClient testSubject;
169 UUID serviceUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
170 UUID artifactUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
174 testSubject = createTestSubject();
176 result = testSubject.getServiceArtifact(serviceUuid, artifactUuid);
177 } catch (Exception e) {
183 public void testGetServices() throws Exception {
184 RestfulAsdcClient testSubject;
185 Collection<Service> result;
188 testSubject = createTestSubject();
190 result = testSubject.getServices();
191 } catch (Exception e) {
197 public void testGetServices_1() throws Exception {
198 RestfulAsdcClient testSubject;
199 Map<String, String[]> filter = null;
200 Collection<Service> result;
203 testSubject = createTestSubject();
205 result = testSubject.getServices(filter);
206 } catch (Exception e) {
212 public void testGetServiceToscaModel() throws Exception {
213 RestfulAsdcClient testSubject;
214 UUID serviceUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
217 testSubject = createTestSubject();
219 testSubject.getServiceToscaModel(serviceUuid);
220 } catch (Exception e) {