2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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.onap.aai.rest;
23 import static org.junit.Assert.assertEquals;
25 import com.jayway.jsonpath.JsonPath;
27 import java.io.IOException;
28 import java.io.UnsupportedEncodingException;
29 import java.util.Arrays;
30 import java.util.Collection;
32 import javax.ws.rs.core.Response;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.junit.runners.Parameterized;
39 import org.onap.aai.AAISetup;
40 import org.onap.aai.HttpTestUtil;
41 import org.onap.aai.PayloadUtil;
42 import org.onap.aai.exceptions.AAIException;
43 import org.onap.aai.serialization.engines.QueryStyle;
44 import org.skyscreamer.jsonassert.JSONAssert;
45 import org.springframework.test.annotation.DirtiesContext;
47 @RunWith(value = Parameterized.class)
48 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
49 public class ModelElementTest extends AAISetup {
51 private HttpTestUtil httpTestUtil;
53 @Parameterized.Parameter(value = 0)
54 public QueryStyle queryStyle;
56 private String modelPayload;
57 private String modelElementPayload;
59 private String modelUri;
60 private String modelElementUri;
62 @Parameterized.Parameters(name = "QueryStyle.{0}")
63 public static Collection<Object[]> data() {
64 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL_URI}});
68 public void setUp() throws IOException {
69 httpTestUtil = new HttpTestUtil(queryStyle);
70 modelPayload = PayloadUtil.getResourcePayload("model.json");
71 modelElementPayload = PayloadUtil.getResourcePayload("model-element.json");
72 modelUri = "/aai/v14/service-design-and-creation/models/model/24c04fc5-f3f8-43ec-8792-c6f940638676-test1";
74 "/aai/v14/service-design-and-creation/models/model/24c04fc5-f3f8-43ec-8792-c6f940638676-test1/model-vers/model-ver/0c4c59f0-9864-43ca-b0c2-ca38746b72a5-test1/model-elements/model-element/0dc2b8b6-af8d-4213-970b-7861a603fc86-test1/model-constraints/model-constraint/782ba24a-28ab-4fd0-8e69-da10cc5373f3-test1/constrained-element-sets/constrained-element-set/a33e65c3-1198-4d4c-9799-2b521e4c4212-test1/element-choice-sets/element-choice-set/7df27a94-06c8-46ef-9fc2-5900d8cffbb0-test1/model-elements/model-element/acf8b6cf-e051-4c1b-bcad-b24792f826cf-test1";
78 public void testPutModelAndThenModelElementAndItShouldSucceed() throws IOException, AAIException {
79 Response response = httpTestUtil.doPut(modelUri, modelPayload);
80 assertEquals("Expected the cloud region to be created", 201, response.getStatus());
82 response = httpTestUtil.doGet(modelUri);
83 assertEquals("Expected the cloud region to be found", 200, response.getStatus());
84 String jsonResponse = response.getEntity().toString();
85 JSONAssert.assertEquals(modelPayload, jsonResponse, false);
87 response = httpTestUtil.doPut(modelElementUri, modelElementPayload);
88 assertEquals("Expected the cloud region to be created", 201, response.getStatus());
92 public void tearDown() throws UnsupportedEncodingException, AAIException {
93 Response response = httpTestUtil.doGet(modelUri);
94 assertEquals("Expected the cloud region to be found", 200, response.getStatus());
95 String jsonResponse = response.getEntity().toString();
96 String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
97 response = httpTestUtil.doDelete(modelUri, resourceVersion);
98 assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());