From 28a565faec2448b5b44bc8e1f7d480e7ed81fdcb Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 17 Jan 2013 16:08:00 +0100 Subject: [PATCH] DATAJPA-286 - Added test infrastructure for plain JPA tests. Added integration tests in org.springframework.data.jpa.infrastructure that will not be included in the normal test execution as they are purely means to quickly identify potential differences in persistence provider implementations. --- pom.xml | 14 ++++ .../EclipseLinkMetamodelIntegrationTests.java | 28 ++++++++ .../MetamodelIntegrationTests.java | 69 +++++++++++++++++++ .../OpenJpaMetamodelIntegrationTests.java | 28 ++++++++ 4 files changed, 139 insertions(+) create mode 100644 src/test/java/org/springframework/data/jpa/infrastructure/EclipseLinkMetamodelIntegrationTests.java create mode 100644 src/test/java/org/springframework/data/jpa/infrastructure/MetamodelIntegrationTests.java create mode 100644 src/test/java/org/springframework/data/jpa/infrastructure/OpenJpaMetamodelIntegrationTests.java diff --git a/pom.xml b/pom.xml index 0e8f4a0ca..7859f8e8e 100644 --- a/pom.xml +++ b/pom.xml @@ -307,6 +307,20 @@ + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*Tests.java + + + **/infrastructure/*.java + + + + org.apache.maven.plugins maven-assembly-plugin diff --git a/src/test/java/org/springframework/data/jpa/infrastructure/EclipseLinkMetamodelIntegrationTests.java b/src/test/java/org/springframework/data/jpa/infrastructure/EclipseLinkMetamodelIntegrationTests.java new file mode 100644 index 000000000..a1aabf9da --- /dev/null +++ b/src/test/java/org/springframework/data/jpa/infrastructure/EclipseLinkMetamodelIntegrationTests.java @@ -0,0 +1,28 @@ +/* + * Copyright 2013 the original author or authors. + * + * 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.springframework.data.jpa.infrastructure; + +import org.springframework.test.context.ContextConfiguration; + +/** + * Metamodel tests using OpenJPA. + * + * @author Oliver Gierke + */ +@ContextConfiguration("classpath:eclipselink.xml") +public class EclipseLinkMetamodelIntegrationTests extends MetamodelIntegrationTests { + +} diff --git a/src/test/java/org/springframework/data/jpa/infrastructure/MetamodelIntegrationTests.java b/src/test/java/org/springframework/data/jpa/infrastructure/MetamodelIntegrationTests.java new file mode 100644 index 000000000..cb84f39da --- /dev/null +++ b/src/test/java/org/springframework/data/jpa/infrastructure/MetamodelIntegrationTests.java @@ -0,0 +1,69 @@ +/* + * Copyright 2013 the original author or authors. + * + * 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.springframework.data.jpa.infrastructure; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Path; +import javax.persistence.criteria.Root; +import javax.persistence.metamodel.Attribute; +import javax.persistence.metamodel.Bindable.BindableType; +import javax.persistence.metamodel.ManagedType; +import javax.persistence.metamodel.Metamodel; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.data.jpa.domain.sample.User; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Oliver Gierke + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration({ "classpath:infrastructure.xml" }) +public class MetamodelIntegrationTests { + + @PersistenceContext + EntityManager em; + + @Test + public void considersOneToOneAttributeAnAssociation() { + + Metamodel metamodel = em.getMetamodel(); + ManagedType type = metamodel.managedType(User.class); + + Attribute attribute = type.getSingularAttribute("manager"); + assertThat(attribute.isAssociation(), is(true)); + } + + @Test + public void pathToEntityIsOfBindableTypeEntityType() { + + CriteriaBuilder builder = em.getCriteriaBuilder(); + CriteriaQuery query = builder.createQuery(User.class); + + Root root = query.from(User.class); + Path path = root.get("manager"); + + assertThat(path.getModel().getBindableType(), is(BindableType.ENTITY_TYPE)); + } +} diff --git a/src/test/java/org/springframework/data/jpa/infrastructure/OpenJpaMetamodelIntegrationTests.java b/src/test/java/org/springframework/data/jpa/infrastructure/OpenJpaMetamodelIntegrationTests.java new file mode 100644 index 000000000..f84df8b11 --- /dev/null +++ b/src/test/java/org/springframework/data/jpa/infrastructure/OpenJpaMetamodelIntegrationTests.java @@ -0,0 +1,28 @@ +/* + * Copyright 2013 the original author or authors. + * + * 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.springframework.data.jpa.infrastructure; + +import org.springframework.test.context.ContextConfiguration; + +/** + * Metamodel tests using OpenJPA. + * + * @author Oliver Gierke + */ +@ContextConfiguration("classpath:openjpa.xml") +public class OpenJpaMetamodelIntegrationTests extends MetamodelIntegrationTests { + +}