Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bean-validation #858

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
5dee8a3
Added comments(description) for all built-in constraints used for Member
girirajsharma Feb 25, 2014
a932f63
Added comments(description) for bean validation annotations.Also, added
girirajsharma Feb 26, 2014
341d79c
Added two new tests for bean validation namely testDateOfBirthViolation
girirajsharma Feb 26, 2014
b1f898a
Changed ${version.jboss.bom.eap} from 6.2.0-build-7 to 6.2.1.GA as it is
girirajsharma Feb 26, 2014
9d93269
Added comment(description) for @Column annotation used to specify a
girirajsharma Feb 26, 2014
f5d5696
Added date_of_birth, event_date, min_quantity and max_quantity as new
girirajsharma Feb 26, 2014
7df11bb
Added date_of_birth, event_date, min_quantity and max_quantity as new
girirajsharma Feb 27, 2014
ee2e91d
Replaced 4 violations with 8 as a Member instance initialized with
girirajsharma Feb 27, 2014
17b39b9
Added imports (javax.validation.constraints.*) for validation
girirajsharma Feb 28, 2014
d9bd5dc
bean-validation-custom-constraints : Bean validation using custom
girirajsharma Feb 28, 2014
65ea145
Declared the proxy server settings in Maven configuration file
girirajsharma Mar 6, 2014
8e28c17
bean-validation-custom-constraints : Bean validation using custom
girirajsharma Mar 13, 2014
1cd5de4
Added License Information and Contributor Agreement to pom.xml
girirajsharma Mar 13, 2014
4a83e37
bean-validation-custom-constraints
girirajsharma Mar 14, 2014
9e16cae
Set valid values for Person and Address entity beans as per custom
girirajsharma Apr 11, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
102 changes: 102 additions & 0 deletions bean-validation-custom-constraint/README.md
@@ -0,0 +1,102 @@
bean-validation-custom-constraint: Bean Validation using custom constraints via Arquillian Example
===================================================================================================
Author: Giriraj Sharma
Level: Beginner
Technologies: Bean Validation, JPA
Summary: Shows how to use Arquillian to test Bean Validation using custom constraints
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need 2 spaces at the end of this line so it renders a carriage return.

Target Product: EAP
Product Versions: EAP 6.1, EAP 6.2
Source: <https://github.com/jboss-developer/jboss-eap-quickstarts/>

What is it?
-----------

This project demonstrates how to use CDI 1.0, JPA 2.0 and Bean Validation 1.0. Bean Validation API allows the developers to define their own constraints by creating a new annotation and writing the validator which is used to validate the value. This quickstart will show you how to create custom constraints and

then use it to validate your data. It includes a persistence unit and some sample persistence code to introduce you to database access in enterprise Java. This quickstart does not contain a user interface layer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why there is a blank line breaking up this sentence.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't break between 'custom constraints and ' ... 'then use it to validate'


The purpose of this project is to show you how to test bean validation using custom constraints with Arquillian. If you want to see an example of how to test bean validation with a user interface, look at the [kitchensink](../kitchensink/README.md) example.

_Note: This quickstart uses the H2 database included with JBoss EAP 6. It is a lightweight, relational example datasource that is used for examples only. It is not robust or scalable and should NOT be used in a production environment!_

System requirements
-------------------

The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 6.1 or later.

All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later.


Configure Maven
---------------

If you have not yet done so, you must [Configure Maven](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/CONFIGURE_MAVEN.md#configure-maven-to-build-and-deploy-the-quickstarts) before testing the quickstarts.


Start the JBoss Server
-------------------------

1. Open a command prompt and navigate to the root of the JBoss server directory.
2. The following shows the command line to start the server:

For Linux: JBOSS_HOME/bin/standalone.sh
For Windows: JBOSS_HOME\bin\standalone.bat


Run the Arquillian Tests
-------------------------

This quickstart provides Arquillian tests. By default, these tests are configured to be skipped as Arquillian tests require the use of a container.

_NOTE: The following commands assume you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See [Run the Arquillian Tests](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/RUN_ARQUILLIAN_TESTS.md#run-the-arquillian-tests) for complete instructions and additional options._

1. Make sure you have started the JBoss Server as described above.
2. Open a command prompt and navigate to the root directory of this quickstart.
3. Type the following command to run the test goal with the following profile activated:

mvn clean test -Parq-jbossas-remote


Investigate the Console Output
----------------------------

When you run the tests, JUnit will present you test report summary:

Tests run: 5, Failures: 0, Errors: 0, Skipped: 0

If you are interested in more details, look in the `target/surefire-reports` directory.

You can also check the server console output to verify that the Arquillian tests deployed to and ran in the application server. Search for lines similar to the following ones in the server output log:

[timestamp] INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) Starting deployment of "test.war"
...
[timestamp] INFO [org.jboss.as.server] (management-handler-threads - 1) JBAS018559: Deployed "test.war"
...
[timestamp] INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) Stopped deployment test.war in 48ms
...
[timestamp] INFO [org.jboss.as.server] (management-handler-threads - 1) JBAS018558: Undeployed "test.war

Server Log: Expected warnings and errors
-----------------------------------

_Note:_ You will see the following warnings and errors in the server log. Hibernate attempts to drop the table and constraints before they are created because the `hibernate.hbm2ddl.auto` value is set to `create-drop`. You can ignore these warnings and errors.

HHH000431: Unable to determine H2 database version, certain features may not work

HHH000389: Unsuccessful: drop sequence hibernate_sequence
Sequence "HIBERNATE_SEQUENCE" not found; SQL statement: drop sequence hibernate_sequence [90036-168]


Test the Quickstart in JBoss Developer Studio or Eclipse
-------------------------------------
You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/USE_JDBS.md#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts)


Debug the Application
------------------------------------

If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.

mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc

257 changes: 257 additions & 0 deletions bean-validation-custom-constraint/pom.xml
@@ -0,0 +1,257 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.

Licensed 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.jboss.quickstarts.eap</groupId>
<artifactId>jboss-bean-validation-custom-constraint</artifactId>
<version>6.2.0-redhat-SNAPSHOT</version>
<packaging>war</packaging>

<name>JBoss EAP Quickstart: bean-validation-custom-constraint</name>
<description>An example that demonstrates Arquillian Bean Validation Custom Constraints </description>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<distribution>repo</distribution>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
</license>
</licenses>

<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- JBoss dependency versions -->

<version.jboss.maven.plugin>7.4.Final</version.jboss.maven.plugin>

<!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. -->
<version.jboss.bom.eap>6.2.0-build-7</version.jboss.bom.eap>

<!-- other plugin versions -->
<version.surefire.plugin>2.10</version.surefire.plugin>
<version.war.plugin>2.1.1</version.war.plugin>

<!-- maven-compiler-plugin -->
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
</properties>

<dependencyManagement>
<dependencies>
<!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
of artifacts. We use this here so that we always get the correct versions
of artifacts. Here we use the jboss-javaee-6.0-with tools stack (you can read this as
the JBoss stack of the Java EE 6 APIs, with some extras tools for your project, such
as Arquillian for testing) -->
<dependency>
<groupId>org.jboss.bom.eap</groupId>
<artifactId>jboss-javaee-6.0-with-tools</artifactId>
<version>${version.jboss.bom.eap}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.bom.eap</groupId>
<artifactId>jboss-javaee-6.0-with-hibernate</artifactId>
<version>${version.jboss.bom.eap}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<!-- First declare the APIs we depend on and need for compilation.
All of them are provided by JBoss EAP 6 -->

<!-- Import the CDI API, we use provided scope as the API is included in JBoss EAP 6 -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- Import the JPA API, we use provided scope as the API is included in JBoss EAP 6 -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- JSR-303 (Bean Validation) Implementation -->
<!-- Provides portable constraints such as @Email -->
<!-- Hibernate Validator is shipped in JBoss EAP 6 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Now we declare any tools needed -->

<!-- Annotation processor to generate the JPA 2.0 metamodel classes
for typesafe criteria queries -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>

<!-- Needed for Hibernate Annotations -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<scope>provided</scope>
</dependency>

<!-- Needed for running tests (you may also use TestNG) -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<!-- Arquillian allows you to test enterprise code such as EJBs and
Transactional(JTA) JPA from JUnit/TestNG -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>

<!-- Arquillian Servlet 3.0 protocol -->
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<!-- Maven will append the version to the finalName (which is the name
given to the generated war, and hence the context root) -->
<finalName>${project.artifactId}</finalName>

<!-- Define plugin versions required for Deployment and Testing Tools -->
<pluginManagement>
<plugins>
<!-- The Maven Surefire plugin tests your application. Here we ensure we are using a version compatible with Arquillian -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire.plugin}</version>
</plugin>
<!-- The JBoss AS plugin deploys your war to a local JBoss EAP container -->
<!-- To use, set the JBOSS_HOME environment variable and run:
mvn package jboss-as:deploy -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>${version.jboss.maven.plugin}</version>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<!-- Java EE 6 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<!-- The default profile skips all tests, though you can tune it
to run just unit tests based on a custom pattern -->
<!-- Seperate profiles are provided for running all tests, including
Arquillian tests that execute in the specified container -->
<id>default</id>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<!-- The JBoss AS plugin deploys your war to a local JBoss EAP container -->
<!-- To use, set the JBOSS_HOME environment variable and run:
mvn package jboss-as:deploy -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>

<profile>
<!-- An optional Arquillian testing profile that executes tests
in your JBoss EAP instance -->
<!-- This profile will start a new JBoss EAP instance, and execute the
test, shutting it down when done -->
<!-- Run with: mvn clean test -Parq-jbossas-managed -->
<id>arq-jbossas-managed</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>

<profile>
<!-- An optional Arquillian testing profile that executes tests
in a remote JBoss EAP instance -->
<!-- Run with: mvn clean test -Parq-jbossas-remote -->
<id>arq-jbossas-remote</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-remote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>

</profiles>
</project>