1 Reply Latest reply on Jun 18, 2013 2:22 PM by rzvikas

    Method parameter validation

    itahir

      Hi All,

       

      how do I call bean validation on method parameters?

       

      For example in sample app I added @NotNull and @Valid annotations to register method parameter,

       

      @Stateless

      public class MemberRegistration {

       

         private EntityManager em;

       

         public void register(@NotNull @Valid Member member) throws Exception {

       

            // continue if member is not null and valid

       

         }

      }

       

       

      @RunWith(Arquillian.class)

      public class MemberRegistrationTest {

        

      @Deployment

         public static Archive<?> createTestArchive() {

            return ShrinkWrap.create(WebArchive.class, "test.war")

                  .addClasses(Member.class, MemberRegistration.class, Resources.class)

                  .addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")

                  .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")

                  // Deploy our test datasource

                  .addAsWebInfResource("test-ds.xml", "test-ds.xml");

         }

       

      @Test(

         public void should_register() throws Exception {    

                memberRegistration.register(null);     

         }

      }

       

       

      I am expecting above test to fail because of  not null constraint violation.  What am I missing here ? Do I need to configure Jboss-as 7.1.1 ? 

       

       

      thanks