Skip to content

Commit

Permalink
Added a testcase for XmlMarshallingValidationProcessor.Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
leonschenk authored and christophd committed Sep 9, 2024
1 parent 9953169 commit 4ac1678
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.citrusframework.validation.xml;

import org.citrusframework.UnitTestSupport;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.SimpleReferenceResolver;
import org.citrusframework.validation.GenericValidationProcessor;
import org.citrusframework.xml.Unmarshaller;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

class XmlMarshallingValidationProcessorTest extends UnitTestSupport {
final Unmarshaller unmarshaller = Object::toString;
final GenericValidationProcessor<String> validationProcessor = (payload, headers, context) ->
logger.info("Validating message %s".formatted(payload));

@Test
void builderWithoutUnmarshallerTest() {
XmlMarshallingValidationProcessor<String> build = XmlMarshallingValidationProcessor.Builder.validate(validationProcessor)
.unmarshaller(unmarshaller)
.build();

build.setReferenceResolver(new SimpleReferenceResolver());

assertDoesNotThrow(() -> build.validate(new DefaultMessage().setPayload("hi"), null));
}

@Test
void builderWithUnmarshallerTest() {
final ReferenceResolver referenceResolver = new SimpleReferenceResolver();
referenceResolver.bind("anyName", unmarshaller);

XmlMarshallingValidationProcessor<String> build = XmlMarshallingValidationProcessor.Builder.validate(validationProcessor)
.withReferenceResolver(referenceResolver)
.build();

build.setReferenceResolver(referenceResolver);

assertDoesNotThrow(() -> build.validate(new DefaultMessage().setPayload("bye"), null));
}
}

0 comments on commit 4ac1678

Please sign in to comment.