@Test
public void convertStoredDefinitionWorks() {

  StoredWorkflowDefinition convertedOriginal = dao.convert(original);
  assertThat(convertedOriginal.type, is(original.getType()));
  assertThat(convertedOriginal.onError, is(original.getErrorState().name()));
  assertThat(convertedOriginal.description, is(original.getDescription()));
  assertThat(convertedOriginal.states.size(), is(original.getStates().size()));
  for (StoredWorkflowDefinition.State convertedState : convertedOriginal.states) {
    boolean foundMatchingState = false;
    for (DummyTestState originalState : original.getStates()) {
      if (originalState.name().equals(convertedState.id)) {
        assertThat(convertedState.description, is(originalState.getDescription()));
        WorkflowState originalFailureTransition = original.getFailureTransitions().get(originalState.name());
        assertThat(convertedState.onFailure, is(originalFailureTransition != null ? originalFailureTransition.name() : null));
        List<String> originalStateTransitions = original.getAllowedTransitions().get(originalState.name());
        if (originalStateTransitions != null) {
          assertThat(convertedState.transitions, containsElementsInAnyOrder(originalStateTransitions));
        } else {
          assertThat(convertedState.transitions.size(), is(0));
        }
        foundMatchingState = true;
        break;
      }
    }
    assertThat("Not found match for state " + convertedState.id, foundMatchingState, is(true));
  }
  assertThat(convertedOriginal.supportedSignals.size(), is(original.getSupportedSignals().size()));
  for (StoredWorkflowDefinition.Signal convertedSignal : convertedOriginal.supportedSignals) {
    boolean foundMatchingSignal = false;
    for (Entry<Integer, String> originalSignal : original.getSupportedSignals().entrySet()) {
      if (originalSignal.getKey().equals(convertedSignal.value)) {
        assertThat(convertedSignal.description, is(originalSignal.getValue()));
        foundMatchingSignal = true;
        break;
      }
    }
    assertThat("Not found match for signal " + convertedSignal.value, foundMatchingSignal, is(true));
  }
}