[SDC-29] rebase continue work to align source
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / validation / CategoryValidationUtils.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.utils.validation;
22
23 import static org.testng.AssertJUnit.assertNotNull;
24 import static org.testng.AssertJUnit.assertTrue;
25 import static org.testng.AssertJUnit.assertEquals;
26 import org.json.JSONObject;
27 import org.openecomp.sdc.be.model.category.CategoryDefinition;
28 import org.openecomp.sdc.be.model.category.GroupingDefinition;
29 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
30 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
31 import org.openecomp.sdc.ci.tests.utils.rest.CategoryRestUtils;
32
33 public class CategoryValidationUtils {
34
35         public static void verifyCategoryExistInGetResponse(RestResponse getAllCategoryRest,
36                         CategoryDefinition categoryDefinition) {
37
38                 int categoriesNum = CategoryRestUtils.getMatchingCategoriesNum(getAllCategoryRest, categoryDefinition);
39                 assertEquals("category " + categoryDefinition.getName() + " not found during get or found more than once", 1,
40                                 categoriesNum);
41         }
42
43         public static void verifyCategoryNotExistsInGetResponse(RestResponse getAllCategoryRest,
44                         CategoryDefinition categoryDefinition) {
45
46                 int categoriesNum = CategoryRestUtils.getMatchingCategoriesNum(getAllCategoryRest, categoryDefinition);
47                 assertEquals("category " + categoryDefinition.getName() + " should't be found during get", 0, categoriesNum);
48         }
49
50         public static void verifySubCategoryExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
51                         SubCategoryDefinition expectedSubCategoryDefinition) {
52
53                 int subCategoriesNum = CategoryRestUtils.getMatchingSubCategoriesNum(getAllCategoryRest, parentCategoryId,
54                                 expectedSubCategoryDefinition);
55                 assertEquals(
56                                 "sub-category " + expectedSubCategoryDefinition.getName()
57                                                 + " not found during get or found more than once for parentId " + parentCategoryId,
58                                 1, subCategoriesNum);
59         }
60
61         public static void verifyGroupingExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
62                         String subCategoryId, GroupingDefinition expectedGroupingDefinition) {
63
64                 int groupingNum = CategoryRestUtils.getMatchingGroupingNum(getAllCategoryRest, parentCategoryId, subCategoryId,
65                                 expectedGroupingDefinition);
66                 assertEquals(
67                                 "sub-category " + expectedGroupingDefinition.getName()
68                                                 + " not found during get or found more than once for parentId " + parentCategoryId,
69                                 1, groupingNum);
70         }
71
72         public static void verifyGroupingNotExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
73                         String subCategoryId, GroupingDefinition expectedGroupingDefinition) {
74
75                 int groupingNum = CategoryRestUtils.getMatchingGroupingNum(getAllCategoryRest, parentCategoryId, subCategoryId,
76                                 expectedGroupingDefinition);
77                 assertEquals(
78                                 "sub-category " + expectedGroupingDefinition.getName()
79                                                 + " not found during get or found more than once for parentId " + parentCategoryId,
80                                 0, groupingNum);
81         }
82
83         public static void verifySubCategoryNotExistsInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
84                         SubCategoryDefinition expectedSubCategoryDefinition) {
85
86                 int subCategoriesNum = CategoryRestUtils.getMatchingSubCategoriesNum(getAllCategoryRest, parentCategoryId,
87                                 expectedSubCategoryDefinition);
88                 assertEquals("sub-category " + expectedSubCategoryDefinition.getName()
89                                 + " should't be found during get for parentId " + parentCategoryId, 0, subCategoriesNum);
90         }
91
92         /// NEE Benny
93         public static void validateCreateGroupResponse(RestResponse createSubCategoryRest,
94                         GroupingDefinition expectedGroupDefinition) throws Exception {
95
96                 String response = createSubCategoryRest.getResponse();
97                 JSONObject jobject = new JSONObject(response);
98                 assertTrue(jobject.get("name").equals(expectedGroupDefinition.getName()));
99                 assertTrue(jobject.get("normalizedName").equals(expectedGroupDefinition.getNormalizedName()));
100                 // assertNotNull(jobject.get("normalizedName"));
101                 assertNotNull(jobject.get("uniqueId"));
102                 expectedGroupDefinition.setUniqueId(jobject.get("uniqueId").toString());
103
104         }
105
106         public static void validateCreateSubCategoryResponse(RestResponse createSubCategoryRest,
107                         SubCategoryDefinition expectedSubCategoryDefinition) throws Exception {
108
109                 String response = createSubCategoryRest.getResponse();
110                 JSONObject jobject = new JSONObject(response);
111                 assertTrue(jobject.get("name").equals(expectedSubCategoryDefinition.getName()));
112                 assertNotNull(jobject.get("normalizedName"));
113                 assertNotNull(jobject.get("uniqueId"));
114         }
115
116         public static void validateCreateCategoryResponse(RestResponse createCategoryRest,
117                         CategoryDefinition expectedCategoryDefinition) throws Exception {
118                 String response = createCategoryRest.getResponse();
119                 JSONObject jobject = new JSONObject(response);
120                 assertTrue(jobject.get("name").equals(expectedCategoryDefinition.getName()));
121                 assertTrue(jobject.get("normalizedName").equals(expectedCategoryDefinition.getNormalizedName()));
122                 assertNotNull(jobject.get("uniqueId"));
123         }
124
125 }