Skip to content

Commit

Permalink
Add API to UriValidator to check if URI has wildcard (#143)
Browse files Browse the repository at this point in the history
The API checks to see if any portion of the URI contains a wildcard character and if so it returns true.

#142
---------

Co-authored-by: Neelam Kushwah <neelam.kushwah@gm.com>
  • Loading branch information
Steven Hartley and neelam-kushwah authored Jul 11, 2024
1 parent 2b8e537 commit 1791c98
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ static boolean matches(UUri uriToMatch, UUri candidateUri) {
matchesEntity(uriToMatch, candidateUri) &&
matchesResource(uriToMatch, candidateUri);
}


/**
* Checks if the URI has a wildcard in any of its fields.
*
* @param uri The URI to check for wildcards.
* @return True if the URI has a wildcard, False otherwise.
*/
static boolean hasWildcard(UUri uri) {
return !isEmpty(uri) &&
(uri.getAuthorityName().equals(UriFactory.WILDCARD_AUTHORITY) ||
(uri.getUeId() & UriFactory.WILDCARD_ENTITY_ID) == UriFactory.WILDCARD_ENTITY_ID ||
uri.getUeVersionMajor() == UriFactory.WILDCARD_ENTITY_VERSION ||
uri.getResourceId() == UriFactory.WILDCARD_RESOURCE_ID);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,51 @@ public void test_Matches_Fail_For_Different_Resource() {
UUri candidate = UriSerializer.deserialize("//authority/A410/3/1003");
assertFalse(UriValidator.matches(pattern, candidate));
}

@Test
@DisplayName("hasWildcard() for an null UUri")
void test_hasWildcard_for_null_UUri() {
assertFalse(UriValidator.hasWildcard(null));
}

@Test
@DisplayName("hasWildcard() for a UUri with empty URI")
void test_hasWildcard_for_empty_UUri() {
assertFalse(UriValidator.hasWildcard(UUri.getDefaultInstance()));
}

@Test
@DisplayName("hasWildcard() for a UUri with wildcard authority")
void test_hasWildcard_for_UUri_with_wildcard_authority() {
UUri uri = UriSerializer.deserialize("//*/A410/3/1003");
assertTrue(UriValidator.hasWildcard(uri));
}

@Test
@DisplayName("hasWildcard() for a UUri with wildcard entity ID")
void test_hasWildcard_for_UUri_with_wildcard_entity_id() {
UUri uri = UriSerializer.deserialize("//authority/FFFF/3/1003");
assertTrue(UriValidator.hasWildcard(uri));
}

@Test
@DisplayName("hasWildcard() for a UUri with wildcard entity version")
void test_hasWildcard_for_UUri_with_wildcard_entity_instance() {
UUri uri = UriSerializer.deserialize("//authority/A410/FF/1003");
assertTrue(UriValidator.hasWildcard(uri));
}

@Test
@DisplayName("hasWildcard() for a UUri with wildcard resource")
void test_hasWildcard_for_UUri_with_wildcard_resource() {
UUri uri = UriSerializer.deserialize("//authority/A410/3/FFFF");
assertTrue(UriValidator.hasWildcard(uri));
}

@Test
@DisplayName("hasWildcard() for a UUri with no wildcards")
void test_hasWildcard_for_UUri_with_no_wildcards() {
UUri uri = UriSerializer.deserialize("//authority/A410/3/1003");
assertFalse(UriValidator.hasWildcard(uri));
}
}

0 comments on commit 1791c98

Please sign in to comment.