Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBPM-9276 - Stunner Empty ErrorRef for the Error Start Event produces build errors #3386

Merged
merged 2 commits into from Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -46,6 +46,8 @@
import org.kie.workbench.common.stunner.bpmn.definition.property.event.timer.TimerSettings;
import org.kie.workbench.common.stunner.bpmn.definition.property.event.timer.TimerSettingsValue;
import org.kie.workbench.common.stunner.bpmn.definition.property.general.SLADueDate;
import org.kie.workbench.common.stunner.core.util.StringUtils;
import org.kie.workbench.common.stunner.core.util.UUID;

import static org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2;
import static org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.Scripts.asCData;
Expand Down Expand Up @@ -110,15 +112,18 @@ public void addError(ErrorRef errorRef) {
addEventDefinition(errorEventDefinition);

String errorCode = errorRef.getValue();
if (errorCode == null || errorCode.isEmpty()) {
return;
String errorId;
if (StringUtils.nonEmpty(errorCode)) {
error.setErrorCode(errorCode);
CustomAttribute.errorName.of(errorEventDefinition).set(errorCode);
errorId = errorCode;
} else {
errorId = UUID.uuid();
}

error.setId(errorCode);
error.setErrorCode(errorCode);
error.setId(errorId);
errorEventDefinition.setErrorRef(error);

CustomAttribute.errorName.of(errorEventDefinition).set(errorCode);
addRootElement(error);
}

Expand Down
Expand Up @@ -19,30 +19,40 @@
import java.util.HashSet;

import bpsim.ElementParameters;
import org.eclipse.bpmn2.CatchEvent;
import org.eclipse.bpmn2.ErrorEventDefinition;
import org.eclipse.bpmn2.StartEvent;
import org.junit.Before;
import org.junit.Test;
import org.kie.workbench.common.stunner.bpmn.definition.property.simulation.SimulationAttributeSet;

import static org.junit.Assert.assertEquals;
import static org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2;
import static org.mockito.Mockito.spy;

public class CatchEventPropertyWriterTest {
public class CatchEventPropertyWriterTest extends EventPropertyWriterTest {

@Test
public void simulationSetMustHaveElementRef() {
String elementId = "MY_ID";
StartEvent startEvent = bpmn2.createStartEvent();
startEvent.setId(elementId);

CatchEventPropertyWriter p =
new CatchEventPropertyWriter(
startEvent,
new FlatVariableScope(), new HashSet<>());
@Before
public void init() {
event = bpmn2.createStartEvent();
event.setId(elementId);
propertyWriter = spy(new CatchEventPropertyWriter((StartEvent) event,
new FlatVariableScope(),
new HashSet<>()));
}

@Test
public void testSimulationSetMustHaveElementRef() {
CatchEventPropertyWriter catchEventPropertyWriter = (CatchEventPropertyWriter) propertyWriter;
SimulationAttributeSet defaults = new SimulationAttributeSet();
p.setSimulationSet(defaults);
catchEventPropertyWriter.setSimulationSet(defaults);

ElementParameters simulationParameters = p.getSimulationParameters();
ElementParameters simulationParameters = catchEventPropertyWriter.getSimulationParameters();
assertEquals(elementId, simulationParameters.getElementRef());
}

@Override
public ErrorEventDefinition getErrorDefinition() {
return (ErrorEventDefinition) ((CatchEvent)event).getEventDefinitions().get(0);
}
}
@@ -0,0 +1,78 @@
/*
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties;

import org.eclipse.bpmn2.Error;
import org.eclipse.bpmn2.ErrorEventDefinition;
import org.eclipse.bpmn2.Event;
import org.eclipse.bpmn2.RootElement;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.stunner.bpmn.definition.property.event.error.ErrorRef;
import org.mockito.ArgumentCaptor;
import org.mockito.runners.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public abstract class EventPropertyWriterTest {

protected Event event;
protected final static String ERROR_CODE = "ERROR_CODE";
protected final static String elementId = "MY_ID";
protected EventPropertyWriter propertyWriter;

@Test
public void testAddEmptyError() {
final ArgumentCaptor<RootElement> captor = ArgumentCaptor.forClass(RootElement.class);

ErrorRef errorRef = new ErrorRef();
propertyWriter.addError(errorRef);
ErrorEventDefinition definition = getErrorDefinition();
assertNull(definition.getErrorRef().getErrorCode());
assertFalse(definition.getErrorRef().getId().isEmpty());

verify(propertyWriter).addRootElement(captor.capture());
Error error = (Error) captor.getValue();

assertNull(error.getErrorCode());
assertFalse(error.getId().isEmpty());
}

public abstract ErrorEventDefinition getErrorDefinition();

@Test
public void testAddError() {
final ArgumentCaptor<RootElement> captor = ArgumentCaptor.forClass(RootElement.class);

ErrorRef errorRef = new ErrorRef();
errorRef.setValue(ERROR_CODE);
propertyWriter.addError(errorRef);
ErrorEventDefinition definition = getErrorDefinition();
assertEquals(ERROR_CODE, definition.getErrorRef().getErrorCode());
assertFalse(definition.getErrorRef().getId().isEmpty());

verify(propertyWriter).addRootElement(captor.capture());
Error error = (Error) captor.getValue();

assertEquals(ERROR_CODE, error.getErrorCode());
assertFalse(error.getId().isEmpty());
}
}
@@ -0,0 +1,44 @@
/*
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties;

import java.util.HashSet;

import org.eclipse.bpmn2.EndEvent;
import org.eclipse.bpmn2.ErrorEventDefinition;
import org.eclipse.bpmn2.ThrowEvent;
import org.junit.Before;

import static org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2;
import static org.mockito.Mockito.spy;

public class ThrowEventPropertyWriterTest extends EventPropertyWriterTest {

@Before
public void init() {
event = bpmn2.createEndEvent();
event.setId(elementId);
propertyWriter = spy(new ThrowEventPropertyWriter((EndEvent) event,
new FlatVariableScope(),
new HashSet<>()));
}

@Override
public ErrorEventDefinition getErrorDefinition() {
return (ErrorEventDefinition) ((ThrowEvent) event).getEventDefinitions().get(0);
}
}
Expand Up @@ -47,6 +47,8 @@
import org.kie.workbench.common.stunner.bpmn.definition.property.event.timer.TimerSettings;
import org.kie.workbench.common.stunner.bpmn.definition.property.event.timer.TimerSettingsValue;
import org.kie.workbench.common.stunner.bpmn.definition.property.general.SLADueDate;
import org.kie.workbench.common.stunner.core.util.StringUtils;
import org.kie.workbench.common.stunner.core.util.UUID;

import static org.kie.workbench.common.stunner.bpmn.client.marshall.converters.fromstunner.Factories.bpmn2;
import static org.kie.workbench.common.stunner.bpmn.client.marshall.converters.tostunner.properties.Scripts.asCData;
Expand Down Expand Up @@ -118,15 +120,18 @@ public void addError(ErrorRef errorRef) {
addEventDefinition(errorEventDefinition);

String errorCode = errorRef.getValue();
if (errorCode == null || errorCode.isEmpty()) {
return;
String errorId;
if (StringUtils.nonEmpty(errorCode)) {
error.setErrorCode(errorCode);
CustomAttribute.errorName.of(errorEventDefinition).set(errorCode);
errorId = errorCode;
} else {
errorId = UUID.uuid();
}

error.setId(errorCode);
error.setErrorCode(errorCode);
error.setId(errorId);
errorEventDefinition.setErrorRef(error);

CustomAttribute.errorName.of(errorEventDefinition).set(errorCode);
addRootElement(error);
}

Expand Down
Expand Up @@ -19,31 +19,42 @@
import java.util.HashSet;

import bpsim.ElementParameters;
import org.eclipse.bpmn2.ErrorEventDefinition;
import org.eclipse.bpmn2.StartEvent;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.stunner.bpmn.definition.property.simulation.SimulationAttributeSet;
import org.mockito.runners.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.kie.workbench.common.stunner.bpmn.client.marshall.converters.fromstunner.Factories.bpmn2;

public class CatchEventPropertyWriterTest {
import static org.mockito.Mockito.spy;

@RunWith(MockitoJUnitRunner.class)
public class CatchEventPropertyWriterTest extends EventPropertyWriterTest {

@Before
public void init() {
event = bpmn2.createStartEvent();
event.setId(elementId);
propertyWriter = spy(new CatchEventPropertyWriter((StartEvent) event,
new FlatVariableScope(),
new HashSet<>()));
}

@Test
public void simulationSetMustHaveElementRef() {
String elementId = "MY_ID";
StartEvent startEvent = bpmn2.createStartEvent();
startEvent.setId(elementId);

CatchEventPropertyWriter p =
new CatchEventPropertyWriter(
startEvent,
new FlatVariableScope(),
new HashSet<>());

SimulationAttributeSet defaults = new SimulationAttributeSet();
p.setSimulationSet(defaults);
CatchEventPropertyWriter catchEventPropertyWriter = (CatchEventPropertyWriter) propertyWriter;
catchEventPropertyWriter.setSimulationSet(defaults);

ElementParameters simulationParameters = p.getSimulationParameters();
ElementParameters simulationParameters = propertyWriter.getSimulationParameters();
assertEquals(elementId, simulationParameters.getElementRef());
}

@Override
public ErrorEventDefinition getErrorDefinition() {
return (ErrorEventDefinition) ((StartEvent) event).getEventDefinitions().get(0);
}
}