Return-Path: X-Original-To: apmail-deltaspike-users-archive@www.apache.org Delivered-To: apmail-deltaspike-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E455418233 for ; Thu, 4 Feb 2016 10:57:39 +0000 (UTC) Received: (qmail 50339 invoked by uid 500); 4 Feb 2016 10:57:39 -0000 Delivered-To: apmail-deltaspike-users-archive@deltaspike.apache.org Received: (qmail 50304 invoked by uid 500); 4 Feb 2016 10:57:39 -0000 Mailing-List: contact users-help@deltaspike.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@deltaspike.apache.org Delivered-To: mailing list users@deltaspike.apache.org Received: (qmail 50292 invoked by uid 99); 4 Feb 2016 10:57:39 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Feb 2016 10:57:39 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id E530FC094E for ; Thu, 4 Feb 2016 10:57:38 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.179 X-Spam-Level: * X-Spam-Status: No, score=1.179 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 6aqQJUlL4s2N for ; Thu, 4 Feb 2016 10:57:36 +0000 (UTC) Received: from mail-oi0-f49.google.com (mail-oi0-f49.google.com [209.85.218.49]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id D063C20546 for ; Thu, 4 Feb 2016 10:57:35 +0000 (UTC) Received: by mail-oi0-f49.google.com with SMTP id j125so12958387oih.0 for ; Thu, 04 Feb 2016 02:57:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Ux7n7t0v8E2kiFBijNasgohZYOM2iJsCUyIDJdsCbik=; b=cbAyzZjrSD0HmBijNr+aWvXaXJhLskMar6hPUGO0xkXZyOniz935xStAnJ8NUeiK4P 1iSBURWpAdcnVgt7c9t5rg64yUyohUKwKyUGvQzBk5hKvDfGTe6LbWIr4vFuwLz1TSxH rfMusSaeU6xREX3/8Lv/6cqxOq2lXrc11ZpZcb5C/i5Bemg60seaxQVu4RTA7LPQoFbw Aa39VQA+1AmfKDhutSfdfOcY4r/yZV4w3iWwRH7Ei3qddEnuM8pLyIFTjp0SeJ5cBS2n 5kCXi9iqwmCo5fa6GoCbr2Rwh/OtwxV8/bBE7tY9xMaSHW5ySSQsAnFwnoQk29sDSJh0 hkxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=Ux7n7t0v8E2kiFBijNasgohZYOM2iJsCUyIDJdsCbik=; b=Rdwl0uAHlgSKVoKj7zONHe/h8LK2Ig4vhCpZ0bF1q4zd26JVH93Pz8gYjgDQubIvw2 mqW57Vfh8uULVpEcbk+dn8q0gVQeFtmwsoJbOoLCoQ/fu/eRoSL1XtDcUrH7pFq6FSRT mObk5Z6a0pN/WS8BZypcjBy+XQtxKHPxpS3nzJKH35aQyGQXemL7npJEJY1y2zyk3O/J SQFuembrwp3bazadR+b9ZKA7mQex2yFgxtyvDEDNtudqtSABV4lACSfFcCHjt17FLnfL 1pMaEW2Hi0MTrka4W+u3oxknkVKfytAb25Knr0vdZ5DRRq/5J1hhtTN4orrNAIVjIBf5 qTww== X-Gm-Message-State: AG10YOSaVpw27X3ZINby8zhqyH5P0ST/FKoyXbPeWr3pzfpZkLiOsDQJTEdglB+8ulZ4F6UP60OfWhUhozlCWg== MIME-Version: 1.0 X-Received: by 10.202.75.13 with SMTP id y13mr2819551oia.116.1454583449434; Thu, 04 Feb 2016 02:57:29 -0800 (PST) Received: by 10.202.204.23 with HTTP; Thu, 4 Feb 2016 02:57:29 -0800 (PST) In-Reply-To: References: Date: Thu, 4 Feb 2016 12:57:29 +0200 Message-ID: Subject: Re: Unit tests with deltaspike, weld and hibernate bean-validation From: alebu To: users@deltaspike.apache.org Content-Type: multipart/alternative; boundary=001a11c17750ccbf3e052aef9992 --001a11c17750ccbf3e052aef9992 Content-Type: text/plain; charset=UTF-8 Thank you Gerhard, Forwarding to hibernate validator AND CDI was a good hint. By replacing 'hibernate-validator' artifact with 'hibernate-validator-cdi' I got validation right where I wanted it. Additionally I removed deltaspike bean-validation and it still works fine. On Thu, Feb 4, 2016 at 12:40 PM, Gerhard Petracek wrote: > hi, > > parameter-validation just works if it's integrated (like with jax-rs). > such an integration is done e.g. via an interceptor. > -> if you can't use an out-of-the-box integration (provided by the > validation-provider you are using), > you have to do it on your own (it isn't the task of the test-control-module > to support it). > e.g. via a cdi-extension you can add an interceptor(-binding-annotation) to > your beans dynamically (and you can even limit that to project-stage > development). > with that you would introduce a significant difference in your test-code. > -> instead of that i would ask the hibernate-validator-team, if they > support parameter-validation in a java-se + cdi based application. > (in that case it would also work with the test-control-module without > changes.) > > regards, > gerhard > > > > 2016-02-04 10:30 GMT+01:00 alebu : > > > Hi all, > > I want to configure unit tests so I could use bean-validation but for > some > > reason my validation constraints are ignored. The idea behind is to > > simulate JEE application server (AS) as max as possible and test business > > logic this way. I defined a very simple case which consist of service > class > > which has a method with some constraints on parameters. And I expect to > get > > a ConstraintViolationException if I call this method with "wrong" > > parameters. However method is executed without any exceptions and it > looks > > like no validation happens. > > Here is my setup in maven but briefly: > > 1) I added hivernate validator because I was getting > > javax.validation.ValidationException with message below otherwise: > > Unable to create a Configuration, because no Bean Validation provider > could > > be found. Add a provider like Hibernate Validator (RI) to your classpath. > > > > 2) Based on docs > > https://deltaspike.apache.org/documentation/configure.html > > I added: > > deltaspike-core-api and deltaspike-core-impl artifacts. > > > > 3) Based on docs > > https://deltaspike.apache.org/documentation/bean-validation.html I > added: > > deltaspike-bean-validation-module-impl > > > > 4) Based on > https://deltaspike.apache.org/documentation/test-control.html > > I > > added > > deltaspike-test-control-module-api > > deltaspike-test-control-module-impl > > and weld realted artifacts: > > deltaspike-cdictrl-weld > > weld-se-core > > > > DETAILS: > > > > > > ... > > 1.5.2 > > 2.3.2.Final > > > > ... > > > > org.hibernate > > hibernate-validator > > 5.2.3.Final > > test > > > > > > > > org.apache.deltaspike.core > > deltaspike-core-api > > ${deltaspike.version} > > test > > > > > > > > org.apache.deltaspike.core > > deltaspike-core-impl > > ${deltaspike.version} > > test > > > > > > > > org.apache.deltaspike.modules > > > deltaspike-bean-validation-module-impl > > ${deltaspike.version} > > test > > > > > > > > org.apache.deltaspike.modules > > deltaspike-test-control-module-api > > ${deltaspike.version} > > test > > > > > > > > org.apache.deltaspike.modules > > deltaspike-test-control-module-impl > > ${deltaspike.version} > > test > > > > > > > > org.apache.deltaspike.cdictrl > > deltaspike-cdictrl-weld > > ${deltaspike.version} > > test > > > > > > > > org.jboss.weld.se > > weld-se-core > > ${weld.version} > > test > > > > > > ----- > > > > JUNIT looks like: > > @RunWith(CdiTestRunner.class) > > public class TestDeltaspike { > > > > @Inject > > DummyService dummyService; > > > > @Test > > public void testValidAnnotationScenario(){ > > assertNotNull(dummyService); > > > > > > > //Validation.byDefaultProvider().configure().constraintValidatorFactory(new > > CDIAwareConstraintValidatorFactory()).buildValidatorFactory(); > > > > dummyService.validateValue(7); > > fail("Expected validation exception"); > > } > > } > > > > where DummyService looks like: > > public class DummyService { > > > > public void validateValue( @Min(10) int value ){ > > System.out.println( "XXX: value "+value+" was validated at this > > point and must be at least 10" ); > > } > > } > > > > ----- > > I also have beans.xml in src/test/resources/META-INF/beans.xml like: > > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee > > http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" > > version="1.2" bean-discovery-mode="all"> > > > > > > and validation.xml in src/test/resources/META-INF/validation.xml > > but from logs it looks like it does nothing. I am making this assumption > > because when I uncommenting the line in my test > > //Validation.byDefaultProvider().configure() ... > > then I see something in logs related to validator configuration, > otherwise > > no validation is mentioned in logs. > > But non of the both helps anyway. > > Test fails on: > > fail("Expected validation exception"); > > > --001a11c17750ccbf3e052aef9992--