Browse Source

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.
pull/19/merge
Oliver Gierke 13 years ago
parent
commit
28a565faec
  1. 14
      pom.xml
  2. 28
      src/test/java/org/springframework/data/jpa/infrastructure/EclipseLinkMetamodelIntegrationTests.java
  3. 69
      src/test/java/org/springframework/data/jpa/infrastructure/MetamodelIntegrationTests.java
  4. 28
      src/test/java/org/springframework/data/jpa/infrastructure/OpenJpaMetamodelIntegrationTests.java

14
pom.xml

@ -307,6 +307,20 @@ @@ -307,6 +307,20 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
<excludes>
<exclude>**/infrastructure/*.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>

28
src/test/java/org/springframework/data/jpa/infrastructure/EclipseLinkMetamodelIntegrationTests.java

@ -0,0 +1,28 @@ @@ -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 {
}

69
src/test/java/org/springframework/data/jpa/infrastructure/MetamodelIntegrationTests.java

@ -0,0 +1,69 @@ @@ -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<User> type = metamodel.managedType(User.class);
Attribute<? super User, ?> attribute = type.getSingularAttribute("manager");
assertThat(attribute.isAssociation(), is(true));
}
@Test
public void pathToEntityIsOfBindableTypeEntityType() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<User> query = builder.createQuery(User.class);
Root<User> root = query.from(User.class);
Path<Object> path = root.get("manager");
assertThat(path.getModel().getBindableType(), is(BindableType.ENTITY_TYPE));
}
}

28
src/test/java/org/springframework/data/jpa/infrastructure/OpenJpaMetamodelIntegrationTests.java

@ -0,0 +1,28 @@ @@ -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 {
}
Loading…
Cancel
Save