[java-metadata-aggregator] branch master updated: MDA-202 - Add Accept/Reject String Value/Regex validator components

Ian Young ian at iay.org.uk
Wed Jan 31 10:07:11 EST 2018


This is an automated email from the git hooks/post-receive script.

iay pushed a commit to branch master
in repository java-metadata-aggregator.

View the commit online:
http://git.shibboleth.net/view/?p=java-metadata-aggregator.git;a=commit;h=a84a466d867f94e2f8d1c9c2be91ffa740c59b57

The following commit(s) were added to refs/heads/master by this push:
       new  a84a466   MDA-202 - Add Accept/Reject String Value/Regex validator components
a84a466 is described below

commit a84a466d867f94e2f8d1c9c2be91ffa740c59b57
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Wed Jan 31 15:04:51 2018 +0000

    MDA-202 - Add Accept/Reject String Value/Regex validator components
---
 .../string/AcceptStringRegexValidator.java         | 45 ++++++++++++
 .../string/AcceptStringValueValidator.java         | 42 +++++++++++
 .../validate/string/BaseStringRegexValidator.java  | 84 ++++++++++++++++++++++
 .../validate/string/BaseStringValueValidator.java  | 60 ++++++++++++++++
 .../string/RejectStringRegexValidator.java         | 45 ++++++++++++
 .../string/RejectStringValueValidator.java         | 43 +++++++++++
 .../metadata/validate/string/package-info.java     | 21 ++++++
 .../resources/net/shibboleth/metadata/beans.xml    | 16 +++++
 .../string/AcceptStringRegexValidatorTest.java     | 47 ++++++++++++
 .../string/AcceptStringValueValidatorTest.java     | 47 ++++++++++++
 .../string/RejectStringRegexValidatorTest.java     | 70 ++++++++++++++++++
 .../string/RejectStringValueValidatorTest.java     | 47 ++++++++++++
 12 files changed, 567 insertions(+)

diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/AcceptStringRegexValidator.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/AcceptStringRegexValidator.java
new file mode 100644
index 0000000..bc3628a
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/AcceptStringRegexValidator.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 net.shibboleth.metadata.validate.string;
+
+import java.util.regex.Matcher;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.validate.Validator;
+
+/**
+ * A <code>Validator</code> that accepts {@link String} values matching a regular expression.
+ *
+ * This validator returns {@link net.shibboleth.metadata.validate.Validator.Action#DONE}
+ * if the entire value is matched by the regular expression, thus terminating any validator sequence.
+ */
+public class AcceptStringRegexValidator extends BaseStringRegexValidator implements Validator<String> {
+
+    @Override
+    public Action validate(@Nonnull final String e, @Nonnull final Item<?> item, @Nonnull final String stageId) {
+        final Matcher matcher = getPattern().matcher(e);
+        if (matcher.matches()) {
+            return Action.DONE;
+        } else {
+            return Action.CONTINUE;
+        }
+    }
+
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/AcceptStringValueValidator.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/AcceptStringValueValidator.java
new file mode 100644
index 0000000..109f6dd
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/AcceptStringValueValidator.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 net.shibboleth.metadata.validate.string;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.validate.Validator;
+
+/**
+ * A <code>Validator</code> that accepts a fixed {@link String} value.
+ *
+ * This validator returns {@link net.shibboleth.metadata.validate.Validator.Action#DONE}
+ * if the value is matched, thus terminating any validator sequence.
+ */
+public class AcceptStringValueValidator extends BaseStringValueValidator implements Validator<String> {
+
+    @Override
+    public Action validate(@Nonnull final String e, @Nonnull final Item<?> item, @Nonnull final String stageId) {
+        if (e.equals(getValue())) {
+            return Action.DONE;
+        } else {
+            return Action.CONTINUE;
+        }
+    }
+
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/BaseStringRegexValidator.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/BaseStringRegexValidator.java
new file mode 100644
index 0000000..77f986d
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/BaseStringRegexValidator.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 net.shibboleth.metadata.validate.string;
+
+import java.util.regex.Pattern;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.validate.BaseValidator;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.component.ComponentSupport;
+
+/**
+ * A base class for <code>Validator</code>s that match {@link String} values against a regular expression.
+ */
+public abstract class BaseStringRegexValidator extends BaseValidator {
+
+    /** Regular expression to be accepted by this validator. */
+    @NonnullAfterInit
+    private String regex;
+
+    /** Compiled regular expression to use in match operations. */
+    @NonnullAfterInit
+    private Pattern pattern;
+
+    /**
+     * Returns the regular expression.
+     *
+     * @return Returns the regular expression.
+     */
+    @NonnullAfterInit
+    public String getRegex() {
+        return regex;
+    }
+
+    /**
+     * Sets the regular expression to be accepted.
+     *
+     * @param r the regular expression to set.
+     */
+    public void setRegex(@Nonnull final String r) {
+        ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
+        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+
+        regex = r;
+    }
+
+    /**
+     * Get the compiled regular expression for use in matching.
+     *
+     * @return the compiled {@link Pattern}
+     */
+    protected Pattern getPattern() {
+        return pattern;
+    }
+
+    @Override
+    protected void doInitialize() throws ComponentInitializationException {
+        super.doInitialize();
+
+        if (getRegex() == null) {
+            throw new ComponentInitializationException("regular expression to be matched can not be null");
+        }
+
+        pattern = Pattern.compile(regex);
+    }
+
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/BaseStringValueValidator.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/BaseStringValueValidator.java
new file mode 100644
index 0000000..3911a90
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/BaseStringValueValidator.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 net.shibboleth.metadata.validate.string;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.validate.BaseValidator;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+
+/**
+ * A base class for <code>Validator</code>s that match {@link String} values.
+ */
+public abstract class BaseStringValueValidator extends BaseValidator {
+
+    /** Value to be accepted by this validator. */
+    @NonnullAfterInit private String value;
+
+    /**
+     * Returns the value.
+     *
+     * @return Returns the value.
+     */
+    @NonnullAfterInit public String getValue() {
+        return value;
+    }
+
+    /**
+     * Sets the value to be matched.
+     *
+     * @param v the value to set.
+     */
+    public void setValue(@Nonnull final String v) {
+        value = v;
+    }
+
+    @Override protected void doInitialize() throws ComponentInitializationException {
+        super.doInitialize();
+
+        if (getValue() == null) {
+            throw new ComponentInitializationException("value to be matched can not be null");
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/RejectStringRegexValidator.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/RejectStringRegexValidator.java
new file mode 100644
index 0000000..1f82b55
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/RejectStringRegexValidator.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 net.shibboleth.metadata.validate.string;
+
+import java.util.regex.Matcher;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.validate.Validator;
+
+/**
+ * A <code>Validator</code> that rejects {@link String} values matching a regular expression.
+ *
+ * This validator returns {@link net.shibboleth.metadata.validate.Validator.Action#DONE}
+ * if the entire value is matched by the regular expression, thus terminating any validator sequence.
+ */
+public class RejectStringRegexValidator extends BaseStringRegexValidator implements Validator<String> {
+
+    @Override
+    public Action validate(@Nonnull final String e, @Nonnull final Item<?> item, @Nonnull final String stageId) {
+        final Matcher matcher = getPattern().matcher(e);
+        if (matcher.matches()) {
+            addErrorMessage(e, item, stageId);
+            return Action.DONE;
+        } else {
+            return Action.CONTINUE;
+        }
+    }
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/RejectStringValueValidator.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/RejectStringValueValidator.java
new file mode 100644
index 0000000..30acff1
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/RejectStringValueValidator.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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 net.shibboleth.metadata.validate.string;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.validate.Validator;
+
+/**
+ * A <code>Validator</code> that rejects a fixed {@link String} value.
+ *
+ * This validator returns {@link net.shibboleth.metadata.validate.Validator.Action#DONE}
+ * if the value is matched, thus terminating any validator sequence.
+ */
+public class RejectStringValueValidator extends BaseStringValueValidator implements Validator<String> {
+
+    @Override
+    public Action validate(@Nonnull final String e, @Nonnull final Item<?> item, @Nonnull final String stageId) {
+        if (e.equals(getValue())) {
+            addErrorMessage(e, item, stageId);
+            return Action.DONE;
+        } else {
+            return Action.CONTINUE;
+        }
+    }
+
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/package-info.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/package-info.java
new file mode 100644
index 0000000..34555ca
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/string/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.
+ */
+
+/**
+ * Validation classes for {@link java.lang.String} values.
+ */
+package net.shibboleth.metadata.validate.string;
diff --git a/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml b/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml
index 180500b..378fa0e 100644
--- a/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml
+++ b/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml
@@ -272,6 +272,22 @@
         class="net.shibboleth.metadata.validate.RejectAllValidator"/>
 
     <!--
+        net.shibboleth.metadata.validate.string
+    -->
+
+    <bean id="mda.AcceptStringRegexValidator" abstract="true" parent="mda.validator_parent"
+        class="net.shibboleth.metadata.validate.string.AcceptStringRegexValidator"/>
+
+    <bean id="mda.AcceptStringValueValidator" abstract="true" parent="mda.validator_parent"
+        class="net.shibboleth.metadata.validate.string.AcceptStringValueValidator"/>
+
+    <bean id="mda.RejectStringRegexValidator" abstract="true" parent="mda.validator_parent"
+        class="net.shibboleth.metadata.validate.string.RejectStringRegexValidator"/>
+
+    <bean id="mda.RejectStringValueValidator" abstract="true" parent="mda.validator_parent"
+        class="net.shibboleth.metadata.validate.string.RejectStringValueValidator"/>
+
+    <!--
         net.shibboleth.metadata.validate.x509
     -->
 
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/AcceptStringRegexValidatorTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/AcceptStringRegexValidatorTest.java
new file mode 100644
index 0000000..88843a8
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/AcceptStringRegexValidatorTest.java
@@ -0,0 +1,47 @@
+
+package net.shibboleth.metadata.validate.string;
+
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.ErrorStatus;
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.MockItem;
+import net.shibboleth.metadata.validate.Validator;
+import net.shibboleth.metadata.validate.Validator.Action;
+
+public class AcceptStringRegexValidatorTest {
+
+    @Test
+    public void validateMatch() throws Exception {
+        final AcceptStringRegexValidator v = new AcceptStringRegexValidator();
+        v.setId("comp");
+        v.setRegex("a*b");
+        v.initialize();
+
+        final Item<String> item = new MockItem("content");
+        final Validator.Action action = v.validate("aaaab", item, "stage");
+        Assert.assertEquals(action, Action.DONE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 0);
+    }
+
+    @Test
+    public void validateMismatch() throws Exception {
+        final AcceptStringValueValidator v = new AcceptStringValueValidator();
+        v.setId("comp");
+        v.setValue("a*b");
+        v.initialize();
+
+        final Item<String> item = new MockItem("content");
+        final Validator.Action action = v.validate("aaaaaaabc", item, "stage");
+        Assert.assertEquals(action, Action.CONTINUE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 0);
+    }
+
+}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/AcceptStringValueValidatorTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/AcceptStringValueValidatorTest.java
new file mode 100644
index 0000000..f59b800
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/AcceptStringValueValidatorTest.java
@@ -0,0 +1,47 @@
+
+package net.shibboleth.metadata.validate.string;
+
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.ErrorStatus;
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.MockItem;
+import net.shibboleth.metadata.validate.Validator;
+import net.shibboleth.metadata.validate.Validator.Action;
+
+public class AcceptStringValueValidatorTest {
+
+    @Test
+    public void validateMatch() throws Exception {
+        final AcceptStringValueValidator v = new AcceptStringValueValidator();
+        v.setId("comp");
+        v.setValue("match");
+        v.initialize();
+
+        final Item<String> item = new MockItem("content");
+        final Validator.Action action = v.validate("match", item, "stage");
+        Assert.assertEquals(action, Action.DONE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 0);
+    }
+
+    @Test
+    public void validateMismatch() throws Exception {
+        final AcceptStringValueValidator v = new AcceptStringValueValidator();
+        v.setId("comp");
+        v.setValue("match");
+        v.initialize();
+
+        final Item<String> item = new MockItem("content");
+        final Validator.Action action = v.validate("no match", item, "stage");
+        Assert.assertEquals(action, Action.CONTINUE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 0);
+    }
+
+}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/RejectStringRegexValidatorTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/RejectStringRegexValidatorTest.java
new file mode 100644
index 0000000..8d27559
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/RejectStringRegexValidatorTest.java
@@ -0,0 +1,70 @@
+
+package net.shibboleth.metadata.validate.string;
+
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.ErrorStatus;
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.MockItem;
+import net.shibboleth.metadata.validate.Validator;
+import net.shibboleth.metadata.validate.Validator.Action;
+
+public class RejectStringRegexValidatorTest {
+
+    @Test
+    public void validateMatch() throws Exception {
+        final RejectStringRegexValidator v = new RejectStringRegexValidator();
+        v.setId("comp");
+        v.setRegex("a*b");
+        v.setMessage("the lazy fox jumped over the %s");
+        v.initialize();
+
+        final Item<String> item = new MockItem("content");
+        final Validator.Action action = v.validate("aaaab", item, "stage");
+        Assert.assertEquals(action, Action.DONE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 1);
+        final ErrorStatus err = errs.get(0);
+        Assert.assertTrue(err.getStatusMessage().contains("the lazy fox"));
+        Assert.assertTrue(err.getStatusMessage().contains("aaaab"));
+    }
+
+    @Test
+    public void whitespaceMatch() throws Exception {
+        final RejectStringRegexValidator v = new RejectStringRegexValidator();
+        v.setId("comp");
+        v.setRegex(".*\\s.*");
+        v.setMessage("the lazy fox jumped over the '%s'");
+        v.initialize();
+
+        final Item<String> item = new MockItem("content");
+        final Validator.Action action = v.validate(" example.org", item, "stage");
+        Assert.assertEquals(action, Action.DONE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 1);
+        final ErrorStatus err = errs.get(0);
+        Assert.assertTrue(err.getStatusMessage().contains("the lazy fox"));
+        Assert.assertTrue(err.getStatusMessage().contains("' example.org'"));
+    }
+
+    @Test
+    public void validateMismatch() throws Exception {
+        final AcceptStringValueValidator v = new AcceptStringValueValidator();
+        v.setId("comp");
+        v.setValue("a*b");
+        v.initialize();
+
+        final Item<String> item = new MockItem("content");
+        final Validator.Action action = v.validate("aaaaaaabc", item, "stage");
+        Assert.assertEquals(action, Action.CONTINUE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 0);
+    }
+
+}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/RejectStringValueValidatorTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/RejectStringValueValidatorTest.java
new file mode 100644
index 0000000..2d407ac
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/string/RejectStringValueValidatorTest.java
@@ -0,0 +1,47 @@
+
+package net.shibboleth.metadata.validate.string;
+
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.ErrorStatus;
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.MockItem;
+import net.shibboleth.metadata.validate.Validator;
+import net.shibboleth.metadata.validate.Validator.Action;
+
+public class RejectStringValueValidatorTest {
+
+    @Test
+    public void validateMatch() throws Exception {
+        final RejectStringValueValidator v = new RejectStringValueValidator();
+        v.setId("comp");
+        v.setValue("match");
+        v.initialize();
+
+        final Item<String> item = new MockItem("content");
+        final Validator.Action action = v.validate("match", item, "stage");
+        Assert.assertEquals(action, Action.DONE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 1);
+    }
+
+    @Test
+    public void validateMismatch() throws Exception {
+        final RejectStringValueValidator v = new RejectStringValueValidator();
+        v.setId("comp");
+        v.setValue("match");
+        v.initialize();
+
+        final Item<String> item = new MockItem("content");
+        final Validator.Action action = v.validate("no match", item, "stage");
+        Assert.assertEquals(action, Action.CONTINUE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 0);
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list