[SDC-29] rebase continue work to align source
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / general / UuidTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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.sdc.ci.tests.execute.general;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
25
26 import java.io.IOException;
27 import java.util.List;
28 import java.util.UUID;
29
30 import org.junit.Rule;
31 import org.junit.rules.TestName;
32 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
33 import org.openecomp.sdc.ci.tests.config.Config;
34 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
35 import org.openecomp.sdc.ci.tests.utils.rest.CatalogRestUtils;
36 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
37 import org.openecomp.sdc.common.api.Constants;
38 import org.testng.AssertJUnit;
39 import org.testng.annotations.Test;
40
41 public class UuidTest extends ComponentBaseTest {
42
43         @Rule
44         public static TestName name = new TestName();
45
46         public UuidTest() {
47                 super(name, UuidTest.class.getName());
48                 config = Config.instance();
49         }
50
51         @Test
52         public void testE2EUuidHeaderReturnedAndPreserved() throws IOException {
53                 UUID randomUUID = UUID.randomUUID();
54                 String uuidStr = randomUUID.toString();
55                 RestResponse allTagsTowardsCatalogFe = CatalogRestUtils.getAllCategoriesTowardsCatalogFeWithUuid(uuidStr);
56                 AssertJUnit.assertEquals(allTagsTowardsCatalogFe.getErrorCode(), new Integer(200));
57                 List<String> list = allTagsTowardsCatalogFe.getHeaderFields().get(Constants.X_ECOMP_REQUEST_ID_HEADER);
58                 // check that header is returned
59                 AssertJUnit.assertTrue(list != null && !list.isEmpty());
60                 String receivedUuid = list.get(0);
61                 // Check that same uuid returned
62                 AssertJUnit.assertEquals(uuidStr, receivedUuid);
63         }
64
65         @Test
66         public void testUuidHeaderGeneratedBe() throws IOException {
67                 RestResponse allTagsTowardsCatalogBe = CatalogRestUtils.getAllCategoriesTowardsCatalogBe();
68                 List<String> list = allTagsTowardsCatalogBe.getHeaderFields().get(Constants.X_ECOMP_REQUEST_ID_HEADER);
69                 // check that response was OK
70                 assertEquals(allTagsTowardsCatalogBe.getErrorCode(), new Integer(200));
71                 // check that header is returned
72                 assertTrue(list != null && !list.isEmpty());
73                 String uuid = list.get(0);
74                 // Check there is no conversion error
75                 UUID.fromString(uuid);
76         }
77
78         @Test
79         public void testE2EOptionsNoUuid() throws IOException {
80                 RestResponse allTagsTowardsCatalogFe = ResourceRestUtils.sendOptionsTowardsCatalogFeWithUuid();
81                 assertEquals(allTagsTowardsCatalogFe.getErrorCode(), new Integer(200));
82                 List<String> list = allTagsTowardsCatalogFe.getHeaderFields().get(Constants.X_ECOMP_REQUEST_ID_HEADER);
83                 // check that header is returned (generated by BE)
84                 assertTrue(list != null && !list.isEmpty());
85                 String receivedUuid = list.get(0);
86                 // Check there is no conversion error
87                 UUID.fromString(receivedUuid);
88         }
89
90         @Test
91         public void testE2EMethodNotAllowedWithUuid() throws IOException {
92                 UUID randomUUID = UUID.randomUUID();
93                 String uuidStr = randomUUID.toString();
94                 RestResponse allTagsTowardsCatalogFe = ResourceRestUtils
95                                 .putAllCategoriesTowardsCatalogFeWithUuidNotAllowed(uuidStr);
96                 assertEquals(allTagsTowardsCatalogFe.getErrorCode(), new Integer(405));
97                 List<String> list = allTagsTowardsCatalogFe.getHeaderFields().get(Constants.X_ECOMP_REQUEST_ID_HEADER);
98                 // check that header is returned (generated by BE)
99                 assertTrue(list != null && !list.isEmpty());
100                 String receivedUuid = list.get(0);
101                 // Check that same uuid returned
102                 assertEquals(uuidStr, receivedUuid);
103         }
104 }