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