Search in sources :

Example 11 with DefaultRuleViolations

use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.

the class SetChildNodeCommandTest method testExecuteCheckFailed.

@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());
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Test(org.junit.Test)

Example 12 with DefaultRuleViolations

use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.

the class SetParentNodeCommandTest method testNotAllowed.

@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());
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Test(org.junit.Test)

Example 13 with DefaultRuleViolations

use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshallerTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    // Graph utils.
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.registry()).thenReturn(adapterRegistry);
    // initApplicationFactoryManagerAlt();
    when(rulesManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(new DefaultRuleViolations());
    DefinitionUtils definitionUtils = new DefinitionUtils(definitionManager, applicationFactoryManager);
    TestScopeModelFactory testScopeModelFactory = new TestScopeModelFactory(new BPMNDefinitionSet.BPMNDefinitionSetBuilder().build());
    // Definition manager.
    final BackendDefinitionAdapter definitionAdapter = new BackendDefinitionAdapter(definitionUtils);
    final BackendDefinitionSetAdapter definitionSetAdapter = new BackendDefinitionSetAdapter(definitionAdapter);
    final BackendPropertySetAdapter propertySetAdapter = new BackendPropertySetAdapter();
    final BackendPropertyAdapter propertyAdapter = new BackendPropertyAdapter();
    mockAdapterManager(definitionAdapter, definitionSetAdapter, propertySetAdapter, propertyAdapter);
    mockAdapterRegistry(definitionAdapter, definitionSetAdapter, propertySetAdapter, propertyAdapter);
    applicationFactoryManager = new MockApplicationFactoryManager(definitionManager, new GraphFactoryImpl(definitionManager), testScopeModelFactory, new EdgeFactoryImpl(definitionManager), new NodeFactoryImpl(definitionUtils));
    GraphCommandManagerImpl commandManager = new GraphCommandManagerImpl(null, null, null);
    GraphCommandFactory commandFactory = new GraphCommandFactory();
    // The tested BPMN marshaller.
    tested = new BPMNDirectDiagramMarshaller(new XMLEncoderDiagramMetadataMarshaller(), definitionManager, rulesManager, applicationFactoryManager, commandFactory, commandManager);
}
Also used : BackendPropertySetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertySetAdapter) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) BackendPropertyAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertyAdapter) NodeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.NodeFactoryImpl) BackendDefinitionAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionAdapter) GraphFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.GraphFactoryImpl) GraphCommandManagerImpl(org.kie.workbench.common.stunner.core.graph.command.GraphCommandManagerImpl) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) TestScopeModelFactory(org.kie.workbench.common.stunner.backend.definition.factory.TestScopeModelFactory) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) EdgeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.EdgeFactoryImpl) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) BPMNDirectDiagramMarshaller(org.kie.workbench.common.stunner.bpmn.backend.BPMNDirectDiagramMarshaller) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) BackendDefinitionSetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionSetAdapter) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) Before(org.junit.Before)

Example 14 with DefaultRuleViolations

use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.

the class MigrationDiagramMarshallerTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    definitionManager = mock(DefinitionManager.class);
    adapterManager = mock(AdapterManager.class);
    adapterRegistry = mock(AdapterRegistry.class);
    rulesManager = mock(RuleManager.class);
    cloneManager = mock(CloneManager.class);
    // Graph utils.
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.registry()).thenReturn(adapterRegistry);
    DefinitionUtils definitionUtils1 = new DefinitionUtils(definitionManager, applicationFactoryManager);
    testScopeModelFactory = new TestScopeModelFactory(new BPMNDefinitionSet.BPMNDefinitionSetBuilder().build());
    // Definition manager.
    final BackendDefinitionAdapter definitionAdapter = new BackendDefinitionAdapter(definitionUtils1);
    final BackendDefinitionSetAdapter definitionSetAdapter = new BackendDefinitionSetAdapter(definitionAdapter);
    final BackendPropertySetAdapter propertySetAdapter = new BackendPropertySetAdapter();
    final BackendPropertyAdapter propertyAdapter = new BackendPropertyAdapter();
    when(adapterManager.forDefinitionSet()).thenReturn(definitionSetAdapter);
    when(adapterManager.forDefinition()).thenReturn(definitionAdapter);
    when(adapterManager.forPropertySet()).thenReturn(propertySetAdapter);
    when(adapterManager.forProperty()).thenReturn(propertyAdapter);
    when(adapterRegistry.getDefinitionSetAdapter(any(Class.class))).thenReturn(definitionSetAdapter);
    when(adapterRegistry.getDefinitionAdapter(any(Class.class))).thenReturn(definitionAdapter);
    when(adapterRegistry.getPropertySetAdapter(any(Class.class))).thenReturn(propertySetAdapter);
    when(adapterRegistry.getPropertyAdapter(any(Class.class))).thenReturn(propertyAdapter);
    GraphCommandManager commandManager1 = new GraphCommandManagerImpl(null, null, null);
    GraphCommandFactory commandFactory1 = new GraphCommandFactory();
    connectionEdgeFactory = new EdgeFactoryImpl(definitionManager);
    viewNodeFactory = new NodeFactoryImpl(definitionUtils1);
    bpmnGraphFactory = new GraphFactoryImpl(definitionManager);
    doAnswer(invocationOnMock -> {
        String id = (String) invocationOnMock.getArguments()[0];
        return testScopeModelFactory.build(id);
    }).when(applicationFactoryManager).newDefinition(anyString());
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        String id = (String) invocationOnMock.getArguments()[1];
        if (BPMNDefinitionSet.class.getName().equals(id)) {
            return bpmnGraphFactory.build(uuid, BPMN_DEF_SET_ID);
        }
        Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
        if (null != model) {
            Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
            if (element.isAssignableFrom(NodeFactory.class)) {
                return viewNodeFactory.build(uuid, model);
            } else if (element.isAssignableFrom(EdgeFactory.class)) {
                return connectionEdgeFactory.build(uuid, model);
            }
        }
        return null;
    }).when(applicationFactoryManager).newElement(anyString(), anyString());
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        Class type = (Class) invocationOnMock.getArguments()[1];
        String id = BindableAdapterUtils.getGenericClassName(type);
        if (BPMNDefinitionSet.class.equals(type)) {
            return bpmnGraphFactory.build(uuid, BPMN_DEF_SET_ID);
        }
        Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
        if (null != model) {
            Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
            if (element.isAssignableFrom(NodeFactory.class)) {
                return viewNodeFactory.build(uuid, model);
            } else if (element.isAssignableFrom(EdgeFactory.class)) {
                return connectionEdgeFactory.build(uuid, model);
            }
        }
        return null;
    }).when(applicationFactoryManager).newElement(anyString(), any(Class.class));
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        String defSetId = (String) invocationOnMock.getArguments()[1];
        final Graph graph = (Graph) applicationFactoryManager.newElement(uuid, defSetId);
        final DiagramImpl result = new DiagramImpl(uuid, new MetadataImpl.MetadataImplBuilder(defSetId).build());
        result.setGraph(graph);
        return result;
    }).when(applicationFactoryManager).newDiagram(anyString(), anyString(), any(Metadata.class));
    // Work items stuff.
    workItemDefinitionMockRegistry = new WorkItemDefinitionMockRegistry();
    // Bpmn 2 oryx stuff.
    Bpmn2OryxIdMappings oryxIdMappings = new Bpmn2OryxIdMappings(definitionManager, () -> workItemDefinitionMockRegistry);
    StringTypeSerializer stringTypeSerializer = new StringTypeSerializer();
    BooleanTypeSerializer booleanTypeSerializer = new BooleanTypeSerializer();
    ColorTypeSerializer colorTypeSerializer = new ColorTypeSerializer();
    DoubleTypeSerializer doubleTypeSerializer = new DoubleTypeSerializer();
    IntegerTypeSerializer integerTypeSerializer = new IntegerTypeSerializer();
    EnumTypeSerializer enumTypeSerializer = new EnumTypeSerializer(definitionUtils1);
    AssignmentsTypeSerializer assignmentsTypeSerializer = new AssignmentsTypeSerializer();
    VariablesTypeSerializer variablesTypeSerializer = new VariablesTypeSerializer();
    TimerSettingsTypeSerializer timerSettingsTypeSerializer = new TimerSettingsTypeSerializer();
    ScriptTypeTypeSerializer scriptTypeTypeSerializer = new ScriptTypeTypeSerializer();
    ScriptTypeListTypeSerializer scriptTypeListTypeSerializer = new ScriptTypeListTypeSerializer();
    TaskTypeSerializer taskTypeSerializer = new TaskTypeSerializer(definitionUtils1, enumTypeSerializer);
    List<Bpmn2OryxPropertySerializer<?>> propertySerializers = new LinkedList<>();
    propertySerializers.add(stringTypeSerializer);
    propertySerializers.add(booleanTypeSerializer);
    propertySerializers.add(colorTypeSerializer);
    propertySerializers.add(doubleTypeSerializer);
    propertySerializers.add(integerTypeSerializer);
    propertySerializers.add(enumTypeSerializer);
    propertySerializers.add(assignmentsTypeSerializer);
    propertySerializers.add(variablesTypeSerializer);
    propertySerializers.add(timerSettingsTypeSerializer);
    propertySerializers.add(scriptTypeTypeSerializer);
    propertySerializers.add(scriptTypeListTypeSerializer);
    propertySerializers.add(taskTypeSerializer);
    Bpmn2OryxPropertyManager oryxPropertyManager = new Bpmn2OryxPropertyManager(propertySerializers);
    Bpmn2OryxManager oryxManager = new Bpmn2OryxManager(oryxIdMappings, oryxPropertyManager);
    oryxManager.init();
    // Marshalling factories.
    BPMNGraphObjectBuilderFactory objectBuilderFactory = new BPMNGraphObjectBuilderFactory(definitionManager, oryxManager, () -> workItemDefinitionMockRegistry);
    taskMorphDefinition = new TaskTypeMorphDefinition();
    Collection<MorphDefinition> morphDefinitions = new ArrayList<MorphDefinition>() {

        {
            add(taskMorphDefinition);
        }
    };
    BackendBindableMorphAdapter<Object> morphAdapter = new BackendBindableMorphAdapter(definitionUtils1, applicationFactoryManager, cloneManager, morphDefinitions);
    when(adapterRegistry.getMorphAdapter(eq(UserTask.class))).thenReturn(morphAdapter);
    when(adapterRegistry.getMorphAdapter(eq(NoneTask.class))).thenReturn(morphAdapter);
    when(adapterRegistry.getMorphAdapter(eq(ScriptTask.class))).thenReturn(morphAdapter);
    when(adapterRegistry.getMorphAdapter(eq(BusinessRuleTask.class))).thenReturn(morphAdapter);
    GraphIndexBuilder<?> indexBuilder = new MapIndexBuilder();
    when(rulesManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(new DefaultRuleViolations());
    // The work item definition registry.
    WorkItemDefinitionBackendRegistry widRegistry = mock(WorkItemDefinitionBackendRegistry.class);
    when(widRegistry.getRegistry()).thenReturn(workItemDefinitionMockRegistry);
    when(widRegistry.items()).thenReturn(workItemDefinitionMockRegistry.items());
    when(widRegistry.load(any(Metadata.class))).thenReturn(widRegistry);
    doAnswer(invocationOnMock -> workItemDefinitionMockRegistry.get((String) invocationOnMock.getArguments()[0])).when(widRegistry).get(anyString());
    // The tested BPMN marshaller.
    oldMarshaller = new BPMNDiagramMarshaller(new XMLEncoderDiagramMetadataMarshaller(), objectBuilderFactory, definitionManager, indexBuilder, oryxManager, applicationFactoryManager, rulesManager, commandManager1, commandFactory1, widRegistry);
    // Graph utils.
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.registry()).thenReturn(adapterRegistry);
    // initApplicationFactoryManagerAlt();
    when(rulesManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(new DefaultRuleViolations());
    DefinitionUtils definitionUtils = new DefinitionUtils(definitionManager, applicationFactoryManager);
    TestScopeModelFactory testScopeModelFactory = new TestScopeModelFactory(new BPMNDefinitionSet.BPMNDefinitionSetBuilder().build());
    // Definition manager.
    mockAdapterManager(definitionAdapter, definitionSetAdapter, propertySetAdapter, propertyAdapter);
    mockAdapterRegistry(definitionAdapter, definitionSetAdapter, propertySetAdapter, propertyAdapter);
    applicationFactoryManager = new MockApplicationFactoryManager(definitionManager, new GraphFactoryImpl(definitionManager), testScopeModelFactory, new EdgeFactoryImpl(definitionManager), new NodeFactoryImpl(definitionUtils));
    GraphCommandManagerImpl commandManager = new GraphCommandManagerImpl(null, null, null);
    GraphCommandFactory commandFactory = new GraphCommandFactory();
    // The tested BPMN marshaller.
    newMarshaller = new BPMNDirectDiagramMarshaller(new XMLEncoderDiagramMetadataMarshaller(), definitionManager, rulesManager, applicationFactoryManager, commandFactory, commandManager);
}
Also used : BackendPropertyAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertyAdapter) NodeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.NodeFactoryImpl) BackendDefinitionAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionAdapter) ArrayList(java.util.ArrayList) GraphFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.GraphFactoryImpl) Matchers.anyString(org.mockito.Matchers.anyString) AdapterRegistry(org.kie.workbench.common.stunner.core.registry.definition.AdapterRegistry) BackendBindableMorphAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.bind.BackendBindableMorphAdapter) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) ScriptTypeListTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer) BackendPropertySetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertySetAdapter) CloneManager(org.kie.workbench.common.stunner.core.definition.clone.CloneManager) Bpmn2OryxPropertyManager(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.Bpmn2OryxPropertyManager) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) NoneTask(org.kie.workbench.common.stunner.bpmn.definition.NoneTask) GraphCommandManager(org.kie.workbench.common.stunner.core.graph.command.GraphCommandManager) LinkedList(java.util.LinkedList) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) Bpmn2OryxPropertySerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.Bpmn2OryxPropertySerializer) Graph(org.kie.workbench.common.stunner.core.graph.Graph) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) BPMNGraphObjectBuilderFactory(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.builder.BPMNGraphObjectBuilderFactory) EdgeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.EdgeFactoryImpl) EdgeFactory(org.kie.workbench.common.stunner.core.factory.graph.EdgeFactory) TaskTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.TaskTypeSerializer) Bpmn2OryxManager(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager) DoubleTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.DoubleTypeSerializer) ColorTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ColorTypeSerializer) MapIndexBuilder(org.kie.workbench.common.stunner.core.graph.processing.index.map.MapIndexBuilder) BPMNDefinitionSet(org.kie.workbench.common.stunner.bpmn.BPMNDefinitionSet) WorkItemDefinitionBackendRegistry(org.kie.workbench.common.stunner.bpmn.backend.workitem.WorkItemDefinitionBackendRegistry) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BusinessRuleTask(org.kie.workbench.common.stunner.bpmn.definition.BusinessRuleTask) Bpmn2OryxIdMappings(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxIdMappings) ScriptTypeTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeTypeSerializer) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) TimerSettingsTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.TimerSettingsTypeSerializer) EnumTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.EnumTypeSerializer) BackendDefinitionSetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionSetAdapter) StringTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.StringTypeSerializer) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) GraphCommandManagerImpl(org.kie.workbench.common.stunner.core.graph.command.GraphCommandManagerImpl) TestScopeModelFactory(org.kie.workbench.common.stunner.backend.definition.factory.TestScopeModelFactory) IntegerTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.IntegerTypeSerializer) AssignmentsTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.AssignmentsTypeSerializer) VariablesTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.VariablesTypeSerializer) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) BPMNDirectDiagramMarshaller(org.kie.workbench.common.stunner.bpmn.backend.BPMNDirectDiagramMarshaller) BPMNDiagramMarshaller(org.kie.workbench.common.stunner.bpmn.backend.BPMNDiagramMarshaller) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) BooleanTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.BooleanTypeSerializer) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) Before(org.junit.Before)

Example 15 with DefaultRuleViolations

use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.

the class BPMNDiagramMarshallerTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    // Work Items.
    workItemDefinitionMockRegistry = new WorkItemDefinitionMockRegistry();
    // Graph utils.
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.registry()).thenReturn(adapterRegistry);
    definitionUtils = new DefinitionUtils(definitionManager, applicationFactoryManager);
    testScopeModelFactory = new BPMNTestScopeModelFactory(new BPMNDefinitionSet.BPMNDefinitionSetBuilder().build(), workItemDefinitionMockRegistry);
    // Definition manager.
    final BackendDefinitionAdapter definitionAdapter = new BackendDefinitionAdapter(definitionUtils);
    final BackendDefinitionSetAdapter definitionSetAdapter = new BackendDefinitionSetAdapter(definitionAdapter);
    final BackendPropertySetAdapter propertySetAdapter = new BackendPropertySetAdapter();
    final BackendPropertyAdapter propertyAdapter = new BackendPropertyAdapter();
    when(adapterManager.forDefinitionSet()).thenReturn(definitionSetAdapter);
    when(adapterManager.forDefinition()).thenReturn(definitionAdapter);
    when(adapterManager.forPropertySet()).thenReturn(propertySetAdapter);
    when(adapterManager.forProperty()).thenReturn(propertyAdapter);
    when(adapterRegistry.getDefinitionSetAdapter(any(Class.class))).thenReturn(definitionSetAdapter);
    when(adapterRegistry.getDefinitionAdapter(any(Class.class))).thenReturn(definitionAdapter);
    when(adapterRegistry.getPropertySetAdapter(any(Class.class))).thenReturn(propertySetAdapter);
    when(adapterRegistry.getPropertyAdapter(any(Class.class))).thenReturn(propertyAdapter);
    commandManager = new GraphCommandManagerImpl(null, null, null);
    commandFactory = new GraphCommandFactory();
    connectionEdgeFactory = new EdgeFactoryImpl(definitionManager);
    viewNodeFactory = new NodeFactoryImpl(definitionUtils);
    bpmnGraphFactory = new GraphFactoryImpl(definitionManager);
    doAnswer(invocationOnMock -> {
        String id = (String) invocationOnMock.getArguments()[0];
        return testScopeModelFactory.build(id);
    }).when(applicationFactoryManager).newDefinition(anyString());
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        String id = (String) invocationOnMock.getArguments()[1];
        if (BPMNDefinitionSet.class.getName().equals(id)) {
            Graph graph = (Graph) bpmnGraphFactory.build(uuid, BPMN_DEF_SET_ID);
            return graph;
        }
        Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
        if (null != model) {
            Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
            if (element.isAssignableFrom(NodeFactory.class)) {
                Node node = viewNodeFactory.build(uuid, model);
                return node;
            } else if (element.isAssignableFrom(EdgeFactory.class)) {
                Edge edge = connectionEdgeFactory.build(uuid, model);
                return edge;
            }
        }
        return null;
    }).when(applicationFactoryManager).newElement(anyString(), anyString());
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        Class type = (Class) invocationOnMock.getArguments()[1];
        String id = BindableAdapterUtils.getGenericClassName(type);
        if (BPMNDefinitionSet.class.equals(type)) {
            Graph graph = (Graph) bpmnGraphFactory.build(uuid, BPMN_DEF_SET_ID);
            return graph;
        }
        Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
        if (null != model) {
            Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
            if (element.isAssignableFrom(NodeFactory.class)) {
                Node node = viewNodeFactory.build(uuid, model);
                return node;
            } else if (element.isAssignableFrom(EdgeFactory.class)) {
                Edge edge = connectionEdgeFactory.build(uuid, model);
                return edge;
            }
        }
        return null;
    }).when(applicationFactoryManager).newElement(anyString(), any(Class.class));
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        String defSetId = (String) invocationOnMock.getArguments()[1];
        final Graph graph = (Graph) applicationFactoryManager.newElement(uuid, defSetId);
        final DiagramImpl result = new DiagramImpl(uuid, new MetadataImpl.MetadataImplBuilder(defSetId).build());
        result.setGraph(graph);
        return result;
    }).when(applicationFactoryManager).newDiagram(anyString(), anyString(), any(Metadata.class));
    // Bpmn 2 oryx stuff.
    oryxIdMappings = new Bpmn2OryxIdMappings(definitionManager, () -> workItemDefinitionMockRegistry);
    StringTypeSerializer stringTypeSerializer = new StringTypeSerializer();
    BooleanTypeSerializer booleanTypeSerializer = new BooleanTypeSerializer();
    ColorTypeSerializer colorTypeSerializer = new ColorTypeSerializer();
    DoubleTypeSerializer doubleTypeSerializer = new DoubleTypeSerializer();
    IntegerTypeSerializer integerTypeSerializer = new IntegerTypeSerializer();
    EnumTypeSerializer enumTypeSerializer = new EnumTypeSerializer(definitionUtils);
    AssignmentsTypeSerializer assignmentsTypeSerializer = new AssignmentsTypeSerializer();
    VariablesTypeSerializer variablesTypeSerializer = new VariablesTypeSerializer();
    TimerSettingsTypeSerializer timerSettingsTypeSerializer = new TimerSettingsTypeSerializer();
    ScriptTypeTypeSerializer scriptTypeTypeSerializer = new ScriptTypeTypeSerializer();
    ScriptTypeListTypeSerializer scriptTypeListTypeSerializer = new ScriptTypeListTypeSerializer();
    TaskTypeSerializer taskTypeSerializer = new TaskTypeSerializer(definitionUtils, enumTypeSerializer);
    List<Bpmn2OryxPropertySerializer<?>> propertySerializers = new LinkedList<>();
    propertySerializers.add(stringTypeSerializer);
    propertySerializers.add(booleanTypeSerializer);
    propertySerializers.add(colorTypeSerializer);
    propertySerializers.add(doubleTypeSerializer);
    propertySerializers.add(integerTypeSerializer);
    propertySerializers.add(enumTypeSerializer);
    propertySerializers.add(assignmentsTypeSerializer);
    propertySerializers.add(variablesTypeSerializer);
    propertySerializers.add(timerSettingsTypeSerializer);
    propertySerializers.add(scriptTypeTypeSerializer);
    propertySerializers.add(scriptTypeListTypeSerializer);
    propertySerializers.add(taskTypeSerializer);
    oryxPropertyManager = new Bpmn2OryxPropertyManager(propertySerializers);
    oryxManager = new Bpmn2OryxManager(oryxIdMappings, oryxPropertyManager);
    oryxManager.init();
    // Marshalling factories.
    objectBuilderFactory = new BPMNGraphObjectBuilderFactory(definitionManager, oryxManager, () -> workItemDefinitionMockRegistry);
    taskMorphDefinition = new TaskTypeMorphDefinition();
    Collection<MorphDefinition> morphDefinitions = new ArrayList<MorphDefinition>() {

        {
            add(taskMorphDefinition);
        }
    };
    BackendBindableMorphAdapter<Object> morphAdapter = new BackendBindableMorphAdapter(definitionUtils, applicationFactoryManager, cloneManager, morphDefinitions);
    when(adapterRegistry.getMorphAdapter(eq(UserTask.class))).thenReturn(morphAdapter);
    when(adapterRegistry.getMorphAdapter(eq(NoneTask.class))).thenReturn(morphAdapter);
    when(adapterRegistry.getMorphAdapter(eq(ScriptTask.class))).thenReturn(morphAdapter);
    when(adapterRegistry.getMorphAdapter(eq(BusinessRuleTask.class))).thenReturn(morphAdapter);
    GraphIndexBuilder<?> indexBuilder = new MapIndexBuilder();
    when(rulesManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(new DefaultRuleViolations());
    // The work item definition registry.
    WorkItemDefinitionBackendRegistry widRegistry = mock(WorkItemDefinitionBackendRegistry.class);
    when(widRegistry.getRegistry()).thenReturn(workItemDefinitionMockRegistry);
    when(widRegistry.items()).thenReturn(workItemDefinitionMockRegistry.items());
    when(widRegistry.load(any(Metadata.class))).thenReturn(widRegistry);
    doAnswer(invocationOnMock -> workItemDefinitionMockRegistry.get((String) invocationOnMock.getArguments()[0])).when(widRegistry).get(anyString());
    // The tested BPMN marshaller.
    tested = new BPMNDiagramMarshaller(new XMLEncoderDiagramMetadataMarshaller(), objectBuilderFactory, definitionManager, indexBuilder, oryxManager, applicationFactoryManager, rulesManager, commandManager, commandFactory, widRegistry);
}
Also used : BackendPropertyAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertyAdapter) NodeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.NodeFactoryImpl) BackendDefinitionAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionAdapter) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) GraphFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.GraphFactoryImpl) Matchers.anyString(org.mockito.Matchers.anyString) BackendBindableMorphAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.bind.BackendBindableMorphAdapter) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) ScriptTypeListTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer) BackendPropertySetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertySetAdapter) Bpmn2OryxPropertyManager(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.Bpmn2OryxPropertyManager) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) NoneTask(org.kie.workbench.common.stunner.bpmn.definition.NoneTask) LinkedList(java.util.LinkedList) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) Bpmn2OryxPropertySerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.Bpmn2OryxPropertySerializer) Graph(org.kie.workbench.common.stunner.core.graph.Graph) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) BPMNGraphObjectBuilderFactory(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.builder.BPMNGraphObjectBuilderFactory) EdgeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.EdgeFactoryImpl) EdgeFactory(org.kie.workbench.common.stunner.core.factory.graph.EdgeFactory) TaskTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.TaskTypeSerializer) Bpmn2OryxManager(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager) DoubleTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.DoubleTypeSerializer) ColorTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ColorTypeSerializer) MapIndexBuilder(org.kie.workbench.common.stunner.core.graph.processing.index.map.MapIndexBuilder) BPMNDefinitionSet(org.kie.workbench.common.stunner.bpmn.BPMNDefinitionSet) WorkItemDefinitionBackendRegistry(org.kie.workbench.common.stunner.bpmn.backend.workitem.WorkItemDefinitionBackendRegistry) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BusinessRuleTask(org.kie.workbench.common.stunner.bpmn.definition.BusinessRuleTask) Bpmn2OryxIdMappings(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxIdMappings) ScriptTypeTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeTypeSerializer) TimerSettingsTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.TimerSettingsTypeSerializer) EnumTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.EnumTypeSerializer) BackendDefinitionSetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionSetAdapter) StringTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.StringTypeSerializer) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) GraphCommandManagerImpl(org.kie.workbench.common.stunner.core.graph.command.GraphCommandManagerImpl) IntegerTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.IntegerTypeSerializer) AssignmentsTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.AssignmentsTypeSerializer) VariablesTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.VariablesTypeSerializer) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) BPMNDiagramMarshaller(org.kie.workbench.common.stunner.bpmn.backend.BPMNDiagramMarshaller) BooleanTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.BooleanTypeSerializer) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Before(org.junit.Before)

Aggregations

DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)37 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)18 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)18 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)16 Test (org.junit.Test)13 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)13 ContainmentRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)12 Edge (org.kie.workbench.common.stunner.core.graph.Edge)11 Node (org.kie.workbench.common.stunner.core.graph.Node)9 View (org.kie.workbench.common.stunner.core.graph.content.view.View)7 Before (org.junit.Before)5 Graph (org.kie.workbench.common.stunner.core.graph.Graph)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 List (java.util.List)3 TestScopeModelFactory (org.kie.workbench.common.stunner.backend.definition.factory.TestScopeModelFactory)3 BPMNDefinitionSet (org.kie.workbench.common.stunner.bpmn.BPMNDefinitionSet)3 BPMNDiagramMarshaller (org.kie.workbench.common.stunner.bpmn.backend.BPMNDiagramMarshaller)3 BPMNDirectDiagramMarshaller (org.kie.workbench.common.stunner.bpmn.backend.BPMNDirectDiagramMarshaller)3 BPMNGraphObjectBuilderFactory (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.builder.BPMNGraphObjectBuilderFactory)3