diff options
Diffstat (limited to 'sandbox/old/contrib/persistence/openjpa/src')
10 files changed, 597 insertions, 0 deletions
diff --git a/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/Constants.java b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/Constants.java new file mode 100644 index 0000000000..820f57bcad --- /dev/null +++ b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/Constants.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.service.openjpa; + +/** + * Constants used by the JPA extension + * + * @version $Rev$ $Date$ + */ +public final class Constants { + + public static final String PERSISTENCE_UNIT = "persistenceUnit"; + public static final String CONFIG_PROPERTIES = "configProperties"; + + private Constants() { + } + + +} diff --git a/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerFactoryImplementation.java b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerFactoryImplementation.java new file mode 100644 index 0000000000..d818f145bd --- /dev/null +++ b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerFactoryImplementation.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.service.openjpa; + +import org.apache.tuscany.spi.model.AtomicImplementation; +import org.apache.tuscany.spi.model.ComponentType; + +/** + * Represents the implementation type of a system service that manages JPA + * <code>EntityManagerFactoryImplementation</code> implementations + * + * @version $Rev$ $Date$ + */ +public class EntityManagerFactoryImplementation extends AtomicImplementation<ComponentType> { + + public EntityManagerFactoryImplementation() { + } + + public EntityManagerFactoryImplementation(ComponentType componentType) { + super(componentType); + } +} diff --git a/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerFactoryNotConfiguredException.java b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerFactoryNotConfiguredException.java new file mode 100644 index 0000000000..34e69b8951 --- /dev/null +++ b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerFactoryNotConfiguredException.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.service.openjpa; + +import org.apache.tuscany.spi.implementation.java.ProcessingException; + +/** + * @version $Rev$ $Date$ + */ +public class EntityManagerFactoryNotConfiguredException extends ProcessingException { + + public EntityManagerFactoryNotConfiguredException() { + super("Entity manager factory not configured"); + } +} diff --git a/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerObjectFactory.java b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerObjectFactory.java new file mode 100644 index 0000000000..45d4e1a077 --- /dev/null +++ b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerObjectFactory.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.service.openjpa; + +import java.util.Map; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +import org.apache.tuscany.spi.ObjectCreationException; +import org.apache.tuscany.spi.ObjectFactory; + +/** + * Creates a JPA <code>EntityManager</code> to be injected on a component implementation instance. + * + * @version $Rev$ $Date$ + */ +public class EntityManagerObjectFactory implements ObjectFactory<EntityManager> { + + private EntityManagerFactory emf; + private Map props; + + public EntityManagerObjectFactory(EntityManagerFactory emf) { + this.emf = emf; + } + + public EntityManagerObjectFactory(EntityManagerFactory emf, Map props) { + this.emf = emf; + this.props = props; + } + + public EntityManager getInstance() throws ObjectCreationException { + if (props == null) { + return emf.createEntityManager(); + } else { + return emf.createEntityManager(props); + } + } +} diff --git a/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerProcessor.java b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerProcessor.java new file mode 100644 index 0000000000..8046c0a7c0 --- /dev/null +++ b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/EntityManagerProcessor.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.service.openjpa; + +import java.lang.reflect.Member; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceContext; + +import org.apache.tuscany.spi.ObjectFactory; +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.TargetException; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.implementation.java.AbstractPropertyProcessor; +import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService; +import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; +import org.apache.tuscany.spi.implementation.java.ProcessingException; +import org.apache.tuscany.spi.wire.InboundWire; + + +/** + * Evaluates constructors, methods, and fields annotated with {@link PersistenceContext }, creating a mapped property + * that will inject an {@link EntityManager} on an implementation instance. + * + * @version $Rev$ $Date$ + */ +public class EntityManagerProcessor extends AbstractPropertyProcessor<PersistenceContext> { + + public EntityManagerProcessor(@Autowire ImplementationProcessorService service) { + super(PersistenceContext.class, service); + } + + protected String getName(PersistenceContext annotation) { + String name = annotation.unitName(); + if (name == null) { + return "_defaultJPAPersistenceUnit"; + } + return name; + } + + protected <T> JavaMappedProperty<T> createProperty(String name, + Class<T> javaType, + Member member) throws ProcessingException { + if (!EntityManager.class.equals(javaType)) { + throw new InvalidInjectionSite("Injection site must by of type " + EntityManager.class.getName(), name); + } + return super.createProperty(name, javaType, member); + } + + @SuppressWarnings("unchecked") + protected <T> void initProperty(JavaMappedProperty<T> property, + PersistenceContext annotation, + CompositeComponent parent, + DeploymentContext context) throws ProcessingException { + EntityManagerFactory emf; + try { + InboundWire wire = parent.resolveSystemAutowire(EntityManagerFactory.class); + if (wire == null) { + throw new EntityManagerFactoryNotConfiguredException(); + } + Object o = wire.getTargetService(); + assert o instanceof EntityManagerFactory; + emf = (EntityManagerFactory) o; + } catch (TargetException e) { + throw new ProcessingException(e); + } + ObjectFactory factory = new EntityManagerObjectFactory(emf); + property.setDefaultValueFactory(factory); + } + +} diff --git a/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/InvalidInjectionSite.java b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/InvalidInjectionSite.java new file mode 100644 index 0000000000..0ac5e9ffa1 --- /dev/null +++ b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/InvalidInjectionSite.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.service.openjpa; + +import org.apache.tuscany.spi.implementation.java.ProcessingException; + +/** + * @version $Rev$ $Date$ + */ +public class InvalidInjectionSite extends ProcessingException { + + public InvalidInjectionSite(String message) { + super(message); + } + + public InvalidInjectionSite(String message, String identifier) { + super(message, identifier); + } +} diff --git a/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/JPAAtomicComponent.java b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/JPAAtomicComponent.java new file mode 100644 index 0000000000..df74625b49 --- /dev/null +++ b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/JPAAtomicComponent.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.service.openjpa; + +import java.util.Map; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import org.apache.tuscany.spi.ObjectCreationException; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.component.TargetResolutionException; +import org.apache.tuscany.spi.extension.SystemAtomicComponentExtension; + +/** + * A system service that manages a JPA <code>EntityManagerFactory</code>. This service is used by {@link + * EntityManagerProcessor} to inject an <code>EntityManager<code> on a constructor parameter, field, or method of an + * implementation instance. Since a JPA persistence context is specific to an application, this system service is scoped + * to the application composite. That is, it is contained as a system child of the application composite. + * + * @version $Rev$ $Date$ + */ +public class JPAAtomicComponent extends SystemAtomicComponentExtension { + private EntityManagerFactory factory; + private String persistenceUnit; + private Map<Object, Object> configProps; + + public JPAAtomicComponent(String name, + CompositeComponent parent, + ScopeContainer scopeContainer, + String persistenceUnit, + Map<Object, Object> configProps, + int initLevel) { + super(name, parent, initLevel); + assert persistenceUnit != null; + this.persistenceUnit = persistenceUnit; + this.configProps = configProps; + } + + public Object createInstance() throws ObjectCreationException { + if (configProps != null) { + factory = Persistence.createEntityManagerFactory(persistenceUnit, configProps); + } else { + factory = Persistence.createEntityManagerFactory(persistenceUnit); + } + return factory; + } + + public Object getTargetInstance() throws TargetResolutionException { + return factory; + } + + +} diff --git a/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/JPAComponentBuilder.java b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/JPAComponentBuilder.java new file mode 100644 index 0000000000..d979b93ca2 --- /dev/null +++ b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/JPAComponentBuilder.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.service.openjpa; + +import org.apache.tuscany.spi.builder.BuilderConfigException; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.ComponentBuilderExtension; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.ComponentType; +import org.apache.tuscany.spi.model.Property; + +import static org.apache.tuscany.service.openjpa.Constants.PERSISTENCE_UNIT; + +/** + * @version $Rev$ $Date$ + */ +public class JPAComponentBuilder extends ComponentBuilderExtension { + protected Class getImplementationType() { + return null; + } + + public Component build(CompositeComponent parent, ComponentDefinition definition, DeploymentContext ctx) + throws BuilderConfigException { +// String name = definition.getName(); +// ScopeContainer moduleScope = ctx.getCompositeScope(); +// Integer initLevel = definition.getInitLevel(); + ComponentType<?, ?, ?> type = definition.getImplementation().getComponentType(); + Property<?> persistenceUnit = type.getProperties().get(PERSISTENCE_UNIT); + if (persistenceUnit == null) { + throw new BuilderConfigException("Persistence Unit not specified in JPA import in composite", + parent.getName()); + } +// Property<?> configProps = type.getProperties().get(PERSISTENCE_UNIT); + return null; +// return new JPAAtomicComponent(name, parent, moduleScope, initLevel); + } +} diff --git a/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/JPAImportLoader.java b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/JPAImportLoader.java new file mode 100644 index 0000000000..94508e5408 --- /dev/null +++ b/sandbox/old/contrib/persistence/openjpa/src/main/java/org/apache/tuscany/service/openjpa/JPAImportLoader.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.service.openjpa; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import static org.osoa.sca.Version.XML_NAMESPACE_1_0; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.model.ModelObject; + +/** + * @version $Rev$ $Date$ + */ +public class JPAImportLoader extends LoaderExtension { + private static final QName IMPORT = new QName(XML_NAMESPACE_1_0, "import.jpa"); + + public JPAImportLoader(@Autowire LoaderRegistry registry) { + super(registry); + } + + public QName getXMLType() { + return IMPORT; + } + + public ModelObject load(CompositeComponent parent, ModelObject object, XMLStreamReader reader, + DeploymentContext deploymentContext) + throws XMLStreamException, LoaderException { + //ComponentDefinition definition = new ComponentDefinition() + // TODO read in persisitence unit setting and properties, and set them as properties on the component + return null; + } +} diff --git a/sandbox/old/contrib/persistence/openjpa/src/test/java/org/apache/tuscany/service/openjpa/EntityManagerProcessorTestCase.java b/sandbox/old/contrib/persistence/openjpa/src/test/java/org/apache/tuscany/service/openjpa/EntityManagerProcessorTestCase.java new file mode 100644 index 0000000000..a32c850e32 --- /dev/null +++ b/sandbox/old/contrib/persistence/openjpa/src/test/java/org/apache/tuscany/service/openjpa/EntityManagerProcessorTestCase.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tuscany.service.openjpa; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceContext; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.implementation.java.ImplementationProcessor; +import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService; +import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; +import org.apache.tuscany.spi.implementation.java.JavaMappedReference; +import org.apache.tuscany.spi.implementation.java.JavaMappedService; +import org.apache.tuscany.spi.implementation.java.PojoComponentType; +import org.apache.tuscany.spi.wire.InboundWire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev$ $Date$ + */ +public class EntityManagerProcessorTestCase extends TestCase { + + private ImplementationProcessor processor; + private CompositeComponent parent; + + public void testVisitMethod() throws Exception { + Method method = Foo.class.getMethod("setBar", EntityManager.class); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + processor.visitMethod(parent, method, type, null); + JavaMappedProperty<?> prop = type.getProperties().get("bar"); + assertEquals(EntityManagerObjectFactory.class, prop.getDefaultValueFactory().getClass()); + } + + public void testVisitBadMethod() throws Exception { + Method method = Foo.class.getMethod("setBadBar", String.class); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + try { + processor.visitMethod(parent, method, type, null); + fail(); + } catch (InvalidInjectionSite e) { + // expected + } + } + + public void testVisitField() throws Exception { + Field field = Foo.class.getDeclaredField("bar"); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + processor.visitField(parent, field, type, null); + JavaMappedProperty<?> prop = type.getProperties().get("bar"); + assertEquals(EntityManagerObjectFactory.class, prop.getDefaultValueFactory().getClass()); + } + + public void testBadVisitField() throws Exception { + Field field = Foo.class.getDeclaredField("badField"); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + try { + processor.visitField(null, field, type, null); + fail(); + } catch (InvalidInjectionSite e) { + // expected + } + } + + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class); + EasyMock.replay(emf); + + InboundWire wire = EasyMock.createMock(InboundWire.class); + EasyMock.expect(wire.getTargetService()).andReturn(emf); + EasyMock.replay(wire); + + parent = EasyMock.createMock(CompositeComponent.class); + EasyMock.expect(parent.resolveSystemAutowire(EntityManagerFactory.class)).andReturn(wire).atLeastOnce(); + EasyMock.replay(parent); + ImplementationProcessorService service = EasyMock.createMock(ImplementationProcessorService.class); + service.addName(EasyMock.isA(List.class), EasyMock.eq(0), EasyMock.isA(String.class)); + EasyMock.expectLastCall().andStubAnswer(new IAnswer() { + @SuppressWarnings({"unchecked"}) + public Object answer() throws Throwable { + ((List<Object>) EasyMock.getCurrentArguments()[0]).add(EasyMock.getCurrentArguments()[2]); + return null; + } + }); + EasyMock.replay(service); + processor = new EntityManagerProcessor(service); + } + + private static class Foo { + + + @PersistenceContext + protected EntityManager bar; + + @PersistenceContext + protected String badField; + + @PersistenceContext + public void setBar(EntityManager d) { + } + + @PersistenceContext + public void setBadBar(String d) { + } + + } +} |