-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Applied anchors to regex, fixed character groupings and supplied tests
- Loading branch information
Showing
1 changed file
with
125 additions
and
0 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
hivemq-edge/src/test/java/com/hivemq/uns/UnsModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package com.hivemq.uns; | ||
|
||
import com.hivemq.api.utils.ApiValidation; | ||
import com.hivemq.edge.HiveMQEdgeConstants; | ||
import org.junit.Assert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* @author Simon L Johnson | ||
*/ | ||
public class UnsModelTest { | ||
|
||
@Test | ||
void testApiAlphaNumValidation_empty_null() { | ||
|
||
Assert.assertTrue("Empty string should be allowed when specified", | ||
ApiValidation.validAlphaNumericSpaces("", true)); | ||
Assert.assertFalse("Empty string should NOT be allowed when specified", | ||
ApiValidation.validAlphaNumericSpaces("", false)); | ||
|
||
Assert.assertTrue("<null> string should be allowed when specified", | ||
ApiValidation.validAlphaNumericSpaces(null, true)); | ||
Assert.assertFalse("<null> string should NOT be allowed when specified", | ||
ApiValidation.validAlphaNumericSpaces(null, false)); | ||
} | ||
|
||
@Test | ||
void testApiAlphaNumSpacesValidation() { | ||
|
||
Assert.assertTrue("Valid value (with spaces) should be valid", | ||
ApiValidation.validAlphaNumericSpaces("valid value", false)); | ||
|
||
Assert.assertTrue("Valid value (without spaces) should be valid", | ||
ApiValidation.validAlphaNumericSpaces("validvalue", false)); | ||
|
||
Assert.assertTrue("Multi character should be valid", | ||
ApiValidation.validAlphaNumericSpaces("vv", false)); | ||
|
||
Assert.assertTrue("Multi character with space should be valid", | ||
ApiValidation.validAlphaNumericSpaces("v ", false)); | ||
|
||
Assert.assertTrue("Single character should be valid", | ||
ApiValidation.validAlphaNumericSpaces("v", false)); | ||
|
||
Assert.assertFalse("Special char should not be invalid", | ||
ApiValidation.validAlphaNumericSpaces("\'", false)); | ||
|
||
Assert.assertTrue("Mixed case should be valid", | ||
ApiValidation.validAlphaNumericSpaces("aAb", false)); | ||
} | ||
|
||
@Test | ||
void testApiAlphaNumValidation() { | ||
|
||
Assert.assertFalse("Invalid value (with spaces) should be invalid", | ||
ApiValidation.validAlphaNumeric("invalid value", false)); | ||
|
||
Assert.assertTrue("Valid value (without spaces) should be valid", | ||
ApiValidation.validAlphaNumeric("validvalue", false)); | ||
|
||
Assert.assertTrue("Multi character should be valid", | ||
ApiValidation.validAlphaNumeric("vv", false)); | ||
|
||
Assert.assertFalse("Multi character with space should NOT be valid", | ||
ApiValidation.validAlphaNumeric("v ", false)); | ||
|
||
Assert.assertTrue("Single character should be valid", | ||
ApiValidation.validAlphaNumeric("v", false)); | ||
|
||
Assert.assertFalse("Special char should not be invalid", | ||
ApiValidation.validAlphaNumeric("\'", false)); | ||
|
||
Assert.assertTrue("Mixed case should be valid", | ||
ApiValidation.validAlphaNumericSpaces("aAb", false)); | ||
} | ||
|
||
@Test | ||
void testApiAlphaNumSpacesAndDashesValidation() { | ||
|
||
Assert.assertTrue("Valid value (with spaces) should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("valid value", false)); | ||
|
||
Assert.assertTrue("Valid value (without spaces) should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("validvalue", false)); | ||
|
||
Assert.assertTrue("Multi character should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("vv", false)); | ||
|
||
Assert.assertTrue("Multi character with space should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("v ", false)); | ||
|
||
Assert.assertTrue("Single character should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("v", false)); | ||
|
||
Assert.assertFalse("Special char should not be invalid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("\'", false)); | ||
|
||
Assert.assertTrue("Mixed case should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("aAb", false)); | ||
|
||
Assert.assertTrue("Dashes should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("a-b", false)); | ||
|
||
Assert.assertTrue("Leading dashes should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("-ab", false)); | ||
|
||
Assert.assertTrue("Trailing dashes should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("ab-", false)); | ||
|
||
Assert.assertTrue("Underscores should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("a_b", false)); | ||
|
||
Assert.assertTrue("Trailing Underscores should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("a_", false)); | ||
|
||
Assert.assertTrue("Leading Underscores should be valid", | ||
ApiValidation.validAlphaNumericSpacesAndDashes("_a", false)); | ||
} | ||
} |