Example #1
0
  /**
   * Creates default configuration of <code>RuntimeManager</code> with given <code>strategy</code>
   * and all <code>resources</code> being added to knowledge base. <br>
   * There should be only one <code>RuntimeManager</code> created during single test.
   *
   * @param strategy - selected strategy of those that are supported
   * @param resources - resources that shall be added to knowledge base
   * @param identifier - identifies the runtime manager
   * @return new instance of RuntimeManager
   */
  protected RuntimeManager createRuntimeManager(
      Strategy strategy, Map<String, ResourceType> resources, String identifier) {
    if (manager != null) {
      throw new IllegalStateException("There is already one RuntimeManager active");
    }

    RuntimeEnvironmentBuilder builder = null;
    if (!setupDataSource) {
      builder =
          RuntimeEnvironmentBuilder.getEmpty()
              .addConfiguration(
                  "drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName())
              .addConfiguration(
                  "drools.processInstanceManagerFactory",
                  DefaultProcessInstanceManagerFactory.class.getName());
    } else if (sessionPersistence) {
      builder = RuntimeEnvironmentBuilder.getDefault().entityManagerFactory(emf);
    } else {
      builder = RuntimeEnvironmentBuilder.getDefaultInMemory();
    }
    builder.userGroupCallback(new JBossUserGroupCallbackImpl("classpath:/usergroups.properties"));

    for (Map.Entry<String, ResourceType> entry : resources.entrySet()) {
      builder.addAsset(ResourceFactory.newClassPathResource(entry.getKey()), entry.getValue());
    }

    return createRuntimeManager(strategy, resources, builder.get(), identifier);
  }
Example #2
0
  /**
   * Creates default configuration of <code>RuntimeManager</code> with given <code>strategy</code>
   * and all <code>resources</code> being added to knowledge base. <br>
   * There should be only one <code>RuntimeManager</code> created during single test.
   *
   * @param strategy - selected strategy of those that are supported
   * @param resources - resources that shall be added to knowledge base
   * @return new instance of RuntimeManager
   */
  protected RuntimeManager createRuntimeManager(
      Strategy strategy, Map<String, ResourceType> resources) {
    if (manager != null) {
      throw new IllegalStateException("There is already one RuntimeManager active");
    }

    RuntimeEnvironmentBuilder builder = null;
    if (!setupDataSource) {
      builder =
          RuntimeEnvironmentBuilder.getEmpty()
              .addConfiguration(
                  "drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName())
              .addConfiguration(
                  "drools.processInstanceManagerFactory",
                  DefaultProcessInstanceManagerFactory.class.getName());
    } else if (sessionPersistence) {
      builder = RuntimeEnvironmentBuilder.getDefault().entityManagerFactory(emf);
    } else {
      builder = RuntimeEnvironmentBuilder.getDefaultInMemory();
    }
    builder.userGroupCallback(new JBossUserGroupCallbackImpl("classpath:/usergroups.properties"));

    for (Map.Entry<String, ResourceType> entry : resources.entrySet()) {
      builder.addAsset(ResourceFactory.newClassPathResource(entry.getKey()), entry.getValue());
    }
    switch (strategy) {
      case SINGLETON:
        manager = managerFactory.newSingletonRuntimeManager(builder.get());
        break;
      case REQUEST:
        manager = managerFactory.newPerRequestRuntimeManager(builder.get());
        break;
      case PROCESS_INSTANCE:
        manager = managerFactory.newPerProcessInstanceRuntimeManager(builder.get());
        break;
      default:
        manager = managerFactory.newSingletonRuntimeManager(builder.get());
        break;
    }

    return manager;
  }