2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.client.aai;
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;
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;
37 import com.github.tomakehurst.wiremock.junit.WireMockRule;
38 public class AAIResourcesClientTest {
43 public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443));
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()))
52 .withHeader("Content-Type", "text/plain")
55 AAIResourcesClient client = new AAIResourcesClient();
56 boolean result = client.exists(path);
57 assertEquals("path not found", false, result);
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()))
67 .withHeader("Content-Type", "application/json")
68 .withBodyFile("aai/resources/mockObject.json")
70 wireMockRule.stubFor(delete(
71 urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString()))
72 .withQueryParam("resource-version", equalTo("1234"))
76 AAIResourcesClient client = new AAIResourcesClient();
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"))
88 .withHeader("Content-Type", "application/json")
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());