Skip to content

Commit

Permalink
chore: reference latest Smooks artifacts (#119)
Browse files Browse the repository at this point in the history
* chore: reference latest Smooks artifacts

* fix: solve compilation errors caused by removal of org.smooks.io.sink.FilterSink
  • Loading branch information
cjmamo authored Nov 6, 2024
1 parent 87cf4f7 commit 5e16da1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
<dependency>
<groupId>org.smooks.cartridges</groupId>
<artifactId>smooks-rules-cartridge</artifactId>
<version>2.0.0</version>
<version>2.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.smooks.cartridges</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
*/
package org.smooks.cartridges.validation;

import org.smooks.api.io.Sink;
import org.smooks.assertion.AssertArgument;
import org.smooks.io.sink.FilterSink;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -58,7 +58,7 @@
*
* @author <a href="mailto:danielbevenius@gmail.com">Daniel Bevenius</a>
*/
public class ValidationSink extends FilterSink {
public class ValidationSink implements Sink {
/**
* The validation result Map, keyed by OnFail Type.
*/
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/smooks/cartridges/validation/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.smooks.api.ExecutionContext;
import org.smooks.api.SmooksConfigException;
import org.smooks.api.SmooksException;
import org.smooks.api.io.Sink;
import org.smooks.api.resource.config.ResourceConfig;
import org.smooks.api.resource.visitor.VisitAfterReport;
import org.smooks.api.resource.visitor.VisitBeforeReport;
Expand All @@ -62,7 +63,6 @@
import org.smooks.engine.memento.TextAccumulatorVisitorMemento;
import org.smooks.engine.resource.config.xpath.IndexedSelectorPath;
import org.smooks.engine.resource.config.xpath.step.AttributeSelectorStep;
import org.smooks.io.sink.FilterSink;
import org.smooks.resource.URIResourceLocator;
import org.smooks.support.DomUtils;
import org.smooks.support.FreeMarkerTemplate;
Expand All @@ -75,6 +75,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
Expand Down Expand Up @@ -280,14 +281,11 @@ private OnFailResultImpl _validate(final String text, final ExecutionContext exe
}

private ValidationSink getValidationResult(ExecutionContext executionContext) {
ValidationSink validationResult = (ValidationSink) FilterSink.getSink(executionContext, ValidationSink.class);
// Create a new ValidationResult if one was not available in the execution context.
// This would be the case for example if one as not specified to Smooks filter method.
if (validationResult == null) {
validationResult = new ValidationSink();
}
Optional<Sink> validationSink = executionContext.getOrDefault(Sink.SINKS_TYPED_KEY, Collections.emptyList()).stream().filter(s -> ValidationSink.class.isAssignableFrom(s.getClass())).findFirst();

return validationResult;
// Create a new ValidationSink if one was not available in the execution context.
// This would be the case for example if one as not specified to Smooks filter method.
return validationSink.map(sink -> (ValidationSink) sink).orElseGet(ValidationSink::new);
}

private synchronized void setRuleProvider(ExecutionContext executionContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@
import org.junit.jupiter.api.Test;
import org.smooks.Smooks;
import org.smooks.api.ApplicationContext;
import org.smooks.api.io.Sink;
import org.smooks.cartridges.rules.RuleProviderAccessor;
import org.smooks.cartridges.rules.regex.RegexProvider;
import org.smooks.engine.DefaultApplicationContextBuilder;
import org.smooks.io.sink.FilterSink;
import org.smooks.io.source.StringSource;
import org.smooks.testkit.MockApplicationContext;
import org.smooks.testkit.MockExecutionContext;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void testValidateWarn() {
final ValidationSink sink = new ValidationSink();

MockExecutionContext executionContext = new MockExecutionContext();
FilterSink.setSinks(executionContext, sink);
executionContext.put(Sink.SINKS_TYPED_KEY, Collections.singletonList(sink));
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
Expand All @@ -116,7 +117,7 @@ public void testValidateOks() {
final ValidationSink sink = new ValidationSink();

MockExecutionContext executionContext = new MockExecutionContext();
FilterSink.setSinks(executionContext, sink);
executionContext.put(Sink.SINKS_TYPED_KEY, Collections.singletonList(sink));
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
Expand All @@ -136,7 +137,7 @@ public void testValidateErrors() {
final ValidationSink sink = new ValidationSink();

MockExecutionContext executionContext = new MockExecutionContext();
FilterSink.setSinks(executionContext, sink);
executionContext.put(Sink.SINKS_TYPED_KEY, Collections.singletonList(sink));
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
Expand Down Expand Up @@ -208,7 +209,7 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {
ValidationSink sink = new ValidationSink();

MockExecutionContext executionContext = new MockExecutionContext();
FilterSink.setSinks(executionContext, sink);
executionContext.put(Sink.SINKS_TYPED_KEY, Collections.singletonList(sink));
try {
validator.validate("xyz", executionContext);
switch (onFail) {
Expand Down

0 comments on commit 5e16da1

Please sign in to comment.