c1833bb759ae33ea4fa5ca97f22b8e8da710003c
[vid.git] / vid-app-common / src / test / java / org / onap / vid / asdc / rest / RestfulAsdcClientTest.java
1 package org.onap.vid.asdc.rest;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.net.URI;
6 import java.net.URISyntaxException;
7 import java.util.Collection;
8 import java.util.Map;
9 import java.util.Properties;
10 import java.util.UUID;
11
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;
16
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;
23
24 import nu.xom.Builder;
25
26 public class RestfulAsdcClientTest {
27
28     private RestfulAsdcClient createTestSubject() {
29         return new RestfulAsdcClient.Builder(restClient, uri).auth(auth)
30                 .build();
31     }
32
33     /** The rest client. */
34     private Client restClient;
35
36     /** The uri. */
37     private URI uri;
38
39     /** The properties. */
40     private Properties properties;
41
42     /** The auth. */
43     private String auth;
44
45     /**
46      * Sets the up.
47      *
48      * @throws URISyntaxException
49      *             the URI syntax exception
50      * @throws IOException
51      *             Signals that an I/O exception has occurred.
52      */
53     @Before
54     public void setUp() throws URISyntaxException, IOException {
55         final InputStream propertiesFile = getClass().getClassLoader()
56                 .getResourceAsStream("asdc.properties");
57
58         properties = new Properties();
59         properties.load(propertiesFile);
60
61         final String protocol = properties.getProperty("protocol", "http");
62
63         restClient = ClientBuilder.newBuilder()
64                 .hostnameVerifier(new HostnameVerifier() {
65
66                     @Override
67                     public boolean verify(String arg0, SSLSession arg1) {
68                         return true;
69                     }
70                 })
71                 .build();
72         uri = new URI(protocol + "://" + properties.getProperty("host", "localhost") + ":"
73                 + properties.getProperty("port", "80") + "/");
74         auth = properties.getProperty("auth");
75     }
76
77     @Test
78     public void testGetResource() throws Exception {
79         RestfulAsdcClient testSubject;
80         UUID uuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
81         Resource result;
82
83         // default test
84         testSubject = createTestSubject();
85         try {
86             result = testSubject.getResource(uuid);
87         } catch (Exception e) {
88
89         }
90     }
91
92     @Test
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");
97         Artifact result;
98
99         // default test
100         testSubject = createTestSubject();
101         try {
102             result = testSubject.getResourceArtifact(resourceUuid, artifactUuid);
103         } catch (Exception e) {
104
105         }
106     }
107
108     @Test
109     public void testGetResources() throws Exception {
110         RestfulAsdcClient testSubject;
111         Collection<Resource> result;
112
113         // default test
114         testSubject = createTestSubject();
115         try {
116             result = testSubject.getResources();
117         } catch (Exception e) {
118
119         }
120     }
121
122     @Test
123     public void testGetResources_1() throws Exception {
124         RestfulAsdcClient testSubject;
125         Map<String, String[]> filter = null;
126         Collection<Resource> result;
127
128         // default test
129         testSubject = createTestSubject();
130         try {
131             result = testSubject.getResources(filter);
132         } catch (Exception e) {
133
134         }
135     }
136
137     @Test
138     public void testGetResourceToscaModel() throws Exception {
139         RestfulAsdcClient testSubject;
140         UUID resourceUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
141
142         // default test
143         testSubject = createTestSubject();
144         try {
145             testSubject.getResourceToscaModel(resourceUuid);
146         } catch (Exception e) {
147
148         }
149     }
150
151     @Test
152     public void testGetService() throws Exception {
153         RestfulAsdcClient testSubject;
154         UUID uuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
155         Service result;
156
157         // default test
158         testSubject = createTestSubject();
159         try {
160             result = testSubject.getService(uuid);
161         } catch (Exception e) {
162
163         }
164     }
165
166     @Test
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");
171         Artifact result;
172
173         // default test
174         testSubject = createTestSubject();
175         try {
176             result = testSubject.getServiceArtifact(serviceUuid, artifactUuid);
177         } catch (Exception e) {
178
179         }
180     }
181
182     @Test
183     public void testGetServices() throws Exception {
184         RestfulAsdcClient testSubject;
185         Collection<Service> result;
186
187         // default test
188         testSubject = createTestSubject();
189         try {
190             result = testSubject.getServices();
191         } catch (Exception e) {
192
193         }
194     }
195
196     @Test
197     public void testGetServices_1() throws Exception {
198         RestfulAsdcClient testSubject;
199         Map<String, String[]> filter = null;
200         Collection<Service> result;
201
202         // default test
203         testSubject = createTestSubject();
204         try {
205             result = testSubject.getServices(filter);
206         } catch (Exception e) {
207
208         }
209     }
210
211     @Test
212     public void testGetServiceToscaModel() throws Exception {
213         RestfulAsdcClient testSubject;
214         UUID serviceUuid = UUID.fromString("123e4567-e89b-12d3-a456-556642440000");
215
216         // default test
217         testSubject = createTestSubject();
218         try {
219             testSubject.getServiceToscaModel(serviceUuid);
220         } catch (Exception e) {
221
222         }
223     }
224
225 }