HHH-8763 osgi extension point test cases

This commit is contained in:
Brett Meyer 2013-12-04 10:13:23 -05:00
parent 7ee5fa104d
commit c2f115e5c9
5 changed files with 179 additions and 1 deletions

View File

@ -49,6 +49,7 @@ dependencies {
osgiRuntime( libraries.commons_annotations ) { transitive = false }
osgiRuntime( libraries.classmate ) { transitive = false }
osgiRuntime( libraries.logging ) { transitive = false }
// needed for BND
osgiRuntimeBnd( libraries.jandex ) { transitive = false }
osgiRuntimeBnd( "javax.enterprise:cdi-api:1.1" ) { transitive = false }
@ -143,7 +144,18 @@ task testClientBundleJar(type: Jar) {
"Bundle-Activator" : "org.hibernate.osgi.test.client.OsgiTestActivator",
"Bundle-ManifestVersion" : "2",
"Bundle-SymbolicName" : "testClientBundle",
"Import-Package" : "javassist.util.proxy,javax.persistence,javax.persistence.spi,org.h2,org.hibernate,org.hibernate.proxy,org.osgi.framework")
"Import-Package" : "javassist.util.proxy,javax.persistence,javax.persistence.spi,org.h2,org.osgi.framework,"
+ "org.hibernate,"
+ "org.hibernate.boot.registry.selector,"
+ "org.hibernate.boot.registry.selector.spi,"
+ "org.hibernate.cfg,"
+ "org.hibernate.engine.spi,"
+ "org.hibernate.integrator.spi,"
+ "org.hibernate.metamodel.source,"
+ "org.hibernate.metamodel.spi,"
+ "org.hibernate.proxy,"
+ "org.hibernate.service,"
+ "org.hibernate.service.spi")
}
}

View File

@ -29,8 +29,13 @@ import javax.persistence.spi.PersistenceProvider;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.metamodel.spi.TypeContributor;
import org.hibernate.osgi.test.result.OsgiTestResults;
import org.hibernate.osgi.test.result.OsgiTestResultsImpl;
import org.hibernate.service.ServiceRegistry;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@ -45,14 +50,25 @@ public class OsgiTestActivator implements BundleActivator {
private OsgiTestResults testResult = new OsgiTestResultsImpl();
private TestIntegrator integrator = new TestIntegrator();
private TestStrategyRegistrationProvider strategyRegistrationProvider = new TestStrategyRegistrationProvider();
private TestTypeContributor typeContributor = new TestTypeContributor();
@Override
public void start(BundleContext context) throws Exception {
// register the test result service
context.registerService( OsgiTestResults.class, testResult, new Hashtable() );
// register example extension point services
context.registerService( Integrator.class, integrator, new Hashtable() );
context.registerService( StrategyRegistrationProvider.class, strategyRegistrationProvider, new Hashtable() );
context.registerService( TypeContributor.class, typeContributor, new Hashtable() );
testUnmanagedJpa( context );
testUnmanagedNative( context );
testLazyLoading( context );
testExtensionPoints( context );
}
@Override
@ -189,4 +205,27 @@ public class OsgiTestActivator implements BundleActivator {
}
}
private void testExtensionPoints(BundleContext context) {
try {
final ServiceReference serviceReference = context.getServiceReference( SessionFactory.class.getName() );
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) context.getService(
serviceReference );
final ServiceRegistry serviceRegistry = sessionFactory.getServiceRegistry();
// test extension points in the client bundle
if (!integrator.passed) {
testResult.addFailure( "Could not discover " + integrator.getClass() );
}
if (!strategyRegistrationProvider.passed) {
testResult.addFailure( "Could not discover " + strategyRegistrationProvider.getClass() );
}
if (!typeContributor.passed) {
testResult.addFailure( "Could not discover " + typeContributor.getClass() );
}
}
catch ( Exception e ) {
testResult.addFailure( "Exception: " + e.getMessage(), e );
}
}
}

View File

@ -0,0 +1,49 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.osgi.test.client;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
/**
* @author Brett Meyer
*/
public class TestIntegrator implements Integrator {
public boolean passed = false;
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
passed = true;
}
public void integrate(MetadataImplementor metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
passed = true;
}
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
passed = true;
}
}

View File

@ -0,0 +1,39 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.osgi.test.client;
import java.util.Collections;
import org.hibernate.boot.registry.selector.StrategyRegistration;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
/**
* @author Brett Meyer
*/
public class TestStrategyRegistrationProvider implements StrategyRegistrationProvider {
public boolean passed = false;
public Iterable<StrategyRegistration> getStrategyRegistrations() {
passed = true;
return Collections.EMPTY_LIST;
}
}

View File

@ -0,0 +1,39 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.osgi.test.client;
import org.hibernate.metamodel.spi.TypeContributions;
import org.hibernate.metamodel.spi.TypeContributor;
import org.hibernate.service.ServiceRegistry;
/**
* @author Brett Meyer
*/
public class TestTypeContributor implements TypeContributor {
public boolean passed = false;
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
passed = true;
}
}