예제 #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());
  }
예제 #2
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());
  }
예제 #3
0
 public void testStep_Success() throws Exception {
   JavaActor actor = MultiplyBean.getConfiguredActor();
   actor.initialize();
   actor.setInputValue("originalValue", 1);
   actor.step();
   assertEquals(2, actor.getOutputValue("multipliedValue"));
 }
예제 #4
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();
  }
예제 #5
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());
 }
예제 #6
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());
 }
예제 #7
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());
  }
예제 #8
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());
  }
예제 #9
0
  public void testConfigure_CustomStep() throws Exception {

    JavaActor actor = new JavaActor();
    MultiplyBean bean = new MultiplyBean();
    actor.setStepMethod("customStep");
    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", 1);

    assertFalse(bean.stepped);
    actor.step();
    assertTrue(bean.stepped);
    assertTrue(bean.customStep);
  }
예제 #10
0
  public void testStep_SetInputValue_NullValue_Nullable() 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 + "  nullable: true" + EOL));
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();
    actor.initialize();

    actor.setInputValue("originalValue", null);
    try {
      actor.step();
    } catch (Exception e) {
    }
    assertNull(bean.getOriginalValue());
  }
예제 #11
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"));
  }
예제 #12
0
  public void testInitialize_setSettings() 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: 3" + EOL));
    actor.setApplicationContext(_context);
    actor.afterPropertiesSet();
    actor.elaborate();
    actor.configure();

    actor.initialize();

    actor.setInputValue("originalValue", 4);
    actor.step();
    assertEquals(12, actor.getOutputValue("multipliedValue"));
  }
예제 #13
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);
  }
예제 #14
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());
  }