AT&T 1712 and 1802 release code
[so.git] / common / src / test / java / org / openecomp / mso / client / aai / AAIResourcesClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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.openecomp.mso.client.aai;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
25 import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
26 import static com.github.tomakehurst.wiremock.client.WireMock.get;
27 import static com.github.tomakehurst.wiremock.client.WireMock.put;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
29 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
30 import static org.junit.Assert.assertEquals;
31
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri;
35 import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory;
36
37 import com.github.tomakehurst.wiremock.junit.WireMockRule;
38 public class AAIResourcesClientTest {
39
40         
41         
42         @Rule
43         public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443));
44         
45         @Test
46         public void verifyNotExists() {
47                 AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
48                 wireMockRule.stubFor(get(
49                                 urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString()))
50                                 .willReturn(
51                                         aResponse()
52                                         .withHeader("Content-Type", "text/plain")
53                                         .withBody("hello")
54                                         .withStatus(404)));
55                 AAIResourcesClient client = new AAIResourcesClient();
56                 boolean result = client.exists(path);
57                 assertEquals("path not found", false, result);
58         }
59         
60         @Test
61         public void verifyDelete() {
62                 AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
63                 wireMockRule.stubFor(get(
64                                 urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString()))
65                                 .willReturn(
66                                         aResponse()
67                                         .withHeader("Content-Type", "application/json")
68                                         .withBodyFile("aai/resources/mockObject.json")
69                                         .withStatus(200)));
70                 wireMockRule.stubFor(delete(
71                                 urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString()))
72                                 .withQueryParam("resource-version", equalTo("1234"))
73                                 .willReturn(
74                                         aResponse()
75                                         .withStatus(204)));
76                 AAIResourcesClient client = new AAIResourcesClient();
77                 client.delete(path);
78         }
79         
80         @Test
81         public void verifyConnect() {
82                 AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
83                 AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
84                 wireMockRule.stubFor(put(
85                                 urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString() + "/relationship-list/relationship"))
86                                 .willReturn(
87                                         aResponse()
88                                         .withHeader("Content-Type", "application/json")
89                                         .withStatus(200)));
90                 
91                 AAIResourceUri pathClone = path.clone();
92                 AAIResourcesClient client = new AAIResourcesClient();
93                 client.connect(path, path2);
94                 assertEquals("uri not modified", pathClone.build().toString(), path.build().toString());
95         }
96 }