Author: niallp Date: Sat Oct 24 01:04:26 2009 New Revision: 829295 URL: http://svn.apache.org/viewvc?rev=829295&view=rev Log: Add AssertFalse, AssertTrue, Null & NotNull ConstraintValidator implementations
Added: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/ commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertFalseValidator.java (with props) commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertTrueValidator.java (with props) commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NotNullValidator.java (with props) commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NullValidator.java (with props) commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/ commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertFalseValidatorTest.java (with props) commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertTrueValidatorTest.java (with props) commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NotNullValidatorTest.java (with props) commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NullValidatorTest.java (with props) Added: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertFalseValidator.java URL: http://svn.apache.org/viewvc/commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertFalseValidator.java?rev=829295&view=auto ============================================================================== --- commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertFalseValidator.java (added) +++ commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertFalseValidator.java Sat Oct 24 01:04:26 2009 @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 org.apache.commons.validation.framework.validators; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import javax.validation.constraints.AssertFalse; + +/** + * {...@link ConstraintValidator} for the {...@link AssertFalse} constraint. + * + * @version $Revision$ $Date$ + * @since 1.0 + */ +public class AssertFalseValidator implements ConstraintValidator<AssertFalse, Boolean> { + + /** + * Initialize the validator. + * + * @param constraint The associated constraint annotation + */ + public void initialize(AssertFalse constraint) { + } + + /** + * Validate the value. + * + * @param value the value + * @param context The validator context + * @return true if valid or false if invalid + */ + public boolean isValid(Boolean value, ConstraintValidatorContext context) { + if (value == null) { + return true; // null is valid + } + return (value.booleanValue() == false); + } + +} Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertFalseValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertFalseValidator.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertTrueValidator.java URL: http://svn.apache.org/viewvc/commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertTrueValidator.java?rev=829295&view=auto ============================================================================== --- commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertTrueValidator.java (added) +++ commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertTrueValidator.java Sat Oct 24 01:04:26 2009 @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 org.apache.commons.validation.framework.validators; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import javax.validation.constraints.AssertTrue; + +/** + * {...@link ConstraintValidator} for the {...@link AssertTrue} constraint. + * + * @version $Revision$ $Date$ + * @since 1.0 + */ +public class AssertTrueValidator implements ConstraintValidator<AssertTrue, Boolean> { + + /** + * Initialize the validator. + * + * @param constraint The associated constraint annotation + */ + public void initialize(AssertTrue constraint) { + } + + /** + * Validate the value. + * + * @param value the value + * @param context The validator context + * @return true if valid or false if invalid + */ + public boolean isValid(Boolean value, ConstraintValidatorContext context) { + if (value == null) { + return true; // null is valid + } + return value; + } + +} Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertTrueValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/AssertTrueValidator.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NotNullValidator.java URL: http://svn.apache.org/viewvc/commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NotNullValidator.java?rev=829295&view=auto ============================================================================== --- commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NotNullValidator.java (added) +++ commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NotNullValidator.java Sat Oct 24 01:04:26 2009 @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 org.apache.commons.validation.framework.validators; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import javax.validation.constraints.NotNull; + +/** + * {...@link ConstraintValidator} for the {...@link NotNull} constraint. + * + * @version $Revision$ $Date$ + * @since 1.0 + */ +public class NotNullValidator implements ConstraintValidator<NotNull, Object> { + + /** + * Initialize the validator. + * + * @param constraint The associated constraint annotation + */ + public void initialize(NotNull constraint) { + } + + /** + * Validate the value. + * + * @param value the value + * @param context The validator context + * @return true if valid or false if invalid + */ + public boolean isValid(Object value, ConstraintValidatorContext context) { + return (value != null); + } + +} Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NotNullValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NotNullValidator.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NullValidator.java URL: http://svn.apache.org/viewvc/commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NullValidator.java?rev=829295&view=auto ============================================================================== --- commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NullValidator.java (added) +++ commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NullValidator.java Sat Oct 24 01:04:26 2009 @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 org.apache.commons.validation.framework.validators; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import javax.validation.constraints.Null; + +/** + * {...@link ConstraintValidator} for the {...@link Null} constraint. + * + * @version $Revision$ $Date$ + * @since 1.0 + */ +public class NullValidator implements ConstraintValidator<Null, Object> { + + /** + * Initialize the validator. + * + * @param constraint The associated constraint annotation + */ + public void initialize(Null constraint) { + } + + /** + * Validate the value. + * + * @param value the value + * @param context The validator context + * @return true if valid or false if invalid + */ + public boolean isValid(Object value, ConstraintValidatorContext context) { + return (value == null); + } + +} Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NullValidator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/main/java/org/apache/commons/validation/framework/validators/NullValidator.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertFalseValidatorTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertFalseValidatorTest.java?rev=829295&view=auto ============================================================================== --- commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertFalseValidatorTest.java (added) +++ commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertFalseValidatorTest.java Sat Oct 24 01:04:26 2009 @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 org.apache.commons.validation.framework.validators; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + + +/** + * Test case for {...@link AssertFalseValidator}. + * + * @version $Revision$ $Date$ + * @since 1.0 + */ +public class AssertFalseValidatorTest { + + private AssertFalseValidator validator = new AssertFalseValidator(); + + @Test + public void testFalse() { + assertTrue(validator.isValid(false, null)); + } + + @Test + public void testTrue() { + assertFalse(validator.isValid(true, null)); + } + + @Test + public void testNull() { + assertTrue(validator.isValid(null, null)); + } +} Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertFalseValidatorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertFalseValidatorTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertTrueValidatorTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertTrueValidatorTest.java?rev=829295&view=auto ============================================================================== --- commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertTrueValidatorTest.java (added) +++ commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertTrueValidatorTest.java Sat Oct 24 01:04:26 2009 @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 org.apache.commons.validation.framework.validators; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + + +/** + * Test case for {...@link AssertTrueValidator}. + * + * @version $Revision$ $Date$ + * @since 1.0 + */ +public class AssertTrueValidatorTest { + + private AssertTrueValidator validator = new AssertTrueValidator(); + + @Test + public void testFalse() { + assertFalse(validator.isValid(false, null)); + } + + @Test + public void testTrue() { + assertTrue(validator.isValid(true, null)); + } + + @Test + public void testNull() { + assertTrue(validator.isValid(null, null)); + } +} Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertTrueValidatorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/AssertTrueValidatorTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NotNullValidatorTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NotNullValidatorTest.java?rev=829295&view=auto ============================================================================== --- commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NotNullValidatorTest.java (added) +++ commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NotNullValidatorTest.java Sat Oct 24 01:04:26 2009 @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 org.apache.commons.validation.framework.validators; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + + +/** + * Test case for {...@link NotNullValidator}. + * + * @version $Revision$ $Date$ + * @since 1.0 + */ +public class NotNullValidatorTest { + + private NotNullValidator validator = new NotNullValidator(); + + @Test + public void testNotNull() { + assertTrue(validator.isValid(new Object(), null)); + } + + @Test + public void testNull() { + assertFalse(validator.isValid(null, null)); + } +} Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NotNullValidatorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NotNullValidatorTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NullValidatorTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NullValidatorTest.java?rev=829295&view=auto ============================================================================== --- commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NullValidatorTest.java (added) +++ commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NullValidatorTest.java Sat Oct 24 01:04:26 2009 @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 org.apache.commons.validation.framework.validators; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + + +/** + * Test case for {...@link NullValidator}. + * + * @version $Revision$ $Date$ + * @since 1.0 + */ +public class NullValidatorTest { + + private NullValidator validator = new NullValidator(); + + @Test + public void testNotNull() { + assertFalse(validator.isValid(new Object(), null)); + } + + @Test + public void testNull() { + assertTrue(validator.isValid(null, null)); + } +} Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NullValidatorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/validator2/branches/alternative/validation-framework/src/test/java/org/apache/commons/validation/framework/validators/NullValidatorTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL