Skip to content

Commit

Permalink
HV-371: Added tests for existing PropertyDescriptor functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarmorling committed Mar 4, 2011
1 parent 4dc2c22 commit 290e7a7
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 3 deletions.
@@ -0,0 +1,32 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.validator.test.metadata;

import javax.validation.Valid;


/**
* @author Gunnar Morling
*/
public class ChildWithAtValid extends ParentWithoutAtValid {

@Valid
public Order getOrder() {
return null;
}

}
@@ -0,0 +1,29 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.validator.test.metadata;


/**
* @author Gunnar Morling
*/
public class ChildWithoutAtValid extends ParentWithAtValid {

public Order getOrder() {
return null;
}

}
@@ -0,0 +1,32 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.validator.test.metadata;

import javax.validation.constraints.NotNull;


/**
* @author Gunnar Morling
*/
public class ChildWithoutAtValid2 extends ParentWithoutAtValid {

@NotNull
public Order getOrder() {
return null;
}

}
Expand Up @@ -21,14 +21,17 @@
import javax.validation.metadata.BeanDescriptor;
import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.metadata.ElementDescriptor;
import javax.validation.metadata.PropertyDescriptor;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import org.testng.annotations.Test;

import org.hibernate.validator.test.util.TestUtil;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;


/**
* @author Hardy Ferentschik
Expand Down Expand Up @@ -83,4 +86,41 @@ public void testElementDescriptorImmutable() {
// success
}
}

@Test
public void testAtValidDefinedInHierarchyForPropertyDescriptor() {

PropertyDescriptor propertyDescriptor = TestUtil.getPropertyDescriptor( ChildWithoutAtValid.class, "order" );
assertTrue(
propertyDescriptor.isCascaded(),
"@Valid defined on getter in super type should be reflected by PropertyDescriptor."
);
}

@Test
public void testAtValidDefinedLocallyForPropertyDescriptor() {

PropertyDescriptor propertyDescriptor = TestUtil.getPropertyDescriptor( ChildWithAtValid.class, "order" );
assertTrue(
propertyDescriptor.isCascaded(),
"@Valid defined on local getter in type hierarchy should be reflected by PropertyDescriptor."
);
}

@Test
public void testAtValidNotDefinedForPropertyDescriptor() {

PropertyDescriptor propertyDescriptor = TestUtil.getPropertyDescriptor( ChildWithoutAtValid2.class, "order" );
assertFalse(
propertyDescriptor.isCascaded(),
"@Valid given neither locally nor in hierarchy should be reflected by PropertyDescriptor."
);
}

@Test
public void testGetNameFromPropertyDescriptor() {

PropertyDescriptor propertyDescriptor = TestUtil.getPropertyDescriptor( ChildWithoutAtValid2.class, "order" );
assertEquals( propertyDescriptor.getPropertyName(), "order" );
}
}
@@ -0,0 +1,31 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.validator.test.metadata;

import javax.validation.Valid;

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

@Valid
public Order getOrder() {
return null;
}

}
@@ -0,0 +1,29 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.validator.test.metadata;


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

public Order getOrder() {
return null;
}

}

0 comments on commit 290e7a7

Please sign in to comment.