@Test @SuppressWarnings("unchecked") public void checkHasExistingConnection() { final Node node1 = new NodeImpl<>("node1"); final Node node2 = new NodeImpl<>("node2"); final Edge existingConnector = new EdgeImpl<>("edge1"); final ViewConnector existingConnectorView = mock(ViewConnector.class); existingConnector.setContent(existingConnectorView); when(existingConnectorView.getDefinition()).thenReturn(new Definition()); node1.getOutEdges().add(existingConnector); node2.getInEdges().add(existingConnector); existingConnector.setSourceNode(node1); existingConnector.setTargetNode(node2); graph.addNode(node1); graph.addNode(node2); when(context.getSource()).thenReturn(Optional.of(node1)); when(context.getTarget()).thenReturn(Optional.of(node2)); when(context.getConnector()).thenReturn(connector); final RuleViolations result = check.evaluate(rule, context); assertNotNull(result); assertTrue(result.violations().iterator().hasNext()); final RuleViolation violation = result.violations().iterator().next(); assertNotNull(violation); assertTrue(violation.getArguments().isPresent()); assertEquals(1, violation.getArguments().get().length); assertEquals(SingleConnectorPerTypeGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]); }
@Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final RuleExtension rule, final GraphConnectionContext context) { final Optional<Node<? extends View<?>, ? extends Edge>> oSource = context.getSource(); final Optional<Node<? extends View<?>, ? extends Edge>> oTarget = context.getTarget(); final DefaultRuleViolations result = new DefaultRuleViolations(); if (!(oSource.isPresent() && oTarget.isPresent())) { return result; } final Node<? extends View<?>, ? extends Edge> source = oSource.get(); final Node<? extends View<?>, ? extends Edge> target = oTarget.get(); final Edge<? extends View<?>, ? extends Node> connector = context.getConnector(); if (isConnectionAlreadyFormed(source, target, connector)) { result.addViolation(new RuleViolationImpl(ERROR_MESSAGE)); } return result; }
SingleConnectorPerTypeGraphRule extends RuleExtensionHandler<SingleConnectorPerTypeGraphRule, GraphConnectionContext> { @Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final RuleExtension rule, final GraphConnectionContext context) { final Optional<Node<? extends View<?>, ? extends Edge>> oSource = context.getSource(); final Optional<Node<? extends View<?>, ? extends Edge>> oTarget = context.getTarget(); final DefaultRuleViolations result = new DefaultRuleViolations(); if (!(oSource.isPresent() && oTarget.isPresent())) { return result; } final Node<? extends View<?>, ? extends Edge> source = oSource.get(); final Node<? extends View<?>, ? extends Edge> target = oTarget.get(); final Edge<? extends View<?>, ? extends Node> connector = context.getConnector(); if (isConnectionAlreadyFormed(source, target, connector)) { result.addViolation(new RuleViolationImpl(ERROR_MESSAGE)); } return result; } }
SingleConnectorPerTypeGraphRule extends RuleExtensionHandler<SingleConnectorPerTypeGraphRule, GraphConnectionContext> { @Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final RuleExtension rule, final GraphConnectionContext context) { final Optional<Node<? extends View<?>, ? extends Edge>> oSource = context.getSource(); final Optional<Node<? extends View<?>, ? extends Edge>> oTarget = context.getTarget(); final DefaultRuleViolations result = new DefaultRuleViolations(); if (!(oSource.isPresent() && oTarget.isPresent())) { return result; } final Node<? extends View<?>, ? extends Edge> source = oSource.get(); final Node<? extends View<?>, ? extends Edge> target = oTarget.get(); final Edge<? extends View<?>, ? extends Node> connector = context.getConnector(); if (isConnectionAlreadyFormed(source, target, connector)) { result.addViolation(new RuleViolationImpl(ERROR_MESSAGE)); } return result; }  }
SingleConnectorPerTypeGraphRule extends RuleExtensionHandler<SingleConnectorPerTypeGraphRule, GraphConnectionContext> { @Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final RuleExtension rule, final GraphConnectionContext context) { final Optional<Node<? extends View<?>, ? extends Edge>> oSource = context.getSource(); final Optional<Node<? extends View<?>, ? extends Edge>> oTarget = context.getTarget(); final DefaultRuleViolations result = new DefaultRuleViolations(); if (!(oSource.isPresent() && oTarget.isPresent())) { return result; } final Node<? extends View<?>, ? extends Edge> source = oSource.get(); final Node<? extends View<?>, ? extends Edge> target = oTarget.get(); final Edge<? extends View<?>, ? extends Node> connector = context.getConnector(); if (isConnectionAlreadyFormed(source, target, connector)) { result.addViolation(new RuleViolationImpl(ERROR_MESSAGE)); } return result; }  @Override Class<SingleConnectorPerTypeGraphRule> getExtensionType(); @Override Class<GraphConnectionContext> getContextType(); @Override boolean accepts(final RuleExtension rule,
                           final GraphConnectionContext context); @Override @SuppressWarnings("unchecked") RuleViolations evaluate(final RuleExtension rule,
                                   final GraphConnectionContext context); }
SingleConnectorPerTypeGraphRule extends RuleExtensionHandler<SingleConnectorPerTypeGraphRule, GraphConnectionContext> { @Override @SuppressWarnings("unchecked") public RuleViolations evaluate(final RuleExtension rule, final GraphConnectionContext context) { final Optional<Node<? extends View<?>, ? extends Edge>> oSource = context.getSource(); final Optional<Node<? extends View<?>, ? extends Edge>> oTarget = context.getTarget(); final DefaultRuleViolations result = new DefaultRuleViolations(); if (!(oSource.isPresent() && oTarget.isPresent())) { return result; } final Node<? extends View<?>, ? extends Edge> source = oSource.get(); final Node<? extends View<?>, ? extends Edge> target = oTarget.get(); final Edge<? extends View<?>, ? extends Node> connector = context.getConnector(); if (isConnectionAlreadyFormed(source, target, connector)) { result.addViolation(new RuleViolationImpl(ERROR_MESSAGE)); } return result; }  @Override Class<SingleConnectorPerTypeGraphRule> getExtensionType(); @Override Class<GraphConnectionContext> getContextType(); @Override boolean accepts(final RuleExtension rule,
                           final GraphConnectionContext context); @Override @SuppressWarnings("unchecked") RuleViolations evaluate(final RuleExtension rule,
                                   final GraphConnectionContext context);  }