diff options
Diffstat (limited to 'test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category')
6 files changed, 6651 insertions, 0 deletions
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/CatalogDataApiTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/CatalogDataApiTest.java new file mode 100644 index 0000000000..9938266602 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/CatalogDataApiTest.java @@ -0,0 +1,236 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.ci.tests.execute.category; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.lf5.util.ResourceUtils; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.ci.tests.api.ComponentBaseTest; +import org.openecomp.sdc.ci.tests.api.Urls; +import org.openecomp.sdc.ci.tests.config.Config; +import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum; +import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum; +import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum; +import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; +import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum; +import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.utils.Utils; +import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; +import org.openecomp.sdc.ci.tests.utils.rest.CatalogRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser; +import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils; +import org.testng.AssertJUnit; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.gson.Gson; + +public class CatalogDataApiTest extends ComponentBaseTest { + + protected Config config = Config.instance(); + protected String contentTypeHeaderData = "application/json"; + protected String acceptHeaderDate = "application/json"; + + @Rule + public static TestName name = new TestName(); + protected User user; + protected RestResponse res1; + protected RestResponse res2; + protected RestResponse svc1; + protected ResourceReqDetails resourceDetails1; + protected ResourceReqDetails resourceDetails2; + protected ServiceReqDetails svcDetails1; + + public CatalogDataApiTest() { + super(name, CatalogDataApiTest.class.getName()); + } + + @BeforeMethod + public void setUp() throws Exception { + user = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + resourceDetails1 = buildResourceDetails(user, "TestResource1"); + resourceDetails2 = buildResourceDetails(user, "TestResource2"); + svcDetails1 = buildServiceDetails("TestService1"); + + res1 = createResource(user, resourceDetails1); + AssertJUnit.assertEquals("create resorce failed", 201, res1.getErrorCode().intValue()); + resourceDetails1.setUniqueId(ResponseParser.getUniqueIdFromResponse(res1)); + resourceDetails2.setVersion(ResponseParser.getVersionFromResponse(res1)); + + res2 = createResource(user, resourceDetails2); + AssertJUnit.assertEquals("create resorce failed", 201, res2.getErrorCode().intValue()); + resourceDetails2.setUniqueId(ResponseParser.getUniqueIdFromResponse(res2)); + resourceDetails2.setVersion(ResponseParser.getVersionFromResponse(res2)); + + svc1 = createService(user, svcDetails1); + AssertJUnit.assertEquals("create resorce failed", 201, svc1.getErrorCode().intValue()); + svcDetails1.setUniqueId(ResponseParser.convertServiceResponseToJavaObject(svc1.getResponse()).getUniqueId()); + svcDetails1.setVersion(ResponseParser.convertServiceResponseToJavaObject(svc1.getResponse()).getVersion()); + } + + @AfterMethod + public void tearDown() throws Exception { + deleteResource(resourceDetails1.getUniqueId(), user.getUserId()); + deleteResource(resourceDetails2.getUniqueId(), user.getUserId()); + deleteService(svcDetails1.getUniqueId(), user); + } + + // Keep 1 + @Test + public void getCatalogData() throws Exception { + + RestResponse checkInResponse = LifecycleRestUtils.changeResourceState(resourceDetails1, user, "0.1", + LifeCycleStatesEnum.CHECKIN); + AssertJUnit.assertEquals("check in operation failed", 200, checkInResponse.getErrorCode().intValue()); + + RestResponse res = CatalogRestUtils.getCatalog(user.getUserId()); + String json = res.getResponse(); + JSONObject jsonResp = (JSONObject) JSONValue.parse(json); + JSONArray resources = (JSONArray) jsonResp.get("resources"); + JSONArray services = (JSONArray) jsonResp.get("services"); + + // Verify all the expected resources received. + AssertJUnit.assertTrue("check resource1 is in response", + isComponentInArray(resourceDetails1.getUniqueId(), resources)); + AssertJUnit.assertTrue("check resource2 is in response", + isComponentInArray(resourceDetails2.getUniqueId(), resources)); + AssertJUnit.assertTrue("check service1 is in response", + isComponentInArray(svcDetails1.getUniqueId(), services)); + + } + + protected void deleteResource(String resourceUniqueId, String httpCspUserId) throws Exception { + RestResponse deleteResourceResponse = ResourceRestUtils.deleteResource(resourceUniqueId, httpCspUserId); + + } + + protected RestResponse createResource(User user, ResourceReqDetails resourceDetails) throws Exception { + deleteResource(resourceDetails.getName(), user.getUserId()); + return ResourceRestUtils.createResource(resourceDetails, user); + } + + protected ResourceReqDetails buildResourceDetails(User user, String resourceName) { + String description = "description"; + ArrayList<String> resourceTags = new ArrayList<String>(); + resourceTags.add(resourceName); + ArrayList<String> derivedFrom = new ArrayList<String>(); + derivedFrom.add("tosca.nodes.Root"); + String vendorName = "Oracle"; + String vendorRelease = "1.0"; + String contactId = user.getUserId(); + String icon = "myICON"; + + ResourceReqDetails resourceDetails = new ResourceReqDetails(resourceName, description, resourceTags, null, + derivedFrom, vendorName, vendorRelease, contactId, icon); + resourceDetails.addCategoryChain(ResourceCategoryEnum.GENERIC_DATABASE.getCategory(), + ResourceCategoryEnum.GENERIC_DATABASE.getSubCategory()); + return resourceDetails; + } + + protected boolean isComponentInArray(String id, JSONArray component) { + for (int i = 0; i < component.size(); i++) { + JSONObject jobject = (JSONObject) component.get(i); + if (jobject.get("uniqueId").toString().equals(id.toLowerCase())) { + return true; + } + } + return false; + } + + protected RestResponse createService(User user, ServiceReqDetails svcDetails) throws Exception { + + Config config = Utils.getConfig(); + + Map<String, String> headersMap = getHeadersMap(user); + + Gson gson = new Gson(); + String body = gson.toJson(svcDetails); + HttpRequest http = new HttpRequest(); + String url = String.format(Urls.CREATE_SERVICE, config.getCatalogBeHost(), config.getCatalogBePort()); + RestResponse res = http.httpSendPost(url, body, headersMap); + // System.out.println("Create service was finished with response: + // "+res.getErrorCode()); + return res; + } + + protected Map<String, String> getHeadersMap(User user) { + Map<String, String> headersMap = new HashMap<String, String>(); + headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData); + headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate); + headersMap.put("USER_ID", user.getUserId()); + return headersMap; + } + + protected ServiceReqDetails buildServiceDetails(String serviceName) { + String description = "description"; + ArrayList<String> serviceTags = new ArrayList<String>(); + serviceTags.add("tag1"); + serviceTags.add(serviceName); + String category = ServiceCategoriesEnum.MOBILITY.getValue(); + String vendorName = "Oracle"; + String vendorRelease = "0.1"; + String contactId = "al1976"; + String icon = "myIcon"; + + ServiceReqDetails svcdetails = new ServiceReqDetails(serviceName, category, serviceTags, description, + contactId, icon); + return svcdetails; + } + + public RestResponse deleteService(String serviceId, User user) throws Exception { + HttpRequest httpRequest = new HttpRequest(); + String url = String.format(Urls.DELETE_SERVICE, config.getCatalogBeHost(), config.getCatalogBePort(), + serviceId); + + Map<String, String> headersMap = getHeadersMap(user); + RestResponse res = httpRequest.httpSendDelete(url, headersMap); + // System.out.println("Delete service was finished with response: + // "+res.getErrorCode()); + return res; + } + + public class NewObject { + private String _name; + + public String getName() { + return _name; + } + + public void setName(String name) { + this._name = name; + } + } + +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/CategoriesBaseTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/CategoriesBaseTest.java new file mode 100644 index 0000000000..d68f3f5582 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/CategoriesBaseTest.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.ci.tests.execute.category; + +import org.junit.rules.TestName; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.ci.tests.api.ComponentBaseTest; +import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; +import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; + +public abstract class CategoriesBaseTest extends ComponentBaseTest { + + public CategoriesBaseTest(TestName testName, String className) { + super(testName, className); + } + + protected static final String AUDIT_SERVICE_TYPE = "Service"; + protected static final String AUDIT_RESOURCE_TYPE = "Resource"; + protected static final String AUDIT_PRODUCT_TYPE = "Product"; + protected static final String GET_CATEGORY_HIERARCHY = "GetCategoryHierarchy"; + protected static User sdncAdminUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + protected static User sdncAdminUserDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + protected static User sdncDesignerUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + protected static User sdncTesterUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.TESTER); + protected static User sdncGovernorUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.GOVERNOR); + protected static User sdncOpsUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.OPS); + protected static User sdncProductManagerUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.PRODUCT_MANAGER1); + protected static User sdncProductStrategistUserDetails = ElementFactory + .getDefaultUser(UserRoleEnum.PRODUCT_STRATEGIST1); + +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/CategoriesTests.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/CategoriesTests.java new file mode 100644 index 0000000000..3b85c052a1 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/CategoriesTests.java @@ -0,0 +1,2303 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.ci.tests.execute.category; + +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.PRODUCT_COMPONENT_TYPE; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.RESOURCE_COMPONENT_TYPE; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.SERVICE_COMPONENT_TYPE; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_ALREADY_EXISTS; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_CREATED; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_INVALID_CONTENT; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_MISSING_INFORMATION; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_RESTRICTED_OPERATION; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_SUCCESS; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertTrue; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.text.WordUtils; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.FileBody; +import org.json.JSONArray; +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.category.CategoryDefinition; +import org.openecomp.sdc.be.model.category.SubCategoryDefinition; +import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo; +import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; +import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedCategoryAudit; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.utils.DbUtils; +import org.openecomp.sdc.ci.tests.utils.Utils; +import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; +import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.CategoryRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser; +import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.CategoryValidationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils; +import org.testng.SkipException; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class CategoriesTests extends CategoriesBaseTest { + + private static final String GET_CATEGORY_HIERARCHY = "GetCategoryHierarchy"; + protected static final String ADD_CATEGORY = "AddCategory"; + protected static final String DELETE_CATEGORY = "DeleteCategory"; + + public CategoriesTests() { + super(name, CategoriesTests.class.getName()); + } + + @Rule + public static TestName name = new TestName(); + private CategoryDefinition categoryDefinition; + private List<CategoryDefinition> categoryList; + private List<SubCategoryDefinition> subCategoryList; + private Map<String, List<String>> subCategoriesToDeleteMap; + + @BeforeMethod + public void init() throws Exception { + subCategoriesToDeleteMap = new HashMap<String, List<String>>(); + DbUtils.deleteFromEsDbByPattern("_all"); + + categoryDefinition = new CategoryDefinition(); + categoryDefinition.setName("Abcd"); + categoryList = defineCategories(); + subCategoryList = defineSubCategories(categoryList.size()); + } + + // pass + @Test + public void createServiceCategorySuccessFlow() throws Exception { + // Add New category + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + // get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); // also + // set + // catalog + // uniqeId + + } + + // pass + @Test + public void createResourceCategorySuccessFlow() throws Exception { + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get Category + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + // pass + @Test + public void createProductCategorySuccessFlow() throws Exception { + // Add Category by Product-strategist + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, + sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + + // Get Category + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncProductStrategistUserDetails, + STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void CategoryNameValidation_FirstWordStartWithAlphaNumeric_01() throws Exception { // category + // for + // service + categoryDefinition.setName("Category14AadE &&&---+++.'''###=:@@@____"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Category14AadE &-+.'#=:@_"); + categoryDefinition.setNormalizedName("category14aade &-+.'#=:@_"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_FirstWordStartWithAlphaNumeric_02() throws Exception { // category + // for + // resource + categoryDefinition.setName("Category14AadE &&&---+++.'''###=:@@@____"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Category14AadE &-+.'#=:@_"); + categoryDefinition.setNormalizedName("category14aade &-+.'#=:@_"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void categoryNameValidation_FirstWordStartWithAlphaNumeric_03() throws Exception { // category + // for + // resource + categoryDefinition.setName("Category14AadE &&&---+++.'''###=:@@@____"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, + sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Category14AadE &-+.'#=:@_"); + categoryDefinition.setNormalizedName("category14aade &-+.'#=:@_"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncProductStrategistUserDetails, + STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + // pass + @Test + public void createServiceCategoryByNonAdminUser() throws Exception { + // Add New category + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, + sdncProductStrategistUserDetails, SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_RESTRICTED_OPERATION, + createCategotyRest.getErrorCode().intValue()); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditFailure(ADD_CATEGORY, categoryDefinition, sdncProductStrategistUserDetails, + ActionStatus.RESTRICTED_OPERATION, STATUS_CODE_RESTRICTED_OPERATION, AUDIT_SERVICE_TYPE); + } + + // pass + @Test + public void createResourceCategoryByNonAdminUser() throws Exception { + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, + sdncProductStrategistUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_RESTRICTED_OPERATION, + createCategotyRest.getErrorCode().intValue()); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditFailure(ADD_CATEGORY, categoryDefinition, sdncProductStrategistUserDetails, + ActionStatus.RESTRICTED_OPERATION, STATUS_CODE_RESTRICTED_OPERATION, AUDIT_RESOURCE_TYPE); + } + + // pass + @Test + public void createProductCategoryByNonProductStrategistUser() throws Exception { + // Add New product category not by Product-Strategist + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_RESTRICTED_OPERATION, + createCategotyRest.getErrorCode().intValue()); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditFailure(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + ActionStatus.RESTRICTED_OPERATION, STATUS_CODE_RESTRICTED_OPERATION, AUDIT_PRODUCT_TYPE); + + } + + // pass + @Test + public void addCategoryByNonExistingUser() throws Exception { + User sdncAdminUserDetailsNonExisting = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + sdncAdminUserDetailsNonExisting.setUserId("bt555h"); + // Add New category + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, + sdncAdminUserDetailsNonExisting, SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_RESTRICTED_OPERATION, + createCategotyRest.getErrorCode().intValue()); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.RESTRICTED_OPERATION.name()); + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(ADD_CATEGORY); + expectedCatrgoryAuditJavaObject.setModifier("(" + sdncAdminUserDetailsNonExisting.getUserId() + ")"); + expectedCatrgoryAuditJavaObject.setCategoryName(categoryDefinition.getName()); + expectedCatrgoryAuditJavaObject.setSubCategoryName(""); + expectedCatrgoryAuditJavaObject.setGroupingName(""); + expectedCatrgoryAuditJavaObject.setResourceType(AUDIT_SERVICE_TYPE); + expectedCatrgoryAuditJavaObject.setStatus(String.valueOf(STATUS_CODE_RESTRICTED_OPERATION)); + expectedCatrgoryAuditJavaObject.setDesc(errorInfo.getAuditDesc()); + AuditValidationUtils.validateCategoryAudit(expectedCatrgoryAuditJavaObject, ADD_CATEGORY); + } + + @Test + public void addServiceCategoryAllowedcharacters_01() throws Exception { + categoryDefinition.setName("1234AbcdE&"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde&"); // normalization + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void addServiceCategoryAllowedcharacters_02() throws Exception { + categoryDefinition.setName("1234AbcdE-"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde-"); // normalization + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void addServiceCategoryAllowedcharacters_03() throws Exception { + categoryDefinition.setName("1234AbcdE+"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde+"); // normalization + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void addServiceCategoryAllowedcharacters_04() throws Exception { + categoryDefinition.setName("1234AbcdE."); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde."); // normalization + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void addServiceCategoryAllowedcharacters_05() throws Exception { + categoryDefinition.setName("1234AbcdE'"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde'"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void addServiceCategoryAllowedcharacters_06() throws Exception { + categoryDefinition.setName("1234AbcdE="); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde="); // normalization + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void addServiceCategoryAllowedcharacters_07() throws Exception { + categoryDefinition.setName("1234AbcdE:"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde:"); // normalization + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void addServiceCategoryAllowedcharacters_08() throws Exception { + categoryDefinition.setName("1234AbcdE@"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde@"); // normalization + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void addServiceCategoryAllowedcharacters_09() throws Exception { + categoryDefinition.setName("1234AbcdE_"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde_"); // normalization + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void addServiceCategoryAllowedcharacters_10() throws Exception { + categoryDefinition.setName("1234AbcdE#"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde#"); // normalization + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void addServiceCategoryAllowedcharacters_11() throws Exception { + categoryDefinition.setName("1234AbcdE d"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde d"); // normalization + categoryDefinition.setName("1234AbcdE D"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void addServiceCategoryAllowedcharacters_12() throws Exception { + categoryDefinition.setName("1234AbcdE &_=+.-'#:@ d"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("1234abcde &_=+.-'#:@ d"); // normalization + categoryDefinition.setName("1234AbcdE &_=+.-'#:@ D"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveSpaceFromBeginning() throws Exception { + categoryDefinition.setName(" Category01"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("category01"); // normalization + categoryDefinition.setName("Category01"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveSpaceFromEnd() throws Exception { + categoryDefinition.setName("Category01 "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("category01"); // normalization + categoryDefinition.setName("Category01"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveExtraSpace() throws Exception { + categoryDefinition.setName("Category 02"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("category 02"); // normalization + categoryDefinition.setName("Category 02"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveExtraAmpersand() throws Exception { + categoryDefinition.setName("Category&& &02"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("category& &02"); // normalization + categoryDefinition.setName("Category& &02"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveExtraDash() throws Exception { + categoryDefinition.setName("CategorY-- --02"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("CategorY- -02"); + categoryDefinition.setNormalizedName("category- -02"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveExtraPlus() throws Exception { + categoryDefinition.setName("CateGory++++ +02"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("CateGory+ +02"); + categoryDefinition.setNormalizedName("category+ +02"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveExtraPeriod() throws Exception { + categoryDefinition.setName("Category.... .02"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Category. .02"); + categoryDefinition.setNormalizedName("category. .02"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveExtraApostrophe() throws Exception { + categoryDefinition.setName("CaTegory''' '02"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("CaTegory' '02"); + categoryDefinition.setNormalizedName("category' '02"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveExtraHashtag() throws Exception { + categoryDefinition.setName("Category### #02"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Category# #02"); + categoryDefinition.setNormalizedName("category# #02"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveExtrEequal() throws Exception { + categoryDefinition.setName("Category=== =02"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Category= =02"); + categoryDefinition.setNormalizedName("category= =02"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveExtrColon() throws Exception { + categoryDefinition.setName("Category::: :02"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Category: :02"); + categoryDefinition.setNormalizedName("category: :02"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveExtrAt() throws Exception { + categoryDefinition.setName("Category@@@ @a2"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Category@ @a2"); + categoryDefinition.setNormalizedName("category@ @a2"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_RemoveExtraUnderscore() throws Exception { + categoryDefinition.setName("Category___ _22"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Category_ _22"); + categoryDefinition.setNormalizedName("category_ _22"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_FirstWordStartWithNumber() throws Exception { + categoryDefinition.setName("1Category one"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("1Category One"); + categoryDefinition.setNormalizedName("1category one"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_FirstWordStartWithNonAlphaNumeric() throws Exception { // The + // first + // word + // must + // start + // with + // an + // alpha-numeric + // character + // [a-Z + // A..Z, + // 0..9] + char invalidChars[] = { '&', '-', '+', '.', '\'', '#', '=', ':', '@', '_' }; + for (int i = 0; i < invalidChars.length; i++) { + DbUtils.deleteFromEsDbByPattern("_all"); + categoryDefinition.setName(invalidChars[i] + "AbcD123"); + categoryDefinition.setNormalizedName((invalidChars[i] + "AbcD123").toLowerCase()); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, + sdncAdminUserDetails1, SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_INVALID_CONTENT, + createCategotyRest.getErrorCode().intValue()); + + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditFailure(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails1, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, STATUS_CODE_INVALID_CONTENT, AUDIT_SERVICE_TYPE, + "Service", "category"); + + } + } + + @Test + public void addServiceCategoryAlreadyExist_uniqueness() throws Exception { // Verify + // category + // name + // duplication + // ("uniqueness") + // as + // non-case-sensitive, + // so + // we + // don’t + // create + // duplicate + // names + // with + // upper/lower + // case + // inconsistency. + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); // also + // set + // catalog + // uniqeId + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + // Create same category name again + DbUtils.deleteFromEsDbByPattern("_all"); + CategoryDefinition categoryDataDefinition2 = new CategoryDefinition(); + categoryDataDefinition2.setName(categoryDefinition.getName()); + RestResponse addDuplicateCategoryRest = CategoryRestUtils.createCategory(categoryDataDefinition2, + sdncAdminUserDetails, SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_ALREADY_EXISTS, + addDuplicateCategoryRest.getErrorCode().intValue()); + // Audit validation + AuditValidationUtils.categoryAuditFailure(ADD_CATEGORY, categoryDataDefinition2, sdncAdminUserDetails, + ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS, STATUS_CODE_ALREADY_EXISTS, AUDIT_SERVICE_TYPE, + "Service", categoryDefinition.getName()); + // Get Category and verify that category was created is not deleted + getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + + } + + @Test + public void categoryNameValidation_ReplaceAndWithAmpersand_01() throws Exception { + categoryDefinition.setName("At and T"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("At & T"); + categoryDefinition.setNormalizedName("at & t"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_ReplaceAndWithAmpersand_02() throws Exception { + categoryDefinition.setName("At and t"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("At & T"); + categoryDefinition.setNormalizedName("at & t"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_ReplaceAndWithAmpersand_03() throws Exception { + categoryDefinition.setName("Atand T"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("atand t"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_ReplaceAndWithAmpersand_04() throws Exception { + categoryDefinition.setName("At andT"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("at andt"); + categoryDefinition.setName("At AndT"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_ReplaceAndWithAmpersand_05() throws Exception { + categoryDefinition.setName(" and AttT"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("and attt"); + categoryDefinition.setName("And AttT"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidation_ReplaceAndWithAmpersand_06() throws Exception { + categoryDefinition.setName("AttT and "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("attt and"); + categoryDefinition.setName("AttT And"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + // Bug + @Test + public void categoryNameValidation_ReplaceAndWithAmpersand_07() throws Exception { + categoryDefinition.setName(" and a"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("and a"); + categoryDefinition.setName("And a"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationMaxLength() throws Exception { + categoryDefinition.setName("AsdfghjQ234567890@#.&:+-_"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("asdfghjq234567890@#.&:+-_"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + + } + + @Test + public void categoryNameValidationMaxLengthAfterNormalization() throws Exception { + categoryDefinition.setName(" A jQ234 @@@___ +++ At and T and and "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("A JQ234 @_ + At & T & And"); + categoryDefinition.setNormalizedName("a jq234 @_ + at & t & and"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + + } + + @Test + public void categoryNameValidationExceedMaxLengthAfterNormalization() throws Exception { + categoryDefinition.setName(" AbdfghBCVa jQ234 @@___ +++ At and T "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_INVALID_CONTENT, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("abdfghbcva jq234 @_ + at&t"); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditFailure(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, STATUS_CODE_INVALID_CONTENT, AUDIT_SERVICE_TYPE, + "Service", "category"); + } + + @Test + public void categoryNameValidationMinLengthAfterNormalization() throws Exception { // MinLengthAfterNormalization + // = + // 4 + // characters + categoryDefinition.setName(" At and T "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("At & T"); + categoryDefinition.setNormalizedName("at & t"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationLessThanMinLengthAfterNormalization() throws Exception { + categoryDefinition.setName(" A&&&&&&&&&&&&&&&&&T "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_INVALID_CONTENT, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName("a&t"); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditFailure(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, STATUS_CODE_INVALID_CONTENT, AUDIT_SERVICE_TYPE, + "Service", "category"); + } + + @Test + public void categoryNameValidationIsNull() throws Exception { + categoryDefinition.setName(null); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_INVALID_CONTENT, + createCategotyRest.getErrorCode().intValue()); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditFailure(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, STATUS_CODE_INVALID_CONTENT, AUDIT_SERVICE_TYPE, + "Service", "category"); + } + + @Test + public void categoryNameValidationIsEmpty() throws Exception { + categoryDefinition.setName(""); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_INVALID_CONTENT, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName(""); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditFailure(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, STATUS_CODE_INVALID_CONTENT, AUDIT_SERVICE_TYPE, + "Service", "category"); + } + + @Test + public void categoryNameValidationInvalidCharacters() throws Exception { + char invalidChars[] = { '~', '!', '$', '%', '^', '*', '(', ')', '"', '{', '}', '[', ']', '?', '>', '<', '/', + '|', '\\', ',' }; + for (int i = 0; i < invalidChars.length; i++) { + DbUtils.deleteFromEsDbByPattern("_all"); + // DbUtils.cleanAllAudits(); + categoryDefinition.setName("AbcD123" + invalidChars[i]); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_INVALID_CONTENT, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setNormalizedName(""); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditFailure(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, STATUS_CODE_INVALID_CONTENT, AUDIT_SERVICE_TYPE, + "Service", "category"); + } + } + + @Test + public void categoryNameValidationSameNameDifferentResourceType() throws Exception { // same + // Catalog + // Name + // for + // service/resource/product + // is + // allowed + String name = ("Abcd"); + CategoryDefinition categoryDataDefinition1 = new CategoryDefinition(); + CategoryDefinition categoryDataDefinition2 = new CategoryDefinition(); + CategoryDefinition categoryDataDefinition3 = new CategoryDefinition(); + categoryDataDefinition1.setName(name); + categoryDataDefinition2.setName(name); + categoryDataDefinition3.setName(name); + // CREATE CATEGORY FOR SERVICE + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDataDefinition1, + sdncAdminUserDetails, SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDataDefinition1.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDataDefinition1); + // get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDataDefinition1); // also + // set + // catalog + // uniqeId + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDataDefinition1, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + // CREATE CATEGORY FOR RESOURCE_COMPONENT_TYPE + DbUtils.deleteFromEsDbByPattern("_all"); + createCategotyRest = CategoryRestUtils.createCategory(categoryDataDefinition2, sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDataDefinition2.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDataDefinition2); + // Get Category + getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDataDefinition2); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDataDefinition2, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + // CREATE CATEGORY FOR PRODUCT + DbUtils.deleteFromEsDbByPattern("_all"); + RestResponse addCategotyRest = CategoryRestUtils.createCategory(categoryDataDefinition3, + sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + addCategotyRest.getErrorCode().intValue()); + categoryDataDefinition3.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateCategoryResponse(addCategotyRest, categoryDataDefinition3); + + // Get Category + getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDataDefinition3); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncProductStrategistUserDetails, + STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void categoryNameValidationFirstLetterOfKeyWordsCapitalized() throws Exception { // First + // letter + // of + // key + // words + // are + // capitalized + categoryDefinition.setName("beNNy shaY michEl"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("BeNNy ShaY MichEl"); + categoryDefinition.setNormalizedName("benny shay michel"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationConjunctions_01() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" bank OF america "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Bank of America"); + categoryDefinition.setNormalizedName("bank of america"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationConjunctions_02() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName("THE america bank "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("THE America Bank"); + categoryDefinition.setNormalizedName("the america bank"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationConjunctions_03() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" A bank OF america "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("A Bank of America"); + categoryDefinition.setNormalizedName("a bank of america"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationConjunctions_04() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" bank america is A big ban "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Bank America Is a Big Ban"); + categoryDefinition.setNormalizedName("bank america is a big ban"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationConjunctions_05() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" aN apple comPany inC "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("AN Apple ComPany InC"); + categoryDefinition.setNormalizedName("an apple company inc"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationConjunctions_06() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" eat AN apple ANAN"); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Eat an Apple ANAN"); + categoryDefinition.setNormalizedName("eat an apple anan"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationConjunctions_07() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" united states OF americA "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("United States of AmericA"); + categoryDefinition.setNormalizedName("united states of america"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + // need to re-check + @Test + public void categoryNameValidationConjunctions_08() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" oF united states OF amer "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("OF United States of Amer"); + categoryDefinition.setNormalizedName("of united states of amer"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationConjunctions_09() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" to Apple TO at&T TOO "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("To Apple to At&T TOO"); + categoryDefinition.setNormalizedName("to apple to at&t too"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationConjunctions_10() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" eat apple AS you liiikeas "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Eat Apple as You Liiikeas"); + categoryDefinition.setNormalizedName("eat apple as you liiikeas"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationConjunctions_11() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" as you may want "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("As You May Want"); + categoryDefinition.setNormalizedName("as you may want"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void categoryNameValidationConjunctions_12() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" the bank OF america "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("The Bank of America"); + categoryDefinition.setNormalizedName("the bank of america"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + // need to recheck + @Test + public void categoryNameValidationConjunctions_13() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" To tel-toto "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("To Tel-toto"); + categoryDefinition.setNormalizedName("to tel-toto"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + // recheck + @Test + public void categoryNameValidationConjunctions_14() throws Exception { // Normalize + // the + // category + // name + // conjunctions + // ('of', + // 'to', + // 'for', + // 'as', + // 'a', + // 'an' + // , + // 'the') + // are + // lower + // case. + categoryDefinition.setName(" tel-aviv To la "); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_CREATED, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Tel-aviv to La"); + categoryDefinition.setNormalizedName("tel-aviv to la"); + CategoryValidationUtils.validateCreateCategoryResponse(createCategotyRest, categoryDefinition); + // Get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + AuditValidationUtils.categoryAuditSuccess(ADD_CATEGORY, categoryDefinition, sdncAdminUserDetails, + STATUS_CODE_CREATED, AUDIT_SERVICE_TYPE); + } + + @Test + public void createServiceCategoryHttpCspUserIdIsEmpty() throws Exception { + User sdncAdminUserDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + sdncAdminUserDetails1.setUserId(""); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Consumer", STATUS_CODE_MISSING_INFORMATION, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Abcd"); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.MISSING_INFORMATION.name()); + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(ADD_CATEGORY); + expectedCatrgoryAuditJavaObject.setModifier(""); + expectedCatrgoryAuditJavaObject.setCategoryName(categoryDefinition.getName()); + expectedCatrgoryAuditJavaObject.setSubCategoryName(""); + expectedCatrgoryAuditJavaObject.setGroupingName(""); + expectedCatrgoryAuditJavaObject.setResourceType(AUDIT_SERVICE_TYPE); + expectedCatrgoryAuditJavaObject.setStatus(String.valueOf(STATUS_CODE_MISSING_INFORMATION)); + expectedCatrgoryAuditJavaObject.setDesc(errorInfo.getAuditDesc()); + AuditValidationUtils.validateCategoryAudit(expectedCatrgoryAuditJavaObject, ADD_CATEGORY); + } + + @Test + public void createServiceCategorHttpCspUserIdIsNull() throws Exception { + User sdncAdminUserDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + sdncAdminUserDetails1.setUserId(null); + RestResponse createCategotyRest = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails1, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Consumer", STATUS_CODE_MISSING_INFORMATION, + createCategotyRest.getErrorCode().intValue()); + categoryDefinition.setName("Abcd"); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.MISSING_INFORMATION.name()); + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(ADD_CATEGORY); + expectedCatrgoryAuditJavaObject.setModifier(""); + expectedCatrgoryAuditJavaObject.setCategoryName(categoryDefinition.getName()); + expectedCatrgoryAuditJavaObject.setSubCategoryName(""); + expectedCatrgoryAuditJavaObject.setGroupingName(""); + expectedCatrgoryAuditJavaObject.setResourceType(AUDIT_SERVICE_TYPE); + expectedCatrgoryAuditJavaObject.setStatus(String.valueOf(STATUS_CODE_MISSING_INFORMATION)); + expectedCatrgoryAuditJavaObject.setDesc(errorInfo.getAuditDesc()); + AuditValidationUtils.validateCategoryAudit(expectedCatrgoryAuditJavaObject, ADD_CATEGORY); + } + + @Test + public void createSrvcCategoryHttpCspUserIdHeaderIsMissing() throws Exception { + RestResponse createConsumerRest = CategoryRestUtils + .createServiceCategoryHttpCspAtuUidIsMissing(categoryDefinition, sdncAdminUserDetails); + assertEquals("Check response code after create Consumer", STATUS_CODE_MISSING_INFORMATION, + createConsumerRest.getErrorCode().intValue()); + categoryDefinition.setName("Abcd"); + // get service category and validate that category was not added + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyCategoryNotExistsInGetResponse(getAllCategoriesRest, categoryDefinition); + // Audit validation + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.MISSING_INFORMATION.name()); + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(ADD_CATEGORY); + expectedCatrgoryAuditJavaObject.setModifier(""); + expectedCatrgoryAuditJavaObject.setCategoryName(categoryDefinition.getName()); + expectedCatrgoryAuditJavaObject.setSubCategoryName(""); + expectedCatrgoryAuditJavaObject.setGroupingName(""); + expectedCatrgoryAuditJavaObject.setResourceType(AUDIT_SERVICE_TYPE); + expectedCatrgoryAuditJavaObject.setStatus(String.valueOf(STATUS_CODE_MISSING_INFORMATION)); + expectedCatrgoryAuditJavaObject.setDesc(errorInfo.getAuditDesc()); + AuditValidationUtils.validateCategoryAudit(expectedCatrgoryAuditJavaObject, ADD_CATEGORY); + } + + @Test + public void getServiceCategoryHierarchySuccessFlow() throws Exception { + + int numOfCategories = 3; + List<CategoryDefinition> categories = new ArrayList<CategoryDefinition>(); + RestResponse restResponse; + CategoryDefinition category; + String categoryName = categoryDefinition.getName(); + for (int i = 0; i < numOfCategories; i++) { + categoryDefinition.setName(categoryName + i); + restResponse = CategoryRestUtils.createCategory(categoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + category = ResponseParser.parseToObject(restResponse.getResponse(), CategoryDefinition.class); + categories.add(category); + } + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + + AuditValidationUtils.GetCategoryHierarchyAuditSuccess(GET_CATEGORY_HIERARCHY, AUDIT_SERVICE_TYPE, + sdncAdminUserDetails, STATUS_CODE_SUCCESS); + for (CategoryDefinition categoryCurr : categories) { + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryCurr); + } + } + + ///////////////////////////////// US570520 ///////////////////////////////// + private List<CategoryDefinition> defineCategories() throws Exception { + String firstCategory = "FirstCategory"; + String secondCategory = "secondCategory"; + String thirdCategory = "ThirdCategory"; + String forthCategory = "forthCategory"; + CategoryDefinition category1 = new CategoryDefinition(categoryDefinition); + category1.setName(firstCategory); + CategoryDefinition category2 = new CategoryDefinition(categoryDefinition); + category2.setName(secondCategory); + CategoryDefinition category3 = new CategoryDefinition(categoryDefinition); + category3.setName(thirdCategory); + CategoryDefinition category4 = new CategoryDefinition(categoryDefinition); + category4.setName(forthCategory); + ArrayList<CategoryDefinition> categoryList = new ArrayList<CategoryDefinition>(); + categoryList.add(category1); + categoryList.add(category2); + categoryList.add(category3); + categoryList.add(category4); + return categoryList; + } + + @Test + public void getAllResourceCategoriesHirarchy() throws Exception { + createAndValidateCategoriesExist(RESOURCE_COMPONENT_TYPE, categoryList); + + for (int i = 0; i < categoryList.size(); i++) { + List<String> subCategorieUniqueIdList = new ArrayList<String>(); + for (int j = 0; j < subCategoryList.size(); j++) { + RestResponse createSubCategory = CategoryRestUtils.createSubCategory(subCategoryList.get(j), + categoryList.get(i), sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + if (createSubCategory.getErrorCode().intValue() == STATUS_CODE_CREATED) { + String subCategoryUniqeId = ResponseParser.getUniqueIdFromResponse(createSubCategory); + subCategorieUniqueIdList.add(subCategoryUniqeId); + subCategoriesToDeleteMap.put(categoryList.get(i).getUniqueId(), subCategorieUniqueIdList); + } + } + } + + DbUtils.deleteFromEsDbByPattern("_all"); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + + for (int i = 0; i < categoryList.size(); i++) { + for (int j = 0; j < subCategoryList.size(); j++) { + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + categoryList.get(i).getUniqueId(), subCategoryList.get(j)); + } + } + + checkAuditSuccess(RESOURCE_COMPONENT_TYPE); + } + + private List<SubCategoryDefinition> defineSubCategories(int catListSize) { + List<SubCategoryDefinition> subCatList = new ArrayList<SubCategoryDefinition>(); + for (int j = 1; j <= catListSize; j++) { + SubCategoryDefinition subCategory = new SubCategoryDefinition(); + subCategory.setName("SubCategory" + String.valueOf(j)); + subCatList.add(subCategory); + } + return subCatList; + } + + private void createAndValidateCategoriesExist(String comp, List<CategoryDefinition> categoryList) throws Exception { + createCategories(comp, categoryList); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, comp); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + verifyCategoriesExist(categoryList, getAllCategoriesRest); + } + + private void verifyCategoriesExist(List<CategoryDefinition> categoryList, RestResponse getAllCategoriesRest) { + for (int i = 0; i < categoryList.size(); i++) { + categoryList.get(i).setName(WordUtils.capitalize(categoryList.get(i).getName())); + CategoryValidationUtils.verifyCategoryExistInGetResponse(getAllCategoriesRest, categoryList.get(i)); + } + } + + private void createCategories(String comp, List<CategoryDefinition> categoryList) throws Exception { + for (int i = 0; i < categoryList.size(); i++) { + CategoryRestUtils.createCategory(categoryList.get(i), sdncAdminUserDetails, comp); + } + } + + @Test + public void getAllServiceCategoriesHirarchy() throws Exception { + // deleteCategories(categoryList, SERVICE_COMPONENT_TYPE); + createAndValidateCategoriesExist(SERVICE_COMPONENT_TYPE, categoryList); + checkAuditSuccess(SERVICE_COMPONENT_TYPE); + // deleteCategories(categoryList, SERVICE_COMPONENT_TYPE); + } + + @Test + public void getAllResourceCategories_noAttUserHeader() throws Exception { + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(new User(), RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", 403, getAllCategoriesRest.getErrorCode().intValue()); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.MISSING_INFORMATION.name(), new ArrayList<String>(), + getAllCategoriesRest.getResponse()); + + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.MISSING_INFORMATION.name()); + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(GET_CATEGORY_HIERARCHY); + expectedCatrgoryAuditJavaObject.setModifierName(""); + expectedCatrgoryAuditJavaObject.setModifierUid(""); + expectedCatrgoryAuditJavaObject.setDetails(RESOURCE_COMPONENT_TYPE); + expectedCatrgoryAuditJavaObject.setStatus(String.valueOf(STATUS_CODE_MISSING_INFORMATION)); + expectedCatrgoryAuditJavaObject.setDesc(errorInfo.getAuditDesc()); + AuditValidationUtils.validateGetCategoryHirarchy(expectedCatrgoryAuditJavaObject, GET_CATEGORY_HIERARCHY); + } + + @Test + public void getAllResourceCategories_userNotProvisioned() throws Exception { + User notProvisionedUser = new User(); + notProvisionedUser.setUserId("aa0001"); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(notProvisionedUser, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", 409, getAllCategoriesRest.getErrorCode().intValue()); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESTRICTED_OPERATION.name(), new ArrayList<String>(), + getAllCategoriesRest.getResponse()); + + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.RESTRICTED_OPERATION.name()); + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(GET_CATEGORY_HIERARCHY); + expectedCatrgoryAuditJavaObject.setModifierName(""); + expectedCatrgoryAuditJavaObject.setModifierUid(notProvisionedUser.getUserId()); + expectedCatrgoryAuditJavaObject.setDetails(RESOURCE_COMPONENT_TYPE); + expectedCatrgoryAuditJavaObject.setStatus(String.valueOf(STATUS_CODE_RESTRICTED_OPERATION)); + expectedCatrgoryAuditJavaObject.setDesc(errorInfo.getAuditDesc()); + AuditValidationUtils.validateGetCategoryHirarchy(expectedCatrgoryAuditJavaObject, GET_CATEGORY_HIERARCHY); + } + + @Test + public void getAllResourceCategories_unsupportedComponent() throws Exception { + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, "comp"); + assertEquals("Check response code after get all categories hirarchy", 400, + getAllCategoriesRest.getErrorCode().intValue()); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.UNSUPPORTED_ERROR.name(), + new ArrayList<String>(Arrays.asList("component type")), getAllCategoriesRest.getResponse()); + + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.UNSUPPORTED_ERROR.name()); + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(GET_CATEGORY_HIERARCHY); + expectedCatrgoryAuditJavaObject.setModifierUid(sdncAdminUserDetails.getUserId()); + expectedCatrgoryAuditJavaObject.setModifierName(sdncAdminUserDetails.getFullName()); + expectedCatrgoryAuditJavaObject.setDetails("comp"); + expectedCatrgoryAuditJavaObject.setStatus(String.valueOf(STATUS_CODE_INVALID_CONTENT)); + expectedCatrgoryAuditJavaObject.setDesc(AuditValidationUtils.buildAuditDescription(errorInfo, + new ArrayList<String>(Arrays.asList("component type")))); + AuditValidationUtils.validateGetCategoryHirarchy(expectedCatrgoryAuditJavaObject, GET_CATEGORY_HIERARCHY); + } + + @Test(enabled = false) + public void getAllResourceCategories_emptyList() throws Exception { + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + JSONArray jArr = new JSONArray(getAllCategoriesRest.getResponse()); + assertTrue(jArr.length() == 0); + + checkAuditSuccess(RESOURCE_COMPONENT_TYPE); + } + + private void checkAuditSuccess(String componentType) throws Exception { + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(GET_CATEGORY_HIERARCHY); + expectedCatrgoryAuditJavaObject.setModifierName(sdncAdminUserDetails.getFullName()); + expectedCatrgoryAuditJavaObject.setModifierUid(sdncAdminUserDetails.getUserId()); + expectedCatrgoryAuditJavaObject.setDetails(componentType); + expectedCatrgoryAuditJavaObject.setStatus("200"); + expectedCatrgoryAuditJavaObject.setDesc("OK"); + AuditValidationUtils.validateGetCategoryHirarchy(expectedCatrgoryAuditJavaObject, GET_CATEGORY_HIERARCHY); + } + + @Test(enabled = false) + public void getAllServiceCategories_emptyList() throws Exception { + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + JSONArray jArr = new JSONArray(getAllCategoriesRest.getResponse()); + assertTrue(jArr.length() == 0); + + checkAuditSuccess(SERVICE_COMPONENT_TYPE); + } + + @Test(enabled = false) + public void getAllProductCategories_emptyList() throws Exception { + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get Category", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + JSONArray jArr = new JSONArray(getAllCategoriesRest.getResponse()); + assertTrue(jArr.length() == 0); + + checkAuditSuccess(PRODUCT_COMPONENT_TYPE); + } + + // @Test + // public void getAllResourceCategories_generalError() throws Exception + // { + // User user = new User(); + // RestResponse getAllCategoriesRest = + // CategoryRestUtils.getAllCategories(user, SERVICE_COMPONENT_TYPE); + // assertEquals("Check response code after get Category", 500, + // getAllCategoriesRest.getErrorCode().intValue()); + // Utils.checkBodyResponseOnError(ActionStatus.GENERAL_ERROR.name(), new + // ArrayList<String>(), getAllCategoriesRest.getResponse()); + // } + + ////////////////////////////////////////////////////////////////////////////// + + @Test + public void importCategories() throws Exception { + + String importResourceDir = config.getImportTypesConfigDir() + File.separator + "categoryTypesTest.zip"; + + MultipartEntityBuilder mpBuilder = MultipartEntityBuilder.create(); + mpBuilder.addPart("categoriesZip", new FileBody(new File(importResourceDir))); + + RestResponse importResult = CategoryRestUtils.importCategories(mpBuilder, sdncAdminUserDetails.getUserId()); + assertEquals("Check response code after Import", BaseRestUtils.STATUS_CODE_CREATED, + importResult.getErrorCode().intValue()); + + Map<String, Object> map = ResponseParser.parseToObjectUsingMapper(importResult.getResponse(), Map.class); + assertEquals("Check entries count", 2, map.size()); + + List<Map<String, Object>> resources = (List<Map<String, Object>>) map.get("resources"); + assertEquals("Check resource category entries count", 1, resources.size()); + + List<Map<String, Object>> services = (List<Map<String, Object>>) map.get("services"); + assertEquals("Check resource category entries count", 2, services.size()); + + RestResponse allCategories = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, "resources"); + List<CategoryDefinition> resourceCategories = ResponseParser.parseCategories(allCategories); + for (Map<String, Object> resource : resources) { + boolean exist = false; + + for (CategoryDefinition categ : resourceCategories) { + if (categ.getName().equals(resource.get("name"))) { + exist = true; + break; + } + } + assertTrue("Check existance resource category " + resource.get("name"), exist); + } + + allCategories = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, "services"); + List<CategoryDefinition> servicesCategories = ResponseParser.parseCategories(allCategories); + for (Map<String, Object> service : services) { + boolean exist = false; + + for (CategoryDefinition categ : servicesCategories) { + if (categ.getName().equals(service.get("name"))) { + exist = true; + break; + } + } + assertTrue("Check existance service category " + service.get("name"), exist); + } + } +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/ElementsApiTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/ElementsApiTest.java new file mode 100644 index 0000000000..2f48f4fa1e --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/ElementsApiTest.java @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.ci.tests.execute.category; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.lf5.util.ResourceUtils; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.ci.tests.api.ComponentBaseTest; +import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.utils.rest.CatalogRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils; +import org.testng.annotations.Test; + +public class ElementsApiTest extends ComponentBaseTest { + + @Rule + public static TestName name = new TestName(); + + public ElementsApiTest() { + super(name, ElementsApiTest.class.getName()); + } + + // public LCSbaseTest(TestName testName, String className) { + // super(testName, className); + // } + + // public ElementsApiTest(TestName name, String name2) { + //// super(name, name2); + // // TODO Auto-generated constructor stub + // } + + // Expected 200 Keep + @Test + public void getAllPropertyScopesSuccess() throws Exception { + RestResponse response = ResourceRestUtils.getAllPropertyScopesTowardsCatalogBe(); + String action = "Get All Property Scopes"; + int expectedCode = 200; + verifyErrorCode(response, action, expectedCode); + } + + // Expected 200 Keep + @Test + public void getAllArtifactTypes() throws Exception { + RestResponse response = ResourceRestUtils.getAllArtifactTypesTowardsCatalogBe(); + String action = "Get All Artifact Types"; + int expectedCode = 200; + verifyErrorCode(response, action, expectedCode); + } + + // Expected 200 Keep + @Test + public void getConfiguration() throws Exception { + RestResponse response = ResourceRestUtils.getConfigurationTowardsCatalogBe(); + String action = "Get All Artifact Types"; + int expectedCode = 200; + + String json = response.getResponse(); + JSONObject jsonResp = (JSONObject) JSONValue.parse(json); + + HashMap<String, Object> artifacts = (HashMap<String, Object>) jsonResp.get("artifacts"); + Long defaultHeatTimeout = (Long) jsonResp.get("defaultHeatTimeout"); + + if (defaultHeatTimeout == null) { + response.setErrorCode(500); + verifyErrorCode(response, action, expectedCode); + return; + } + + if (artifacts == null) { + response.setErrorCode(500); + verifyErrorCode(response, action, expectedCode); + return; + } + + JSONObject deploymentResources = (JSONObject) artifacts.get("deployment"); + JSONArray otherResources = (JSONArray) artifacts.get("other"); + if (deploymentResources == null || otherResources == null) { + response.setErrorCode(500); + verifyErrorCode(response, action, expectedCode); + return; + } + + JSONArray roles = (JSONArray) jsonResp.get("roles"); + if (roles == null) { + response.setErrorCode(500); + verifyErrorCode(response, action, expectedCode); + return; + } + + } + + public void verifyErrorCode(RestResponse response, String action, int expectedCode) { + assertNotNull("check response object is not null after " + action, response); + assertNotNull("check error code exists in response after " + action, response.getErrorCode()); + assertEquals("Check response code after + action" + action, expectedCode, response.getErrorCode().intValue()); + } + + @Test(enabled = false) + public void getAllCategoriesSuccess() throws Exception { + Map<String, String> headersMap = new HashMap<String, String>(); + headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json"); + headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json"); + RestResponse response = CatalogRestUtils.getAllCategoriesTowardsCatalogBe(); + String action = "Get All Categories"; + int expectedCode = 200; + verifyErrorCode(response, action, expectedCode); + } + + @Test(enabled = false) + public void getAllTagSuccess() throws Exception { + Map<String, String> headersMap = new HashMap<String, String>(); + headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json"); + headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json"); + RestResponse response = ResourceRestUtils.getAllTagsTowardsCatalogBe(); + String action = "Get All Categories"; + int expectedCode = 200; + verifyErrorCode(response, action, expectedCode); + } + +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/GroupingTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/GroupingTest.java new file mode 100644 index 0000000000..f6b6113b99 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/GroupingTest.java @@ -0,0 +1,2007 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.ci.tests.execute.category; + +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.PRODUCT_COMPONENT_TYPE; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.RESOURCE_COMPONENT_TYPE; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.SERVICE_COMPONENT_TYPE; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_ALREADY_EXISTS; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_CREATED; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_INVALID_CONTENT; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_MISSING_INFORMATION; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_NOT_FOUND; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_RESTRICTED_OPERATION; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_SUCCESS; +import static org.testng.AssertJUnit.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.category.CategoryDefinition; +import org.openecomp.sdc.be.model.category.GroupingDefinition; +import org.openecomp.sdc.be.model.category.SubCategoryDefinition; +import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo; +import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; +import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedCategoryAudit; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.utils.DbUtils; +import org.openecomp.sdc.ci.tests.utils.Utils; +import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; +import org.openecomp.sdc.ci.tests.utils.rest.CategoryRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser; +import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.CategoryValidationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils; +import org.testng.SkipException; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class GroupingTest extends CategoriesBaseTest { + + protected static final String ADD_GROUPING = "AddGrouping"; + protected static final String CATEGORY = "category"; + protected static final String SUB_CATEGORY = "sub-category"; + protected static final String GROUPING = "grouping"; + + public GroupingTest() { + super(name, GroupingTest.class.getName()); + } + + @Rule + public static TestName name = new TestName(); + + private CategoryDefinition productCategoryDefinition; + private CategoryDefinition productCategoryDefinition2; + + private SubCategoryDefinition productSubCategoryDefinition; + private SubCategoryDefinition productSubCategoryDefinition2; + private SubCategoryDefinition productSubCategoryDefinition3; + + private GroupingDefinition productGroupingDefinition; + private GroupingDefinition productGroupingDefinition2; + private GroupingDefinition productGroupingDefinition3; + + @BeforeMethod + public void init() throws Exception { + + // Category setup + productCategoryDefinition = new CategoryDefinition(); + productCategoryDefinition.setName("Category1"); + productCategoryDefinition2 = new CategoryDefinition(); + productCategoryDefinition2.setName("Category2"); + + // Subcategory setup + productSubCategoryDefinition = new SubCategoryDefinition(); + productSubCategoryDefinition.setName("SubCategory1"); + + productSubCategoryDefinition2 = new SubCategoryDefinition(); + productSubCategoryDefinition2.setName("SubCategory2"); + + productSubCategoryDefinition3 = new SubCategoryDefinition(); + productSubCategoryDefinition3.setName("SubCategory1"); + + // Group setup + productGroupingDefinition = new GroupingDefinition(); + productGroupingDefinition.setName("Grouping1"); + + productGroupingDefinition2 = new GroupingDefinition(); + productGroupingDefinition2.setName("Grouping2"); + + productGroupingDefinition3 = new GroupingDefinition(); + productGroupingDefinition3.setName("Grouping1"); + + // Init product category + RestResponse createCategory = CategoryRestUtils.createCategory(productCategoryDefinition, + sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create category", STATUS_CODE_CREATED, + createCategory.getErrorCode().intValue()); + CategoryDefinition category = ResponseParser.parseToObject(createCategory.getResponse(), + CategoryDefinition.class); + assertEquals("Check category name after creating category ", productCategoryDefinition.getName(), + category.getName()); + productCategoryDefinition = category; + + // Init product category1 + createCategory = CategoryRestUtils.createCategory(productCategoryDefinition2, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create category", STATUS_CODE_CREATED, + createCategory.getErrorCode().intValue()); + category = ResponseParser.parseToObject(createCategory.getResponse(), CategoryDefinition.class); + assertEquals("Check category name after creating category ", productCategoryDefinition2.getName(), + category.getName()); + productCategoryDefinition2 = category; + + // Init product productSubCategoryDefinition to + // productCategoryDefinition + RestResponse createSubCategory = CategoryRestUtils.createSubCategory(productSubCategoryDefinition, + productCategoryDefinition, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create category", STATUS_CODE_CREATED, + createSubCategory.getErrorCode().intValue()); + SubCategoryDefinition subCategory = ResponseParser.parseToObject(createSubCategory.getResponse(), + SubCategoryDefinition.class); + assertEquals("Check category name after creating category ", productSubCategoryDefinition.getName(), + subCategory.getName()); + productSubCategoryDefinition = subCategory; + productCategoryDefinition.addSubCategory(productSubCategoryDefinition); + + // Init product productSubCategoryDefinition1 to + // productCategoryDefinition + createSubCategory = CategoryRestUtils.createSubCategory(productSubCategoryDefinition2, + productCategoryDefinition, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create category", STATUS_CODE_CREATED, + createSubCategory.getErrorCode().intValue()); + subCategory = ResponseParser.parseToObject(createSubCategory.getResponse(), SubCategoryDefinition.class); + assertEquals("Check category name after creating category ", productSubCategoryDefinition2.getName(), + subCategory.getName()); + productSubCategoryDefinition2 = subCategory; + productCategoryDefinition.addSubCategory(productSubCategoryDefinition2); + + // Init product productSubCategoryDefinition3 to + // productCategoryDefinition2 + createSubCategory = CategoryRestUtils.createSubCategory(productSubCategoryDefinition3, + productCategoryDefinition2, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create category", STATUS_CODE_CREATED, + createSubCategory.getErrorCode().intValue()); + subCategory = ResponseParser.parseToObject(createSubCategory.getResponse(), SubCategoryDefinition.class); + assertEquals("Check category name after creating category ", productSubCategoryDefinition3.getName(), + subCategory.getName()); + productSubCategoryDefinition3 = subCategory; + productCategoryDefinition2.addSubCategory(productSubCategoryDefinition3); + } + + @Test + public void createProductGroupCategorySuccess() throws Exception { + createGroupingSuccess(productGroupingDefinition, productSubCategoryDefinition, productCategoryDefinition, + sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE, AUDIT_PRODUCT_TYPE); + } + + private void createGroupingSuccess(GroupingDefinition groupingDefinition, + SubCategoryDefinition subCategoryDefinition, CategoryDefinition categoryDefinition, + User sdncProductStrategistUserDetails, String productComponentType, String auditType) throws Exception { + + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(groupingDefinition, subCategoryDefinition, + categoryDefinition, sdncProductStrategistUserDetails, productComponentType); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("grouping1"); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + productComponentType); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, categoryDefinition.getUniqueId(), + subCategoryDefinition.getUniqueId(), groupingDefinition); + + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, categoryDefinition, subCategoryDefinition, + groupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, auditType); + } + + //// Benny + + @Test + public void createProductGroupByProductStrategist() throws Exception { + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("grouping1"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void createProductGroupAlreadyExistInSameCategorySubCategory() throws Exception { + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("grouping1"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + // Create Same Group already exist on same Category/SubCategory + DbUtils.deleteFromEsDbByPattern("_all"); + createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, productSubCategoryDefinition, + productCategoryDefinition, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_ALREADY_EXISTS, + createGroupingRest.getErrorCode().intValue()); + AuditValidationUtils.groupingAuditFailure(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, + ActionStatus.COMPONENT_GROUPING_EXISTS_FOR_SUB_CATEGORY, STATUS_CODE_ALREADY_EXISTS, AUDIT_PRODUCT_TYPE, + AUDIT_PRODUCT_TYPE, productGroupingDefinition.getName(), productSubCategoryDefinition.getName()); + } + + @Test + public void createProductGroupUnderSameCategoryButDifferentSubCategory() throws Exception { + // Setting : Category-A, Sub-category-B , group : aBcd (display-Name : + // ABcd, normalized: abcd) ïƒ [A, B, ABcd] + // Action : Category-A, Sub-category-C, group : abcD (display-Name : + // ABcd, normalized: abcd) ïƒ [A, C, ABcd] + productGroupingDefinition.setName("ABCd"); + productGroupingDefinition2.setName("abcD"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + + DbUtils.deleteFromEsDbByPattern("_all"); + createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition2, productSubCategoryDefinition2, + productCategoryDefinition, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition2.setName("ABCd"); + productGroupingDefinition2.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition2); + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, + productSubCategoryDefinition2, productGroupingDefinition2, sdncProductStrategistUserDetails, + STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition2.getUniqueId(), + productGroupingDefinition2); + } + + @Test + public void createProductGroupUnderSameSubCategoryButDifferentCategory() throws Exception { + // Setting : Category-A, Sub-category-B , group : aBcd (display-Name : + // ABcd, normalized: abcd) ïƒ [A, B, ABcd] + // : Category-A, Sub-category-C, group : abcD (display-Name : ABcd, + // normalized: abcd) ïƒ [A, C, ABcd] + // : Category-K, Sub-category-B, group : abcD (display-Name : ABcd, + // normalized: abcd) ïƒ [K, B, ABcd] + productGroupingDefinition.setName("ABCd"); + productGroupingDefinition2.setName("abcD"); + productGroupingDefinition3.setName("aBCd"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + + DbUtils.deleteFromEsDbByPattern("_all"); + createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition2, productSubCategoryDefinition2, + productCategoryDefinition, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition2.setName("ABCd"); + productGroupingDefinition2.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition2); + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, + productSubCategoryDefinition2, productGroupingDefinition2, sdncProductStrategistUserDetails, + STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + DbUtils.deleteFromEsDbByPattern("_all"); + createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition3, productSubCategoryDefinition3, + productCategoryDefinition2, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition3.setName("ABCd"); + productGroupingDefinition3.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition3); + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition2, + productSubCategoryDefinition3, productGroupingDefinition3, sdncProductStrategistUserDetails, + STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition2.getUniqueId(), + productGroupingDefinition2); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition2.getUniqueId(), productSubCategoryDefinition3.getUniqueId(), + productGroupingDefinition3); + + } + + @Test + public void createProductGroupsOnSameCategorySubCategory() throws Exception { + // Setting : Category-A, Sub-category-B , group : ABcd (display-Name : + // ABcd, normalized: abcd) [A ,B, ABcd] + // Action : Category-A, Sub-category-B, group : ZXcv (display-Name : + // ZXcv, normalized: zxcv) [A, B, ZXcv] + productGroupingDefinition.setName("ABcd"); + productGroupingDefinition2.setName("ZXcv"); + productGroupingDefinition2.setNormalizedName("zxcv"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + + DbUtils.deleteFromEsDbByPattern("_all"); + createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition2, productSubCategoryDefinition, + productCategoryDefinition, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition2); + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition2, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition2); + } + + @Test + public void createProductGroupUnderDifferentCategory() throws Exception { + // Setting : Category-A, Sub-category-B , group : aBcd (display-Name : + // ABcd, normalized: abcd) [A ,B, ABcd] + // Action : Category-K, Sub-category-B, group : abcD (display-Name : + // ABcd, normalized: abcd) [K, B, ABcd] + // productGroupingDefinition.setName("ABCd"); + productGroupingDefinition.setName("ABcD"); + productGroupingDefinition2.setName("abcD"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("abcd"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + + DbUtils.deleteFromEsDbByPattern("_all"); + createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition2, productSubCategoryDefinition3, + productCategoryDefinition2, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition2.setNormalizedName("abcd"); + productGroupingDefinition2.setName("ABcD"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition2); + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition2, + productSubCategoryDefinition3, productGroupingDefinition2, sdncProductStrategistUserDetails, + STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition2.getUniqueId(), productSubCategoryDefinition3.getUniqueId(), + productGroupingDefinition2); + } + + /////////// + @Test + public void createProductGroupByNonProductStrategist() throws Exception { + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncAdminUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_RESTRICTED_OPERATION, + createGroupingRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + productCategoryDefinition.setName(productCategoryDefinition.getUniqueId()); + productSubCategoryDefinition.setName(productSubCategoryDefinition.getUniqueId()); + AuditValidationUtils.groupingAuditFailure(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncAdminUserDetails, ActionStatus.RESTRICTED_OPERATION, + STATUS_CODE_RESTRICTED_OPERATION, AUDIT_PRODUCT_TYPE); + } + + // @Ignore("DE176245") + @Test + public void createProductGroupForNonExistingComponentType() throws Exception { + String nonSupportedComponentType = "NonExistingComponentType"; // instead + // resource/product + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + nonSupportedComponentType); + assertEquals("Check response code after create Sub category", STATUS_CODE_INVALID_CONTENT, + createGroupingRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + productCategoryDefinition.setName(productCategoryDefinition.getUniqueId()); + productSubCategoryDefinition.setName(productSubCategoryDefinition.getUniqueId()); + AuditValidationUtils.groupingAuditFailure(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, ActionStatus.INVALID_CONTENT, + STATUS_CODE_INVALID_CONTENT, nonSupportedComponentType); + } + + // @Ignore("DE176245") + @Test + public void createResourceGroup() throws Exception { + // Resource doesn't have group + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_INVALID_CONTENT, + createGroupingRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + productCategoryDefinition.setName(productCategoryDefinition.getUniqueId()); + productSubCategoryDefinition.setName(productSubCategoryDefinition.getUniqueId()); + AuditValidationUtils.groupingAuditFailure(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, ActionStatus.INVALID_CONTENT, + STATUS_CODE_INVALID_CONTENT, AUDIT_RESOURCE_TYPE); + } + + // @Ignore("DE176245") + @Test + public void createServiceGroup() throws Exception { + // Service doesn't have group + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_INVALID_CONTENT, + createGroupingRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + productCategoryDefinition.setName(productCategoryDefinition.getUniqueId()); + productSubCategoryDefinition.setName(productSubCategoryDefinition.getUniqueId()); + AuditValidationUtils.groupingAuditFailure(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, ActionStatus.INVALID_CONTENT, + STATUS_CODE_INVALID_CONTENT, AUDIT_SERVICE_TYPE); + } + + @Test + public void createProductGroupForNonExistingCategory() throws Exception { + + CategoryDefinition productCategoryDefinition100 = new CategoryDefinition(); + productCategoryDefinition100.setName("category.nonexistingCategory"); + productCategoryDefinition100.setUniqueId("category.nonexistingCategory"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition100, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_NOT_FOUND, + createGroupingRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + productSubCategoryDefinition.setName(productSubCategoryDefinition.getUniqueId()); + AuditValidationUtils.groupingAuditFailure(ADD_GROUPING, productCategoryDefinition100, + productSubCategoryDefinition, productGroupingDefinition, sdncProductStrategistUserDetails, + ActionStatus.COMPONENT_CATEGORY_NOT_FOUND, STATUS_CODE_NOT_FOUND, AUDIT_PRODUCT_TYPE, + PRODUCT_COMPONENT_TYPE, CATEGORY, ""); + } + + @Test + public void createProductGroupForNonExistingSunCategory() throws Exception { + throw new SkipException( + "Skipping - failed in audit validation expected \"products\" actual result was \"product\" "); + // SubCategoryDefinition productSubCategoryDefinition100 = new + // SubCategoryDefinition(); + // productSubCategoryDefinition100.setUniqueId("category.nonexistingSubCategory"); + // RestResponse createGroupingRest = + // CategoryRestUtils.createGrouping(productGroupingDefinition, + // productSubCategoryDefinition100, productCategoryDefinition, + // sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + // assertEquals("Check response code after create Sub category", + // STATUS_CODE_NOT_FOUND, createGroupingRest.getErrorCode().intValue()); + // RestResponse getAllCategoriesRest = + // CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + // PRODUCT_COMPONENT_TYPE); + // assertEquals("Check response code after get all categories ", + // STATUS_CODE_SUCCESS, getAllCategoriesRest.getErrorCode().intValue()); + // CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + // productCategoryDefinition.getUniqueId(), + // productSubCategoryDefinition.getUniqueId(), + // productGroupingDefinition); + // //Audit validation + // productSubCategoryDefinition100.setName(productSubCategoryDefinition100.getUniqueId()); + // AuditValidationUtils.groupingAuditFailure(ADD_GROUPING , + // productCategoryDefinition, productSubCategoryDefinition100, + // productGroupingDefinition, sdncProductStrategistUserDetails, + // ActionStatus.COMPONENT_CATEGORY_NOT_FOUND, + // STATUS_CODE_NOT_FOUND,AUDIT_PRODUCT_TYPE, PRODUCT_COMPONENT_TYPE, + // SUB_CATEGORY, ""); + } + + @Test + public void ProductGroupAllowedcharacters_01() throws Exception { + productGroupingDefinition.setName("1234AbcdE-"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde-"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_02() throws Exception { + productGroupingDefinition.setName("1234AbcdE+"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde+"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_03() throws Exception { + productGroupingDefinition.setName("1234AbcdE&"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde&"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_04() throws Exception { + productGroupingDefinition.setName("1234AbcdE-"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde-"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_05() throws Exception { + productGroupingDefinition.setName("1234AbcdE+"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde+"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_06() throws Exception { + productGroupingDefinition.setName("1234AbcdE."); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde."); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_07() throws Exception { + productGroupingDefinition.setName("1234AbcdE'"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde'"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_08() throws Exception { + productGroupingDefinition.setName("1234AbcdE="); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde="); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_09() throws Exception { + productGroupingDefinition.setName("1234AbcdE:"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde:"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_10() throws Exception { + productGroupingDefinition.setName("1234AbcdE@"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde@"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_11() throws Exception { + productGroupingDefinition.setName("1234AbcdE_"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde_"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_12() throws Exception { + productGroupingDefinition.setName("1234AbcdE#"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("1234abcde#"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void ProductGroupAllowedcharacters_13() throws Exception { + productGroupingDefinition.setName("1234AbcdE d"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("1234AbcdE D"); + productGroupingDefinition.setNormalizedName("1234abcde d"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveSpaceFromBeginning() throws Exception { + productGroupingDefinition.setName(" Category01"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("category01"); + productGroupingDefinition.setName("Category01"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveSpaceFromEnd() throws Exception { + productGroupingDefinition.setName("Category01 "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("category01"); + productGroupingDefinition.setName("Category01"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveExtraSpace() throws Exception { + productGroupingDefinition.setName("Category 02"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("category 02"); + productGroupingDefinition.setName("Category 02"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveExtraAmpersand() throws Exception { + productGroupingDefinition.setName("Category&& &02"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("category& &02"); + productGroupingDefinition.setName("Category& &02"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveExtraDash() throws Exception { + productGroupingDefinition.setName("CategorY-- --02"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("category- -02"); + productGroupingDefinition.setName("CategorY- -02"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveExtraPlus() throws Exception { + productGroupingDefinition.setName("CateGory++++ +02"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("CateGory+ +02"); + productGroupingDefinition.setNormalizedName("category+ +02"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveExtraPeriod() throws Exception { + productGroupingDefinition.setName("Category.... .02"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("Category. .02"); + productGroupingDefinition.setNormalizedName("category. .02"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveExtraApostrophe() throws Exception { + productGroupingDefinition.setName("CaTegory''' '02"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("CaTegory' '02"); + productGroupingDefinition.setNormalizedName("category' '02"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveExtraHashtag() throws Exception { + productGroupingDefinition.setName("Category### #02"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("Category# #02"); + productGroupingDefinition.setNormalizedName("category# #02"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveExtrEequal() throws Exception { + productGroupingDefinition.setName("Category=== =02"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("Category= =02"); + productGroupingDefinition.setNormalizedName("category= =02"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveExtrColon() throws Exception { + productGroupingDefinition.setName("Category::: :02"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("Category: :02"); + productGroupingDefinition.setNormalizedName("category: :02"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveExtrAt() throws Exception { + productGroupingDefinition.setName("Category@@@ @a2"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("Category@ @a2"); + productGroupingDefinition.setNormalizedName("category@ @a2"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_RemoveExtraUnderscore() throws Exception { + productGroupingDefinition.setName("Category___ _22"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("Category_ _22"); + productGroupingDefinition.setNormalizedName("category_ _22"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_FirstWordStartWithNumber() throws Exception { + productGroupingDefinition.setName("1Category one"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("1Category One"); + productGroupingDefinition.setNormalizedName("1category one"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_FirstWordStartWithNonAlphaNumeric() throws Exception { // The + // first + // word + // must + // start + // with + // an + // alpha-numeric + // character + // [a-Z + // A..Z, + // 0..9] + char invalidChars[] = { '&', '-', '+', '.', '\'', '#', '=', ':', '@', '_' }; + RestResponse createGroupingRest; + RestResponse getAllCategoriesRest; + for (int i = 0; i < invalidChars.length; i++) { + DbUtils.deleteFromEsDbByPattern("_all"); + productGroupingDefinition.setName(invalidChars[i] + "AbcD123"); + productGroupingDefinition.setNormalizedName((invalidChars[i] + "AbcD123").toLowerCase()); + createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_INVALID_CONTENT, + createGroupingRest.getErrorCode().intValue()); + + getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + } + } + + @Test + public void groupNameValidation_ReplaceAndWithAmpersand_01() throws Exception { + productGroupingDefinition.setName("At and T"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("At & T"); + productGroupingDefinition.setNormalizedName("at & t"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_ReplaceAndWithAmpersand_02() throws Exception { + productGroupingDefinition.setName("At and t"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("At & T"); + productGroupingDefinition.setNormalizedName("at & t"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_ReplaceAndWithAmpersand_03() throws Exception { + productGroupingDefinition.setName("Atand T"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("atand t"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_ReplaceAndWithAmpersand_04() throws Exception { + productGroupingDefinition.setName("At andT"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("at andt"); + productGroupingDefinition.setName("At AndT"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_ReplaceAndWithAmpersand_05() throws Exception { + productGroupingDefinition.setName(" and AttT"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("and attt"); + productGroupingDefinition.setName("And AttT"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_ReplaceAndWithAmpersand_06() throws Exception { + productGroupingDefinition.setName("AttT and "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("attt and"); + productGroupingDefinition.setName("AttT And"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidation_ReplaceAndWithAmpersand_07() throws Exception { + productGroupingDefinition.setName(" and a"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("and a"); + productGroupingDefinition.setName("And a"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationMaxLength() throws Exception { + productGroupingDefinition.setName("AsdfghjQ234567890@#.&:+-_"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("asdfghjq234567890@#.&:+-_"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationMaxLengthAfterNormalization() throws Exception { + productGroupingDefinition.setName(" A jQ234 @@@___ +++ At and T and and "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("a jq234 @_ + at & t & and"); + productGroupingDefinition.setName("A JQ234 @_ + At & T & And"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationExceedMaxLengthAfterNormalization() throws Exception { + productGroupingDefinition.setName(" AbdfghBCVa jQ234 @@___ +++ At and T "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_INVALID_CONTENT, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("abdfghbcva jq234 @_ + at&t"); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditFailure(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, STATUS_CODE_INVALID_CONTENT, AUDIT_PRODUCT_TYPE, + AUDIT_PRODUCT_TYPE, GROUPING); + } + + @Test + public void groupNameValidationMinLengthAfterNormalization() throws Exception { + productGroupingDefinition.setName(" At&&&&&&&&&&&&t "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("at&t"); + productGroupingDefinition.setName("At&t"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationLessThanMinLengthAfterNormalization() throws Exception { + productGroupingDefinition.setName(" A&&&&&&&&&&&&T "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_INVALID_CONTENT, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("a&t"); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditFailure(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, STATUS_CODE_INVALID_CONTENT, AUDIT_PRODUCT_TYPE, + AUDIT_PRODUCT_TYPE, GROUPING); + } + + @Test + public void groupNameValidationIsEmpty() throws Exception { + productGroupingDefinition.setName(""); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_INVALID_CONTENT, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName(""); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditFailure(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, STATUS_CODE_INVALID_CONTENT, AUDIT_PRODUCT_TYPE, + AUDIT_PRODUCT_TYPE, GROUPING); + } + + @Test + public void groupNameValidationInvalidCharacters() throws Exception { + RestResponse createGroupingRest; + RestResponse getAllCategoriesRest; + char invalidChars[] = { '~', '!', '$', '%', '^', '*', '(', ')', '"', '{', '}', '[', ']', '?', '>', '<', '/', + '|', '\\', ',' }; + for (int i = 0; i < invalidChars.length; i++) { + DbUtils.deleteFromEsDbByPattern("_all"); + productGroupingDefinition.setName("AbcD123" + invalidChars[i]); + createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_INVALID_CONTENT, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName(""); + getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditFailure(ADD_GROUPING, productCategoryDefinition, + productSubCategoryDefinition, productGroupingDefinition, sdncProductStrategistUserDetails, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, STATUS_CODE_INVALID_CONTENT, AUDIT_PRODUCT_TYPE, + AUDIT_PRODUCT_TYPE, GROUPING); + } + } + + @Test + public void groupNameValidationConjunctions_01() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" bank OF america "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setNormalizedName("bank of america"); + productGroupingDefinition.setName("Bank of America"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_02() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName("THE america bank "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("THE America Bank"); + productGroupingDefinition.setNormalizedName("the america bank"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_03() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" A bank OF america "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("A Bank of America"); + productGroupingDefinition.setNormalizedName("a bank of america"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_04() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" bank america is A big ban "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("Bank America Is a Big Ban"); + productGroupingDefinition.setNormalizedName("bank america is a big ban"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_05() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" aN apple comPany inC "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("AN Apple ComPany InC"); + productGroupingDefinition.setNormalizedName("an apple company inc"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_06() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" eat AN apple ANAN"); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("Eat an Apple ANAN"); + productGroupingDefinition.setNormalizedName("eat an apple anan"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_07() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" united states OF americA "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("United States of AmericA"); + productGroupingDefinition.setNormalizedName("united states of america"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_08() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" oF united states OF amer "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("OF United States of Amer"); + productGroupingDefinition.setNormalizedName("of united states of amer"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_09() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" to Apple TO at&T TOO "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("To Apple to At&T TOO"); + productGroupingDefinition.setNormalizedName("to apple to at&t too"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_10() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" eat apple AS you liiikeas "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("Eat Apple as You Liiikeas"); + productGroupingDefinition.setNormalizedName("eat apple as you liiikeas"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_11() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" as you may want "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("As You May Want"); + productGroupingDefinition.setNormalizedName("as you may want"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_12() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" the bank OF america "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("The Bank of America"); + productGroupingDefinition.setNormalizedName("the bank of america"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_13() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" To tel-toto "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("To Tel-toto"); + productGroupingDefinition.setNormalizedName("to tel-toto"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void groupNameValidationConjunctions_14() throws Exception { + // Normalize the grouping name conjunctions ('of', 'to', 'for', 'as', + // 'a', 'an' , 'the') are lower case. + productGroupingDefinition.setName(" tel-aviv To la "); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create product group", STATUS_CODE_CREATED, + createGroupingRest.getErrorCode().intValue()); + productGroupingDefinition.setName("Tel-aviv to La"); + productGroupingDefinition.setNormalizedName("tel-aviv to la"); + CategoryValidationUtils.validateCreateGroupResponse(createGroupingRest, productGroupingDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + AuditValidationUtils.groupingAuditSuccess(ADD_GROUPING, productCategoryDefinition, productSubCategoryDefinition, + productGroupingDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, AUDIT_PRODUCT_TYPE); + } + + @Test + public void createProductGroupHttpCspUserIdIsEmpty() throws Exception { + User sdncPS = ElementFactory.getDefaultUser(UserRoleEnum.PRODUCT_STRATEGIST1); + sdncPS.setUserId(""); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncPS, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Consumer", STATUS_CODE_MISSING_INFORMATION, + createGroupingRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.MISSING_INFORMATION.name()); + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(ADD_GROUPING); + expectedCatrgoryAuditJavaObject.setModifier(""); + expectedCatrgoryAuditJavaObject.setCategoryName(productCategoryDefinition.getUniqueId()); + expectedCatrgoryAuditJavaObject.setSubCategoryName(productSubCategoryDefinition.getUniqueId()); + expectedCatrgoryAuditJavaObject.setGroupingName(productGroupingDefinition.getName()); + expectedCatrgoryAuditJavaObject.setResourceType(AUDIT_PRODUCT_TYPE); + expectedCatrgoryAuditJavaObject.setStatus(String.valueOf(STATUS_CODE_MISSING_INFORMATION)); + expectedCatrgoryAuditJavaObject.setDesc(errorInfo.getAuditDesc()); + AuditValidationUtils.validateCategoryAudit(expectedCatrgoryAuditJavaObject, ADD_GROUPING); + } + + @Test + public void createProductGroupHttpCspUserIdIsNull() throws Exception { + User sdncPS = ElementFactory.getDefaultUser(UserRoleEnum.PRODUCT_STRATEGIST1); + sdncPS.setUserId(null); + RestResponse createGroupingRest = CategoryRestUtils.createGrouping(productGroupingDefinition, + productSubCategoryDefinition, productCategoryDefinition, sdncPS, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Consumer", STATUS_CODE_MISSING_INFORMATION, + createGroupingRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifyGroupingNotExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition.getUniqueId(), + productGroupingDefinition); + // Audit validation + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.MISSING_INFORMATION.name()); + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(ADD_GROUPING); + expectedCatrgoryAuditJavaObject.setModifier(""); + expectedCatrgoryAuditJavaObject.setCategoryName(productCategoryDefinition.getUniqueId()); + expectedCatrgoryAuditJavaObject.setSubCategoryName(productSubCategoryDefinition.getUniqueId()); + expectedCatrgoryAuditJavaObject.setGroupingName(productGroupingDefinition.getName()); + expectedCatrgoryAuditJavaObject.setResourceType(AUDIT_PRODUCT_TYPE); + expectedCatrgoryAuditJavaObject.setStatus(String.valueOf(STATUS_CODE_MISSING_INFORMATION)); + expectedCatrgoryAuditJavaObject.setDesc(errorInfo.getAuditDesc()); + AuditValidationUtils.validateCategoryAudit(expectedCatrgoryAuditJavaObject, ADD_GROUPING); + } + + //////////////////////////////////////////////// + /////////////////////////////////////////////// + @Test + public void getProductCategoryHierarchySuccessFlow() throws Exception { + throw new SkipException( + "Skipping - failed in audit validation expected \"products\" actual result was \"product\" "); + // int numOfGrouping = 3; + // List<GroupingDefinition> groupingList = new ArrayList<>(); + // RestResponse restResponse; + // GroupingDefinition grouping; + // String groupingName = productGroupingDefinition.getName(); + // for (int i = 0; i < numOfGrouping; i++) { + // productGroupingDefinition.setName(groupingName+i); + // restResponse = + // CategoryRestUtils.createGrouping(productGroupingDefinition, + // productSubCategoryDefinition, productCategoryDefinition, + // sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + // grouping = ResponseParser.parseToObject(restResponse.getResponse(), + // GroupingDefinition.class); + // groupingList.add(grouping); + // } + // RestResponse getAllCategoriesRest = + // CategoryRestUtils.getAllCategories(sdncProductStrategistUserDetails, + // PRODUCT_COMPONENT_TYPE); + // assertEquals("Check response code after get all categories ", + // STATUS_CODE_SUCCESS, getAllCategoriesRest.getErrorCode().intValue()); + // AuditValidationUtils.GetCategoryHierarchyAuditSuccess(GET_CATEGORY_HIERARCHY, + // AUDIT_PRODUCT_TYPE, sdncProductStrategistUserDetails, + // STATUS_CODE_SUCCESS); + // + // for (GroupingDefinition group : groupingList) { + // CategoryValidationUtils.verifyGroupingExistInGetResponse(getAllCategoriesRest, + // productCategoryDefinition.getUniqueId(), + // productSubCategoryDefinition.getUniqueId(), group); + // } + } +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/SubCategoriesTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/SubCategoriesTest.java new file mode 100644 index 0000000000..dcc3172d59 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/category/SubCategoriesTest.java @@ -0,0 +1,1908 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.ci.tests.execute.category; + +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.PRODUCT_COMPONENT_TYPE; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.RESOURCE_COMPONENT_TYPE; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.SERVICE_COMPONENT_TYPE; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_ALREADY_EXISTS; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_CREATED; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_INVALID_CONTENT; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_MISSING_INFORMATION; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_NOT_FOUND; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_RESTRICTED_OPERATION; +import static org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils.STATUS_CODE_SUCCESS; +import static org.testng.AssertJUnit.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.category.CategoryDefinition; +import org.openecomp.sdc.be.model.category.SubCategoryDefinition; +import org.openecomp.sdc.ci.tests.api.ComponentBaseTest; +import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo; +import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; +import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedCategoryAudit; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.utils.DbUtils; +import org.openecomp.sdc.ci.tests.utils.Utils; +import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; +import org.openecomp.sdc.ci.tests.utils.rest.CategoryRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser; +import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.CategoryValidationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class SubCategoriesTest extends ComponentBaseTest { + + protected static final String ADD_SUB_CATEGORY = "AddSubCategory"; + protected static final String CATEGORY = "category"; + protected static final String SUB_CATEGORY = "sub-category"; + + protected static final String AUDIT_SERVICE_TYPE = "Service"; + protected static final String AUDIT_RESOURCE_TYPE = "Resource"; + protected static final String AUDIT_PRODUCT_TYPE = "Product"; + protected static final String GET_CATEGORY_HIERARCHY = "GetCategoryHierarchy"; + protected static User sdncAdminUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + protected static User sdncAdminUserDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + protected static User sdncDesignerUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + protected static User sdncTesterUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.TESTER); + protected static User sdncGovernorUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.GOVERNOR); + protected static User sdncOpsUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.OPS); + protected static User sdncProductManagerUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.PRODUCT_MANAGER1); + protected static User sdncProductStrategistUserDetails = ElementFactory + .getDefaultUser(UserRoleEnum.PRODUCT_STRATEGIST1); + + public SubCategoriesTest() { + super(name, SubCategoriesTest.class.getName()); + } + + @Rule + public static TestName name = new TestName(); + + private CategoryDefinition resourceCategoryDefinition; + private CategoryDefinition resourceCategoryDefinition1; + private CategoryDefinition serviceCategoryDefinition; + private CategoryDefinition productCategoryDefinition; + private CategoryDefinition productCategoryDefinition1; + private CategoryDefinition resourceCategoryDefinition100; + private CategoryDefinition productCategoryDefinition200; + + private SubCategoryDefinition resourceSubCategoryDefinition; + private SubCategoryDefinition resourceSubCategoryDefinition1; + private SubCategoryDefinition serviceSubCategoryDefinition; + private SubCategoryDefinition productSubCategoryDefinition; + private SubCategoryDefinition productSubCategoryDefinition1; + + @BeforeMethod + public void init() throws Exception { + + // Category setup + resourceCategoryDefinition = new CategoryDefinition(); + resourceCategoryDefinition1 = new CategoryDefinition(); + serviceCategoryDefinition = new CategoryDefinition(); + productCategoryDefinition = new CategoryDefinition(); + productCategoryDefinition1 = new CategoryDefinition(); + resourceCategoryDefinition100 = new CategoryDefinition(); // for + // negative + // tests + productCategoryDefinition200 = new CategoryDefinition(); // for negative + // tests + + resourceCategoryDefinition.setName("Category1"); + resourceCategoryDefinition1.setName("Category2"); + serviceCategoryDefinition.setName("Category1"); + productCategoryDefinition.setName("Category2"); + productCategoryDefinition1.setName("Category3"); + resourceCategoryDefinition100.setName("Category100"); + productCategoryDefinition200.setName("Category100"); + + // Subcategory setup + resourceSubCategoryDefinition = new SubCategoryDefinition(); + resourceSubCategoryDefinition1 = new SubCategoryDefinition(); + serviceSubCategoryDefinition = new SubCategoryDefinition(); + productSubCategoryDefinition = new SubCategoryDefinition(); + productSubCategoryDefinition1 = new SubCategoryDefinition(); + + resourceSubCategoryDefinition.setName("Resource-subcat"); + // Service sub - for negative testing since it's not allowed + serviceSubCategoryDefinition.setName("Service-subcat"); + productSubCategoryDefinition.setName("Product-subcat"); + + // Init resource category + RestResponse createCategory = CategoryRestUtils.createCategory(resourceCategoryDefinition, sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create category", STATUS_CODE_CREATED, + createCategory.getErrorCode().intValue()); + CategoryDefinition category = ResponseParser.parseToObject(createCategory.getResponse(), + CategoryDefinition.class); + assertEquals("Check category name after creating category ", resourceCategoryDefinition.getName(), + category.getName()); + resourceCategoryDefinition = category; + + // Init resource category1 + createCategory = CategoryRestUtils.createCategory(resourceCategoryDefinition1, sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create category", STATUS_CODE_CREATED, + createCategory.getErrorCode().intValue()); + category = ResponseParser.parseToObject(createCategory.getResponse(), CategoryDefinition.class); + assertEquals("Check category name after creating category ", resourceCategoryDefinition1.getName(), + category.getName()); + resourceCategoryDefinition1 = category; + + // Init service category + createCategory = CategoryRestUtils.createCategory(serviceCategoryDefinition, sdncAdminUserDetails, + SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create category", STATUS_CODE_CREATED, + createCategory.getErrorCode().intValue()); + category = ResponseParser.parseToObject(createCategory.getResponse(), CategoryDefinition.class); + assertEquals("Check category name after creating category ", serviceCategoryDefinition.getName(), + category.getName()); + serviceCategoryDefinition = category; + + // Init product category + createCategory = CategoryRestUtils.createCategory(productCategoryDefinition, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create category", STATUS_CODE_CREATED, + createCategory.getErrorCode().intValue()); + category = ResponseParser.parseToObject(createCategory.getResponse(), CategoryDefinition.class); + assertEquals("Check category name after creating category ", productCategoryDefinition.getName(), + category.getName()); + productCategoryDefinition = category; + + // Init product category1 + createCategory = CategoryRestUtils.createCategory(productCategoryDefinition1, sdncProductStrategistUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create category", STATUS_CODE_CREATED, + createCategory.getErrorCode().intValue()); + category = ResponseParser.parseToObject(createCategory.getResponse(), CategoryDefinition.class); + assertEquals("Check category name after creating category ", productCategoryDefinition1.getName(), + category.getName()); + productCategoryDefinition1 = category; + + } + + @Test + public void createResourceSubCategorySuccess() throws Exception { + createSubCategorySuccess(resourceCategoryDefinition, resourceSubCategoryDefinition, sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE, AUDIT_RESOURCE_TYPE); + } + + @Test + public void createProductSubCategorySuccess() throws Exception { + createSubCategorySuccess(productCategoryDefinition, productSubCategoryDefinition, + sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE, AUDIT_PRODUCT_TYPE); + } + + @Test + public void createProductSubCategoryTwoCategoriesCaseInsensitive() throws Exception { + String componentType = PRODUCT_COMPONENT_TYPE; + String auditType = AUDIT_PRODUCT_TYPE; + User user = sdncProductStrategistUserDetails; + // Create product sub Category2-->Product-subcat + createSubCategorySuccess(productCategoryDefinition, productSubCategoryDefinition, user, componentType, + auditType); + DbUtils.deleteFromEsDbByPattern("_all"); + + // Create product sub Category3-->PRoDUCT-SUBcat + // Should be created Category3-->Product-subcat + productSubCategoryDefinition1.setName("PRoDUCT-SUBcat"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(productSubCategoryDefinition1, + productCategoryDefinition1, user, componentType); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(user, componentType); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + productSubCategoryDefinition1.setName(productSubCategoryDefinition.getName()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition1.getUniqueId(), productSubCategoryDefinition1); + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, productCategoryDefinition1, + productSubCategoryDefinition1, user, STATUS_CODE_CREATED, auditType); + } + + // Benny + @Test + public void createResourceSubCategoryAlreadyExistInDifferentResourceCategory() throws Exception { + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + DbUtils.deleteFromEsDbByPattern("_all"); + resourceSubCategoryDefinition1.setName("ResourcE-subCat"); + createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition1, + resourceCategoryDefinition1, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + resourceSubCategoryDefinition1.setName(resourceSubCategoryDefinition.getName()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition1.getUniqueId(), resourceSubCategoryDefinition1); // also + // set + // catalog + // uniqeId + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition1, + resourceSubCategoryDefinition1, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void createProductSubCategoryAlreadyExistInDifferentProductCategory() throws Exception { + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(productSubCategoryDefinition, + productCategoryDefinition, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, productCategoryDefinition, + productSubCategoryDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, + AUDIT_PRODUCT_TYPE); + DbUtils.deleteFromEsDbByPattern("_all"); + productSubCategoryDefinition1.setName("PRoDUCT-SUBcat"); + createSubCategoryRest = CategoryRestUtils.createSubCategory(productSubCategoryDefinition1, + productCategoryDefinition1, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + productSubCategoryDefinition1.setName(productSubCategoryDefinition.getName()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition1.getUniqueId(), productSubCategoryDefinition1); // also + // set + // catalog + // uniqeId + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, productCategoryDefinition1, + productSubCategoryDefinition1, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, + AUDIT_PRODUCT_TYPE); + } + + @Test + public void createResourceSubCategoryAlreadyExistInCategory() throws Exception { + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + DbUtils.deleteFromEsDbByPattern("_all"); + resourceSubCategoryDefinition1.setName("ResourcE-subCat"); + createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition1, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_ALREADY_EXISTS, + createSubCategoryRest.getErrorCode().intValue()); + getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition1, sdncAdminUserDetails, + ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY, STATUS_CODE_ALREADY_EXISTS, + AUDIT_RESOURCE_TYPE, AUDIT_RESOURCE_TYPE, resourceSubCategoryDefinition1.getName(), + resourceCategoryDefinition.getName()); + } + + @Test + public void createProductSubCategoryAlreadyExistInCategory() throws Exception { + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(productSubCategoryDefinition, + productCategoryDefinition, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, productCategoryDefinition, + productSubCategoryDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, + AUDIT_PRODUCT_TYPE); + DbUtils.deleteFromEsDbByPattern("_all"); + productSubCategoryDefinition1.setName("ProducT-subCat"); + createSubCategoryRest = CategoryRestUtils.createSubCategory(productSubCategoryDefinition1, + productCategoryDefinition, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_ALREADY_EXISTS, + createSubCategoryRest.getErrorCode().intValue()); + getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition); + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, productCategoryDefinition, + productSubCategoryDefinition1, sdncProductStrategistUserDetails, + ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY, STATUS_CODE_ALREADY_EXISTS, AUDIT_PRODUCT_TYPE, + AUDIT_PRODUCT_TYPE, productSubCategoryDefinition1.getName(), productCategoryDefinition.getName()); + } + + @Test + public void addSameNormalizedSubCategoryNameForRecourceAndProductCategory() throws Exception { + // add sub-categoty name "SubCaT" to resource category + // add sub-categoty name "SUbcAt" to product category + resourceSubCategoryDefinition.setName("SubCaT"); // normalized 'subcat' + productSubCategoryDefinition.setName("SUbcAt"); // normalized 'subcat' + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + + DbUtils.deleteFromEsDbByPattern("_all"); + createSubCategoryRest = CategoryRestUtils.createSubCategory(productSubCategoryDefinition, + productCategoryDefinition, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, productCategoryDefinition, + productSubCategoryDefinition, sdncProductStrategistUserDetails, STATUS_CODE_CREATED, + AUDIT_PRODUCT_TYPE); + } + + @Test + public void createResourceSubCategoryByNonAdminUser() throws Exception { + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncTesterUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_RESTRICTED_OPERATION, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + resourceCategoryDefinition.setName(resourceCategoryDefinition.getUniqueId()); + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncTesterUserDetails, ActionStatus.RESTRICTED_OPERATION, + STATUS_CODE_RESTRICTED_OPERATION, AUDIT_RESOURCE_TYPE); + } + + @Test + public void createResourceSubCategoryByProducStrategistUser() throws Exception { + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncProductStrategistUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_RESTRICTED_OPERATION, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + resourceCategoryDefinition.setName(resourceCategoryDefinition.getUniqueId()); + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncProductStrategistUserDetails, ActionStatus.RESTRICTED_OPERATION, + STATUS_CODE_RESTRICTED_OPERATION, AUDIT_RESOURCE_TYPE); + } + + @Test + public void createProductSubCategoryByNonProducStrategistUser() throws Exception { + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(productSubCategoryDefinition, + productCategoryDefinition, sdncDesignerUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_RESTRICTED_OPERATION, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition); + // Audit validation + productCategoryDefinition.setName(productCategoryDefinition.getUniqueId()); + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, productCategoryDefinition, + productSubCategoryDefinition, sdncDesignerUserDetails, ActionStatus.RESTRICTED_OPERATION, + STATUS_CODE_RESTRICTED_OPERATION, AUDIT_PRODUCT_TYPE); + } + + @Test + public void createProductSubCategoryByAdminUser() throws Exception { + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(productSubCategoryDefinition, + productCategoryDefinition, sdncAdminUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_RESTRICTED_OPERATION, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition); + // Audit validation + productCategoryDefinition.setName(productCategoryDefinition.getUniqueId()); + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, productCategoryDefinition, + productSubCategoryDefinition, sdncAdminUserDetails, ActionStatus.RESTRICTED_OPERATION, + STATUS_CODE_RESTRICTED_OPERATION, AUDIT_PRODUCT_TYPE); + } + + // @Ignore("DE176245") + @Test + public void createResourceSubCategoryForNonExistingComponentType() throws Exception { + String nonSupportedComponentType = "NonExistingComponentType"; // instead + // resource/product + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, nonSupportedComponentType); + assertEquals("Check response code after create Sub category", STATUS_CODE_INVALID_CONTENT, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + resourceCategoryDefinition.setName(resourceCategoryDefinition.getUniqueId()); + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, ActionStatus.INVALID_CONTENT, + STATUS_CODE_INVALID_CONTENT, nonSupportedComponentType); + } + + // @Ignore("DE176245") + @Test + public void createProductSubCategoryForNonExistingComponentType() throws Exception { + String nonSupportedComponentType = "NonExistingComponentType"; // instead + // resource/product + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(productSubCategoryDefinition, + productCategoryDefinition, sdncProductStrategistUserDetails, nonSupportedComponentType); + assertEquals("Check response code after create Sub category", STATUS_CODE_INVALID_CONTENT, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition); + // Audit validation + productCategoryDefinition.setName(productCategoryDefinition.getUniqueId()); + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, productCategoryDefinition, + productSubCategoryDefinition, sdncProductStrategistUserDetails, ActionStatus.INVALID_CONTENT, + STATUS_CODE_INVALID_CONTENT, nonSupportedComponentType); + } + + @Test + public void createServiceSubCategoryByAdmin() throws Exception { + // Service doesn't have sub-category + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_INVALID_CONTENT, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + resourceCategoryDefinition.setName(resourceCategoryDefinition.getUniqueId()); + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, ActionStatus.INVALID_CONTENT, + STATUS_CODE_INVALID_CONTENT, AUDIT_SERVICE_TYPE); + } + + @Test + public void createServiceSubCategoryByProductStrategist() throws Exception { + // Service doesn't have sub-category + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(productSubCategoryDefinition, + productCategoryDefinition, sdncProductStrategistUserDetails, SERVICE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_INVALID_CONTENT, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + productCategoryDefinition.getUniqueId(), productSubCategoryDefinition); + // Audit validation + productCategoryDefinition.setName(productCategoryDefinition.getUniqueId()); + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, productCategoryDefinition, + productSubCategoryDefinition, sdncProductStrategistUserDetails, ActionStatus.INVALID_CONTENT, + STATUS_CODE_INVALID_CONTENT, AUDIT_SERVICE_TYPE); + } + + @Test + public void createResourceSubCategoryForNonExistingCategory() throws Exception { + resourceCategoryDefinition100.setUniqueId(resourceCategoryDefinition100.getName()); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition100, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_NOT_FOUND, + createSubCategoryRest.getErrorCode().intValue()); + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, resourceCategoryDefinition100, + resourceSubCategoryDefinition, sdncAdminUserDetails, ActionStatus.COMPONENT_CATEGORY_NOT_FOUND, + STATUS_CODE_NOT_FOUND, AUDIT_RESOURCE_TYPE, RESOURCE_COMPONENT_TYPE, CATEGORY, ""); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition100.getUniqueId(), resourceSubCategoryDefinition); + } + + @Test + public void createProductSubCategoryForNonExistingCategory() throws Exception { + productCategoryDefinition200.setUniqueId(productCategoryDefinition200.getName()); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(productSubCategoryDefinition, + productCategoryDefinition200, sdncProductStrategistUserDetails, PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_NOT_FOUND, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + PRODUCT_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + productCategoryDefinition200.getUniqueId(), productSubCategoryDefinition); + // Audit validation // need to change ActionStatus + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, productCategoryDefinition200, + productSubCategoryDefinition, sdncProductStrategistUserDetails, + ActionStatus.COMPONENT_CATEGORY_NOT_FOUND, STATUS_CODE_NOT_FOUND, AUDIT_PRODUCT_TYPE, + PRODUCT_COMPONENT_TYPE, CATEGORY, ""); + } + + // pass + @Test + public void subCategoryAllowedcharacters_01() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE-"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); // also + // set + // catalog + // uniqeId + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + // pass + @Test + public void subCategoryAllowedcharacters_02() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE+"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryAllowedcharacters_03() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE&"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryAllowedcharacters_04() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE."); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryAllowedcharacters_05() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE'"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryAllowedcharacters_06() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE="); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryAllowedcharacters_07() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE:"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryAllowedcharacters_08() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE@"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryAllowedcharacters_09() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE_"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryAllowedcharacters_10() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE#"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryAllowedcharacters_11() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE d"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("1234AbcdE D"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryAllowedcharacters_12() throws Exception { + resourceSubCategoryDefinition.setName("1234AbcdE &_=+.-'#:@ d"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("1234AbcdE &_=+.-'#:@ D"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveSpaceFromBeginning() throws Exception { + resourceSubCategoryDefinition.setName(" Category01"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Category01"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveSpaceFromEnd() throws Exception { + resourceSubCategoryDefinition.setName("Category01 "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Category01"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveExtraSpace() throws Exception { + resourceSubCategoryDefinition.setName("Category 02"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Category 02"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveExtraAmpersand() throws Exception { + resourceSubCategoryDefinition.setName("Category&& &02"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Category& &02"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveExtraDash() throws Exception { + resourceSubCategoryDefinition.setName("CategorY-- --02"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("CategorY- -02"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveExtraPlus() throws Exception { + resourceSubCategoryDefinition.setName("CateGory++++ +02"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("CateGory+ +02"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveExtraPeriod() throws Exception { + resourceSubCategoryDefinition.setName("Category.... .02"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Category. .02"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveExtraApostrophe() throws Exception { + resourceSubCategoryDefinition.setName("CaTegory''' '02"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("CaTegory' '02"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveExtraHashtag() throws Exception { + resourceSubCategoryDefinition.setName("Category### #02"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Category# #02"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveExtrEequal() throws Exception { + resourceSubCategoryDefinition.setName("Category=== =02"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Category= =02"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveExtrColon() throws Exception { + resourceSubCategoryDefinition.setName("Category::: :02"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Category: :02"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveExtrAt() throws Exception { + resourceSubCategoryDefinition.setName("Category@@@ @a2"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Category@ @a2"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryRemoveExtraUnderscore() throws Exception { + resourceSubCategoryDefinition.setName("Category___ _22"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Category_ _22"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryFirstWordStartWithNumber() throws Exception { + resourceSubCategoryDefinition.setName("1Category one"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("1Category One"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + // Bug + // Desc=<ACTION = "AddSubCategory" MODIFIER = "Jimmy Hendrix(jh0003)" + // CATEGORY_NAME = "Category1" SUB_CATEGORY_NAME = "&AbcD123" GROUPING_NAME + // = "" RESOURCE_TYPE = "Resource" STATUS = "400" DESC = "SVC4556: Error: + // Invalid Resource sub-category name format."> + // DESC=SVC4556: Error: InvalidResourcesub-categorynameformat., + // @Ignore + @Test + public void subCategoryFirstWordStartWithNonAlphaNumeric() throws Exception { + // The first word must start with an alpha-numeric character [a-Z A..Z, + // 0..9] + char invalidChars[] = { '&', '-', '+', '.', '\'', '#', '=', ':', '@', '_' }; + for (int i = 0; i < invalidChars.length; i++) { + DbUtils.deleteFromEsDbByPattern("_all"); + resourceSubCategoryDefinition.setName(invalidChars[i] + "AbcD123"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Category", STATUS_CODE_INVALID_CONTENT, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, STATUS_CODE_INVALID_CONTENT, + AUDIT_RESOURCE_TYPE, AUDIT_RESOURCE_TYPE, SUB_CATEGORY); + + } + } + + @Test + public void subCategoryReplaceAndWithAmpersand_01() throws Exception { + resourceSubCategoryDefinition.setName("At and T"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("At & T"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryReplaceAndWithAmpersand_02() throws Exception { + resourceSubCategoryDefinition.setName("At and t"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("At & T"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryReplaceAndWithAmpersand_03() throws Exception { + resourceSubCategoryDefinition.setName("Atand T"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryReplaceAndWithAmpersand_04() throws Exception { + resourceSubCategoryDefinition.setName("At andT"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("At AndT"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryReplaceAndWithAmpersand_05() throws Exception { + resourceSubCategoryDefinition.setName(" and AttT"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("And AttT"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryReplaceAndWithAmpersand_06() throws Exception { + resourceSubCategoryDefinition.setName("AttT and "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("AttT And"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryReplaceAndWithAmpersand_07() throws Exception { + resourceSubCategoryDefinition.setName(" and a"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("And a"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationMaxLength() throws Exception { + resourceSubCategoryDefinition.setName("AsdfghjQ234567890@#.&:+-_"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationMaxLengthAfterNormalization() throws Exception { + resourceSubCategoryDefinition.setName(" A jQ234 @@@___ +++ At and T and and "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("A JQ234 @_ + At & T & And"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + // bug : + // Desc=<ACTION = "AddSubCategory" MODIFIER = "Jimmy Hendrix(jh0003)" + // CATEGORY_NAME = "Category1" SUB_CATEGORY_NAME = " AbdfghBCVa jQ234 @@___ + // +++ At and T " GROUPING_NAME = "" RESOURCE_TYPE = "Resource" STATUS = + // "400" DESC = "SVC4555: Error: Invalid Resource sub-category name + // length."> + @Test + public void subCategoryNameValidationExceedMaxLengthAfterNormalization() throws Exception { + resourceSubCategoryDefinition.setName(" AbdfghBCVa jQ234 @@___ +++ At and T "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_INVALID_CONTENT, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, + STATUS_CODE_INVALID_CONTENT, AUDIT_RESOURCE_TYPE, AUDIT_RESOURCE_TYPE, SUB_CATEGORY); + } + + @Test + public void subCategoryNameValidationMinLengthAfterNormalization() throws Exception { + resourceSubCategoryDefinition.setName(" AT&&&&&&&&&T "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("AT&T"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + // bug + // Desc=<ACTION = "AddSubCategory" MODIFIER = "Jimmy Hendrix(jh0003)" + // CATEGORY_NAME = "Category1" SUB_CATEGORY_NAME = " A and T " GROUPING_NAME + // = "" RESOURCE_TYPE = "Resource" STATUS = "400" DESC = "SVC4555: Error: + // Invalid Resource sub-category name length."> + @Test + public void subCategoryNameValidationLessThanMinLengthAfterNormalization() throws Exception { + resourceSubCategoryDefinition.setName(" A&&&T "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_INVALID_CONTENT, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, + STATUS_CODE_INVALID_CONTENT, AUDIT_RESOURCE_TYPE, AUDIT_RESOURCE_TYPE, SUB_CATEGORY); + } + + @Test + public void subCategoryNameIsEmpty() throws Exception { + resourceSubCategoryDefinition.setName(""); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_INVALID_CONTENT, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, + STATUS_CODE_INVALID_CONTENT, AUDIT_RESOURCE_TYPE, AUDIT_RESOURCE_TYPE, SUB_CATEGORY); + } + + // bug + // Desc=<ACTION = "AddSubCategory" MODIFIER = "Jimmy Hendrix(jh0003)" + // CATEGORY_NAME = "Category1" SUB_CATEGORY_NAME = "AbcD123~" GROUPING_NAME + // = "" RESOURCE_TYPE = "Resource" STATUS = "400" DESC = "SVC4556: Error: + // Invalid Resource sub-category name format."> + @Test + public void subCategoryNameValidationInvalidCharacters() throws Exception { + char invalidChars[] = { '~', '!', '$', '%', '^', '*', '(', ')', '"', '{', '}', '[', ']', '?', '>', '<', '/', + '|', '\\', ',' }; + for (int i = 0; i < invalidChars.length; i++) { + DbUtils.deleteFromEsDbByPattern("_all"); + resourceSubCategoryDefinition.setName("AbcD123" + invalidChars[i]); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_INVALID_CONTENT, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditFailure(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, + ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, STATUS_CODE_INVALID_CONTENT, + AUDIT_RESOURCE_TYPE, AUDIT_RESOURCE_TYPE, SUB_CATEGORY); + } + } + + @Test + public void subCategoryNameValidationFirstLetterOfKeyWordsCapitalized() throws Exception { + resourceSubCategoryDefinition.setName("beNNy shaY michEl"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("BeNNy ShaY MichEl"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_01() throws Exception { + resourceSubCategoryDefinition.setName(" bank OF america "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Bank of America"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_02() throws Exception { + resourceSubCategoryDefinition.setName("THE america bank "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("THE America Bank"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_03() throws Exception { + resourceSubCategoryDefinition.setName(" A bank OF america "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("A Bank of America"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_04() throws Exception { + resourceSubCategoryDefinition.setName(" bank america is A big ban "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Bank America Is a Big Ban"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_05() throws Exception { + resourceSubCategoryDefinition.setName(" aN apple comPany inC "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("AN Apple ComPany InC"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_06() throws Exception { + resourceSubCategoryDefinition.setName(" eat AN apple ANAN"); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Eat an Apple ANAN"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_07() throws Exception { + resourceSubCategoryDefinition.setName(" united states OF americA "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("United States of AmericA"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_08() throws Exception { + resourceSubCategoryDefinition.setName(" oF united states OF amer "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("OF United States of Amer"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_09() throws Exception { + resourceSubCategoryDefinition.setName(" to Apple TO at&T TOO "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("To Apple to At&T TOO"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_10() throws Exception { + resourceSubCategoryDefinition.setName(" eat apple AS you liiikeas "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Eat Apple as You Liiikeas"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_11() throws Exception { + resourceSubCategoryDefinition.setName(" as you may want "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("As You May Want"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_12() throws Exception { + resourceSubCategoryDefinition.setName(" the bank OF america "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("The Bank of America"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_13() throws Exception { + resourceSubCategoryDefinition.setName(" To tel-toto "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("To Tel-toto"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void subCategoryNameValidationConjunctions_14() throws Exception { + resourceSubCategoryDefinition.setName(" tel-aviv To la "); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + resourceSubCategoryDefinition.setName("Tel-aviv to La"); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, resourceSubCategoryDefinition); + + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, resourceCategoryDefinition, + resourceSubCategoryDefinition, sdncAdminUserDetails, STATUS_CODE_CREATED, AUDIT_RESOURCE_TYPE); + } + + @Test + public void createSubCategoryHttpCspUserIdHeaderIsMissing() throws Exception { + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategoryHttpCspAtuUidIsMissing( + resourceSubCategoryDefinition, resourceCategoryDefinition, sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_MISSING_INFORMATION, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.MISSING_INFORMATION.name()); + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(ADD_SUB_CATEGORY); + expectedCatrgoryAuditJavaObject.setModifier(""); + expectedCatrgoryAuditJavaObject.setCategoryName(resourceCategoryDefinition.getUniqueId()); + // String subCategoryName = (resourceSubCategoryDefinition != null ? + // resourceSubCategoryDefinition.getName() : Constants.EMPTY_STRING); + expectedCatrgoryAuditJavaObject.setSubCategoryName(resourceSubCategoryDefinition.getName()); + // String groupingName = (groupingDefinition != null ? + // groupingDefinition.getName() : Constants.EMPTY_STRING); + expectedCatrgoryAuditJavaObject.setGroupingName(""); + expectedCatrgoryAuditJavaObject.setResourceType(AUDIT_RESOURCE_TYPE); + expectedCatrgoryAuditJavaObject.setStatus(String.valueOf(STATUS_CODE_MISSING_INFORMATION)); + expectedCatrgoryAuditJavaObject.setDesc(errorInfo.getAuditDesc()); + AuditValidationUtils.validateCategoryAudit(expectedCatrgoryAuditJavaObject, ADD_SUB_CATEGORY); + } + + @Test + public void createSubCategoryHttpCspUserIdIsEmpty() throws Exception { + User sdncAdminUserDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + sdncAdminUserDetails1.setUserId(""); + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails1, RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after create Sub category", STATUS_CODE_MISSING_INFORMATION, + createSubCategoryRest.getErrorCode().intValue()); + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryNotExistsInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), resourceSubCategoryDefinition); + // Audit validation + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.MISSING_INFORMATION.name()); + ExpectedCategoryAudit expectedCatrgoryAuditJavaObject = new ExpectedCategoryAudit(); + expectedCatrgoryAuditJavaObject.setAction(ADD_SUB_CATEGORY); + expectedCatrgoryAuditJavaObject.setModifier(""); + expectedCatrgoryAuditJavaObject.setCategoryName(resourceCategoryDefinition.getUniqueId()); + // String subCategoryName = (resourceSubCategoryDefinition != null ? + // resourceSubCategoryDefinition.getName() : Constants.EMPTY_STRING); + expectedCatrgoryAuditJavaObject.setSubCategoryName(resourceSubCategoryDefinition.getName()); + // String groupingName = (groupingDefinition != null ? + // groupingDefinition.getName() : Constants.EMPTY_STRING); + expectedCatrgoryAuditJavaObject.setGroupingName(""); + expectedCatrgoryAuditJavaObject.setResourceType(AUDIT_RESOURCE_TYPE); + expectedCatrgoryAuditJavaObject.setStatus(String.valueOf(STATUS_CODE_MISSING_INFORMATION)); + expectedCatrgoryAuditJavaObject.setDesc(errorInfo.getAuditDesc()); + AuditValidationUtils.validateCategoryAudit(expectedCatrgoryAuditJavaObject, ADD_SUB_CATEGORY); + } + + //////////////////////////////////////////////////////////// + private void createSubCategorySuccess(CategoryDefinition categoryDefinition, + SubCategoryDefinition subCategoryDefinition, User sdncAdminUserDetails, String componentType, + String auditType) throws Exception { + + RestResponse createSubCategoryRest = CategoryRestUtils.createSubCategory(subCategoryDefinition, + categoryDefinition, sdncAdminUserDetails, componentType); + assertEquals("Check response code after create Sub category", STATUS_CODE_CREATED, + createSubCategoryRest.getErrorCode().intValue()); + CategoryValidationUtils.validateCreateSubCategoryResponse(createSubCategoryRest, subCategoryDefinition); + // Audit validation + AuditValidationUtils.subCategoryAuditSuccess(ADD_SUB_CATEGORY, categoryDefinition, subCategoryDefinition, + sdncAdminUserDetails, STATUS_CODE_CREATED, auditType); + // get service category and validate that category added as defined + // (also set catalog uniqeId) + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, componentType); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + categoryDefinition.getUniqueId(), subCategoryDefinition); // also + // set + // catalog + // uniqeId + } + + @Test + public void getResourceCategoryHierarchySuccessFlow() throws Exception { + int numOfSubCategories = 3; + List<SubCategoryDefinition> subCategories = new ArrayList(); + RestResponse restResponse; + SubCategoryDefinition subCategory; + String subName = resourceSubCategoryDefinition.getName(); + for (int i = 0; i < numOfSubCategories; i++) { + resourceSubCategoryDefinition.setName(subName + i); + restResponse = CategoryRestUtils.createSubCategory(resourceSubCategoryDefinition, + resourceCategoryDefinition, sdncAdminUserDetails, RESOURCE_COMPONENT_TYPE); + subCategory = ResponseParser.parseToObject(restResponse.getResponse(), SubCategoryDefinition.class); + subCategories.add(subCategory); + } + RestResponse getAllCategoriesRest = CategoryRestUtils.getAllCategories(sdncAdminUserDetails, + RESOURCE_COMPONENT_TYPE); + assertEquals("Check response code after get all categories ", STATUS_CODE_SUCCESS, + getAllCategoriesRest.getErrorCode().intValue()); + AuditValidationUtils.GetCategoryHierarchyAuditSuccess(GET_CATEGORY_HIERARCHY, AUDIT_RESOURCE_TYPE, + sdncAdminUserDetails, STATUS_CODE_SUCCESS); + for (SubCategoryDefinition sub : subCategories) { + CategoryValidationUtils.verifySubCategoryExistInGetResponse(getAllCategoriesRest, + resourceCategoryDefinition.getUniqueId(), sub); + } + } + +} |