View Javadoc

1   package org.starobjects.tested.fitnesse.internal.helpers;
2   
3   import org.nakedobjects.metamodel.config.ConfigurationBuilder;
4   import org.nakedobjects.runtime.context.NakedObjectsContext;
5   import org.nakedobjects.runtime.fixturesinstaller.FixturesInstallerNoop;
6   import org.nakedobjects.runtime.installers.InstallerLookupDefault;
7   import org.nakedobjects.runtime.system.DeploymentType;
8   import org.nakedobjects.runtime.system.NakedObjectsSystem;
9   import org.nakedobjects.runtime.system.NakedObjectsSystemBootstrapper;
10  import org.nakedobjects.runtime.system.SystemConstants;
11  import org.nakedobjects.runtime.system.internal.InitialisationSession;
12  import org.nakedobjects.runtime.userprofile.inmemory.InMemoryUserProfileStoreInstaller;
13  import org.starobjects.tested.fitnesse.StoryFixture;
14  import org.starobjects.tested.fitnesse.internal.components.FitnesseAuthenticationManagerInstaller;
15  import org.starobjects.tested.fitnesse.internal.components.FitnesseConfigurationBuilder;
16  import org.starobjects.tested.fitnesse.internal.components.FitnesseInMemoryPersistenceMechanismInstaller;
17  
18  public class InitNakedObjects {
19  
20      private final StoryFixture storyFixture;
21  
22      public InitNakedObjects(final StoryFixture storyFixture) {
23          this.storyFixture = storyFixture;
24      }
25  
26      public void initialize() {
27          final ConfigurationBuilder configurationBuilder = new FitnesseConfigurationBuilder(
28                  storyFixture.getConfigDirectory());
29          final DeploymentType deploymentType = storyFixture.getDeploymentType();
30  
31          configurationBuilder.add(SystemConstants.AUTHENTICATION_INSTALLER_KEY,
32                  FitnesseAuthenticationManagerInstaller.class.getName());
33          configurationBuilder.add(
34                  SystemConstants.OBJECT_PERSISTOR_INSTALLER_KEY,
35                  FitnesseInMemoryPersistenceMechanismInstaller.class.getName());
36          configurationBuilder.add(
37                  SystemConstants.PROFILE_PERSISTOR_INSTALLER_KEY,
38                  InMemoryUserProfileStoreInstaller.class.getName());
39          configurationBuilder.add(SystemConstants.FIXTURES_INSTALLER_KEY,
40                  FixturesInstallerNoop.class.getName());
41          configurationBuilder.add(SystemConstants.NOSPLASH_KEY, "" + true);
42  
43          NakedObjectsSystem system = null;
44          try {
45  
46              final InstallerLookupDefault installerLookup = new InstallerLookupDefault(
47                      getClass());
48              configurationBuilder.injectInto(installerLookup);
49  
50              system = new NakedObjectsSystemBootstrapper(installerLookup)
51                      .bootSystem(deploymentType);
52  
53              storyFixture.setInstallerLookup(installerLookup);
54              storyFixture.setNakedObjectsSystem(system);
55  
56              // provide a session for FitNesse fixtures
57              NakedObjectsContext.openSession(new InitialisationSession());
58  
59          } catch (final RuntimeException e) {
60              if (system != null) {
61                  system.shutdown();
62              }
63              throw e;
64          }
65      }
66  
67  }