private Optional<String> getGraphUUID() { if (Objects.isNull(getGraph())) { return Optional.empty(); } return Optional.of(getGraph().getUUID()); }
@Override public void deregister(final Element element) { if (null != renderer) { renderer.clear(getDiagram().getGraph().getUUID(), element); } }
@Override public void clear() { if (null != renderer) { renderer.clearAll(getDiagram().getGraph().getUUID()); } }
private void domainValidation(Diagram diagram, Consumer<DiagramElementViolation<RuleViolation>> callback) { StreamSupport.stream(validators.spliterator(), false) .filter(validator -> Objects.equals(validator.getDefinitionSetId(), diagram.getMetadata().getDefinitionSetId())) .findFirst() .ifPresent(validator -> validator.validate(diagram, domainViolations -> callback.accept(new ElementViolationImpl.Builder() .setUuid(diagram.getGraph().getUUID()) .setDomainViolations(domainViolations) .build()))); } }
@Override public void startGraphTraversal(final Graph<DefinitionSet, Node<View, Edge>> graph) { if (graph == null) { error("Graph is null!"); } else { final DefinitionSet view = graph.getContent(); log(indent + "Graph UUID: " + graph.getUUID()); log(indent + " Graph Starting nodes"); log(indent + " ===================="); } }
@Before public void setUp() { when(validators.spliterator()).thenReturn(Arrays.asList(domainValidator).spliterator()); when(domainValidator.getDefinitionSetId()).thenReturn(DEF_SET_ID); when(diagram.getMetadata()).thenReturn(metadata); when(metadata.getDefinitionSetId()).thenReturn(DEF_SET_ID); when(diagram.getGraph()).thenReturn(graph); when(graph.getUUID()).thenReturn(GRAPH_UUID); when(domainViolation.getViolationType()).thenReturn(Violation.Type.ERROR); validationService = new ValidationServiceImpl(validators); }
@SuppressWarnings("unchecked") public void init() { MockitoAnnotations.initMocks(this); when(graph.getUUID()).thenReturn(GRAPH_UUID); when(graph.getContent()).thenReturn(graphContent); when(graph.nodes()).thenReturn(graphNodes); when(definitionManager.adapters()).thenReturn(adapterManager); when(adapterManager.registry()).thenReturn(adapterRegistry); when(adapterManager.forDefinition()).thenReturn(definitionAdapter); when(adapterManager.forProperty()).thenReturn(propertyAdapter); when(adapterRegistry.getDefinitionAdapter(any(Class.class))).thenReturn(definitionAdapter); when(adapterRegistry.getPropertyAdapter(any(Class.class))).thenReturn(propertyAdapter); when(graphCommandExecutionContext.getDefinitionManager()).thenReturn(definitionManager); when(graphCommandExecutionContext.getFactoryManager()).thenReturn(factoryManager); when(graphCommandExecutionContext.getRuleManager()).thenReturn(ruleManager); when(graphCommandExecutionContext.getGraphIndex()).thenReturn(graphIndex); when(graphCommandExecutionContext.getRuleSet()).thenReturn(ruleSet); when(graphIndex.getGraph()).thenReturn(graph); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(EMPTY_VIOLATIONS); }
@Override public <S extends ClientSession> void destroy(final S session) { final boolean isCurrent = session.equals(current); final String uuid = session.getSessionUUID(); final Diagram diagram = session.getCanvasHandler().getDiagram(); final String name = null != diagram ? diagram.getName() : null; final String graphUuid = null != diagram ? diagram.getGraph().getUUID() : null; final Metadata metadata = null != diagram ? diagram.getMetadata() : null; ((AbstractSession) session).destroy(); sessionInstances.destroy(session); if (isCurrent) { current = null; } sessionDestroyedEvent.fire(new SessionDestroyedEvent(uuid, name, graphUuid, metadata)); }
@Test @SuppressWarnings("unchecked") public void testExecuteCheckFailed() { final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations() .addViolation(new ContainmentRuleViolation(graph.getUUID(), UUID)); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS); CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext); assertEquals(CommandResult.Type.ERROR, result.getType()); verify(graph, times(0)).addNode(eq(node)); verify(graphIndex, times(0)).addNode(eq(node)); verify(graphIndex, times(0)).addEdge(any(Edge.class)); verify(graph, times(0)).removeNode(eq(UUID)); verify(graphIndex, times(0)).removeNode(eq(node)); verify(graphIndex, times(0)).removeEdge(any(Edge.class)); }
@Test @SuppressWarnings("unchecked") public void testNotAllowed() { final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations() .addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID)); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS); CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext); assertEquals(CommandResult.Type.ERROR, result.getType()); }
@Test @SuppressWarnings("unchecked") public void testNotAllowed() { final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations() .addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID)); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS); CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext); assertEquals(CommandResult.Type.ERROR, result.getType()); }
@Test @SuppressWarnings("unchecked") public void testNotAllowed() { final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations() .addViolation(new ContainmentRuleViolation(graph.getUUID(), UUID)); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS); CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext); assertEquals(CommandResult.Type.ERROR, result.getType()); }
@Test @SuppressWarnings("unchecked") public void testNotAllowed() { final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations() .addViolation(new ContainmentRuleViolation(graph.getUUID(), UUID)); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS); CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext); assertEquals(CommandResult.Type.ERROR, result.getType()); }
@Test @SuppressWarnings("unchecked") public void testNotAllowed() { final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations() .addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID)); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS); CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext); assertEquals(CommandResult.Type.ERROR, result.getType()); }
@Test @SuppressWarnings("unchecked") public void testNotAllowed() { final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations() .addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID)); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS); CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext); assertEquals(CommandResult.Type.ERROR, result.getType()); } }
@Test @SuppressWarnings("unchecked") public void testExecuteCheckFailed() { final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations() .addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID)); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS); CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext); assertEquals(CommandResult.Type.ERROR, result.getType()); assertTrue(parent.getOutEdges().isEmpty()); assertTrue(candidate.getInEdges().isEmpty()); } }
@Test @SuppressWarnings("unchecked") public void testExecuteCheckFailed() { final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations() .addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID)); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS); CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext); assertEquals(CommandResult.Type.ERROR, result.getType()); assertTrue(parent.getOutEdges().isEmpty()); assertTrue(candidate.getInEdges().isEmpty()); } }
private String getFileName() { final Path path = getSession().getCanvasHandler().getDiagram().getMetadata().getPath(); return null != path ? path.getFileName() : getSession().getCanvasHandler().getDiagram().getGraph().getUUID(); } }
@Test @SuppressWarnings("unchecked") public void testExecuteCheckFailed() { final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations() .addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID)); when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS); CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext); assertEquals(CommandResult.Type.ERROR, result.getType()); assertTrue(parent.getOutEdges().isEmpty()); assertTrue(candidate.getInEdges().isEmpty()); } }
@Test public void testBuild() { final Graph<DefinitionSet, Node> graph = tested.build(UUID, ID); assertNotNull(graph); assertEquals(UUID, graph.getUUID()); assertEquals(1, graph.getLabels().size()); assertTrue(graph.getLabels().contains(ID)); } }