コード例 #1
0
  @Before
  public void setupNodes() {
    // Dummy process for each test consists of 3 connected nodes
    // ---------------------------------------------------------
    //
    // [StartNode]--e1-->[DummyNode]--e2-->[EndNode]
    //
    process = new ProcessNode();
    ruleManager = new DefaultRuleManagerImpl();
    node1 = new StartProcessNode();
    node2 = new TestDummyNode();
    node3 = new EndProcessNode();
    commandManager = new DefaultCommandManagerImpl();

    for (Rule rule : getConnectionRules()) {
      ruleManager.addRule(rule);
    }
    for (Rule rule : getCardinalityRules()) {
      ruleManager.addRule(rule);
    }

    // Add StartProcessNode
    final Results results1 =
        commandManager.execute(ruleManager, new AddGraphNodeCommand(process, node1));

    assertNotNull(results1);
    assertEquals(0, results1.getMessages().size());

    // Add TestDummyNode
    final Results results2 =
        commandManager.execute(ruleManager, new AddGraphNodeCommand(process, node2));

    assertNotNull(results2);
    assertEquals(0, results2.getMessages().size());

    // Add EndProcessNode
    final Results results3 =
        commandManager.execute(ruleManager, new AddGraphNodeCommand(process, node3));

    assertNotNull(results3);
    assertEquals(0, results3.getMessages().size());

    // Add Edge between StartNode and DummyNode1
    e1 = new BpmnEdgeImpl(new DefaultRoleImpl("general_edge"));
    final Results results4 =
        commandManager.execute(ruleManager, new AddEdgeCommand(node1, node2, e1));

    assertNotNull(results4);
    assertEquals(0, results4.getMessages().size());

    // Add Edge between DummyNode2 and EndNode
    e2 = new BpmnEdgeImpl(new DefaultRoleImpl("general_edge"));
    final Results results5 =
        commandManager.execute(ruleManager, new AddEdgeCommand(node2, node3, e2));

    assertNotNull(results5);
    assertEquals(0, results5.getMessages().size());
  }
コード例 #2
0
  @Test
  public void testDeleteOutgoingCardinalityIncomingMinimum() {
    ruleManager.addRule(
        new CardinalityRuleImpl(
            "DummyNode Incoming Cardinality Rule",
            new DefaultRoleImpl("dummy"),
            0,
            2,
            Collections.EMPTY_SET,
            new HashSet<CardinalityRule.ConnectorRule>() {
              {
                add(
                    new CardinalityRule.ConnectorRule() {
                      @Override
                      public long getMinOccurrences() {
                        return 1;
                      }

                      @Override
                      public long getMaxOccurrences() {
                        return 2;
                      }

                      @Override
                      public Role getRole() {
                        return new DefaultRoleImpl("general_edge");
                      }

                      @Override
                      public String getName() {
                        return "End Node DummyNode Connector Rule 1";
                      }
                    });
              }
            }));

    // Delete edge between DummyNode1 and DummyNode2
    final Results results1 =
        commandManager.execute(ruleManager, new DeleteEdgeCommand(node2, node3, e2));

    assertNotNull(results1);
    assertEquals(0, results1.getMessages().size());

    assertEquals(1, node2.getInEdges().size());
    assertEquals(1, node2.getOutEdges().size());
    assertEquals(1, node3.getInEdges().size());
    assertEquals(1, node3.getOutEdges().size());

    // Try to delete the other edge between DummyNode1 and DummyNode2 again. This should fail
    // validation.
    final Results results2 =
        commandManager.execute(ruleManager, new DeleteEdgeCommand(node2, node3, e4));

    assertNotNull(results2);
    assertEquals(1, results2.getMessages().size());
    assertEquals(1, results2.getMessages(ResultType.ERROR).size());

    assertEquals(1, node2.getInEdges().size());
    assertEquals(1, node2.getOutEdges().size());
    assertEquals(1, node3.getInEdges().size());
    assertEquals(1, node3.getOutEdges().size());
  }