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