2 * ============LICENSE_START=======================================================
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
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.openecomp.sdc.ci.tests.utils.validation;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
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;
34 public class CategoryValidationUtils {
36 public static void verifyCategoryExistInGetResponse(RestResponse getAllCategoryRest,
37 CategoryDefinition categoryDefinition) {
39 int categoriesNum = CategoryRestUtils.getMatchingCategoriesNum(getAllCategoryRest, categoryDefinition);
40 assertEquals("category " + categoryDefinition.getName() + " not found during get or found more than once", 1,
44 public static void verifyCategoryNotExistsInGetResponse(RestResponse getAllCategoryRest,
45 CategoryDefinition categoryDefinition) {
47 int categoriesNum = CategoryRestUtils.getMatchingCategoriesNum(getAllCategoryRest, categoryDefinition);
48 assertEquals("category " + categoryDefinition.getName() + " should't be found during get", 0, categoriesNum);
51 public static void verifySubCategoryExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
52 SubCategoryDefinition expectedSubCategoryDefinition) {
54 int subCategoriesNum = CategoryRestUtils.getMatchingSubCategoriesNum(getAllCategoryRest, parentCategoryId,
55 expectedSubCategoryDefinition);
57 "sub-category " + expectedSubCategoryDefinition.getName()
58 + " not found during get or found more than once for parentId " + parentCategoryId,
62 public static void verifyGroupingExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
63 String subCategoryId, GroupingDefinition expectedGroupingDefinition) {
65 int groupingNum = CategoryRestUtils.getMatchingGroupingNum(getAllCategoryRest, parentCategoryId, subCategoryId,
66 expectedGroupingDefinition);
68 "sub-category " + expectedGroupingDefinition.getName()
69 + " not found during get or found more than once for parentId " + parentCategoryId,
73 public static void verifyGroupingNotExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
74 String subCategoryId, GroupingDefinition expectedGroupingDefinition) {
76 int groupingNum = CategoryRestUtils.getMatchingGroupingNum(getAllCategoryRest, parentCategoryId, subCategoryId,
77 expectedGroupingDefinition);
79 "sub-category " + expectedGroupingDefinition.getName()
80 + " not found during get or found more than once for parentId " + parentCategoryId,
84 public static void verifySubCategoryNotExistsInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
85 SubCategoryDefinition expectedSubCategoryDefinition) {
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);
94 public static void validateCreateGroupResponse(RestResponse createSubCategoryRest,
95 GroupingDefinition expectedGroupDefinition) throws Exception {
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());
107 public static void validateCreateSubCategoryResponse(RestResponse createSubCategoryRest,
108 SubCategoryDefinition expectedSubCategoryDefinition) throws Exception {
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"));
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"));