diff options
-rw-r--r-- | common-app-api/src/test/java/org/openecomp/sdc/common/util/ValidationUtilsTest.java | 1136 |
1 files changed, 780 insertions, 356 deletions
diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/util/ValidationUtilsTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/util/ValidationUtilsTest.java index f93c4b04f3..e9f607b976 100644 --- a/common-app-api/src/test/java/org/openecomp/sdc/common/util/ValidationUtilsTest.java +++ b/common-app-api/src/test/java/org/openecomp/sdc/common/util/ValidationUtilsTest.java @@ -3,6 +3,7 @@ * SDC * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nokia. 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. @@ -20,604 +21,1027 @@ package org.openecomp.sdc.common.util; +import com.google.common.collect.Lists; +import org.junit.Test; + +import java.util.Collections; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.assertTrue; public class ValidationUtilsTest { - private ValidationUtils createTestSubject() { - return new ValidationUtils(); + @Test + public void checkValidateArtifactLabelReturnsTrueIfInputIsValid() { + final String testLabel = "testArtifactLabel"; + + boolean result = ValidationUtils.validateArtifactLabel(testLabel); + + assertTrue(result); + } + + @Test + public void checkValidateArtifactLabelReturnsFalseIfInputIsInvalid() { + final String testLabel = "wrong*()ArtifactLABEL+="; + + boolean result = ValidationUtils.validateArtifactLabel(testLabel); + + assertFalse(result); + } + + @Test + public void checkValidateArtifactLabelReturnsFalseIfInputIsEmpty() { + final String testLabel = ""; + + boolean result = ValidationUtils.validateArtifactLabel(testLabel); + + assertFalse(result); + } + + @Test + public void checkValidateArtifactDisplayNameReturnsTrueIfInputIsValid() { + final String testDisplayName = "testDisplayName"; + + boolean result = ValidationUtils.validateArtifactDisplayName(testDisplayName); + + assertTrue(result); + } + + @Test + public void checkValidateArtifactDisplayNameReturnsFalseIfInputIsInvalid() { + final String testDisplayName = "wrong*()DisplayNAME+="; + + boolean result = ValidationUtils.validateArtifactDisplayName(testDisplayName); + + assertFalse(result); + } + + @Test + public void checkValidateArtifactDisplayNameReturnsFalseIfInputIsEmpty() { + final String testDisplayName = ""; + + boolean result = ValidationUtils.validateArtifactDisplayName(testDisplayName); + + assertFalse(result); + } + + @Test + public void checkValidateCategoryDisplayNameFormatReturnsTrueIfInputIsValid() { + final String testCatalogDisplayName = "testCatalogDisplayName"; + + boolean result = ValidationUtils.validateCategoryDisplayNameFormat(testCatalogDisplayName); + + assertTrue(result); + } + + @Test + public void checkValidateCategoryDisplayNameLengthReturnsTrueIfNameIsBetweenMinAndMax() { + final String testCatalogDisplayName = "testCatalogDisplayName"; + + boolean result = ValidationUtils.validateCategoryDisplayNameLength(testCatalogDisplayName); + + assertTrue(result); + } + + @Test + public void checkValidateCategoryDisplayNameLengthReturnsFalseIfNameIsToLong() { + final String testCatalogDisplayName = "testCatalogVeryLongDisplayName"; + + boolean result = ValidationUtils.validateCategoryDisplayNameLength(testCatalogDisplayName); + + assertFalse(result); + } + + @Test + public void checkValidateCategoryDisplayNameLengthReturnsFalseIfNameIsToShort() { + final String testCatalogDisplayName = "Na"; + + boolean result = ValidationUtils.validateCategoryDisplayNameLength(testCatalogDisplayName); + + assertFalse(result); + } + + @Test + public void checkValidateProductFullNameLengthReturnsTrueIfNameIsBetweenMinAndMax() { + final String testProductFullName = "testProductFullName"; + + boolean result = ValidationUtils.validateProductFullNameLength(testProductFullName); + + assertTrue(result); + } + + @Test + public void checkValidateProductFullNameLengthReturnsTrueIfNameIsToLong() { + final String testProductFullName = + "testProductVeryVeryLongFullNameThatIsToLong" + + "ToPassValidationBecauseItExceedsTheMaxLengthOfThatParameter"; + + boolean result = ValidationUtils.validateProductFullNameLength(testProductFullName); + + assertFalse(result); + } + + @Test + public void checkValidateProductFullNameLengthReturnsTrueIfNameIsToShort() { + final String testProductFullName = "tes"; + + boolean result = ValidationUtils.validateProductFullNameLength(testProductFullName); + + assertFalse(result); + } + + @Test + public void checkValidateArtifactLabelLengthReturnsTrueIfNameIsBetweenMinAndMax() { + final String testArtifactLabel = "testArtifactLabel"; + + boolean result = ValidationUtils.validateArtifactLabelLength(testArtifactLabel); + + assertTrue(result); + } + + @Test + public void checkValidateArtifactLabelLengthReturnsFalseIfNameIsToLong() { + final String testArtifactLabel = generateLongString(300); + + boolean result = ValidationUtils.validateArtifactLabelLength(testArtifactLabel); + + assertFalse(result); + } + + @Test + public void checkValidateResourceInstanceNameLengthReturnsTrueIfNameIsBetweenMinAndMax() { + final String testResourceInstanceName = "testResourceInstanceName"; + + boolean result = ValidationUtils.validateResourceInstanceNameLength(testResourceInstanceName); + + assertTrue(result); } - @Test - public void testValidateArtifactLabel() throws Exception { - String label = ""; - boolean result; + public void checkValidateResourceInstanceNameReturnsTrueIfNameIsCorrect() { + final String testResourceInstanceName = "testResourceInstanceName"; - // default test - result = ValidationUtils.validateArtifactLabel(label); + boolean result = ValidationUtils.validateResourceInstanceName(testResourceInstanceName); + + assertTrue(result); } - @Test - public void testValidateArtifactDisplayName() throws Exception { - String displayName = ""; - boolean result; + public void checkValidateResourceInstanceNameReturnsFalseIfNameIsNotCorrect() { + final String testResourceInstanceName = "wrong!@#resourceInstance\nName=+"; + + boolean result = ValidationUtils.validateResourceInstanceName(testResourceInstanceName); - // default test - result = ValidationUtils.validateArtifactDisplayName(displayName); + assertFalse(result); } - + @Test + public void checkValidateUrlLengthReturnsTrueIfUrlLengthIsBetweenMinAndMax() { + final String testURL = "test/url/"; + + boolean result = ValidationUtils.validateUrlLength(testURL); + + assertTrue(result); + } - @Test - public void testNormalizeCategoryName4Display() throws Exception { - String str = ""; - String result; + public void checkValidateUrlLengthReturnsFalseIfUrlLengthIsToLong() { + final String testURL = generateLongString(120); - // test 1 - str = "123"; - result = ValidationUtils.normalizeCategoryName4Display(str); - Assert.assertEquals("123", result); + boolean result = ValidationUtils.validateUrlLength(testURL); - // test 2 - str = "123#123"; - result = ValidationUtils.normalizeCategoryName4Display(str); - Assert.assertEquals("123#123", result); + assertFalse(result); } - @Test - public void testNormalizeCategoryName4Uniqueness() throws Exception { - String str = ""; - String result; + public void checkValidateArtifactNameLengthReturnsTrueIfUrlLengthIsBetweenMinAndMax() { + final String testArtifactNameLength = "testArtifact"; - // default test - result = ValidationUtils.normalizeCategoryName4Uniqueness(str); + boolean result = ValidationUtils.validateArtifactNameLength(testArtifactNameLength); + + assertTrue(result); } - @Test - public void testValidateCategoryDisplayNameLength() throws Exception { - String label = ""; - boolean result; + public void checkValidateArtifactNameLengthReturnsFalseIfUrlLengthIsToLong() { + final String testArtifactNameLength = generateLongString(260); + + boolean result = ValidationUtils.validateArtifactNameLength(testArtifactNameLength); - // default test - result = ValidationUtils.validateCategoryDisplayNameLength(label); + assertFalse(result); } - @Test - public void testValidateProductFullNameLength() throws Exception { - String fullName = ""; - boolean result; + public void checkValidateComponentNamePatternReturnsTrueIfNameMatchesPattern() { + final String testComponentName = "testComponent"; + + boolean result = ValidationUtils.validateComponentNamePattern(testComponentName); - // default test - result = ValidationUtils.validateProductFullNameLength(fullName); + assertTrue(result); } - @Test - public void testValidateArtifactLabelLength() throws Exception { - String label = ""; - boolean result; + public void checkValidateComponentNamePatternReturnsFalseIfNameDoesNotMatchesPattern() { + final String testComponentName = "testWRONG!@#Component+!"; - // default test - result = ValidationUtils.validateArtifactLabelLength(label); + boolean result = ValidationUtils.validateComponentNamePattern(testComponentName); + + assertFalse(result); } - @Test - public void testValidateResourceInstanceNameLength() throws Exception { - String resourceInstanceName = ""; - boolean result; + public void checkValidateComponentNameLengthReturnsTrueIfNameLengthIsBetweenMinAndMax() { + final String testComponentName = "testComponent"; + + boolean result = ValidationUtils.validateComponentNameLength(testComponentName); - // default test - result = ValidationUtils.validateResourceInstanceNameLength(resourceInstanceName); + assertTrue(result); } - @Test - public void testValidateResourceInstanceName() throws Exception { - String resourceInstanceName = ""; - boolean result; + public void checkValidateComponentNameLengthReturnsFalseIfNameLengthIsToLong() { + final String testComponentName = generateLongString(1100); - // default test - result = ValidationUtils.validateResourceInstanceName(resourceInstanceName); + boolean result = ValidationUtils.validateComponentNameLength(testComponentName); + + assertFalse(result); } - @Test - public void testValidateUrlLength() throws Exception { - String url = ""; - boolean result; + public void checkValidateIconReturnsTrueIfIconMatchesPattern() { + final String testIcon = "icon"; + + boolean result = ValidationUtils.validateIcon(testIcon); - // default test - result = ValidationUtils.validateUrlLength(url); + assertTrue(result); } - @Test - public void testValidateArtifactNameLength() throws Exception { - String artifactName = ""; - boolean result; + public void checkValidateIconReturnsFalseIfIconDoesNotMatchesPattern() { + final String testIcon = "icon,"; + + boolean result = ValidationUtils.validateIcon(testIcon); - // default test - result = ValidationUtils.validateArtifactNameLength(artifactName); + assertFalse(result); } - @Test - public void testValidateComponentNamePattern() throws Exception { - String componentName = ""; - boolean result; + public void checkValidateIconLengthReturnsTrueIfILengthIsBetweenMinAndMax() { + final String testIcon = "icon"; - // default test - result = ValidationUtils.validateComponentNamePattern(componentName); + boolean result = ValidationUtils.validateIconLength(testIcon); + + assertTrue(result); } - @Test - public void testValidateComponentNameLength() throws Exception { - String componentName = ""; - boolean result; + public void checkValidateIconLengthReturnsTrueFalseIfILengthIsToLong() { + final String testIcon = generateLongString(30); + + boolean result = ValidationUtils.validateIconLength(testIcon); - // default test - result = ValidationUtils.validateComponentNameLength(componentName); + assertFalse(result); } - @Test - public void testValidateIcon() throws Exception { - String icon = ""; - boolean result; + public void checkValidateProjectCodeReturnsTrueIfCodeMatchesPattern() { + final String testProjectCode = "testProjectCode"; - // default test - result = ValidationUtils.validateIcon(icon); + boolean result = ValidationUtils.validateProjectCode(testProjectCode); + + assertTrue(result); } - @Test - public void testValidateIconLength() throws Exception { - String icon = ""; - boolean result; + public void checkValidateProjectCodeReturnsFalseIfCodeDoesNotMatchesPattern() { + final String testProjectCode = "testWRONG!@#ProjectCode"; + + boolean result = ValidationUtils.validateProjectCode(testProjectCode); - // default test - result = ValidationUtils.validateIconLength(icon); + assertFalse(result); } - @Test - public void testValidateProjectCode() throws Exception { - String projectCode = ""; - boolean result; + public void checkValidateProjectCodeLengthReturnsTrueIfCodeMatchesPattern() { + final String testProjectCode = "testProjectCode"; + + boolean result = ValidationUtils.validateProjectCodeLegth(testProjectCode); - // default test - result = ValidationUtils.validateProjectCode(projectCode); + assertTrue(result); } - @Test - public void testValidateProjectCodeLegth() throws Exception { - String projectCode = ""; - boolean result; + public void checkValidateContactIdReturnsTrueIfIdMatchesPattern() { + final String testContactId = "testContactId"; - // default test - result = ValidationUtils.validateProjectCodeLegth(projectCode); + boolean result = ValidationUtils.validateContactId(testContactId); + + assertTrue(result); } - @Test - public void testValidateContactId() throws Exception { - String contactId = ""; - boolean result; + public void checkValidateCostReturnsTrueIfIdMatchesPattern() { + final String testCost = "120.15"; + + boolean result = ValidationUtils.validateCost(testCost); - // default test - result = ValidationUtils.validateContactId(contactId); + assertTrue(result); } - @Test - public void testValidateCost() throws Exception { - String cost = ""; - boolean result; + public void validateRemoveHtmlTagsReturnsStringWithNoHTMLTags() { + final String htmlString = "<div>test with <p>tags</p></div>"; - // default test - result = ValidationUtils.validateCost(cost); + String result = ValidationUtils.removeHtmlTags(htmlString); + + assertEquals(result, "test with tags"); } - @Test - public void testRemoveHtmlTags() throws Exception { - String str = ""; - String result; + public void validateRemoveAllTagsReturnsStringWithNoHTMLTags() { + final String htmlString = "<div>test with <p>tags</p></div>"; + + String result = ValidationUtils.removeAllTags(htmlString); - // default test - result = ValidationUtils.removeHtmlTags(str); + assertEquals(result, "test with tags"); } - @Test - public void testRemoveAllTags() throws Exception { - String htmlText = ""; - String result; + public void validateNormalizeWhitespaceReturnsStringWithNormalizedWhitespace() { + final String whitespaceString = "test normalize whitespace"; + + String result = ValidationUtils.normaliseWhitespace(whitespaceString); - // default test - result = ValidationUtils.removeAllTags(htmlText); + assertEquals(result, "test normalize whitespace"); } - @Test - public void testNormaliseWhitespace() throws Exception { - String str = ""; - String result; + public void validateStripOctetsReturnsStringWithNormalizedWhitespace() { + final String octedString = "%2Dtest strip octets text"; - // default test - result = ValidationUtils.normaliseWhitespace(str); + String result = ValidationUtils.stripOctets(octedString); + + assertEquals(result, "test strip octets text"); } - @Test - public void testStripOctets() throws Exception { - String str = ""; - String result; + public void validateRemoveNoneUtf8CharsRemovesCharacterThatAreNotFromUtf8() { + final String nonUtf8String = "test קקUtf8 קק textקק"; + + String result = ValidationUtils.removeNoneUtf8Chars(nonUtf8String); - // default test - result = ValidationUtils.stripOctets(str); + assertEquals(result, "test Utf8 text"); } - @Test - public void testRemoveNoneUtf8Chars() throws Exception { - String input = ""; - String result; + public void validateIsEnglishReturnsTrueIfStringContainsOnlyEnglishCharacters() { + final String nonUtf8String = "test english text"; - // default test - result = ValidationUtils.removeNoneUtf8Chars(input); + boolean result = ValidationUtils.validateIsEnglish(nonUtf8String); + + assertTrue(result); } - @Test - public void testValidateIsEnglish() throws Exception { - String input = ""; - boolean result; + public void validateIsEnglishReturnsFalseIfStringContainsNoEnglishCharacters() { + final String nonUtf8String = "test noEnglish text文"; + + boolean result = ValidationUtils.validateIsEnglish(nonUtf8String); - // default test - result = ValidationUtils.validateIsEnglish(input); + assertFalse(result); } - @Test - public void testValidateIsAscii() throws Exception { - String input = ""; - boolean result; + public void validateIsAsciiReturnsTrueIfStringContainsOnlyAsciiCharacters() { + final String testAsciiText = "ascii text"; + + boolean result = ValidationUtils.validateIsAscii(testAsciiText); - // default test - result = ValidationUtils.validateIsAscii(input); + assertTrue(result); } - @Test - public void testConvertHtmlTagsToEntities() throws Exception { - String input = ""; - String result; + public void validateIsAsciiReturnsFalseIfStringContainsNotAsciiCharacter() { + final String testAsciiText = "no ascii text ┬á"; - // default test - result = ValidationUtils.convertHtmlTagsToEntities(input); + boolean result = ValidationUtils.validateIsAscii(testAsciiText); + + assertFalse(result); } - + @Test + public void validateConvertHtmlTagsToEntitiesReturnsStringWithReplacedTags() { + final String testAsciiText = "<div>ascii text</div>"; + String result = ValidationUtils.convertHtmlTagsToEntities(testAsciiText); - + assertEquals(result, "<div>ascii text</div>"); + } - @Test - public void testValidateTagListLength() throws Exception { - int tagListLength = 0; - boolean result; + public void validateRemoveDuplicateFromListReturnsListWithoutDuplicates() { + List<String> listOfDuplicates = + Lists.newArrayList("text01","text01","text02","text02","text02","text03"); + + List<String> result = ValidationUtils.removeDuplicateFromList(listOfDuplicates); - // default test - result = ValidationUtils.validateTagListLength(tagListLength); + assertTrue(result.containsAll(Lists.newArrayList("text01","text03","text03"))); + assertEquals(result.size(), 3); } - @Test - public void testValidateDescriptionLength() throws Exception { - String description = ""; - boolean result; + public void checkValidateTagLengthReturnsTrueIfTagIsBetweenMaxAndMin() { + final String testTag = "testTag"; + + boolean result = ValidationUtils.validateTagLength(testTag); - // default test - result = ValidationUtils.validateDescriptionLength(description); + assertTrue(result); } - @Test - public void testValidateStringNotEmpty() throws Exception { - String value = ""; - boolean result; + public void checkValidateTagLengthReturnsFalseIfTagIsToLong() { + final String testTag = generateLongString(1200); - // test 1 - value = null; - result = ValidationUtils.validateStringNotEmpty(value); - Assert.assertEquals(false, result); + boolean result = ValidationUtils.validateTagLength(testTag); - // test 2 - value = ""; - result = ValidationUtils.validateStringNotEmpty(value); - Assert.assertEquals(false, result); + assertFalse(result); } - @Test - public void testValidateListNotEmpty() throws Exception { - List<?> list = null; - boolean result; + public void checkValidateTagLengthReturnsFalseIfTagIsNull() { + boolean result = ValidationUtils.validateTagLength(null); - // test 1 - list = null; - result = ValidationUtils.validateListNotEmpty(list); - Assert.assertEquals(false, result); + assertFalse(result); } - @Test - public void testValidateVendorName() throws Exception { - String vendorName = ""; - boolean result; + public void validateValidateTagListLengthReturnsTrueIfListIsBetweenMaxAndMin() { + boolean result = ValidationUtils.validateTagListLength(5); - // default test - result = ValidationUtils.validateVendorName(vendorName); + assertTrue(result); } - @Test - public void testValidateVendorNameLength() throws Exception { - String vendorName = ""; - boolean result; + public void validateValidateTagListLengthReturnsFalseIfListIsToLong() { + boolean result = ValidationUtils.validateTagListLength(1250); - // default test - result = ValidationUtils.validateVendorNameLength(vendorName); + assertFalse(result); } - @Test - public void testValidateResourceVendorModelNumberLength() throws Exception { - String resourceVendorModelNumber = ""; - boolean result; + public void checkCalidateListNotEmptyReturnsTrueIfListIsNotEmpty() { + boolean result = ValidationUtils.validateListNotEmpty(Collections.singletonList("testItem")); - // default test - result = ValidationUtils.validateResourceVendorModelNumberLength(resourceVendorModelNumber); + assertTrue(result); } - @Test - public void testValidateVendorRelease() throws Exception { - String vendorRelease = ""; - boolean result; + public void checkCalidateListNotEmptyReturnsFalseIfListIsEmpty() { + boolean result = ValidationUtils.validateListNotEmpty(Collections.emptyList()); - // default test - result = ValidationUtils.validateVendorRelease(vendorRelease); + assertFalse(result); } - @Test - public void testValidateVendorReleaseLength() throws Exception { - String vendorRelease = ""; - boolean result; + public void checkValidateDescriptionLengthTestReturnsTrueIfTagIsBetweenMaxAndMin() { + final String testDescription = "testDescription"; - // default test - result = ValidationUtils.validateVendorReleaseLength(vendorRelease); + boolean result = ValidationUtils.validateDescriptionLength(testDescription); + + assertTrue(result); } - @Test - public void testValidateServiceTypeLength() throws Exception { - String serviceType = ""; - boolean result; + public void checkValidateDescriptionLengthTestReturnsFalseIfTagIsToLong() { + final String testDescription = generateLongString(1200); + + boolean result = ValidationUtils.validateDescriptionLength(testDescription); - // default test - result = ValidationUtils.validateServiceTypeLength(serviceType); + assertFalse(result); } - @Test - public void testValidateServiceRoleLength() throws Exception { - String serviceRole = ""; - boolean result; + public void checkValidateStringNotEmptyReturnsFalseIfStringIsNotEmpty() { + final String testString = "test"; - // default test - result = ValidationUtils.validateServiceRoleLength(serviceRole); + boolean result = ValidationUtils.validateStringNotEmpty(testString); + + assertTrue(result); } - @Test - public void testHasBeenCertified() throws Exception { - String version = ""; - boolean result; + public void checkValidateStringNotEmptyReturnsFTrueIfStringIsEmpty() { + final String testString = ""; + + boolean result = ValidationUtils.validateStringNotEmpty(testString); - // default test - result = ValidationUtils.hasBeenCertified(version); + assertFalse(result); } - @Test - public void testNormaliseComponentName() throws Exception { - String name = ""; - String result; + public void checkValidateVendorNameReturnsTrueIfNameFitsPattern() { + final String testVendorName = "testVendor"; + + boolean result = ValidationUtils.validateVendorName(testVendorName); - // default test - result = ValidationUtils.normaliseComponentName(name); + assertTrue(result); } - @Test - public void testNormalizeComponentInstanceName() throws Exception { - String name = ""; - String result; + public void checkValidateVendorNameReturnsFalseIfNameDoesNotFitsPattern() { + final String testVendorName = "test:Vendor"; - // default test - result = ValidationUtils.normalizeComponentInstanceName(name); + boolean result = ValidationUtils.validateVendorName(testVendorName); + + assertFalse(result); } - + @Test + public void checkValidateVendorNameLengthReturnsTrueIfNameIsBetweenMaxAndMin() { + final String testVendorName = "testVendor"; + boolean result = ValidationUtils.validateVendorNameLength(testVendorName); + + assertTrue(result); + } + + @Test + public void checkValidateVendorNameLengthReturnsFalseIfNameIsToLong() { + final String testVendorName = generateLongString(90); + + boolean result = ValidationUtils.validateVendorNameLength(testVendorName); + + assertFalse(result); + } + + @Test + public void checkValidateResourceVendorModelNumberLengthReturnsTrueIfNameIsBetweenMaxAndMin() { + final String testVendorName = "testVendor"; + + boolean result = ValidationUtils.validateResourceVendorModelNumberLength(testVendorName); + + assertTrue(result); + } - @Test - public void testConvertToSystemName() throws Exception { - String name = ""; - String result; + public void checkValidateResourceVendorModelNumberLengthReturnsFalseIfNameIsToLong() { + final String testVendorName = generateLongString(90); + + boolean result = ValidationUtils.validateResourceVendorModelNumberLength(testVendorName); - // default test - result = ValidationUtils.convertToSystemName(name); + assertFalse(result); } - @Test - public void testNormalizeFileName() throws Exception { - String filename = ""; - String result; + public void checkValidateVendorReleaseReturnsTrueIfReleaseFitsPattern() { + final String testVendorRelease = "testVendorRelease"; - // default test - result = ValidationUtils.normalizeFileName(filename); + boolean result = ValidationUtils.validateVendorRelease(testVendorRelease); + + assertTrue(result); } - + @Test + public void checkValidateVendorReleaseReturnsFalseIfReleaseDoesNotFitsPattern() { + final String testVendorRelease = "testVendor:Release"; + + boolean result = ValidationUtils.validateVendorRelease(testVendorRelease); + assertFalse(result); + } - @Test - public void testValidateUrl() throws Exception { - String url = ""; - boolean result; + public void checkValidateVendorReleaseLengthReturnsTrueIfReleaseIsBetweenMaxAndMin() { + final String testVendorRelease = "testVendorRelease"; + + boolean result = ValidationUtils.validateVendorReleaseLength(testVendorRelease); - // default test - result = ValidationUtils.validateUrl(url); + assertTrue(result); } - @Test - public void testCleanArtifactDisplayName() throws Exception { - String strIn = ""; - String result; + public void checkValidateVendorReleaseLengthReturnsFalseIfReleaseIsToLong() { + final String testVendorRelease = generateLongString(30); - // default test - result = ValidationUtils.cleanArtifactDisplayName(strIn); + boolean result = ValidationUtils.validateVendorReleaseLength(testVendorRelease); + + assertFalse(result); } - @Test - public void testNormalizeArtifactLabel() throws Exception { - String strIn = ""; - String result; + public void checkValidateServiceTypeLengthReturnsTrueIfReleaseIsBetweenMaxAndMin() { + final String testServiceType = "testServiceType"; + + boolean result = ValidationUtils.validateServiceTypeLength(testServiceType); - // default test - result = ValidationUtils.normalizeArtifactLabel(strIn); + assertTrue(result); } - @Test - public void testValidateAdditionalInformationKeyName() throws Exception { - String str = ""; - boolean result; + public void checkValidateServiceTypeLengthReturnsFalseIfReleaseIsToLong() { + final String testServiceType = generateLongString(500); - // default test - result = ValidationUtils.validateAdditionalInformationKeyName(str); + boolean result = ValidationUtils.validateServiceTypeLength(testServiceType); + + assertFalse(result); } - + @Test + public void checkValidateServiceRoleLengthReturnsTrueIfReleaseIsBetweenMaxAndMin() { + final String testServiceRoleLength = "testServiceType"; + + boolean result = ValidationUtils.validateServiceRoleLength(testServiceRoleLength); + + assertTrue(result); + } + @Test + public void checkValidateServiceRoleLengthReturnsFalseIfReleaseIsToLong() { + final String testServiceRoleLength = generateLongString(500); - + boolean result = ValidationUtils.validateServiceRoleLength(testServiceRoleLength); + assertFalse(result); + } - @Test - public void testValidateConsumerName() throws Exception { - String consumerName = ""; - boolean result; + public void validateHasBeenCertifiedReturnsTrueIfVersionIsEqualOrBiggerThan1() { + final String testVersion = "1.0"; + + boolean result = ValidationUtils.hasBeenCertified(testVersion); - // default test - result = ValidationUtils.validateConsumerName(consumerName); + assertTrue(result); } - @Test - public void testIsUTF8Str() throws Exception { - String str = ""; - boolean result; + public void validateHasBeenCertifiedReturnsFalseIfVersionIsSmallerThan1() { + final String testVersion = "0.6"; - // default test - result = ValidationUtils.isUTF8Str(str); + boolean result = ValidationUtils.hasBeenCertified(testVersion); + + assertFalse(result); } - @Test - public void testValidateConsumerPassSalt() throws Exception { - String consumerSalt = ""; - boolean result; + public void validateNormaliseComponentNameReturnsNormalizedName() { + final String testName = "test-Component-Service"; + + String result = ValidationUtils.normaliseComponentName(testName); - // default test - result = ValidationUtils.validateConsumerPassSalt(consumerSalt); + assertEquals(result, "testcomponentservice"); } - @Test - public void testIsFloatNumber() throws Exception { - String number = ""; - boolean result; + public void validateNormaliseComponentInstanceNameReturnsNormalizedName() { + final String testName = "test-Component-Service"; - // default test - result = ValidationUtils.isFloatNumber(number); + String result = ValidationUtils.normalizeComponentInstanceName(testName); + + assertEquals(result, "testcomponentservice"); } - @Test - public void testValidateCertifiedVersion() throws Exception { - String version = ""; - boolean result; + public void validateConvertToSystemNameReturnsProperSystemName() { + final String testName = "test-Component-Service"; + + String result = ValidationUtils.convertToSystemName(testName); - // default test - result = ValidationUtils.validateCertifiedVersion(version); + assertEquals(result, "TestComponentService"); } - @Test - public void testValidateMinorVersion() throws Exception { - String version = ""; - boolean result; + public void validateNormalizeFileNameReturnsNormalizedName() { + final String testName = "test File Name"; + + String result = ValidationUtils.normalizeFileName(testName); - // default test - result = ValidationUtils.validateMinorVersion(version); + assertEquals(result, "test-File-Name"); } - @Test - public void testNormaliseProductName() throws Exception { - String name = ""; - String result; + public void checkValidateUrlReturnsTrueIfURLIsValid() { + final String testUrl = "http://test.co/valid/url/"; - // default test - result = ValidationUtils.normaliseProductName(name); + boolean result = ValidationUtils.validateUrl(testUrl); + + assertTrue(result); } - + @Test + public void checkValidateUrlReturnsFalseIfURLIsNotValid() { + final String testUrl = "http//notvalid!#url"; + + boolean result = ValidationUtils.validateUrl(testUrl); + assertFalse(result); + } - @Test - public void testRemoveHtmlTagsOnly() throws Exception { - String htmlText = ""; - String result; + public void checkValidateUrlReturnsFalseIfURLIsNotUtf8() { + final String testUrl = "http://test.co/notutf/קקurl/"; + + boolean result = ValidationUtils.validateUrl(testUrl); + + assertFalse(result); + } + + @Test + public void validateNormalizeArtifactLabelReturnsNormalizeArtifactLabel() { + final String testArtifactLabel = "test-File-Name"; + + String result = ValidationUtils.normalizeArtifactLabel(testArtifactLabel); + + assertEquals(result, "testfilename"); + } + + @Test + public void validateAdditionalInformationKeyNameReturnsTrueIfAdditionalInformationAreValid() { + final String testAdditionalInformationKeyName = "KeyName"; + + boolean result = ValidationUtils.validateAdditionalInformationKeyName(testAdditionalInformationKeyName); + + assertTrue(result); + } + + @Test + public void validateNormalizeAdditionalInformationReturnsNormalizeArtifactLabel() { + final String testArtifactLabel = "additional--Information__Testing"; + + String result = ValidationUtils.normalizeAdditionalInformation(testArtifactLabel); + + assertEquals(result, "additional-Information_Testing"); + } + + @Test + public void checkValidateLengthReturnsTrueIfStringIsShorterThenGivenLength() { + final String testString = "testString"; + + boolean result = ValidationUtils.validateLength(testString,50); + + assertTrue(result); + } + + @Test + public void checkValidateLengthReturnsTrueIfStringIsNull() { + boolean result = ValidationUtils.validateLength(null,50); + + assertTrue(result); + } + + @Test + public void checkValidateLengthReturnsTrueIfStringIsExitsTheGivenLength() { + final String testString = "testString"; + + boolean result = ValidationUtils.validateLength(testString,5); + + assertFalse(result); + } + + @Test + public void validateIsUTF8StrReturnsFalseIfGivenStringContainsUtf8Character() { + final String testString = "testקString"; + + boolean result = ValidationUtils.isUTF8Str(testString); + + assertFalse(result); + } + + @Test + public void validateIsUTF8StrReturnsTrueIfGivenStringDoesNotContainsUtf8Character() { + final String testString = "testString"; + + boolean result = ValidationUtils.isUTF8Str(testString); + + assertTrue(result); + } + + @Test + public void validateIsFloatNumberReturnsTrueIfGivenStringRepresentsFloatNumber() { + final String testString = "12.45"; + + boolean result = ValidationUtils.isFloatNumber(testString); + + assertTrue(result); + } + + @Test + public void validateIsFloatNumberReturnsFalseIfGivenStringDoesNotRepresentsFloatNumber() { + final String testString = "notFloatingPoint"; + + boolean result = ValidationUtils.isFloatNumber(testString); + + assertFalse(result); + } + + @Test + public void validateCertifiedVersionReturnsTrueIfGivenStringRepresentsVersion() { + final String testString = "1.0"; + + boolean result = ValidationUtils.validateCertifiedVersion(testString); + + assertTrue(result); + } + + @Test + public void validateCertifiedVersionReturnsFalseIfGivenStringDoesNotRepresentsVersion() { + final String testString = "notVersion"; + + boolean result = ValidationUtils.validateCertifiedVersion(testString); + + assertFalse(result); + } + + @Test + public void validateMinorVersionReturnsTrueIfGivenStringRepresentsMinorVersion() { + final String testString = "0.1"; + + boolean result = ValidationUtils.validateMinorVersion(testString); + + assertTrue(result); + } + + @Test + public void validateMinorVersionReturnsFalseIfGivenStringDoesNotRepresentsMinorVersion() { + final String testString = "notMinorVersion"; + + boolean result = ValidationUtils.validateMinorVersion(testString); + + assertFalse(result); + } + + @Test + public void validateCleanArtifactDisplayNameReturnsCleanedArtifactName() { + final String testArtifactDisplayName = " test-File Name"; + + String result = ValidationUtils.cleanArtifactDisplayName(testArtifactDisplayName); + + assertEquals(result, "test-File Name"); + } + + @Test + public void checkValidateArtifactLabelReturnsTrueIfLabelIsValid() { + final String testArtifactDisplayName = "testLabel"; + + boolean result = ValidationUtils.validateArtifactLabel(testArtifactDisplayName); + + assertTrue(result); + } + + @Test + public void checkValidateArtifactLabelReturnsFalseIfLabelIsNotValid() { + final String testArtifactDisplayName = "test=notValid=Label"; + + boolean result = ValidationUtils.validateArtifactLabel(testArtifactDisplayName); + + assertFalse(result); + } + + @Test + public void checkValidateConsumerNameReturnsTrueIfLabelIsValid() { + final String testConsumerName = "testConsumerName"; + + boolean result = ValidationUtils.validateConsumerName(testConsumerName); + + assertTrue(result); + } + + @Test + public void checkValidateConsumerNameReturnsFalseIfLabelIsNotValid() { + final String testConsumerName = "test=notValid=ConsumerName"; + + boolean result = ValidationUtils.validateConsumerName(testConsumerName); + + assertFalse(result); + } + + @Test + public void checkValidateConsumerPassSaltReturnsTrueIfLabelIsValid() { + final String testPassSalt = "123qwe"; + + boolean result = ValidationUtils.validateConsumerPassSalt(testPassSalt); + + assertTrue(result); + } + + @Test + public void checkValidateConsumerPassSaltReturnsFalseIfLabelIsNotValid() { + final String testPassSalt = "_123qweLO"; + + boolean result = ValidationUtils.validateConsumerPassSalt(testPassSalt); + + assertFalse(result); + } + + @Test + public void checkValidateCategoryNameFormatReturnsTrueIfLabelIsValid() { + final String testDisplayNameFormat = "DisplayNameFormat"; + + boolean result = ValidationUtils.validateCategoryDisplayNameFormat(testDisplayNameFormat); + + assertTrue(result); + } + + @Test + public void checkValidateCategoryNameFormatReturnsFalseIfLabelIsNotValid() { + final String testDisplayNameFormat = "Display{NotValid}NameFormat"; + + boolean result = ValidationUtils.validateCategoryDisplayNameFormat(testDisplayNameFormat); + + assertFalse(result); + } + + @Test + public void checkValidateCategoryNameFormatReturnsFalseIfLabelIsStartingWihNonAlphabetical() { + final String testDisplayNameFormat = "@DisplayNameFormat"; + + boolean result = ValidationUtils.validateCategoryDisplayNameFormat(testDisplayNameFormat); + + assertFalse(result); + } + + @Test + public void checkValidateCategoryNameLengthReturnsTrueIfLabelLengthIsBetweenMinaAndMax() { + final String testDisplayNameFormat = "DisplayNameFormat"; + + boolean result = ValidationUtils.validateCategoryDisplayNameLength(testDisplayNameFormat); + + assertTrue(result); + } + + @Test + public void checkValidateCategoryNameLengthReturnsFalseIfLabelLengthIsToLong() { + final String testDisplayNameFormat = generateLongString(28); + + boolean result = ValidationUtils.validateCategoryDisplayNameLength(testDisplayNameFormat); + + assertFalse(result); + } + + @Test + public void validateNormalizeCategoryNameReturnsNormalizeName() { + final String testCatalogName = "not Normalize OF CatalogName"; + + String result = ValidationUtils.normalizeCategoryName4Display(testCatalogName); + + assertEquals(result, "Not Normalize of CatalogName"); + } + + @Test + public void validateNormalizeCategoryLabelReturnsNormalizeLabel() { + final String testCatalogLabel = "not Normalize OF CatalogLabel"; + + String result = ValidationUtils.normalizeCategoryName4Uniqueness(testCatalogLabel); + + assertEquals(result, "not normalize of cataloglabel"); + } + + @Test + public void validateNormaliseProductNameReturnsNormalizedName() { + final String testProductName = "Product Name"; + + String result = ValidationUtils.normaliseProductName(testProductName); + + assertEquals(result, "productname"); + + } + + @Test + public void validateRemoveHtmlTagsOnlyReturnsStringWithRemovedHtmlTags() { + final String testHtml = "<div>Product <p>Name</p> <not html tag></div>"; + + String result = ValidationUtils.removeHtmlTagsOnly(testHtml); + + assertEquals(result, "Product Name <not html tag>"); + + } + + @Test + public void checkValidateForwardingPathNamePatternReturnsTrueIfPathIsValid() { + final String testForwardingPath = "test.forwarding.path"; + + boolean result = ValidationUtils.validateForwardingPathNamePattern(testForwardingPath); + + assertTrue(result); + } + + @Test + public void checkValidateForwardingPathNamePatternReturnsFalseIfPathIsNotValid() { + final String testForwardingPath = "test/notValid/forwarding//path"; + + boolean result = ValidationUtils.validateForwardingPathNamePattern(testForwardingPath); + + assertFalse(result); + } - // default test - result = ValidationUtils.removeHtmlTagsOnly(htmlText); + private String generateLongString(int length) { + StringBuilder toLongLabelBuilder = new StringBuilder(); + for(int i=0 ; i<=length ; i++) { + toLongLabelBuilder.append("t"); + } + return toLongLabelBuilder.toString(); } } |