Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uuid v4 validation matcher (docs) #1262

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
import java.util.UUID;

/**
* UuidValidationMatcher checks if valid UUID version 4 is present
* This validation matcher checks if a valid UUID version 4 is present.
*/
public class UuidV4ValidationMatcher implements ValidationMatcher {

@Override
public void validate(String fieldName, String value, List<String> controlParameters, TestContext context) throws ValidationException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @since 2.5
*/
public class DateRangeValidationMatcherIT extends TestNGCitrusSpringSupport {

@Test
@CitrusTestSource(type = TestLoader.SPRING)
public void DateRangeValidationMatcherIT() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright the original author or authors.
*
* 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.
*/

package org.citrusframework.integration.validation;

import org.citrusframework.annotations.CitrusTestSource;
import org.citrusframework.common.TestLoader;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.testng.annotations.Test;

public class UuidV4ValidationMatcherIT extends TestNGCitrusSpringSupport {

@Test
@CitrusTestSource(type = TestLoader.SPRING)
public void UuidV4ValidationMatcherIT() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<spring:beans xmlns="http://www.citrusframework.org/schema/testcase"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:http="http://www.citrusframework.org/schema/http/testcase"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.citrusframework.org/schema/testcase http://www.citrusframework.org/schema/testcase/citrus-testcase.xsd
http://www.citrusframework.org/schema/http/testcase http://www.citrusframework.org/schema/http/testcase/citrus-http-testcase.xsd">
<testcase name="UuidV4ValidationMatcherIT">
<meta-info>
<author>bbortt</author>
<creationdate>2014-11-10</creationdate>
<status>FINAL</status>
<last-updated-by>bbortt</last-updated-by>
<last-updated-on>2014-11-10T00:00:00</last-updated-on>
</meta-info>

<description>
Tests the @isUUIDv4()@ validator
</description>

<variables>
<variable name="validUuid" value="653ce6fd-dca4-4672-bbc0-16e2b74b8b81"/>
<variable name="invalidUuid" value="019314e4-1eab-70a2-84cc-1b1328b36cdb"/>
</variables>

<actions>
<send endpoint="helloEndpoint">
<message>
<data>Hello Citrus!</data>
</message>
<header>
<element name="message-id" value="${validUuid}"/>
</header>
</send>

<receive endpoint="helloEndpoint">
<message type="plaintext">
<data>Hello Citrus!</data>
</message>
<header>
<element name="message-id" value="@isUUIDv4()@"/>
</header>
</receive>

<send endpoint="helloEndpoint">
<message>
<data>Hello Citrus!</data>
</message>
<header>
<element name="message-id" value="${invalidUuid}"/>
</header>
</send>

<assert exception="org.citrusframework.exceptions.ValidationException"
message="UuidV4ValidationMatcher failed for field 'message-id'. Received value '${invalidUuid}' is not a uuid v4.">
<when>
<receive endpoint="helloEndpoint">
<message type="plaintext">
<data>Hello Citrus!</data>
</message>
<header>
<element name="message-id" value="@isUUIDv4()@"/>
</header>
</receive>
</when>
</assert>
</actions>
</testcase>
</spring:beans>
32 changes: 31 additions & 1 deletion src/manual/validation-matchers.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[validation-matcher]]
= Validation matcher
= Validation Matchers

Message validation in Citrus is essential. The framework offers several validation mechanisms for different message types and formats. With test variables we are able to check for simple value equality. We ensure that message entries are equal to predefined expected values. Validation matcher add powerful assertion functionality on top of that. You just can use the predefined validation matcher functionalities in order to perform more complex assertions like *contains* or *isNumber* in your validation statements.

Expand Down Expand Up @@ -393,3 +393,33 @@ You can now skip all whitespaces in your control value.
----
<value>@trimAllWhitespaces('somevalue')@</value>
----

[[matcher-is-uuid-v4]]
== isUUIDv4()

This validation matcher checks if a valid UUID version 4 is present.
Given the `<variable name="validUuid" value="653ce6fd-dca4-4672-bbc0-16e2b74b8b81"/>`, usage is as following.

.Example `isUUIDv4()` validation
[source,xml]
----
<actions>
<send endpoint="helloEndpoint">
<message>
<data>Hello Citrus!</data>
</message>
<header>
<element name="message-id" value="${validUuid}"/>
</header>
</send>

<receive endpoint="helloEndpoint">
<message type="plaintext">
<data>Hello Citrus!</data>
</message>
<header>
<element name="message-id" value="@isUUIDv4()@"/>
</header>
</receive>
</actions>
----
Loading