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.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;
33 public class CategoryValidationUtils {
35 public static void verifyCategoryExistInGetResponse(RestResponse getAllCategoryRest,
36 CategoryDefinition categoryDefinition) {
38 int categoriesNum = CategoryRestUtils.getMatchingCategoriesNum(getAllCategoryRest, categoryDefinition);
39 assertEquals("category " + categoryDefinition.getName() + " not found during get or found more than once", 1,
43 public static void verifyCategoryNotExistsInGetResponse(RestResponse getAllCategoryRest,
44 CategoryDefinition categoryDefinition) {
46 int categoriesNum = CategoryRestUtils.getMatchingCategoriesNum(getAllCategoryRest, categoryDefinition);
47 assertEquals("category " + categoryDefinition.getName() + " should't be found during get", 0, categoriesNum);
50 public static void verifySubCategoryExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
51 SubCategoryDefinition expectedSubCategoryDefinition) {
53 int subCategoriesNum = CategoryRestUtils.getMatchingSubCategoriesNum(getAllCategoryRest, parentCategoryId,
54 expectedSubCategoryDefinition);
56 "sub-category " + expectedSubCategoryDefinition.getName()
57 + " not found during get or found more than once for parentId " + parentCategoryId,
61 public static void verifyGroupingExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
62 String subCategoryId, GroupingDefinition expectedGroupingDefinition) {
64 int groupingNum = CategoryRestUtils.getMatchingGroupingNum(getAllCategoryRest, parentCategoryId, subCategoryId,
65 expectedGroupingDefinition);
67 "sub-category " + expectedGroupingDefinition.getName()
68 + " not found during get or found more than once for parentId " + parentCategoryId,
72 public static void verifyGroupingNotExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
73 String subCategoryId, GroupingDefinition expectedGroupingDefinition) {
75 int groupingNum = CategoryRestUtils.getMatchingGroupingNum(getAllCategoryRest, parentCategoryId, subCategoryId,
76 expectedGroupingDefinition);
78 "sub-category " + expectedGroupingDefinition.getName()
79 + " not found during get or found more than once for parentId " + parentCategoryId,
83 public static void verifySubCategoryNotExistsInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
84 SubCategoryDefinition expectedSubCategoryDefinition) {
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);
93 public static void validateCreateGroupResponse(RestResponse createSubCategoryRest,
94 GroupingDefinition expectedGroupDefinition) throws Exception {
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());
106 public static void validateCreateSubCategoryResponse(RestResponse createSubCategoryRest,
107 SubCategoryDefinition expectedSubCategoryDefinition) throws Exception {
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"));
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"));