//INSTALL the bundle
Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.INSTALLED);
Object o = mgr.addingBundle(persistenceBundle, new BundleEvent(BundleEvent.INSTALLED, persistenceBundle));
//Check the persistence.xml was looked for
Skeleton.getSkeleton(persistenceBundle).assertCalled(new MethodCall(Bundle.class, "getEntry", "META-INF/persistence.xml"));
//Check we didn't use getResource()
Skeleton.getSkeleton(persistenceBundle).assertNotCalled(new MethodCall(Bundle.class, "getResource", String.class));
//Check we didn't get the Provider, register a service or create an EMF
Skeleton.getSkeleton(extenderContext).assertNotCalled(new MethodCall(BundleContext.class, "getService", ServiceReference.class));
Skeleton.getSkeleton(persistenceBundleContext).assertNotCalled(new MethodCall(BundleContext.class, "registerService", EntityManagerFactory.class.getName(), EntityManagerFactory.class, Dictionary.class));
Skeleton.getSkeleton(pp).assertNotCalled(new MethodCall(PersistenceProvider.class, "createContainerEntityManagerFactory", PersistenceUnitInfo.class, Map.class));
BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
//Now try Resolving
Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.RESOLVED);
mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.RESOLVED, persistenceBundle), o);
testSuccessfulCreationEvent(ref, extenderContext, 1);
BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
//Now try starting (This should not create again, so check we only called 1 time)
Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.STARTING);
mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.STARTING, persistenceBundle), o);
testSuccessfulCreationEvent(ref, extenderContext, 1);
testSuccessfulRegistrationEvent(ref, extenderContext, 1);
//Now try active (This should not create again, so check we only called 1 time)
Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.ACTIVE);
mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.STARTED, persistenceBundle), o);
testSuccessfulCreationEvent(ref, extenderContext, 1);
testSuccessfulRegistrationEvent(ref, extenderContext, 1);
//Now stop the bundle, check no extra calls, and the EMFs are still open
Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.STOPPING);
mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.STOPPING, persistenceBundle), o);
testSuccessfulCreationEvent(ref, extenderContext, 1);
BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
Skeleton.getSkeleton(pp).assertNotCalled(new MethodCall(EntityManagerFactory.class, "close"));
//Now Mark the bundle stopped, check no extra calls, and the EMFs are still open
Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.RESOLVED);
mgr.modifiedBundle(persistenceBundle, new BundleEvent(BundleEvent.STOPPING, persistenceBundle), o);
testSuccessfulCreationEvent(ref, extenderContext, 1);
BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
Skeleton.getSkeleton(pp).assertNotCalled(new MethodCall(EntityManagerFactory.class, "close"));
//Now Uninstall, check no extra calls, and the EMFs are closed
Skeleton.getSkeleton(persistenceBundle).setReturnValue(new MethodCall(Bundle.class, "getState"), Bundle.UNINSTALLED);
mgr.removedBundle(persistenceBundle, new BundleEvent(BundleEvent.UNINSTALLED, persistenceBundle), o);
testSuccessfulCreationEvent(ref, extenderContext, 1);
BundleContextMock.assertNoServiceExists(EntityManagerFactory.class.getName());
Skeleton.getSkeleton(pp).assertCalled(new MethodCall(EntityManagerFactory.class, "close"));
}