-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrades to BV 5.2.2.Final and adds tests using JDK8
- Loading branch information
Showing
6 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
bean-validation/tests/src/main/java/org/jboss/forge/addon/validation/ui/NotFoo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2015 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.validation.ui; | ||
|
||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||
import static java.lang.annotation.ElementType.CONSTRUCTOR; | ||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE_USE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
import javax.validation.ReportAsSingleViolation; | ||
|
||
/** | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
@Documented | ||
@Constraint(validatedBy = { NotFooValidator.class }) | ||
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE }) | ||
@Retention(RUNTIME) | ||
@ReportAsSingleViolation | ||
public @interface NotFoo | ||
{ | ||
String message() default "My Error Message"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
|
||
/** | ||
* Defines several {@code @Email} annotations on the same element. | ||
*/ | ||
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
public @interface List | ||
{ | ||
NotFoo[] value(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
bean-validation/tests/src/main/java/org/jboss/forge/addon/validation/ui/NotFooValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2015 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.validation.ui; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
|
||
/** | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public class NotFooValidator implements ConstraintValidator<NotFoo, Object> | ||
{ | ||
|
||
@Override | ||
public void initialize(NotFoo constraintAnnotation) | ||
{ | ||
} | ||
|
||
@Override | ||
public boolean isValid(Object value, ConstraintValidatorContext context) | ||
{ | ||
return !"Foo".equals(value); | ||
} | ||
|
||
} |
File renamed without changes.
44 changes: 44 additions & 0 deletions
44
...dation/tests/src/main/java/org/jboss/forge/addon/validation/ui/ValidationJDK8Command.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright 2014 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.validation.ui; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.hibernate.validator.valuehandling.UnwrapValidatedValue; | ||
import org.jboss.forge.addon.ui.command.AbstractUICommand; | ||
import org.jboss.forge.addon.ui.context.UIBuilder; | ||
import org.jboss.forge.addon.ui.context.UIExecutionContext; | ||
import org.jboss.forge.addon.ui.input.UIInput; | ||
import org.jboss.forge.addon.ui.metadata.WithAttributes; | ||
import org.jboss.forge.addon.ui.result.Result; | ||
import org.jboss.forge.addon.ui.result.Results; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public class ValidationJDK8Command extends AbstractUICommand | ||
{ | ||
@Inject | ||
@WithAttributes(label = "Name") | ||
@UnwrapValidatedValue | ||
private UIInput<@NotFoo String> name; | ||
|
||
@Override | ||
public void initializeUI(UIBuilder builder) throws Exception | ||
{ | ||
builder.add(name); | ||
} | ||
|
||
@Override | ||
public Result execute(UIExecutionContext context) throws Exception | ||
{ | ||
return Results.success(); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...idation/tests/src/test/java/org/jboss/forge/addon/validation/ui/ValidationJDK8UITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.validation.ui; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.forge.addon.ui.controller.CommandController; | ||
import org.jboss.forge.addon.ui.output.UIMessage; | ||
import org.jboss.forge.addon.ui.test.UITestHarness; | ||
import org.jboss.forge.arquillian.AddonDependencies; | ||
import org.jboss.forge.arquillian.AddonDependency; | ||
import org.jboss.forge.arquillian.archive.AddonArchive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.junit.Assert; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@Ignore("HV-1022") | ||
public class ValidationJDK8UITest | ||
{ | ||
@Deployment | ||
@AddonDependencies({ | ||
@AddonDependency(name = "org.jboss.forge.addon:bean-validation"), | ||
@AddonDependency(name = "org.jboss.forge.addon:ui-test-harness"), | ||
@AddonDependency(name = "org.jboss.forge.furnace.container:cdi") | ||
}) | ||
public static AddonArchive getDeployment() | ||
{ | ||
AddonArchive archive = ShrinkWrap | ||
.create(AddonArchive.class) | ||
.addBeansXML() | ||
.addClass(ValidationJDK8Command.class) | ||
.addClass(NotFoo.class) | ||
.addClass(NotFooValidator.class); | ||
|
||
return archive; | ||
} | ||
|
||
@Inject | ||
UITestHarness testHarness; | ||
|
||
@Test | ||
public void testValidation() throws Exception | ||
{ | ||
try (CommandController controller = testHarness.createCommandController(ValidationJDK8Command.class)) | ||
{ | ||
controller.initialize(); | ||
controller.setValueFor("name", "Foo"); | ||
Assert.assertFalse("Controller should not be valid", controller.isValid()); | ||
List<UIMessage> messages = controller.validate(); | ||
Assert.assertEquals("An error should have been captured", 1, messages.size()); | ||
Assert.assertEquals("My Error Message", messages.get(0).getDescription()); | ||
} | ||
} | ||
} |