Skip to content

Commit

Permalink
BVTCK-48 Adding tests for overriding methods with @ValidateOnExecution
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarmorling committed Mar 18, 2013
1 parent 01e41fd commit 1988aba
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 1 deletion.
@@ -0,0 +1,35 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.
*/
package org.hibernate.beanvalidation.tck.tests.integration.cdi.executable;

import javax.validation.constraints.NotNull;
import javax.validation.executable.ExecutableType;
import javax.validation.executable.ValidateOnExecution;

/**
* @author Gunnar Morling
*/
public interface AnotherShipmentService1stInHierarchy extends AnotherShipmentService2stInHierarchy {

// The @ValidateOnExecution annotations here are expected to be ignored
// since the methods override super-type methods

@Override
@NotNull
@ValidateOnExecution(type = ExecutableType.NONE)
public Shipment getShipment();
}
@@ -0,0 +1,32 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.
*/
package org.hibernate.beanvalidation.tck.tests.integration.cdi.executable;

import javax.validation.executable.ExecutableType;
import javax.validation.executable.ValidateOnExecution;

/**
* @author Gunnar Morling
*/
@ValidateOnExecution(type = ExecutableType.IMPLICIT)
public class AnotherShipmentService1stInHierarchyImpl implements AnotherShipmentService1stInHierarchy {

@Override
public Shipment getShipment() {
return null;
}
}
@@ -0,0 +1,31 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.
*/
package org.hibernate.beanvalidation.tck.tests.integration.cdi.executable;

import javax.validation.constraints.NotNull;
import javax.validation.executable.ExecutableType;
import javax.validation.executable.ValidateOnExecution;

/**
* @author Gunnar Morling
*/
public interface AnotherShipmentService2stInHierarchy {

@NotNull
@ValidateOnExecution(type = ExecutableType.ALL)
public Shipment getShipment();
}
Expand Up @@ -33,6 +33,7 @@
import org.jboss.test.audit.annotations.SpecVersion;
import org.testng.annotations.Test;

import org.hibernate.beanvalidation.tck.util.Groups;
import org.hibernate.beanvalidation.tck.util.IntegrationTest;
import org.hibernate.beanvalidation.tck.util.shrinkwrap.WebArchiveBuilder;

Expand Down Expand Up @@ -79,6 +80,15 @@ public class ExecutableValidationTest extends Arquillian {
@Inject
private OrderService orderService;

@Inject
private ShipmentService shipmentService;

@Inject
private ShipmentServiceSubClass shipmentServiceSubClass;

@Inject
private AnotherShipmentService2stInHierarchy anotherShipmentService;

@Deployment
public static WebArchive createTestArchive() {
return new WebArchiveBuilder()
Expand Down Expand Up @@ -128,7 +138,8 @@ public void testReturnValueValidationOfConstrainedMethod() {
}
}

@Test
//TODO Fails due to HV-770
@Test(groups = Groups.FAILING_IN_RI)
@SpecAssertions({
@SpecAssertion(section = "10.1.2", id = "a"),
@SpecAssertion(section = "10.1.2", id = "b"),
Expand Down Expand Up @@ -334,4 +345,93 @@ public void testConstructorValidationInvokesParameterAndReturnValueValidationUsi

assertEquals( AnotherBookingService.getInvocationCount(), 2 );
}

@Test
@SpecAssertion(section = "10.1.2", id = "h")
public void testExecutableValidationUsesDefaultSettingSinceValidatedMethodImplementsAnInterfaceMethod() {
try {
shipmentService.findShipment( null );
fail( "Method invocation should have caused a ConstraintViolationException" );
}
catch ( ConstraintViolationException e ) {
assertCorrectConstraintTypes( e.getConstraintViolations(), NotNull.class );
}
}

@Test
@SpecAssertion(section = "10.1.2", id = "h")
public void testExecutableValidationUsesSettingFromSuperTypeMethodIfValidatedMethodImplementsAnInterfaceMethod() {
try {
shipmentService.getShipment();
fail( "Method invocation should have caused a ConstraintViolationException" );
}
catch ( ConstraintViolationException e ) {
assertCorrectConstraintTypes( e.getConstraintViolations(), NotNull.class );
}
}

@Test
@SpecAssertion(section = "10.1.2", id = "h")
public void testExecutableValidationUsesSettingFromSuperTypeIfValidatedMethodImplementsAnInterfaceMethod() {
try {
shipmentService.getAnotherShipment();
fail( "Method invocation should have caused a ConstraintViolationException" );
}
catch ( ConstraintViolationException e ) {
assertCorrectConstraintTypes( e.getConstraintViolations(), NotNull.class );
}
}

//TODO Fails due to HV-771
@Test(groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "10.1.2", id = "h")
public void testExecutableValidationUsesDefaultSettingIfValidatedMethodOverridesASuperTypeMethod() {
try {
shipmentServiceSubClass.findShipment( null );
fail( "Method invocation should have caused a ConstraintViolationException" );
}
catch ( ConstraintViolationException e ) {
assertCorrectConstraintTypes( e.getConstraintViolations(), NotNull.class );
}
}

//TODO Fails due to HV-771
@Test(groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "10.1.2", id = "h")
public void testExecutableValidationUsesSettingFromSuperTypeMethodIfValidatedMethodOverridesASuperTypeMethod() {
try {
shipmentServiceSubClass.getShipment();
fail( "Method invocation should have caused a ConstraintViolationException" );
}
catch ( ConstraintViolationException e ) {
assertCorrectConstraintTypes( e.getConstraintViolations(), NotNull.class );
}
}

//TODO Fails due to HV-771
@Test(groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "10.1.2", id = "h")
public void testExecutableValidationUsesSettingFromSuperTypeIfValidatedMethodOverridesASuperTypeMethod() {
try {
shipmentServiceSubClass.getAnotherShipment();
fail( "Method invocation should have caused a ConstraintViolationException" );
}
catch ( ConstraintViolationException e ) {
assertCorrectConstraintTypes( e.getConstraintViolations(), NotNull.class );
}
}

//TODO Fails due to HV-772
@Test(groups = Groups.FAILING_IN_RI)
@SpecAssertion(section = "10.1.2", id = "h")
public void testExecutableValidationUsesSettingFromHighestMethodInHierarchyIfValidatedMethodImplementsAnInterfaceMethod()
throws Exception {
try {
anotherShipmentService.getShipment();
fail( "Method invocation should have caused a ConstraintViolationException" );
}
catch ( ConstraintViolationException e ) {
assertCorrectConstraintTypes( e.getConstraintViolations(), NotNull.class );
}
}
}
@@ -0,0 +1,32 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.
*/
package org.hibernate.beanvalidation.tck.tests.integration.cdi.executable;

import javax.validation.constraints.NotNull;

/**
* @author Gunnar Morling
*/
public class Shipment {

@NotNull
private String name;

public String getName() {
return name;
}
}
@@ -0,0 +1,42 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.
*/
package org.hibernate.beanvalidation.tck.tests.integration.cdi.executable;

import javax.validation.constraints.NotNull;
import javax.validation.executable.ExecutableType;
import javax.validation.executable.ValidateOnExecution;

/**
* @author Gunnar Morling
*/
@ValidateOnExecution(type = ExecutableType.ALL)
public class ShipmentBase {

public void findShipment(@NotNull String id) {
}

@ValidateOnExecution(type = ExecutableType.GETTER_METHODS)
@NotNull
public Shipment getShipment() {
return null;
}

@NotNull
public Shipment getAnotherShipment() {
return null;
}
}
@@ -0,0 +1,37 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.
*/
package org.hibernate.beanvalidation.tck.tests.integration.cdi.executable;

import javax.validation.constraints.NotNull;
import javax.validation.executable.ExecutableType;
import javax.validation.executable.ValidateOnExecution;

/**
* @author Gunnar Morling
*/
@ValidateOnExecution(type = ExecutableType.ALL)
public interface ShipmentService {

public void findShipment(@NotNull String id);

@ValidateOnExecution(type = ExecutableType.GETTER_METHODS)
@NotNull
public Shipment getShipment();

@NotNull
public Shipment getAnotherShipment();
}
@@ -0,0 +1,47 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.
*/
package org.hibernate.beanvalidation.tck.tests.integration.cdi.executable;

import javax.validation.constraints.NotNull;
import javax.validation.executable.ExecutableType;
import javax.validation.executable.ValidateOnExecution;

/**
* @author Gunnar Morling
*/
public class ShipmentServiceImpl implements ShipmentService {

// The @ValidateOnExecution annotations here are expected to be ignored
// since the methods override super-type methods

@ValidateOnExecution(type = ExecutableType.NONE)
@Override
public void findShipment(@NotNull String id) {
}

@ValidateOnExecution(type = ExecutableType.NONE)
@Override
public Shipment getShipment() {
return null;
}

@ValidateOnExecution(type = ExecutableType.NONE)
@Override
public Shipment getAnotherShipment() {
return null;
}
}

0 comments on commit 1988aba

Please sign in to comment.