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 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;
30 import static org.testng.AssertJUnit.*;
32 public class CategoryValidationUtils {
34 public static void verifyCategoryExistInGetResponse(RestResponse getAllCategoryRest,
35 CategoryDefinition categoryDefinition) {
37 int categoriesNum = CategoryRestUtils.getMatchingCategoriesNum(getAllCategoryRest, categoryDefinition);
38 assertEquals("category " + categoryDefinition.getName() + " not found during get or found more than once", 1,
42 public static void verifyCategoryNotExistsInGetResponse(RestResponse getAllCategoryRest,
43 CategoryDefinition categoryDefinition) {
45 int categoriesNum = CategoryRestUtils.getMatchingCategoriesNum(getAllCategoryRest, categoryDefinition);
46 assertEquals("category " + categoryDefinition.getName() + " should't be found during get", 0, categoriesNum);
49 public static void verifySubCategoryExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
50 SubCategoryDefinition expectedSubCategoryDefinition) {
52 int subCategoriesNum = CategoryRestUtils.getMatchingSubCategoriesNum(getAllCategoryRest, parentCategoryId,
53 expectedSubCategoryDefinition);
55 "sub-category " + expectedSubCategoryDefinition.getName()
56 + " not found during get or found more than once for parentId " + parentCategoryId,
60 public static void verifyGroupingExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
61 String subCategoryId, GroupingDefinition expectedGroupingDefinition) {
63 int groupingNum = CategoryRestUtils.getMatchingGroupingNum(getAllCategoryRest, parentCategoryId, subCategoryId,
64 expectedGroupingDefinition);
66 "sub-category " + expectedGroupingDefinition.getName()
67 + " not found during get or found more than once for parentId " + parentCategoryId,
71 public static void verifyGroupingNotExistInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
72 String subCategoryId, GroupingDefinition expectedGroupingDefinition) {
74 int groupingNum = CategoryRestUtils.getMatchingGroupingNum(getAllCategoryRest, parentCategoryId, subCategoryId,
75 expectedGroupingDefinition);
77 "sub-category " + expectedGroupingDefinition.getName()
78 + " not found during get or found more than once for parentId " + parentCategoryId,
82 public static void verifySubCategoryNotExistsInGetResponse(RestResponse getAllCategoryRest, String parentCategoryId,
83 SubCategoryDefinition expectedSubCategoryDefinition) {
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);
92 public static void validateCreateGroupResponse(RestResponse createSubCategoryRest,
93 GroupingDefinition expectedGroupDefinition) throws Exception {
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());
105 public static void validateCreateSubCategoryResponse(RestResponse createSubCategoryRest,
106 SubCategoryDefinition expectedSubCategoryDefinition) throws Exception {
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"));
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"));