Exemplo n.º 1
1
  public void testSetInputValue_IncorrectType_Workflow() throws Exception {
    JavaActor actor = BadWorkflowProcessingBean.getConfiguredActor();
    actor.initialize();
    actor.setInputValue("workflow", "hello");

    Exception exception = null;
    try {
      actor.step();
    } catch (InputTypeException inputTypeException) {
      exception = inputTypeException;
    }
    assertEquals(
        "org.restflow.exceptions.InputTypeException: "
            + "Data of incorrect type received on input 'workflow' "
            + "of actor BadWorkflowProcessingActor",
        exception.toString());
    assertNotNull(exception.getCause());
    assertEquals(
        "java.lang.IllegalArgumentException: "
            + "Cannot invoke org.restflow.actors.TestJavaActor$BadWorkflowProcessingBean.setWorkflow on "
            + "bean class 'class org.restflow.actors.TestJavaActor$BadWorkflowProcessingBean' "
            + "- argument type mismatch - had objects of type \"java.lang.String\" "
            + "but expected signature \"org.restflow.actors.Workflow\"",
        exception.getCause().toString());
  }
Exemplo n.º 2
0
  public void testConfigure_ExceptionConstructingBean() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");

    assertNull(actor.getWrappedBean());
    assertNull(actor.getWrappedBeanClass());

    actor.setBeanClassName("org.restflow.actors.TestJavaActor$MultiplyBean");
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();

    MultiplyBean.throwExceptionInConstructor = true;

    Exception exception = null;
    try {
      actor.configure();
    } catch (WorkflowRuntimeException e) {
      exception = e;
    }

    assertEquals(
        "org.restflow.exceptions.WorkflowRuntimeException: "
            + "Error instantiating instance of bean class "
            + "class org.restflow.actors.TestJavaActor$MultiplyBean "
            + "for actor MultiplyActor",
        exception.toString());
    assertNotNull(exception.getCause());
    assertEquals("java.lang.Exception: Exception in constructor", exception.getCause().toString());

    assertNull(actor.getWrappedBean());
  }
Exemplo n.º 3
0
  public void testConfigure_NoBeanSet_NoClassNameSet() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();

    assertNull(actor.getWrappedBean());
    assertNull(actor.getWrappedBeanClass());

    Exception exception = null;
    try {
      actor.configure();
    } catch (ActorDeclarationException e) {
      exception = e;
    }

    assertEquals(
        "org.restflow.exceptions.ActorDeclarationException: "
            + "No bean class provided for actor MultiplyActor",
        exception.toString());
    assertNull(exception.getCause());
    assertNull(actor.getWrappedBean());
    assertNull(actor.getWrappedBeanClass());
  }
Exemplo n.º 4
0
 public void testSetInputs() throws Exception {
   JavaActor actor = new JavaActor();
   actor.setName("MultiplyActor");
   actor.setWrappedBean(new MultiplyBean());
   Yaml yaml = new Yaml();
   actor.setInputs((Map<String, Object>) yaml.load("originalValue:" + EOL));
 }
Exemplo n.º 5
0
 public void testStep_Success() throws Exception {
   JavaActor actor = MultiplyBean.getConfiguredActor();
   actor.initialize();
   actor.setInputValue("originalValue", 1);
   actor.step();
   assertEquals(2, actor.getOutputValue("multipliedValue"));
 }
Exemplo n.º 6
0
  public void testStep_SetInputValue_NullValue_NotNullable() throws Exception {
    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    MultiplyBean bean = new MultiplyBean();
    actor.setWrappedBean(bean);
    Yaml yaml = new Yaml();
    actor.setInputs((Map<String, Object>) yaml.load("originalValue:" + EOL));
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();
    actor.initialize();

    Exception exception = null;
    try {
      actor.setInputValue("originalValue", null);
    } catch (NullInputException e) {
      exception = e;
    }
    assertNotNull(exception);
    assertEquals(
        "org.restflow.exceptions.NullInputException: "
            + "Null data received on non-nullable input 'originalValue' "
            + "of actor 'MultiplyActor'",
        exception.toString());
  }
  @SuppressWarnings("unused")
  public void setUp() throws Exception {

    super.setUp();

    _context = new WorkflowContextBuilder().build();

    _actor =
        new JavaActorBuilder()
            .name("TestActor")
            .context(_context)
            .bean(
                new Object() {
                  public boolean throwExceptionOnStep = false;
                  public boolean actorStepped = false;

                  public void step() throws RestFlowException {
                    actorStepped = true;
                    if (throwExceptionOnStep) {
                      throw new RestFlowException("Error stepping actor");
                    }
                  }
                })
            .build();

    _actor.elaborate();
    _actor.configure();
    _actor.initialize();
  }
Exemplo n.º 8
0
  public void testWrapup_SetStatusException() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    MultiplyBean bean = new MultiplyBean();
    actor.setWrappedBean(bean);
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();
    actor.initialize();

    bean.statusSet = false;
    bean.actorStatus = null;
    assertFalse(bean.wrappedUp);

    MultiplyBean.throwExceptionInStatusSetter = true;

    Exception exception = null;
    try {
      actor.wrapup();
    } catch (RestFlowException e) {
      exception = e;
    }
    assertNotNull(exception);
    assertEquals(
        "org.restflow.exceptions.WorkflowRuntimeException: "
            + "Exception in setStatus() method of actor MultiplyActor",
        exception.toString());
    assertNotNull(exception.getCause());
    assertEquals(
        "java.lang.Exception: Exception in status setter", exception.getCause().toString());
  }
Exemplo n.º 9
0
 public static JavaActor getConfiguredActor() throws Exception {
   JavaActor actor = new JavaActor();
   actor.setName("MultiplyActor");
   actor.setWrappedBean(new MultiplyBean());
   Yaml yaml = new Yaml();
   actor.setInputs((Map<String, Object>) yaml.load("originalValue:" + EOL));
   actor.setOutputs((Map<String, Object>) yaml.load("multipliedValue:" + EOL));
   actor.setSettings((Map<String, Object>) yaml.load("factor: 2" + EOL));
   actor.setApplicationContext(new WorkflowContextBuilder().build());
   actor.afterPropertiesSet();
   actor.elaborate();
   actor.configure();
   return actor;
 }
Exemplo n.º 10
0
  public void testConfigure_CustomWrapupMissing() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    MultiplyBean bean = new MultiplyBean();
    actor.setWrappedBean(bean);
    actor.setWrapupMethod("customWrapupMissing");
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();

    Exception exception = null;
    try {
      actor.configure();
    } catch (ActorDeclarationException e) {
      exception = e;
    }
    assertNotNull(exception);
    assertEquals(
        "org.restflow.exceptions.ActorDeclarationException: "
            + "Error finding declared method customWrapupMissing "
            + "on bean class org.restflow.actors.TestJavaActor$MultiplyBean "
            + "for actor MultiplyActor",
        exception.toString());
    Throwable cause = exception.getCause();
    assertNotNull(cause);
    assertEquals(
        "java.lang.NoSuchMethodException: "
            + "org.restflow.actors.TestJavaActor$MultiplyBean.customWrapupMissing()",
        cause.toString());
  }
  public void testRun_NoException() throws Exception {

    Map<String, Object> variables = new HashMap<String, Object>();
    ActorRunner runner = new SynchronousActorRunner(_actor, variables);
    assertEquals(false, _actor.getFieldValue("actorStepped"));

    runner.run();
    assertEquals(true, _actor.getFieldValue("actorStepped"));
    assertSame(_actor, runner.getActor());
    assertSame(variables, runner.getVariables());

    Exception exception = runner.getException();
    assertNull(exception);
  }
Exemplo n.º 12
0
 public void testStep_StepException() throws Exception {
   JavaActor actor = MultiplyBean.getConfiguredActor();
   MultiplyBean.throwExceptionInStep = true;
   actor.initialize();
   actor.setInputValue("originalValue", 1);
   Exception exception = null;
   try {
     actor.step();
   } catch (RestFlowException ex) {
     exception = ex;
   }
   assertEquals("Exception in step() method of actor 'MultiplyActor'", exception.getMessage());
   assertNotNull(exception.getCause());
   assertEquals("Exception in step", exception.getCause().getMessage());
 }
  public void testRun_WithException() throws Exception {

    _actor.setFieldValue("throwExceptionOnStep", true);
    Map<String, Object> variables = new HashMap<String, Object>();
    ActorRunner runner = new SynchronousActorRunner(_actor, variables);
    assertEquals(false, _actor.getFieldValue("actorStepped"));

    runner.run();
    assertEquals(true, _actor.getFieldValue("actorStepped"));
    assertSame(_actor, runner.getActor());
    assertSame(variables, runner.getVariables());

    Exception exception = runner.getException();
    assertNotNull(exception);
    assertEquals("Exception in step() method of actor 'TestActor'", exception.getMessage());
  }
Exemplo n.º 14
0
  public void testConfigure_NoDefaultMethodsOnBean() throws Exception {

    JavaActor actor = new JavaActor();
    EmptyBean bean = new EmptyBean();
    actor.setWrappedBean(bean);
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();
    actor.initialize();
    actor.step();
    actor.wrapup();
  }
Exemplo n.º 15
0
  public void testConfigure_BeanClassNameSet() throws Exception {

    JavaActor actor = new JavaActor();

    actor.setBeanClassName("org.restflow.actors.TestJavaActor$MultiplyBean");
    assertNull(actor.getWrappedBean());
    assertNull(actor.getWrappedBeanClass());

    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();
    assertEquals(MultiplyBean.class, actor.getWrappedBeanClass());

    Object bean = actor.getWrappedBean();
    assertSame(MultiplyBean.class, bean.getClass());
  }
Exemplo n.º 16
0
 public static JavaActor getConfiguredActor() throws Exception {
   JavaActor actor = new JavaActor();
   actor.setName("BadWorkflowProcessingActor");
   actor.setWrappedBean(new BadWorkflowProcessingBean());
   Yaml yaml = new Yaml();
   actor.setInputs((Map<String, Object>) yaml.load("workflow:" + EOL));
   actor.setApplicationContext(new WorkflowContextBuilder().build());
   actor.afterPropertiesSet();
   actor.elaborate();
   actor.configure();
   return actor;
 }
Exemplo n.º 17
0
  public void testSetInputValue_SetterException() throws Exception {
    JavaActor actor = MultiplyBean.getConfiguredActor();
    MultiplyBean.throwExceptionInSetter = true;
    actor.initialize();

    actor.setInputValue("originalValue", 1);
    Exception exception = null;
    try {
      actor.step();
    } catch (WorkflowRuntimeException ex) {
      exception = ex;
    }
    assertEquals(
        "org.restflow.exceptions.WorkflowRuntimeException: "
            + "Exception calling setter for input 'originalValue' on actor MultiplyActor",
        exception.toString());
    assertNotNull(exception.getCause());
    assertEquals("java.lang.Exception: Exception in setter", exception.getCause().toString());
  }
Exemplo n.º 18
0
  public void testWrapup() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    MultiplyBean bean = new MultiplyBean();
    actor.setWrappedBean(bean);
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();
    actor.initialize();

    assertFalse(bean.wrappedUp);
    actor.wrapup();
    assertTrue(bean.wrappedUp);
  }
Exemplo n.º 19
0
  public void testSetInputValue_IncorrectType() throws Exception {
    JavaActor actor = MultiplyBean.getConfiguredActor();
    actor.initialize();
    actor.setInputValue("originalValue", "hello");

    Exception exception = null;
    try {
      actor.step();
    } catch (InputTypeException ex) {
      exception = ex;
    }
    assertEquals(
        "org.restflow.exceptions.InputTypeException: "
            + "Data of incorrect type received on input 'originalValue' of actor MultiplyActor",
        exception.toString());
    assertNotNull(exception.getCause());
    assertMatchesRegexp(
        ".* - had objects of type \"java.lang.String\" "
            + "but expected signature \"java.lang.Integer\"",
        exception.getCause().toString());
  }
Exemplo n.º 20
0
  public void testConfigure_CustomInitialize() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    MultiplyBean bean = new MultiplyBean();
    actor.setWrappedBean(bean);
    actor.setInitializeMethod("customInitialize");
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();

    actor.configure();
    assertFalse(bean.initialized);

    actor.initialize();
    assertTrue(bean.initialized);
    assertTrue(bean.customInitialization);
  }
Exemplo n.º 21
0
  public void testInitialize_CustomSetStatus() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    MultiplyBean bean = new MultiplyBean();
    actor.setWrappedBean(bean);
    actor.setStatusSetter("customSetStatus");
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();

    actor.configure();
    assertNull(bean.actorStatus);
    assertFalse(bean.statusSet);

    actor.initialize();
    assertNotNull(bean.actorStatus);
    assertTrue(bean.statusSet);
    assertTrue(bean.customSetStatus);
  }
Exemplo n.º 22
0
  public void testConfigure_ExceptionPrivateBeanConstructor() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");

    assertNull(actor.getWrappedBean());
    assertNull(actor.getWrappedBeanClass());

    actor.setBeanClassName("org.restflow.actors.TestJavaActor$BeanWithPrivateConstructor");
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();

    Exception exception = null;
    try {
      actor.configure();
    } catch (WorkflowRuntimeException e) {
      exception = e;
    }

    assertEquals(
        "org.restflow.exceptions.WorkflowRuntimeException: "
            + "Error instantiating instance of bean class "
            + "class org.restflow.actors.TestJavaActor$BeanWithPrivateConstructor "
            + "for actor MultiplyActor",
        exception.toString());
    assertNotNull(exception.getCause());
    assertEquals(
        "java.lang.IllegalAccessException: "
            + "Class org.restflow.actors.JavaActor can not access a member of class "
            + "org.restflow.actors.TestJavaActor$BeanWithPrivateConstructor "
            + "with modifiers \"private\"",
        exception.getCause().toString());

    assertNull(actor.getWrappedBean());
  }
Exemplo n.º 23
0
  public void testConfigure_BothBeanAndClassNameSet() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    actor.setWrappedBean(new MultiplyBean());
    actor.setBeanClassName("org.restflow.actors.TestJavaActor$MultiplyBean");
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();

    Exception exception = null;
    try {
      actor.configure();
    } catch (ActorDeclarationException e) {
      exception = e;
    }
    assertNotNull(exception);
    assertEquals(
        "org.restflow.exceptions.ActorDeclarationException: "
            + "Actor MultiplyActor declared both a bean instance and a bean class.",
        exception.toString());
  }
Exemplo n.º 24
0
 public void testStep_SetInputValue_NonNullValue() throws Exception {
   JavaActor actor = new JavaActor();
   actor.setName("MultiplyActor");
   MultiplyBean bean = new MultiplyBean();
   actor.setWrappedBean(bean);
   Yaml yaml = new Yaml();
   actor.setInputs((Map<String, Object>) yaml.load("originalValue:" + EOL));
   actor.setApplicationContext(_context);
   actor.afterPropertiesSet();
   actor.elaborate();
   actor.configure();
   actor.initialize();
   actor.setInputValue("originalValue", 72);
   actor.step();
   assertEquals(new Integer(72), bean.getOriginalValue());
 }
Exemplo n.º 25
0
  public void testStep_SetAndUpdateStateVariablesWithNulls() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    MultiplyBean bean = new MultiplyBean();
    actor.setWrappedBean(bean);

    Yaml yaml = new Yaml();
    actor.setInputs((Map<String, Object>) yaml.load("originalValue:" + EOL));
    actor.setOutputs((Map<String, Object>) yaml.load("multipliedValue:" + EOL));
    actor.setSettings((Map<String, Object>) yaml.load("factor: 3" + EOL));
    actor.setState((Map<String, Object>) yaml.load("accumulator: 0" + EOL + "count: 0" + EOL));
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();
    actor.initialize();

    actor.setInputValue("originalValue", 4);
    assertEquals(0, bean.getAccumulator());
    assertEquals((Integer) 0, bean.getCount());
    MultiplyBean.setCountToNullInStep = true;
    actor.step();
    assertEquals(12, actor.getOutputValue("multipliedValue"));
    assertNull(bean.getCount());
    assertEquals(12, bean.getAccumulator());

    actor.setInputValue("originalValue", 6);
    bean.setCount(17);
    actor.step();
    assertEquals(18, actor.getOutputValue("multipliedValue"));
    assertNull(bean.getCount());
    assertEquals(30, bean.getAccumulator());
  }
Exemplo n.º 26
0
  public void testClone_UncloneableBean() throws Exception {
    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    UncloneableMultiplyBean bean = new UncloneableMultiplyBean();
    actor.setWrappedBean(bean);
    Yaml yaml = new Yaml();
    actor.setInputs((Map<String, Object>) yaml.load("originalValue:" + EOL));
    actor.setOutputs((Map<String, Object>) yaml.load("multipliedValue:" + EOL));
    actor.setSettings((Map<String, Object>) yaml.load("factor: 4" + EOL));
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();
    actor.initialize();

    JavaActor clone = (JavaActor) actor.clone();
    assertNotSame(bean, clone.getWrappedBean());

    clone.setInputValue("originalValue", 5);
    clone.step();
    assertEquals(20, clone.getOutputValue("multipliedValue"));
  }
Exemplo n.º 27
0
  public void testStep_SetStatusException() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    MultiplyBean bean = new MultiplyBean();
    actor.setWrappedBean(bean);
    Yaml yaml = new Yaml();
    actor.setInputs((Map<String, Object>) yaml.load("originalValue:" + EOL));
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();
    actor.initialize();

    actor.setInputValue("originalValue", 4);
    assertEquals(0, bean.getAccumulator());
    assertEquals((Integer) 0, bean.getCount());
    bean.statusSet = false;
    bean.actorStatus = null;
    MultiplyBean.throwExceptionInStatusSetter = true;

    Exception exception = null;
    try {
      actor.step();
    } catch (RestFlowException e) {
      exception = e;
    }
    assertNotNull(exception);
    assertEquals(
        "org.restflow.exceptions.WorkflowRuntimeException: "
            + "Exception in setStatus() method of actor MultiplyActor",
        exception.toString());
    assertNotNull(exception.getCause());
    assertEquals(
        "java.lang.Exception: Exception in status setter", exception.getCause().toString());
  }
Exemplo n.º 28
0
  public void testStep_SetStatus() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    MultiplyBean bean = new MultiplyBean();
    actor.setWrappedBean(bean);
    Yaml yaml = new Yaml();
    actor.setInputs((Map<String, Object>) yaml.load("originalValue:" + EOL));
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();
    actor.initialize();

    actor.setInputValue("originalValue", 4);
    assertEquals(0, bean.getAccumulator());
    assertEquals((Integer) 0, bean.getCount());
    bean.statusSet = false;
    bean.actorStatus = null;
    actor.step();
    assertNotNull(bean.actorStatus);
    assertTrue(bean.statusSet);
  }
Exemplo n.º 29
0
  public void testSetInputValue_NewValueForSetting() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    MultiplyBean bean = new MultiplyBean();
    actor.setWrappedBean(bean);

    Yaml yaml = new Yaml();
    actor.setInputs((Map<String, Object>) yaml.load("originalValue:" + EOL));
    actor.setOutputs((Map<String, Object>) yaml.load("multipliedValue:" + EOL));
    actor.setSettings((Map<String, Object>) yaml.load("factor: 3" + EOL));
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();
    actor.initialize();

    Exception exception = null;
    try {
      actor.setInputValue("factor", 4);
    } catch (Exception e) {
      exception = e;
    }
    assertNotNull(exception);
    assertEquals(
        "org.restflow.exceptions.RestFlowException: "
            + "Attempt to reassign value of setting 'factor' on actor MultiplyActor",
        exception.toString());
  }
Exemplo n.º 30
0
  public void testInitialize_getUpdatedStateVariables() throws Exception {

    JavaActor actor = new JavaActor();
    actor.setName("MultiplyActor");
    MultiplyBean bean = new MultiplyBean();
    actor.setWrappedBean(bean);

    Yaml yaml = new Yaml();
    actor.setInputs((Map<String, Object>) yaml.load("originalValue:" + EOL));
    actor.setOutputs((Map<String, Object>) yaml.load("multipliedValue:" + EOL));
    actor.setSettings((Map<String, Object>) yaml.load("factor: 3" + EOL));
    actor.setState((Map<String, Object>) yaml.load("accumulator: -1" + EOL + "count: 5" + EOL));
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();

    MultiplyBean.clearAccumulatorInInitialize = true;

    actor.initialize();
    assertEquals(0, bean.getAccumulator());
    assertEquals(new Integer(5), bean.getCount());
  }