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

Already on GitHub? Sign in to your account

bean-validation #858

Closed
wants to merge 15 commits into
from

Conversation

Projects
None yet
3 participants
Contributor

girirajsharma commented Feb 26, 2014

Added comments(description) for bean validation annotations and added two new tests for bean validation in MemberValidationTest.java. Please ignore commit 5dee8a3.

girirajsharma added some commits Feb 25, 2014

@girirajsharma girirajsharma Added comments(description) for all built-in constraints used for Member
bean validation.Also,added dateOfBirth,eventDate,minQuantity and
maxQuantity as additional fields to implement several other constraints
using @Past,@Future,@Min,@Max as annotations.

Signed-off-by: girirajSharma <giriraj.sharma27@gmail.com>
5dee8a3
@girirajsharma girirajsharma Added comments(description) for bean validation annotations.Also, added
dateOfBirth,eventDate,minQuantity,maxQuantity as new fields with
@Past,@Future,@Min,@Max as respective annotations.

Signed-off-by: girirajSharma <giriraj.sharma27@gmail.com>
a932f63
@girirajsharma girirajsharma Added two new tests for bean validation namely testDateOfBirthViolation
and testMinQuantityViolation to test for constraints on dateOfBirth and
minQuantity fields of Member.Also,createValidMember method was modified
to initialize new fields of Member class object(member) with valid
values.

Signed-off-by: girirajSharma <giriraj.sharma27@gmail.com>
341d79c
@girirajsharma girirajsharma Changed ${version.jboss.bom.eap} from 6.2.0-build-7 to 6.2.1.GA as it is
the latest version available from the
jboss-ga-repository(http://maven.repository.redhat.com/techpreview/all).
b1f898a
@girirajsharma girirajsharma Added comment(description) for @Column annotation used to specify a
mapped column for a persistent property or field.
9d93269
@girirajsharma girirajsharma Added date_of_birth, event_date, min_quantity and max_quantity as new
column names into the Table(MEMBER_BEAN_VALIDATION).
f5d5696
@girirajsharma girirajsharma Added date_of_birth, event_date, min_quantity and max_quantity as new
column names into the Table(MEMBER_BEAN_VALIDATION).
7df11bb
@girirajsharma girirajsharma Replaced 4 violations with 8 as a Member instance initialized with
default constructor will fail to validate against 8 Not Null fields.
ee2e91d
@girirajsharma girirajsharma Added imports (javax.validation.constraints.*) for validation
constraints Past,Future,Max and Min.
17b39b9
@girirajsharma girirajsharma bean-validation-custom-constraints : Bean validation using custom
constraints via Arquillan Example
This quickstart will show you how Bean Validation API can be used to
create custom constraints for validation of data and how to use
arquillan to test the same.

Signed-off-by: girirajSharma <giriraj.sharma27@gmail.com>
d9bd5dc

@sgilda sgilda commented on an outdated diff Mar 4, 2014

bean-validation-custom-constraint/README.md
@@ -0,0 +1,102 @@
+bean-validation-custom-constraints: Bean Validation using custom constraints via Arquillian Example
@sgilda

sgilda Mar 4, 2014

Contributor

bean-validation-custom-constraint: Bean Validation using custom constraints via Arquillian Example

(The quickstart name must match the folder name)

@sgilda sgilda commented on the diff Mar 4, 2014

bean-validation-custom-constraint/README.md
@@ -0,0 +1,102 @@
+bean-validation-custom-constraints: 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
@sgilda

sgilda Mar 4, 2014

Contributor

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

@sgilda sgilda commented on an outdated diff Mar 4, 2014

bean-validation-custom-constraint/pom.xml
+
+ 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>jboss-eap-bean-validation-customConstraint</groupId>
@sgilda

sgilda Mar 4, 2014

Contributor

This should be:

    <groupId>org.jboss.quickstarts.eap</groupId>

@sgilda sgilda commented on an outdated diff Mar 4, 2014

bean-validation-custom-constraint/pom.xml
+ 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>jboss-eap-bean-validation-customConstraint</groupId>
+ <artifactId>jboss-eap-bean-validation-customConstraint</artifactId>
@sgilda

sgilda Mar 4, 2014

Contributor

This should be:

    <artifactId>jboss-bean-validation-custom-constraint</artifactId>

@sgilda sgilda commented on an outdated diff Mar 4, 2014

bean-validation-custom-constraint/pom.xml
+ 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>jboss-eap-bean-validation-customConstraint</groupId>
+ <artifactId>jboss-eap-bean-validation-customConstraint</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
@sgilda

sgilda Mar 4, 2014

Contributor
    <version>6.2.0-redhat-SNAPSHOT</version>

@sgilda sgilda commented on an outdated diff Mar 4, 2014

bean-validation-custom-constraint/pom.xml
+ 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>jboss-eap-bean-validation-customConstraint</groupId>
+ <artifactId>jboss-eap-bean-validation-customConstraint</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
@sgilda

sgilda Mar 4, 2014

Contributor

Doesn't this generate a WAR?

@sgilda sgilda commented on an outdated diff Mar 4, 2014

bean-validation-custom-constraint/pom.xml
+ 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>jboss-eap-bean-validation-customConstraint</groupId>
+ <artifactId>jboss-eap-bean-validation-customConstraint</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>JBoss EAP Quickstart: bean-validation-customConstraint</name>
@sgilda

sgilda Mar 4, 2014

Contributor
    <name>JBoss EAP Quickstart: bean-validation-custom-constraint</name>

@sgilda sgilda commented on an outdated diff Mar 4, 2014

bean-validation-custom-constraint/pom.xml
+ 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>jboss-eap-bean-validation-customConstraint</groupId>
+ <artifactId>jboss-eap-bean-validation-customConstraint</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>JBoss EAP Quickstart: bean-validation-customConstraint</name>
+ <description>An Arquillian Bean Validation by Custom Constraints test example</description>
@sgilda

sgilda Mar 4, 2014

Contributor
    <description>An example that demonstrates Arquillian Bean Validation Custom Constraints </description>

@sgilda sgilda and 1 other commented on an outdated diff Mar 4, 2014

bean-validation-custom-constraint/pom.xml
+ </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.1.GA</version.jboss.bom.eap>
@sgilda

sgilda Mar 4, 2014

Contributor
    <version.jboss.bom.eap>6.2.0-build-7</version.jboss.bom.eap>
@girirajsharma

girirajsharma Mar 5, 2014

Contributor

@sgilda @LightGuard When I reset jboss.bom.eap version to 6.2.0-build-7, I face several build errors like "Project build error: Non-resolvable import POM: Failure to find org.jboss.bom.eap:jboss-javaee-6.0-with-tools:pom:6.2.0-build-7 in http://maven.repository.redhat.com/earlyaccess/all/ was cached in the local repository, resolution will not be reattempted until the update interval of jboss-earlyaccess-repository has elapsed or updates are forced " in dependency management.

@sgilda sgilda commented on the diff Mar 4, 2014

bean-validation-custom-constraint/README.md
+bean-validation-custom-constraints: 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
+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.
@sgilda

sgilda Mar 4, 2014

Contributor

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

@sgilda

sgilda Apr 11, 2014

Contributor

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

Contributor

sgilda commented Mar 4, 2014

Nice job on this!

There are a few minor issues I discovered running the QS Tools. I noted them in the README and POM files. See step 8 under 'Basic Steps' in the Contributing Guide for details on how to run the QS Tools report. The problems with the POM file are also causing the Arquillian tests to fail.

After you fix the issues I mentioned, would you mind squashing the commits down to 1 commit? That makes it easier to review.

When you fix the issues, I will get someone to do a code review.

Thanks for submitting this quickstart!

Contributor

sgilda commented Mar 4, 2014

Even when I fix up your POM file, I am still getting an error when I run the tests. I see this in the server log:

13:26:26,152 ERROR [org.jboss.as.server](management-handler-thread - 5) JBAS015870: Deploy of deployment "test.war" was rolled back with the following failure message:
{"JBAS014671: Failed services" => {"jboss.persistenceunit."test.war#primary"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit."test.war#primary": javax.persistence.PersistenceException: [PersistenceUnit: primary] Unable to build EntityManagerFactory
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: primary] Unable to build EntityManagerFactory
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: org.jboss.as.quickstarts.bean_validation_customConstraint.MyPerson"}}

Contributor

girirajsharma commented Mar 4, 2014

@sgilda -Thanks a lot for reviewing and pointing out my errors.I shall try to fix all the bugs , you have mentioned. I will then perform testing using QS tools and will also see to it which problems in POM file are causing arquillian tests to fail. Once I fix the issues you mentioned, I would squash all the commits down to 1 commit so as to make it easy for code reviewer. Between,I also tried to extend the functionality of bean-validation quickstart(one which is already present in git master branch) in my commits (5dee8a3, a932f63, 341d79c, b1f898a, 9d93269, 7df11bb). Please review those commits also by a code reviewer whenever you feel like as per your convenience and time.Thanks.

@LightGuard LightGuard commented on the diff Mar 4, 2014

...an_validation_custom_constraint/AddressValidator.java
+ }
+
+ /**
+ * 1. The address should not be null.
+ * 2. The address should have all the data values specified.
+ * 3. Pin code in the address should be of atleast 6 characters.
+ * 4. The country in the address should be of atleast 4 characters.
+ */
+ public boolean isValid(MyAddress value, ConstraintValidatorContext context) {
+ if (value == null) {
+ return false;
+ }
+
+ if (value.getCity() == null || value.getCountry() == null || value.getLocality() == null
+ || value.getPinCode() == null || value.getState() == null || value.getStreetAddress() == null) {
+ return false;
@LightGuard

LightGuard Mar 4, 2014

Owner

Shouldn't you test for empty too?

@girirajsharma

girirajsharma Mar 4, 2014

Contributor

@LightGuard Thanks for pointing out. I shall make necessary changes and will review the code once again followed by testing.

girirajsharma added some commits Mar 6, 2014

@girirajsharma girirajsharma Declared the proxy server settings in Maven configuration file
contributor-settings.xml to enable downloading of dependencies through
Maven in case of proxy servers.
65ea145
@girirajsharma girirajsharma bean-validation-custom-constraints : Bean validation using custom
constraints via Arquillan Example.
This quickstart will show how Bean Validation API can be used to
create custom constraints for validation of data and how to use
arquillan to test the same.

Signed-off-by: girirajSharma <giriraj.sharma27@gmail.com>
8e28c17
@girirajsharma girirajsharma Added License Information and Contributor Agreement to pom.xml
Signed-off-by: girirajSharma <giriraj.sharma27@gmail.com>
1cd5de4
@girirajsharma girirajsharma bean-validation-custom-constraints
Bean validation using custom constraints via Arquillan Example
This quickstart will show you how Bean Validation API can be used to
create custom constraints for validation of data and how to use
arquillan to test the same.Please ignore all previous commits in
#858.Current commit is wrapped up with entire quickstart source code.

Signed-off-by: girirajSharma <giriraj.sharma27@gmail.com>
4a83e37
Contributor

sgilda commented Apr 11, 2014

@girirajsharma : I just updated to get your latest changes and I get errors when I run mvn clean test -Parq-jbossas-remote

Here are the results:

Running org.jboss.as.quickstarts.bean_validation_custom_constraint.MyPersonTest
Tests run: 5, Failures: 4, Errors: 0, Skipped: 0, Time elapsed: 3.231 sec <<< FAILURE!

Results :

Failed tests: testAddressViolation(org.jboss.as.quickstarts.bean_validation_custom_constraint.MyPersonTest): Address Field was invalid expected:<Address Fields must not be null/empty and obey character limit constraints> but was:
testRegisterEmptyPerson(org.jboss.as.quickstarts.bean_validation_custom_constraint.MyPersonTest): Three violations were found expected:<Name and Address fields must not be null/empty> but was:
testFirstNameSizeViolation(org.jboss.as.quickstarts.bean_validation_custom_constraint.MyPersonTest): First Name was invalid expected:<size must be between 4 and 2147483647> but was:<3>
testFirstNameNullViolation(org.jboss.as.quickstarts.bean_validation_custom_constraint.MyPersonTest): First Name was invalid expected: but was:

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

Contributor

sgilda commented Apr 11, 2014

I also noticed a few minor things in the README, but I can take care of them when everything else is complete.

Can you also squash the commits after you've made the fixes? Thanks!

Contributor

girirajsharma commented Apr 11, 2014

@sgilda The above logs actually indicate test failures in cases where either Person or Address entity beans are not set as per custom constraints. I will modify MyPersonTest.java by setting entity beans in such a way so that it doesn't gives any test failures and results in successful build.

@girirajsharma girirajsharma Set valid values for Person and Address entity beans as per custom
constraints so that mvn clean install results in a successful build.

Signed-off-by: girirajSharma <giriraj.sharma27@gmail.com>
9e16cae
Contributor

sgilda commented May 29, 2014

Closing this pull. @girirajsharma will issue a new pull.

@sgilda sgilda closed this May 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment