method2testcases
stringlengths
118
3.08k
### Question: ProcessTypeProvider extends AbstractProcessFilteredNodeProvider { @Override public String getProviderName() { return getClass().getSimpleName(); } @Inject ProcessTypeProvider(final SessionManager sessionManager); @Override String getProviderName(); @Override Predicate<Node> getFilter(); @Override Function<Node, Pair<Object, String>> getMapper(); @Override @SuppressWarnings("unchecked") SelectorData getSelectorData(final FormRenderingContext context); }### Answer: @Test public void testGetProviderName() { assertEquals(tested.getClass().getSimpleName(), tested.getProviderName()); }
### Question: ProcessTypeProvider extends AbstractProcessFilteredNodeProvider { @Override @SuppressWarnings("unchecked") public SelectorData getSelectorData(final FormRenderingContext context) { return new SelectorData(Arrays.asList(TYPES) .stream() .collect(Collectors.toMap(p -> p, p -> p)), "Public"); } @Inject ProcessTypeProvider(final SessionManager sessionManager); @Override String getProviderName(); @Override Predicate<Node> getFilter(); @Override Function<Node, Pair<Object, String>> getMapper(); @Override @SuppressWarnings("unchecked") SelectorData getSelectorData(final FormRenderingContext context); }### Answer: @Test public void testGetValues() { SelectorData selectorData = tested.getSelectorData(context); assertEquals(2, selectorData.getValues().size()); assertEquals("Public", selectorData.getSelectedValue()); assertTrue(selectorData.getValues().containsValue("Public")); assertTrue(selectorData.getValues().containsValue("Private")); }
### Question: ProcessTypeProvider extends AbstractProcessFilteredNodeProvider { @Override public Predicate<Node> getFilter() { return node -> true; } @Inject ProcessTypeProvider(final SessionManager sessionManager); @Override String getProviderName(); @Override Predicate<Node> getFilter(); @Override Function<Node, Pair<Object, String>> getMapper(); @Override @SuppressWarnings("unchecked") SelectorData getSelectorData(final FormRenderingContext context); }### Answer: @Test public void testGetFilter() { assertTrue(tested.getFilter().test(new NodeImpl("uuid_1"))); }
### Question: ProcessTypeProvider extends AbstractProcessFilteredNodeProvider { @Override public Function<Node, Pair<Object, String>> getMapper() { return null; } @Inject ProcessTypeProvider(final SessionManager sessionManager); @Override String getProviderName(); @Override Predicate<Node> getFilter(); @Override Function<Node, Pair<Object, String>> getMapper(); @Override @SuppressWarnings("unchecked") SelectorData getSelectorData(final FormRenderingContext context); }### Answer: @Test public void testGetMapper() { assertNull(tested.getMapper()); }
### Question: ProcessesDataProvider { void onProcessesUpdatedEvent(final @Observes ProcessDataEvent event) { setProcessIds(toList(event.getProcessIds())); } ProcessesDataProvider(); @Inject ProcessesDataProvider(final StunnerFormsHandler formsHandler); List<String> getProcessIds(); }### Answer: @Test public void testOnProcessesUpdatedEvent() { ProcessDataEvent event = mock(ProcessDataEvent.class); when(event.getProcessIds()).thenReturn(new String[]{"p1", "p2"}); tested.onProcessesUpdatedEvent(event); verify(formsHandler, times(1)).refreshCurrentSessionForms(eq(BPMNDefinitionSet.class)); List<String> values = tested.getProcessIds(); assertNotNull(values); assertEquals(2, values.size()); assertTrue(values.contains("p1")); assertTrue(values.contains("p2")); }
### Question: WorkItemDefinitionClientParser { public static List<WorkItemDefinition> parse(String widStr) { if (empty(widStr)) { return Collections.emptyList(); } List<WorkItemDefinition> widList = new ArrayList<>(); String[] lines = widStr.split("\r\n|\r|\n"); Queue<String> linesQueue = new LinkedList<>(Arrays.asList(lines)); while (!linesQueue.isEmpty()) { String line = linesQueue.peek().trim(); if (!(empty(line) || isStartingObject(line) || isEndingObject(line))) { WorkItemDefinition wid = parseWorkItemDefinitionObject(linesQueue); widList.add(wid); } linesQueue.poll(); } return widList; } static List<WorkItemDefinition> parse(String widStr); }### Answer: @Test public void emptyWidsTest() { List<WorkItemDefinition> defs = WorkItemDefinitionClientParser.parse(""); assertTrue(defs.isEmpty()); defs = WorkItemDefinitionClientParser.parse("[]"); assertTrue(defs.isEmpty()); defs = WorkItemDefinitionClientParser.parse("[\n]"); assertTrue(defs.isEmpty()); defs = WorkItemDefinitionClientParser.parse(null); assertTrue(defs.isEmpty()); }
### Question: BPMNCreateNodeAction extends GeneralCreateNodeAction { public static boolean isAutoMagnetConnection(final Node<View<?>, Edge> sourceNode, final Node<View<?>, Edge> targetNode) { final Object sourceDefinition = null != sourceNode ? sourceNode.getContent().getDefinition() : null; final Object targetDefinition = null != targetNode ? targetNode.getContent().getDefinition() : null; final boolean isSourceGateway = isGateway(sourceDefinition); final boolean isTargetGateway = isGateway(targetDefinition); return !(isSourceGateway || isTargetGateway); } @Inject BPMNCreateNodeAction(final DefinitionUtils definitionUtils, final ClientFactoryManager clientFactoryManager, final CanvasLayoutUtils canvasLayoutUtils, final Event<CanvasSelectionEvent> selectionEvent, final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager, final @Any ManagedInstance<DefaultCanvasCommandFactory> canvasCommandFactories); static boolean isAutoMagnetConnection(final Node<View<?>, Edge> sourceNode, final Node<View<?>, Edge> targetNode); }### Answer: @Test @SuppressWarnings("unchecked") public void testIsAutoConnection() { assertFalse(isAutoMagnetConnection(gatewayNode, taskNode)); assertFalse(isAutoMagnetConnection(gatewayNode, eventNode)); assertFalse(isAutoMagnetConnection(taskNode, gatewayNode)); assertFalse(isAutoMagnetConnection(eventNode, gatewayNode)); assertFalse(isAutoMagnetConnection(gatewayNode, gatewayNode)); assertTrue(isAutoMagnetConnection(taskNode, taskNode)); assertTrue(isAutoMagnetConnection(eventNode, taskNode)); assertTrue(isAutoMagnetConnection(taskNode, eventNode)); assertTrue(isAutoMagnetConnection(eventNode, eventNode)); }
### Question: DecisionComponentsItem { public void show() { HiddenHelper.show(getView().getElement()); } @Inject DecisionComponentsItem(final View view); @PostConstruct void init(); View getView(); void setDecisionComponent(final DecisionComponent decisionComponent); void show(); void hide(); DRGElement getDrgElement(); }### Answer: @Test public void testShow() { final HTMLElement viewElement = mock(HTMLElement.class); when(view.getElement()).thenReturn(viewElement); viewElement.classList = mock(DOMTokenList.class); item.show(); verify(viewElement.classList).remove(HIDDEN_CSS_CLASS); }
### Question: BPMNValidatorImpl implements BPMNValidator { @Override public String getDefinitionSetId() { return BindableAdapterUtils.getDefinitionSetId(BPMNDefinitionSet.class); } BPMNValidatorImpl(); @Inject BPMNValidatorImpl(final @Default DiagramService diagramService); @Override void validate(Diagram diagram, Consumer<Collection<DomainViolation>> resultConsumer); @Override String getDefinitionSetId(); }### Answer: @Test public void getDefinitionSetId() { assertEquals(bpmnValidador.getDefinitionSetId(), BindableAdapterUtils.getDefinitionId(BPMNDefinitionSet.class)); }
### Question: BPMNElementDecorators { public static <T extends FlowElement> MarshallingMessageDecorator<T> flowElementDecorator() { return MarshallingMessageDecorator.of(o -> Optional.ofNullable(o.getName()) .orElseGet(o::getId), g -> g.getClass().getSimpleName()); } static MarshallingMessageDecorator<T> flowElementDecorator(); static MarshallingMessageDecorator<T> baseElementDecorator(); static MarshallingMessageDecorator<T> bpmnNodeDecorator(); static MarshallingMessageDecorator<Result> resultBpmnDecorator(); }### Answer: @Test public void flowElementDecorator() { MarshallingMessageDecorator<FlowElement> decorator = BPMNElementDecorators.flowElementDecorator(); FlowElement element = mock(FlowElement.class); when(element.getName()).thenReturn(NAME); assertEquals(NAME, decorator.getName(element)); assertEquals(element.getClass().getSimpleName(), decorator.getType(element)); }
### Question: BPMNElementDecorators { public static <T extends BaseElement> MarshallingMessageDecorator<T> baseElementDecorator() { return MarshallingMessageDecorator.of(BaseElement::getId, g -> g.getClass().getSimpleName()); } static MarshallingMessageDecorator<T> flowElementDecorator(); static MarshallingMessageDecorator<T> baseElementDecorator(); static MarshallingMessageDecorator<T> bpmnNodeDecorator(); static MarshallingMessageDecorator<Result> resultBpmnDecorator(); }### Answer: @Test public void baseElementDecorator() { MarshallingMessageDecorator<BaseElement> decorator = BPMNElementDecorators.baseElementDecorator(); BaseElement element = mock(FlowElement.class); when(element.getId()).thenReturn(NAME); assertEquals(NAME, decorator.getName(element)); assertEquals(element.getClass().getSimpleName(), decorator.getType(element)); }
### Question: BPMNElementDecorators { public static <T extends BpmnNode> MarshallingMessageDecorator<T> bpmnNodeDecorator() { return MarshallingMessageDecorator.of(o -> Optional.ofNullable(o.value() .getContent() .getDefinition() .getGeneral() .getName() .getValue()) .orElseGet(() -> o.value().getUUID()), bpmnNode -> bpmnNode.value() .getContent() .getDefinition() .getClass() .getSimpleName()); } static MarshallingMessageDecorator<T> flowElementDecorator(); static MarshallingMessageDecorator<T> baseElementDecorator(); static MarshallingMessageDecorator<T> bpmnNodeDecorator(); static MarshallingMessageDecorator<Result> resultBpmnDecorator(); }### Answer: @Test public void bpmnNodeDecorator() { MarshallingMessageDecorator<BpmnNode> decorator = BPMNElementDecorators.bpmnNodeDecorator(); BpmnNode element = mockBpmnNode(); assertEquals(NAME, decorator.getName(element)); assertEquals(element.value().getContent().getDefinition().getClass().getSimpleName(), decorator.getType(element)); }
### Question: BPMNElementDecorators { public static MarshallingMessageDecorator<Result> resultBpmnDecorator() { return MarshallingMessageDecorator.of(r -> { BpmnNode o = (BpmnNode) r.value(); return Optional.ofNullable(o.value() .getContent() .getDefinition() .getGeneral() .getName() .getValue()) .orElseGet(() -> o.value().getUUID()); }, r -> { BpmnNode o1 = (BpmnNode) r.value(); return o1.value() .getContent() .getDefinition() .getClass() .getSimpleName(); }); } static MarshallingMessageDecorator<T> flowElementDecorator(); static MarshallingMessageDecorator<T> baseElementDecorator(); static MarshallingMessageDecorator<T> bpmnNodeDecorator(); static MarshallingMessageDecorator<Result> resultBpmnDecorator(); }### Answer: @Test public void resultBpmnDecorator() { MarshallingMessageDecorator<Result> decorator = BPMNElementDecorators.resultBpmnDecorator(); BpmnNode node = mockBpmnNode(); Result result = Result.success(node); assertEquals(NAME, decorator.getName(result)); assertEquals(node.value().getContent().getDefinition().getClass().getSimpleName(), decorator.getType(result)); }
### Question: Match { public <Sub> Match<In, Out> whenExactly(Class<Sub> type, Function<Sub, Out> then) { Function<Sub, Result<Out>> thenWrapped = sub -> Result.of(then.apply(sub)); return whenExactly_(type, thenWrapped); } Match(Class<?> outputType); static Match<In, Out> of(Class<In> inputType, Class<Out> outputType); static Match<In, Node<? extends View<? extends Out>, ?>> ofNode(Class<In> inputType, Class<Out> outputType); static Match<Node<? extends View<? extends In>, ?>, Out> fromNode(Class<In> inputType, Class<Out> outputType); static Match<In, Edge<? extends View<? extends Out>, ?>> ofEdge(Class<In> inputType, Class<Out> outputType); Match<In, Out> when(Class<Sub> type, Function<Sub, Out> then); Match<In, Out> whenExactly(Class<Sub> type, Function<Sub, Out> then); Match<In, Out> missing(Class<Sub> type); Match<In, Out> ignore(Class<Sub> type); Match<In, Out> ignore(Class<Sub> type, Out outValue); Match<In, Out> orElse(Function<In, Out> then); Match<In, Out> inputDecorator(MarshallingMessageDecorator<In> decorator); Match<In, Out> outputDecorator(MarshallingMessageDecorator<Out> decorator); Match<In, Out> defaultValue(Out value); Match<In, Out> mode(Mode mode); Result<Out> apply(In value); }### Answer: @Test public void whenExactlyTest() { UserTaskImpl element = (UserTaskImpl) Bpmn2Factory.eINSTANCE.createUserTask(); Result<BpmnNode> result = match().apply(element); verify(assertUserTask).apply(element); assertTrue(result.isSuccess()); }
### Question: Match { public <Sub> Match<In, Out> when(Class<Sub> type, Function<Sub, Out> then) { Function<Sub, Result<Out>> thenWrapped = sub -> Result.of(then.apply(sub)); return when_(type, thenWrapped); } Match(Class<?> outputType); static Match<In, Out> of(Class<In> inputType, Class<Out> outputType); static Match<In, Node<? extends View<? extends Out>, ?>> ofNode(Class<In> inputType, Class<Out> outputType); static Match<Node<? extends View<? extends In>, ?>, Out> fromNode(Class<In> inputType, Class<Out> outputType); static Match<In, Edge<? extends View<? extends Out>, ?>> ofEdge(Class<In> inputType, Class<Out> outputType); Match<In, Out> when(Class<Sub> type, Function<Sub, Out> then); Match<In, Out> whenExactly(Class<Sub> type, Function<Sub, Out> then); Match<In, Out> missing(Class<Sub> type); Match<In, Out> ignore(Class<Sub> type); Match<In, Out> ignore(Class<Sub> type, Out outValue); Match<In, Out> orElse(Function<In, Out> then); Match<In, Out> inputDecorator(MarshallingMessageDecorator<In> decorator); Match<In, Out> outputDecorator(MarshallingMessageDecorator<Out> decorator); Match<In, Out> defaultValue(Out value); Match<In, Out> mode(Mode mode); Result<Out> apply(In value); }### Answer: @Test public void whenTest() { EventSubprocess element = Bpmn2Factory.eINSTANCE.createEventSubprocess(); Result<BpmnNode> result = match().apply(element); verify(assertSubProcess).apply(element); assertNotEquals(result.value(), defaultValue); assertTrue(result.isSuccess()); }
### Question: DecisionComponentsItem { public void hide() { HiddenHelper.hide(getView().getElement()); } @Inject DecisionComponentsItem(final View view); @PostConstruct void init(); View getView(); void setDecisionComponent(final DecisionComponent decisionComponent); void show(); void hide(); DRGElement getDrgElement(); }### Answer: @Test public void testHide() { final HTMLElement viewElement = mock(HTMLElement.class); when(view.getElement()).thenReturn(viewElement); viewElement.classList = mock(DOMTokenList.class); item.hide(); verify(viewElement.classList).add(HIDDEN_CSS_CLASS); }
### Question: Match { public <Sub> Match<In, Out> missing(Class<Sub> type) { return when_(type, reportMissing(type)); } Match(Class<?> outputType); static Match<In, Out> of(Class<In> inputType, Class<Out> outputType); static Match<In, Node<? extends View<? extends Out>, ?>> ofNode(Class<In> inputType, Class<Out> outputType); static Match<Node<? extends View<? extends In>, ?>, Out> fromNode(Class<In> inputType, Class<Out> outputType); static Match<In, Edge<? extends View<? extends Out>, ?>> ofEdge(Class<In> inputType, Class<Out> outputType); Match<In, Out> when(Class<Sub> type, Function<Sub, Out> then); Match<In, Out> whenExactly(Class<Sub> type, Function<Sub, Out> then); Match<In, Out> missing(Class<Sub> type); Match<In, Out> ignore(Class<Sub> type); Match<In, Out> ignore(Class<Sub> type, Out outValue); Match<In, Out> orElse(Function<In, Out> then); Match<In, Out> inputDecorator(MarshallingMessageDecorator<In> decorator); Match<In, Out> outputDecorator(MarshallingMessageDecorator<Out> decorator); Match<In, Out> defaultValue(Out value); Match<In, Out> mode(Mode mode); Result<Out> apply(In value); }### Answer: @Test public void missingTest() { ReceiveTask element = Bpmn2Factory.eINSTANCE.createReceiveTask(); Result<BpmnNode> result = match().apply(element); assertEquals(result.value(), defaultValue); assertTrue(result.isFailure()); }
### Question: CallActivityPropertyReader extends MultipleInstanceActivityPropertyReader { public boolean isCase() { return CustomElement.isCase.of(element).get(); } CallActivityPropertyReader(CallActivity callActivity, BPMNDiagram diagram, DefinitionResolver definitionResolver); String getCalledElement(); boolean isIndependent(); boolean isAbortParent(); boolean isWaitForCompletion(); boolean isAsync(); boolean isCase(); boolean isAdHocAutostart(); String getSlaDueDate(); }### Answer: @Test public void testIsCase_true() { String id = UUID.randomUUID().toString(); CallActivity callActivity = bpmn2.createCallActivity(); callActivity.setId(id); CustomElement.isCase.of(callActivity).set(Boolean.TRUE); tested = new CallActivityPropertyReader(callActivity, definitionResolver.getDiagram(), definitionResolver); assertTrue(tested.isCase()); } @Test public void testIsCase_false() { String id = UUID.randomUUID().toString(); CallActivity callActivity = bpmn2.createCallActivity(); callActivity.setId(id); CustomElement.isCase.of(callActivity).set(Boolean.FALSE); tested = new CallActivityPropertyReader(callActivity, definitionResolver.getDiagram(), definitionResolver); assertFalse(tested.isCase()); }
### Question: CallActivityPropertyReader extends MultipleInstanceActivityPropertyReader { public boolean isAdHocAutostart() { return CustomElement.autoStart.of(element).get(); } CallActivityPropertyReader(CallActivity callActivity, BPMNDiagram diagram, DefinitionResolver definitionResolver); String getCalledElement(); boolean isIndependent(); boolean isAbortParent(); boolean isWaitForCompletion(); boolean isAsync(); boolean isCase(); boolean isAdHocAutostart(); String getSlaDueDate(); }### Answer: @Test public void testIsAdHocAutostart_true() { String id = UUID.randomUUID().toString(); CallActivity callActivity = bpmn2.createCallActivity(); callActivity.setId(id); CustomElement.autoStart.of(callActivity).set(Boolean.TRUE); tested = new CallActivityPropertyReader(callActivity, definitionResolver.getDiagram(), definitionResolver); assertTrue(tested.isAdHocAutostart()); } @Test public void testIsAdHocAutostart_false() { String id = UUID.randomUUID().toString(); CallActivity callActivity = bpmn2.createCallActivity(); callActivity.setId(id); CustomElement.autoStart.of(callActivity).set(Boolean.FALSE); tested = new CallActivityPropertyReader(callActivity, definitionResolver.getDiagram(), definitionResolver); assertFalse(tested.isAdHocAutostart()); }
### Question: CallActivityPropertyReader extends MultipleInstanceActivityPropertyReader { public boolean isAsync() { return CustomElement.async.of(element).get(); } CallActivityPropertyReader(CallActivity callActivity, BPMNDiagram diagram, DefinitionResolver definitionResolver); String getCalledElement(); boolean isIndependent(); boolean isAbortParent(); boolean isWaitForCompletion(); boolean isAsync(); boolean isCase(); boolean isAdHocAutostart(); String getSlaDueDate(); }### Answer: @Test public void testIsAsync() { CallActivity callActivity = bpmn2.createCallActivity(); CustomElement.async.of(callActivity).set(Boolean.TRUE); tested = new CallActivityPropertyReader(callActivity, definitionResolver.getDiagram(), definitionResolver); assertTrue(tested.isAsync()); }
### Question: CallActivityPropertyReader extends MultipleInstanceActivityPropertyReader { public String getSlaDueDate() { return CustomElement.slaDueDate.of(element).get(); } CallActivityPropertyReader(CallActivity callActivity, BPMNDiagram diagram, DefinitionResolver definitionResolver); String getCalledElement(); boolean isIndependent(); boolean isAbortParent(); boolean isWaitForCompletion(); boolean isAsync(); boolean isCase(); boolean isAdHocAutostart(); String getSlaDueDate(); }### Answer: @Test public void testGetSlaDueDate() { String rawSlaDueDate = "12/25/1983"; CallActivity callActivity = bpmn2.createCallActivity(); CustomElement.slaDueDate.of(callActivity).set(rawSlaDueDate); tested = new CallActivityPropertyReader(callActivity, definitionResolver.getDiagram(), definitionResolver); assertTrue(tested.getSlaDueDate().contains(rawSlaDueDate)); }
### Question: DecisionComponentsItem { public DRGElement getDrgElement() { return getDecisionComponent().getDrgElement(); } @Inject DecisionComponentsItem(final View view); @PostConstruct void init(); View getView(); void setDecisionComponent(final DecisionComponent decisionComponent); void show(); void hide(); DRGElement getDrgElement(); }### Answer: @Test public void testGetDrgElement() { final DecisionComponent decisionComponent = mock(DecisionComponent.class); final DRGElement expectedDrgElement = null; when(decisionComponent.getDrgElement()).thenReturn(expectedDrgElement); doReturn(decisionComponent).when(item).getDecisionComponent(); final DRGElement actualDrgElement = item.getDrgElement(); assertEquals(expectedDrgElement, actualDrgElement); }
### Question: DataObjectPropertyReader extends BasePropertyReader { public String getName() { return CustomElement.name.of(element).get(); } DataObjectPropertyReader(DataObjectReference ref, BPMNDiagram diagram, BPMNShape shape, double resolutionFactor); String getName(); String getType(); }### Answer: @Test public void getExtendedName() { String name = tested.getName(); assertEquals("custom", name); } @Test public void getName() { when(dataObject.getExtensionValues()).thenReturn(Collections.emptyList()); String name = tested.getName(); assertEquals("name", name); }
### Question: InputAssignmentReader { public AssociationDeclaration getAssociationDeclaration() { return associationDeclaration; } InputAssignmentReader(Assignment assignment, String targetName); InputAssignmentReader(ItemAwareElement source, String targetName); static InputAssignmentReader fromAssociation(DataInputAssociation in); AssociationDeclaration getAssociationDeclaration(); }### Answer: @Test public void testNullBody() { final Assignment assignment = createAssignment(null); final InputAssignmentReader iar = new InputAssignmentReader(assignment, ID); final AssociationDeclaration associationDeclaration = iar.getAssociationDeclaration(); assertEquals(AssociationDeclaration.Type.FromTo, associationDeclaration.getType()); assertEquals("", associationDeclaration.getSource()); }
### Question: PropertyReaderUtils { public static Point2D getSourcePosition(DefinitionResolver definitionResolver, String edgeId, String sourceId) { final double resolutionFactor = definitionResolver.getResolutionFactor(); final Bounds sourceBounds = definitionResolver.getShape(sourceId).getBounds(); final List<Point> waypoint = definitionResolver.getEdge(edgeId).getWaypoint(); return waypoint.isEmpty() ? sourcePosition(sourceBounds, resolutionFactor) : offsetPosition(sourceBounds, waypoint.get(0), resolutionFactor); } static Point2D getSourcePosition(DefinitionResolver definitionResolver, String edgeId, String sourceId); static Point2D getTargetPosition(DefinitionResolver definitionResolver, String edgeId, String targetId); static List<Point2D> getControlPoints(DefinitionResolver definitionResolver, String edgeId); static boolean isAutoConnectionSource(BaseElement element); static boolean isAutoConnectionTarget(BaseElement element); static WSDLImport toWSDLImports(Import imp); }### Answer: @Test public void testGetSourcePositionWithNoWaypoint() { when(edge.getWaypoint()).thenReturn(Collections.emptyList()); Point2D point = PropertyReaderUtils.getSourcePosition(definitionResolver, EDGE_ID, SHAPE_ID); assertPoint(BOUNDS_WIDTH, BOUNDS_HEIGHT / 2, point); } @Test public void testGetSourcePositionWithWaypoint() { when(edge.getWaypoint()).thenReturn(Collections.singletonList(point)); Point2D point = PropertyReaderUtils.getSourcePosition(definitionResolver, EDGE_ID, SHAPE_ID); assertPoint(WAY_POINT_X - BOUNDS_X, WAY_POINT_Y - BOUNDS_Y, point); }
### Question: PropertyReaderUtils { public static Point2D getTargetPosition(DefinitionResolver definitionResolver, String edgeId, String targetId) { final double resolutionFactor = definitionResolver.getResolutionFactor(); final Bounds targetBounds = definitionResolver.getShape(targetId).getBounds(); final List<Point> waypoint = definitionResolver.getEdge(edgeId).getWaypoint(); return waypoint.isEmpty() ? targetPosition(targetBounds, resolutionFactor) : offsetPosition(targetBounds, waypoint.get(waypoint.size() - 1), resolutionFactor); } static Point2D getSourcePosition(DefinitionResolver definitionResolver, String edgeId, String sourceId); static Point2D getTargetPosition(DefinitionResolver definitionResolver, String edgeId, String targetId); static List<Point2D> getControlPoints(DefinitionResolver definitionResolver, String edgeId); static boolean isAutoConnectionSource(BaseElement element); static boolean isAutoConnectionTarget(BaseElement element); static WSDLImport toWSDLImports(Import imp); }### Answer: @Test public void testGetTargetPositionWithNoWaypoint() { when(edge.getWaypoint()).thenReturn(Collections.emptyList()); Point2D point = PropertyReaderUtils.getTargetPosition(definitionResolver, EDGE_ID, SHAPE_ID); assertPoint(0, BOUNDS_HEIGHT / 2, point); } @Test public void testGetTargetPositionWithWaypoint() { when(edge.getWaypoint()).thenReturn(Collections.singletonList(point)); Point2D point = PropertyReaderUtils.getTargetPosition(definitionResolver, EDGE_ID, SHAPE_ID); assertPoint(WAY_POINT_X - BOUNDS_X, WAY_POINT_Y - BOUNDS_Y, point); }
### Question: PropertyReaderUtils { public static List<Point2D> getControlPoints(DefinitionResolver definitionResolver, String edgeId) { final double resolutionFactor = definitionResolver.getResolutionFactor(); final List<Point> waypoint = definitionResolver.getEdge(edgeId).getWaypoint(); final List<Point2D> result = new ArrayList<>(); if (waypoint.size() > 2) { List<Point> points = waypoint.subList(1, waypoint.size() - 1); for (Point p : points) { result.add(createPoint2D(p, resolutionFactor)); } } return result; } static Point2D getSourcePosition(DefinitionResolver definitionResolver, String edgeId, String sourceId); static Point2D getTargetPosition(DefinitionResolver definitionResolver, String edgeId, String targetId); static List<Point2D> getControlPoints(DefinitionResolver definitionResolver, String edgeId); static boolean isAutoConnectionSource(BaseElement element); static boolean isAutoConnectionTarget(BaseElement element); static WSDLImport toWSDLImports(Import imp); }### Answer: @Test public void testGetControlPointsWhenZeroPoints() { when(edge.getWaypoint()).thenReturn(Collections.emptyList()); List<Point2D> result = PropertyReaderUtils.getControlPoints(definitionResolver, EDGE_ID); assertTrue(result.isEmpty()); } @Test public void testGetControlPointsWhenOnePoints() { List<Point> waypoints = mockPoints(1, 2, 1); when(edge.getWaypoint()).thenReturn(waypoints); List<Point2D> result = PropertyReaderUtils.getControlPoints(definitionResolver, EDGE_ID); assertTrue(result.isEmpty()); } @Test public void testGetControlPointsWhenTwoPoints() { List<Point> waypoints = mockPoints(1, 2, 2); when(edge.getWaypoint()).thenReturn(waypoints); List<Point2D> result = PropertyReaderUtils.getControlPoints(definitionResolver, EDGE_ID); assertTrue(result.isEmpty()); }
### Question: DecisionComponents { @PostConstruct public void init() { view.init(this); } DecisionComponents(); @Inject DecisionComponents(final View view, final DMNIncludeModelsClient client, final ManagedInstance<DecisionComponentsItem> itemManagedInstance, final DecisionComponentFilter filter, final DMNDiagramsSession dmnDiagramsSession, final DMNGraphUtils dmnGraphUtils); @PostConstruct void init(); View getView(); void refresh(); void removeAllItems(); }### Answer: @Test public void testInit() { decisionComponents.init(); verify(view).init(decisionComponents); }
### Question: PropertyReaderUtils { public static WSDLImport toWSDLImports(Import imp) { return new WSDLImport(imp.getLocation(), imp.getNamespace()); } static Point2D getSourcePosition(DefinitionResolver definitionResolver, String edgeId, String sourceId); static Point2D getTargetPosition(DefinitionResolver definitionResolver, String edgeId, String targetId); static List<Point2D> getControlPoints(DefinitionResolver definitionResolver, String edgeId); static boolean isAutoConnectionSource(BaseElement element); static boolean isAutoConnectionTarget(BaseElement element); static WSDLImport toWSDLImports(Import imp); }### Answer: @Test public void toWSDLImports() { final String LOCATION = "location"; final String NAMESPACE = "namespace"; WSDLImport wsdlImport = new WSDLImport(LOCATION, NAMESPACE); Import imp = PropertyWriterUtils.toImport(wsdlImport); WSDLImport result = PropertyReaderUtils.toWSDLImports(imp); assertEquals("location", result.getLocation()); assertEquals("namespace", result.getNamespace()); }
### Question: LanePropertyReader extends BasePropertyReader { @Override public RectangleDimensionsSet getRectangleDimensionsSet() { if (shape == null || parentLaneShape == null) { return super.getRectangleDimensionsSet(); } org.eclipse.dd.dc.Bounds bounds = shape.getBounds(); return new RectangleDimensionsSet(parentLaneShape.getBounds().getWidth() * resolutionFactor, bounds.getHeight() * resolutionFactor); } LanePropertyReader(Lane el, BPMNDiagram diagram, BPMNShape shape, BPMNShape parentLaneShape, double resolutionFactor); LanePropertyReader(Lane el, BPMNDiagram diagram, BPMNShape shape, double resolutionFactor); String getName(); @Override RectangleDimensionsSet getRectangleDimensionsSet(); }### Answer: @Test public void testGetRectangleDimensionsSet() { LanePropertyReader propertyReader = new LanePropertyReader(lane, diagram, shape, RESOLUTION_FACTOR); RectangleDimensionsSet dimensionsSet = propertyReader.getRectangleDimensionsSet(); assertRectangleDimensions(WIDTH * RESOLUTION_FACTOR, HEIGHT * RESOLUTION_FACTOR, dimensionsSet); } @Test public void testGetRectangleDimensionsSetWithParentShape() { LanePropertyReader propertyReader = new LanePropertyReader(lane, diagram, shape, parentLaneShape, RESOLUTION_FACTOR); RectangleDimensionsSet dimensionsSet = propertyReader.getRectangleDimensionsSet(); assertRectangleDimensions(PARENT_WIDTH * RESOLUTION_FACTOR, HEIGHT * RESOLUTION_FACTOR, dimensionsSet); }
### Question: TextAnnotationPropertyReader extends BasePropertyReader { public String getName() { String extendedName = CustomElement.name.of(element).get(); return StringUtils.isEmpty(extendedName) ? Optional.ofNullable(element.getText()).orElse("") : extendedName; } TextAnnotationPropertyReader(TextAnnotation element, BPMNDiagram diagram, BPMNShape shape, double resolutionFactor); String getName(); }### Answer: @Test public void getExtendedName() { String name = tested.getName(); assertEquals("custom", name); } @Test public void getName() { when(element.getExtensionValues()).thenReturn(Collections.emptyList()); String name = tested.getName(); assertEquals("name", name); } @Test public void getTextName() { when(element.getExtensionValues()).thenReturn(Collections.emptyList()); when(element.getName()).thenReturn(null); String name = tested.getName(); assertEquals("text", name); } @Test public void getNameNull() { when(element.getExtensionValues()).thenReturn(Collections.emptyList()); when(element.getName()).thenReturn(null); when(element.getText()).thenReturn(null); String name = tested.getName(); assertEquals("", name); }
### Question: DecisionComponents { public View getView() { return view; } DecisionComponents(); @Inject DecisionComponents(final View view, final DMNIncludeModelsClient client, final ManagedInstance<DecisionComponentsItem> itemManagedInstance, final DecisionComponentFilter filter, final DMNDiagramsSession dmnDiagramsSession, final DMNGraphUtils dmnGraphUtils); @PostConstruct void init(); View getView(); void refresh(); void removeAllItems(); }### Answer: @Test public void testGetView() { assertEquals(view, decisionComponents.getView()); }
### Question: PropertyReaderFactory { public FlowElementPropertyReader of(FlowElement el) { return new FlowElementPropertyReader(el, diagram, definitionResolver.getShape(el.getId()), definitionResolver.getResolutionFactor()); } PropertyReaderFactory(DefinitionResolver definitionResolver); FlowElementPropertyReader of(FlowElement el); LanePropertyReader of(Lane el); LanePropertyReader of(Lane el, Lane elParent); SequenceFlowPropertyReader of(SequenceFlow el); AssociationPropertyReader of(Association el); GatewayPropertyReader of(Gateway el); TaskPropertyReader of(Task el); UserTaskPropertyReader of(UserTask el); ScriptTaskPropertyReader of(ScriptTask el); GenericServiceTaskPropertyReader of(ServiceTask el); BusinessRuleTaskPropertyReader of(BusinessRuleTask el); Optional<ServiceTaskPropertyReader> ofCustom(Task el); CallActivityPropertyReader of(CallActivity el); CatchEventPropertyReader of(CatchEvent el); ThrowEventPropertyReader of(ThrowEvent el); SubProcessPropertyReader of(SubProcess el); AdHocSubProcessPropertyReader of(AdHocSubProcess el); MultipleInstanceSubProcessPropertyReader ofMultipleInstance(SubProcess el); ProcessPropertyReader of(Process el); TextAnnotationPropertyReader of(TextAnnotation el); DefinitionsPropertyReader of(Definitions el); DataObjectPropertyReader of(DataObjectReference el); }### Answer: @Test public void ofDefinition() { assertTrue(tested.of(definitions) instanceof DefinitionsPropertyReader); }
### Question: ItemNameReader { public String getName() { return name; } private ItemNameReader(ItemAwareElement element); static ItemNameReader from(ItemAwareElement element); String getName(); }### Answer: @Test public void testGetPropertyName() { when(property.getName()).thenReturn(NAME); when(property.getId()).thenReturn(ID); testGetName(NAME, property); } @Test public void testGetPropertyID() { when(property.getName()).thenReturn(null); when(property.getId()).thenReturn(ID); testGetName(ID, property); } @Test public void testGetDataInputName() { when(dataInput.getName()).thenReturn(NAME); when(dataInput.getId()).thenReturn(ID); testGetName(NAME, dataInput); } @Test public void testGetDataInputID() { when(dataInput.getName()).thenReturn(null); when(dataInput.getId()).thenReturn(ID); testGetName(ID, dataInput); } @Test public void testGetDataOutputName() { when(dataOutput.getName()).thenReturn(NAME); when(dataOutput.getId()).thenReturn(ID); testGetName(NAME, dataOutput); } @Test public void testGetDataOutputID() { when(dataOutput.getName()).thenReturn(null); when(dataOutput.getId()).thenReturn(ID); testGetName(ID, dataOutput); } @Test public void testGetDataObject() { when(dataObject.getName()).thenReturn(null); when(dataObject.getId()).thenReturn(ID); testGetName(ID, dataObject); }
### Question: DecisionComponents { public void refresh() { if (!dmnDiagramsSession.isSessionStatePresent()) { return; } if (!isIncludedNodeListsUpdated()) { refreshIncludedNodesList(); } loadModelComponents(); } DecisionComponents(); @Inject DecisionComponents(final View view, final DMNIncludeModelsClient client, final ManagedInstance<DecisionComponentsItem> itemManagedInstance, final DecisionComponentFilter filter, final DMNDiagramsSession dmnDiagramsSession, final DMNGraphUtils dmnGraphUtils); @PostConstruct void init(); View getView(); void refresh(); void removeAllItems(); }### Answer: @Test public void testRefresh() { final Consumer<List<DMNIncludedNode>> listConsumer = (list) -> {}; final List<DMNIncludedModel> includedModels = new ArrayList<>(); includedModels.add(makeDMNIncludedModel(": includedModels.add(makeDMNIncludedModel(": doReturn(includedModels).when(decisionComponents).getDMNIncludedModels(); doReturn(listConsumer).when(decisionComponents).getNodesConsumer(); decisionComponents.refreshIncludedNodesList(); verify(decisionComponents).startLoading(); verify(client).loadNodesFromImports(includedModels, listConsumer); assertEquals(includedModels, decisionComponents.getLatestIncludedModelsLoaded()); }
### Question: MultipleInstanceActivityPropertyReader extends ActivityPropertyReader { public String getCollectionInput() { String ieDataInputId = getLoopDataInputRefId(); return super.getDataInputAssociations().stream() .filter(dia -> hasTargetRef(dia, ieDataInputId)) .filter(MultipleInstanceActivityPropertyReader::hasSourceRefs) .map(dia -> ItemNameReader.from(dia.getSourceRef().get(0)).getName()) .findFirst() .orElse(null); } MultipleInstanceActivityPropertyReader(Activity activity, BPMNDiagram diagram, DefinitionResolver definitionResolver); boolean isMultipleInstance(); String getCollectionInput(); String getCollectionOutput(); String getDataInput(); String getDataOutput(); String getCompletionCondition(); boolean isSequential(); }### Answer: @Test public void testGetCollectionInput() { ItemAwareElement item = mockItemAwareElement(ITEM_ID); when(miloop.getLoopDataInputRef()).thenReturn(item); List<DataInputAssociation> inputAssociations = Collections.singletonList(mockDataInputAssociation(ITEM_ID, PROPERTY_ID)); when(activity.getDataInputAssociations()).thenReturn(inputAssociations); assertEquals(PROPERTY_ID, reader.getCollectionInput()); } @Test public void testGetCollectionInput() { ItemAwareElement item = mockItemAwareElement(ITEM_ID); when(miloop.getLoopDataInputRef()).thenReturn(item); EList<DataInputAssociation> inputAssociations = ECollections.singletonEList(mockDataInputAssociation(ITEM_ID, PROPERTY_ID)); when(activity.getDataInputAssociations()).thenReturn(inputAssociations); assertEquals(PROPERTY_ID, reader.getCollectionInput()); }
### Question: MultipleInstanceActivityPropertyReader extends ActivityPropertyReader { public String getDataInput() { return getMultiInstanceLoopCharacteristics() .map(MultiInstanceLoopCharacteristics::getInputDataItem) .map(MultipleInstanceActivityPropertyReader::createInputVariable) .orElse(""); } MultipleInstanceActivityPropertyReader(Activity activity, BPMNDiagram diagram, DefinitionResolver definitionResolver); boolean isMultipleInstance(); String getCollectionInput(); String getCollectionOutput(); String getDataInput(); String getDataOutput(); String getCompletionCondition(); boolean isSequential(); }### Answer: @Test public void testGetDataInput() { DataInput item = mockDataInput(ITEM_ID, PROPERTY_ID); when(miloop.getInputDataItem()).thenReturn(item); assertEquals(PROPERTY_ID + DELIMITER + DATA_TYPE, reader.getDataInput()); } @Test public void testGetEmptyDataInput() { DataInput item = mockDataInput(ITEM_ID, null); when(miloop.getInputDataItem()).thenReturn(item); assertEquals(ITEM_ID + DELIMITER + DATA_TYPE, reader.getDataInput()); }
### Question: MultipleInstanceActivityPropertyReader extends ActivityPropertyReader { public String getDataOutput() { return getMultiInstanceLoopCharacteristics() .map(MultiInstanceLoopCharacteristics::getOutputDataItem) .map(MultipleInstanceActivityPropertyReader::createOutputVariable) .orElse(""); } MultipleInstanceActivityPropertyReader(Activity activity, BPMNDiagram diagram, DefinitionResolver definitionResolver); boolean isMultipleInstance(); String getCollectionInput(); String getCollectionOutput(); String getDataInput(); String getDataOutput(); String getCompletionCondition(); boolean isSequential(); }### Answer: @Test public void testGetEmptyDataOutput() { DataOutput item = mockDataOutput(ITEM_ID, null); when(miloop.getOutputDataItem()).thenReturn(item); assertEquals(ITEM_ID + DELIMITER + DATA_TYPE, reader.getDataOutput()); } @Test public void testGetDataOutput() { DataOutput item = mockDataOutput(ITEM_ID, PROPERTY_ID); when(miloop.getOutputDataItem()).thenReturn(item); assertEquals(PROPERTY_ID + DELIMITER + DATA_TYPE, reader.getDataOutput()); }
### Question: MultipleInstanceActivityPropertyReader extends ActivityPropertyReader { public String getCollectionOutput() { String ieDataOutputId = getLoopDataOutputRefId(); return super.getDataOutputAssociations().stream() .filter(doa -> hasSourceRef(doa, ieDataOutputId)) .map(doa -> ItemNameReader.from(doa.getTargetRef()).getName()) .findFirst() .orElse(null); } MultipleInstanceActivityPropertyReader(Activity activity, BPMNDiagram diagram, DefinitionResolver definitionResolver); boolean isMultipleInstance(); String getCollectionInput(); String getCollectionOutput(); String getDataInput(); String getDataOutput(); String getCompletionCondition(); boolean isSequential(); }### Answer: @Test public void testGetCollectionOutput() { ItemAwareElement item = mockItemAwareElement(ITEM_ID); when(miloop.getLoopDataOutputRef()).thenReturn(item); List<DataOutputAssociation> outputAssociations = Collections.singletonList(mockDataOutputAssociation(ITEM_ID, PROPERTY_ID)); when(activity.getDataOutputAssociations()).thenReturn(outputAssociations); assertEquals(PROPERTY_ID, reader.getCollectionOutput()); } @Test public void testGetCollectionOutput() { ItemAwareElement item = mockItemAwareElement(ITEM_ID); when(miloop.getLoopDataOutputRef()).thenReturn(item); EList<DataOutputAssociation> outputAssociations = ECollections.singletonEList(mockDataOutputAssociation(ITEM_ID, PROPERTY_ID)); when(activity.getDataOutputAssociations()).thenReturn(outputAssociations); assertEquals(PROPERTY_ID, reader.getCollectionOutput()); }
### Question: MultipleInstanceActivityPropertyReader extends ActivityPropertyReader { public String getCompletionCondition() { return getMultiInstanceLoopCharacteristics() .map(miloop -> (FormalExpression) miloop.getCompletionCondition()) .map(FormalExpression::getBody) .orElse(""); } MultipleInstanceActivityPropertyReader(Activity activity, BPMNDiagram diagram, DefinitionResolver definitionResolver); boolean isMultipleInstance(); String getCollectionInput(); String getCollectionOutput(); String getDataInput(); String getDataOutput(); String getCompletionCondition(); boolean isSequential(); }### Answer: @Test public void getGetCompletionCondition() { FormalExpression expression = mock(FormalExpression.class); when(expression.getBody()).thenReturn(EXPRESSION); when(miloop.getCompletionCondition()).thenReturn(expression); assertEquals(EXPRESSION, reader.getCompletionCondition()); }
### Question: ProcessVariableReader { static String getProcessVariables(List<Property> properties) { return properties .stream() .filter(ProcessVariableReader::isProcessVariable) .map(ProcessVariableReader::toProcessVariableString) .collect(Collectors.joining(",")); } static String getProcessVariableName(Property p); static boolean isProcessVariable(Property p); }### Answer: @Test public void getProcessVariables() { String result = ProcessVariableReader.getProcessVariables(properties); assertEquals("PV1:Boolean:<![CDATA[internal;input;customTag]]>,PV2::[],PV3::[]", result); }
### Question: ProcessVariableReader { public static String getProcessVariableName(Property p) { String name = p.getName(); return name == null || name.isEmpty() ? p.getId() : name; } static String getProcessVariableName(Property p); static boolean isProcessVariable(Property p); }### Answer: @Test public void getProcessVariableName() { assertEquals("PV1", ProcessVariableReader.getProcessVariableName(property1)); assertEquals("PV2", ProcessVariableReader.getProcessVariableName(property2)); assertEquals("PV3", ProcessVariableReader.getProcessVariableName(property3)); assertEquals("caseFile_CV4", ProcessVariableReader.getProcessVariableName(property4)); assertEquals("caseFile_CV5", ProcessVariableReader.getProcessVariableName(property5)); }
### Question: ProcessVariableReader { public static boolean isProcessVariable(Property p) { return !CaseFileVariableReader.isCaseFileVariable(p); } static String getProcessVariableName(Property p); static boolean isProcessVariable(Property p); }### Answer: @Test public void isProcessVariable() { assertTrue(ProcessVariableReader.isProcessVariable(property1)); assertTrue(ProcessVariableReader.isProcessVariable(property2)); assertTrue(ProcessVariableReader.isProcessVariable(property3)); assertFalse(ProcessVariableReader.isProcessVariable(property4)); assertFalse(ProcessVariableReader.isProcessVariable(property5)); }
### Question: BasePropertyReader implements PropertyReader { @Override public Bounds getBounds() { if (shape == null) { return Bounds.create(); } return computeBounds(shape.getBounds()); } BasePropertyReader(final BaseElement element, final BPMNDiagram diagram, final BPMNShape shape, final double resolutionFactor); @Override String getDocumentation(); @Override String getDescription(); @Override FontSet getFontSet(); @Override BackgroundSet getBackgroundSet(); @Override Bounds getBounds(); @Override CircleDimensionSet getCircleDimensionSet(); @Override RectangleDimensionsSet getRectangleDimensionsSet(); @Override boolean isExpanded(); @Override BaseElement getElement(); @Override BPMNShape getShape(); }### Answer: @Test public void testBounds() { Bounds bounds = tested.getBounds(); assertTrue(bounds.hasLowerRight()); assertTrue(bounds.hasUpperLeft()); assertEquals(0.7150000154972077d, bounds.getUpperLeft().getX(), 0d); assertEquals(1.4300000309944154d, bounds.getUpperLeft().getY(), 0d); assertEquals(65.71500001549721d, bounds.getLowerRight().getX(), 0d); assertEquals(355.9010174870491d, bounds.getLowerRight().getY(), 0d); }
### Question: BasePropertyReader implements PropertyReader { @Override public CircleDimensionSet getCircleDimensionSet() { if (shape == null) { return new CircleDimensionSet(); } return new CircleDimensionSet(new Radius( shape.getBounds().getWidth() * resolutionFactor / 2d)); } BasePropertyReader(final BaseElement element, final BPMNDiagram diagram, final BPMNShape shape, final double resolutionFactor); @Override String getDocumentation(); @Override String getDescription(); @Override FontSet getFontSet(); @Override BackgroundSet getBackgroundSet(); @Override Bounds getBounds(); @Override CircleDimensionSet getCircleDimensionSet(); @Override RectangleDimensionsSet getRectangleDimensionsSet(); @Override boolean isExpanded(); @Override BaseElement getElement(); @Override BPMNShape getShape(); }### Answer: @Test public void testGetCircleDimensionSet() { CircleDimensionSet circleDimensionSet = tested.getCircleDimensionSet(); assertEquals(32.5d, circleDimensionSet.getRadius().getValue(), 0d); }
### Question: BasePropertyReader implements PropertyReader { @Override public RectangleDimensionsSet getRectangleDimensionsSet() { if (shape == null) { return new RectangleDimensionsSet(); } org.eclipse.dd.dc.Bounds bounds = shape.getBounds(); return new RectangleDimensionsSet(bounds.getWidth() * resolutionFactor, bounds.getHeight() * resolutionFactor); } BasePropertyReader(final BaseElement element, final BPMNDiagram diagram, final BPMNShape shape, final double resolutionFactor); @Override String getDocumentation(); @Override String getDescription(); @Override FontSet getFontSet(); @Override BackgroundSet getBackgroundSet(); @Override Bounds getBounds(); @Override CircleDimensionSet getCircleDimensionSet(); @Override RectangleDimensionsSet getRectangleDimensionsSet(); @Override boolean isExpanded(); @Override BaseElement getElement(); @Override BPMNShape getShape(); }### Answer: @Test public void testGetRectangleDimensionsSet() { RectangleDimensionsSet rectangleDimensionsSet = tested.getRectangleDimensionsSet(); assertEquals(65.0d, rectangleDimensionsSet.getWidth().getValue(), 0d); assertEquals(354.4710174560547d, rectangleDimensionsSet.getHeight().getValue(), 0d); }
### Question: BasePropertyReader implements PropertyReader { @Override public boolean isExpanded() { return shape.isIsExpanded(); } BasePropertyReader(final BaseElement element, final BPMNDiagram diagram, final BPMNShape shape, final double resolutionFactor); @Override String getDocumentation(); @Override String getDescription(); @Override FontSet getFontSet(); @Override BackgroundSet getBackgroundSet(); @Override Bounds getBounds(); @Override CircleDimensionSet getCircleDimensionSet(); @Override RectangleDimensionsSet getRectangleDimensionsSet(); @Override boolean isExpanded(); @Override BaseElement getElement(); @Override BPMNShape getShape(); }### Answer: @Test public void testIsExpandedTrue() { when(shape.isIsExpanded()).thenReturn(true); assertTrue(tested.isExpanded()); }
### Question: BasePropertyReader implements PropertyReader { @Override public BaseElement getElement() { return element; } BasePropertyReader(final BaseElement element, final BPMNDiagram diagram, final BPMNShape shape, final double resolutionFactor); @Override String getDocumentation(); @Override String getDescription(); @Override FontSet getFontSet(); @Override BackgroundSet getBackgroundSet(); @Override Bounds getBounds(); @Override CircleDimensionSet getCircleDimensionSet(); @Override RectangleDimensionsSet getRectangleDimensionsSet(); @Override boolean isExpanded(); @Override BaseElement getElement(); @Override BPMNShape getShape(); }### Answer: @Test public void testGetElement() { assertEquals(element, tested.getElement()); }
### Question: BasePropertyReader implements PropertyReader { @Override public BPMNShape getShape() { return shape; } BasePropertyReader(final BaseElement element, final BPMNDiagram diagram, final BPMNShape shape, final double resolutionFactor); @Override String getDocumentation(); @Override String getDescription(); @Override FontSet getFontSet(); @Override BackgroundSet getBackgroundSet(); @Override Bounds getBounds(); @Override CircleDimensionSet getCircleDimensionSet(); @Override RectangleDimensionsSet getRectangleDimensionsSet(); @Override boolean isExpanded(); @Override BaseElement getElement(); @Override BPMNShape getShape(); }### Answer: @Test public void testGetShape() { assertEquals(shape, tested.getShape()); }
### Question: AssociationPropertyReader extends BasePropertyReader implements EdgePropertyReader { @Override public String getSourceId() { return association.getSourceRef().getId(); } AssociationPropertyReader(Association association, BPMNDiagram diagram, DefinitionResolver definitionResolver); @Override String getSourceId(); @Override String getTargetId(); Class<? extends org.kie.workbench.common.stunner.bpmn.definition.Association> getAssociationByDirection(); @Override Connection getSourceConnection(); @Override Connection getTargetConnection(); @Override List<Point2D> getControlPoints(); @Override DefinitionResolver getDefinitionResolver(); }### Answer: @Test public void testGetSourceId() { assertEquals(SOURCE_ID, propertyReader.getSourceId()); }
### Question: AssociationPropertyReader extends BasePropertyReader implements EdgePropertyReader { @Override public String getTargetId() { return association.getTargetRef().getId(); } AssociationPropertyReader(Association association, BPMNDiagram diagram, DefinitionResolver definitionResolver); @Override String getSourceId(); @Override String getTargetId(); Class<? extends org.kie.workbench.common.stunner.bpmn.definition.Association> getAssociationByDirection(); @Override Connection getSourceConnection(); @Override Connection getTargetConnection(); @Override List<Point2D> getControlPoints(); @Override DefinitionResolver getDefinitionResolver(); }### Answer: @Test public void testGetTargetId() { assertEquals(TARGET_ID, propertyReader.getTargetId()); }
### Question: DecisionComponents { List<DMNIncludedModel> getDMNIncludedModels() { return dmnDiagramsSession .getModelImports() .stream() .filter(anImport -> Objects.equals(DMNImportTypes.DMN, determineImportType(anImport.getImportType()))) .map(this::asDMNIncludedModel) .collect(Collectors.toList()); } DecisionComponents(); @Inject DecisionComponents(final View view, final DMNIncludeModelsClient client, final ManagedInstance<DecisionComponentsItem> itemManagedInstance, final DecisionComponentFilter filter, final DMNDiagramsSession dmnDiagramsSession, final DMNGraphUtils dmnGraphUtils); @PostConstruct void init(); View getView(); void refresh(); void removeAllItems(); }### Answer: @Test public void testGetDMNIncludedModelsOnlyIncludesDMN() { final ImportDMN dmnImport = new ImportDMN(); final ImportPMML pmmlImport = new ImportPMML(); dmnImport.getName().setValue("dmn"); dmnImport.setImportType(DMNImportTypes.DMN.getDefaultNamespace()); pmmlImport.setImportType(DMNImportTypes.PMML.getDefaultNamespace()); when(dmnDiagramsSession.getModelImports()).thenReturn(asList(dmnImport, pmmlImport)); final List<DMNIncludedModel> includedModels = decisionComponents.getDMNIncludedModels(); assertThat(includedModels).hasSize(1); assertThat(includedModels.get(0).getModelName()).isEqualTo("dmn"); assertThat(includedModels.get(0).getImportType()).isEqualTo(DMNImportTypes.DMN.getDefaultNamespace()); }
### Question: AssociationPropertyReader extends BasePropertyReader implements EdgePropertyReader { @Override public Connection getSourceConnection() { Point2D sourcePosition = PropertyReaderUtils.getSourcePosition(definitionResolver, element.getId(), getSourceId()); return MagnetConnection.Builder .at(sourcePosition.getX(), sourcePosition.getY()) .setAuto(PropertyReaderUtils.isAutoConnectionSource(element)); } AssociationPropertyReader(Association association, BPMNDiagram diagram, DefinitionResolver definitionResolver); @Override String getSourceId(); @Override String getTargetId(); Class<? extends org.kie.workbench.common.stunner.bpmn.definition.Association> getAssociationByDirection(); @Override Connection getSourceConnection(); @Override Connection getTargetConnection(); @Override List<Point2D> getControlPoints(); @Override DefinitionResolver getDefinitionResolver(); }### Answer: @Test public void testGetSourceConnection() { mockStatic(PropertyReaderUtils.class); PowerMockito.when(PropertyReaderUtils.getSourcePosition(definitionResolver, ASSOCIATION_ID, SOURCE_ID)).thenReturn(position); boolean arbitraryBoolean = true; PowerMockito.when(PropertyReaderUtils.isAutoConnectionSource(association)).thenReturn(arbitraryBoolean); Connection result = propertyReader.getSourceConnection(); assertEquals(X, result.getLocation().getX(), 0); assertEquals(Y, result.getLocation().getY(), 0); }
### Question: AssociationPropertyReader extends BasePropertyReader implements EdgePropertyReader { @Override public Connection getTargetConnection() { Point2D targetPosition = PropertyReaderUtils.getTargetPosition(definitionResolver, element.getId(), getTargetId()); return MagnetConnection.Builder .at(targetPosition.getX(), targetPosition.getY()) .setAuto(PropertyReaderUtils.isAutoConnectionTarget(element)); } AssociationPropertyReader(Association association, BPMNDiagram diagram, DefinitionResolver definitionResolver); @Override String getSourceId(); @Override String getTargetId(); Class<? extends org.kie.workbench.common.stunner.bpmn.definition.Association> getAssociationByDirection(); @Override Connection getSourceConnection(); @Override Connection getTargetConnection(); @Override List<Point2D> getControlPoints(); @Override DefinitionResolver getDefinitionResolver(); }### Answer: @Test public void testGetTargetConnection() { mockStatic(PropertyReaderUtils.class); PowerMockito.when(PropertyReaderUtils.getTargetPosition(definitionResolver, ASSOCIATION_ID, TARGET_ID)).thenReturn(position); boolean arbitraryBoolean = true; PowerMockito.when(PropertyReaderUtils.isAutoConnectionSource(association)).thenReturn(arbitraryBoolean); Connection result = propertyReader.getTargetConnection(); assertEquals(X, result.getLocation().getX(), 0); assertEquals(Y, result.getLocation().getY(), 0); }
### Question: AssociationPropertyReader extends BasePropertyReader implements EdgePropertyReader { public Class<? extends org.kie.workbench.common.stunner.bpmn.definition.Association> getAssociationByDirection() { return Optional.ofNullable(association.getAssociationDirection()) .filter(d -> !AssociationDirection.NONE.equals(d)) .<Class<? extends org.kie.workbench.common.stunner.bpmn.definition.Association>>map(d -> DirectionalAssociation.class) .orElse(NonDirectionalAssociation.class); } AssociationPropertyReader(Association association, BPMNDiagram diagram, DefinitionResolver definitionResolver); @Override String getSourceId(); @Override String getTargetId(); Class<? extends org.kie.workbench.common.stunner.bpmn.definition.Association> getAssociationByDirection(); @Override Connection getSourceConnection(); @Override Connection getTargetConnection(); @Override List<Point2D> getControlPoints(); @Override DefinitionResolver getDefinitionResolver(); }### Answer: @Test public void testGetAssociationByDirection() { final Association association = Bpmn2Factory.eINSTANCE.createAssociation(); association.setAssociationDirection(null); propertyReader = new AssociationPropertyReader(association, bpmnDiagram, definitionResolver); assertEquals(NonDirectionalAssociation.class, propertyReader.getAssociationByDirection()); association.setAssociationDirection(AssociationDirection.NONE); assertEquals(NonDirectionalAssociation.class, propertyReader.getAssociationByDirection()); association.setAssociationDirection(AssociationDirection.ONE); assertEquals(DirectionalAssociation.class, propertyReader.getAssociationByDirection()); }
### Question: AssociationPropertyReader extends BasePropertyReader implements EdgePropertyReader { @Override public List<Point2D> getControlPoints() { return PropertyReaderUtils.getControlPoints(definitionResolver, element.getId()); } AssociationPropertyReader(Association association, BPMNDiagram diagram, DefinitionResolver definitionResolver); @Override String getSourceId(); @Override String getTargetId(); Class<? extends org.kie.workbench.common.stunner.bpmn.definition.Association> getAssociationByDirection(); @Override Connection getSourceConnection(); @Override Connection getTargetConnection(); @Override List<Point2D> getControlPoints(); @Override DefinitionResolver getDefinitionResolver(); }### Answer: @Test @SuppressWarnings("unchecked") public void testGetControlPoints() { List<Point2D> controlPoints = mock(List.class); mockStatic(PropertyReaderUtils.class); PowerMockito.when(PropertyReaderUtils.getControlPoints(definitionResolver, ASSOCIATION_ID)).thenReturn(controlPoints); assertEquals(controlPoints, propertyReader.getControlPoints()); }
### Question: CaseFileVariableReader { static String getCaseFileVariables(List<Property> properties) { return properties .stream() .filter(CaseFileVariableReader::isCaseFileVariable) .map(CaseFileVariableReader::toCaseFileVariableString) .collect(Collectors.joining(",")); } static boolean isCaseFileVariable(Property p); }### Answer: @Test public void getCaseFileVariables() { String caseFileVariables = CaseFileVariableReader.getCaseFileVariables(properties); assertEquals(caseFileVariables, "CFV1:Boolean,CFV2:Boolean"); }
### Question: CaseFileVariableReader { public static boolean isCaseFileVariable(Property p) { String name = getCaseFileVariableName(p); return name.startsWith(CaseFileVariables.CASE_FILE_PREFIX); } static boolean isCaseFileVariable(Property p); }### Answer: @Test public void isCaseFileVariable() { boolean isCaseFile1 = CaseFileVariableReader.isCaseFileVariable(property1); assertTrue(isCaseFile1); boolean isCaseFile2 = CaseFileVariableReader.isCaseFileVariable(property2); assertTrue(isCaseFile2); boolean isCaseFile3 = CaseFileVariableReader.isCaseFileVariable(property3); assertFalse(isCaseFile3); boolean isCaseFile4 = CaseFileVariableReader.isCaseFileVariable(property4); assertFalse(isCaseFile4); }
### Question: DefinitionsPropertyReader extends BasePropertyReader { public List<WSDLImport> getWSDLImports() { return definitions.getImports().stream() .map(PropertyReaderUtils::toWSDLImports) .collect(Collectors.toList()); } DefinitionsPropertyReader(Definitions element, BPMNDiagram diagram, BPMNShape shape, double resolutionFactor); List<WSDLImport> getWSDLImports(); }### Answer: @Test public void getWSDLImports() { final String LOCATION = "location"; final String NAMESPACE = "namespace"; final int QTY = 10; for (int i = 0; i < QTY; i++) { Import imp = PropertyWriterUtils.toImport(new WSDLImport(LOCATION + i, NAMESPACE + i)); definitions.getImports().add(imp); } List<WSDLImport> wsdlImports = tested.getWSDLImports(); assertEquals(QTY, wsdlImports.size()); for (int i = 0; i < QTY; i++) { assertEquals(LOCATION + i, wsdlImports.get(i).getLocation()); assertEquals(NAMESPACE + i, wsdlImports.get(i).getNamespace()); } }
### Question: ProcessPropertyReader extends BasePropertyReader { public List<DefaultImport> getDefaultImports() { return CustomElement.defaultImports.of(process).get(); } ProcessPropertyReader(Process element, BPMNDiagram diagram, BPMNShape shape, double resolutionFactor); String getPackage(); String getProcessType(); String getVersion(); boolean isAdHoc(); @Override Bounds getBounds(); String getProcessVariables(); String getCaseIdPrefix(); String getCaseFileVariables(); String getCaseRoles(); FlowElement getFlowElement(String id); String getGlobalVariables(); String getMetaDataAttributes(); List<DefaultImport> getDefaultImports(); String getSlaDueDate(); }### Answer: @Test public void getDefaultImports() { final String CLASS_NAME = "className"; final int QTY = 10; List<DefaultImport> defaultImports = new ArrayList<>(); for (int i = 0; i < QTY; i++) { defaultImports.add(new DefaultImport(CLASS_NAME + i)); } CustomElement.defaultImports.of(process).set(defaultImports); List<DefaultImport> result = tested.getDefaultImports(); assertEquals(QTY, result.size()); for (int i = 0; i < result.size(); i++) { assertEquals(CLASS_NAME + i, result.get(i).getClassName()); } }
### Question: ProcessPropertyReader extends BasePropertyReader { public String getProcessType() { return process.getProcessType().getName(); } ProcessPropertyReader(Process element, BPMNDiagram diagram, BPMNShape shape, double resolutionFactor); String getPackage(); String getProcessType(); String getVersion(); boolean isAdHoc(); @Override Bounds getBounds(); String getProcessVariables(); String getCaseIdPrefix(); String getCaseFileVariables(); String getCaseRoles(); FlowElement getFlowElement(String id); String getGlobalVariables(); String getMetaDataAttributes(); List<DefaultImport> getDefaultImports(); String getSlaDueDate(); }### Answer: @Test public void getProcessType() { ProcessPropertyWriter writer = new ProcessPropertyWriter( bpmn2.createProcess(), null, null); writer.setType(ProcessType.PRIVATE.getName()); tested = new ProcessPropertyReader(writer.getProcess(), definitionResolver.getDiagram(), definitionResolver.getShape(process.getId()), definitionResolver.getResolutionFactor()); assertEquals(tested.getProcessType(), ProcessType.PRIVATE.getName()); writer.setType(ProcessType.PUBLIC.getName()); tested = new ProcessPropertyReader(writer.getProcess(), definitionResolver.getDiagram(), definitionResolver.getShape(process.getId()), definitionResolver.getResolutionFactor()); assertEquals(tested.getProcessType(), ProcessType.PUBLIC.getName()); writer.setType(ProcessType.NONE.getName()); tested = new ProcessPropertyReader(writer.getProcess(), definitionResolver.getDiagram(), definitionResolver.getShape(process.getId()), definitionResolver.getResolutionFactor()); assertEquals(tested.getProcessType(), ProcessType.NONE.getName()); }
### Question: DecisionComponents { void applyTermFilter(final String value) { getFilter().setTerm(value); applyFilter(); } DecisionComponents(); @Inject DecisionComponents(final View view, final DMNIncludeModelsClient client, final ManagedInstance<DecisionComponentsItem> itemManagedInstance, final DecisionComponentFilter filter, final DMNDiagramsSession dmnDiagramsSession, final DMNGraphUtils dmnGraphUtils); @PostConstruct void init(); View getView(); void refresh(); void removeAllItems(); }### Answer: @Test public void testApplyTermFilter() { final String value = "value"; doNothing().when(decisionComponents).applyFilter(); decisionComponents.applyTermFilter(value); verify(filter).setTerm(value); verify(decisionComponents).applyFilter(); }
### Question: ScriptTaskPropertyReader extends TaskPropertyReader { public ScriptTypeValue getScript() { return new ScriptTypeValue( Scripts.scriptLanguageFromUri(task.getScriptFormat(), Scripts.LANGUAGE.JAVA.language()), Optional.ofNullable(task.getScript()).orElse(null) ); } ScriptTaskPropertyReader(ScriptTask task, BPMNDiagram diagram, DefinitionResolver definitionResolver); ScriptTypeValue getScript(); boolean isAsync(); boolean isAdHocAutoStart(); }### Answer: @Test public void testGetScript() { for (Scripts.LANGUAGE language : Scripts.LANGUAGE.values()) { testGetScript(new ScriptTypeValue(language.language(), SCRIPT), language.format(), SCRIPT); } }
### Question: AdHocSubProcessPropertyReader extends SubProcessPropertyReader { public ScriptTypeValue getAdHocCompletionCondition() { if (process.getCompletionCondition() instanceof FormalExpression) { FormalExpression completionCondition = (FormalExpression) process.getCompletionCondition(); return new ScriptTypeValue( Scripts.scriptLanguageFromUri(completionCondition.getLanguage(), Scripts.LANGUAGE.MVEL.language()), completionCondition.getBody() ); } else { return new ScriptTypeValue(Scripts.LANGUAGE.MVEL.language(), "autocomplete"); } } AdHocSubProcessPropertyReader(AdHocSubProcess element, BPMNDiagram diagram, DefinitionResolver definitionResolver); String getAdHocActivationCondition(); ScriptTypeValue getAdHocCompletionCondition(); String getAdHocOrdering(); boolean isAdHocAutostart(); }### Answer: @Test public void testGetAdHocCompletionConditionWithoutFormalExpression() { when(process.getCompletionCondition()).thenReturn(null); assertEquals(new ScriptTypeValue(Scripts.LANGUAGE.MVEL.language(), "autocomplete"), propertyReader.getAdHocCompletionCondition()); }
### Question: AdHocSubProcessPropertyReader extends SubProcessPropertyReader { public boolean isAdHocAutostart() { return CustomElement.autoStart.of(element).get(); } AdHocSubProcessPropertyReader(AdHocSubProcess element, BPMNDiagram diagram, DefinitionResolver definitionResolver); String getAdHocActivationCondition(); ScriptTypeValue getAdHocCompletionCondition(); String getAdHocOrdering(); boolean isAdHocAutostart(); }### Answer: @Test public void testIsAdHocAutostart_true() { String id = UUID.randomUUID().toString(); AdHocSubProcess adHocSubProcess = bpmn2.createAdHocSubProcess(); adHocSubProcess.setId(id); CustomElement.autoStart.of(adHocSubProcess).set(Boolean.TRUE); tested = new AdHocSubProcessPropertyReader(adHocSubProcess, definitionResolverReal.getDiagram(), definitionResolverReal); assertTrue(tested.isAdHocAutostart()); } @Test public void testIsAdHocAutostart_false() { String id = UUID.randomUUID().toString(); AdHocSubProcess adHocSubProcess = bpmn2.createAdHocSubProcess(); adHocSubProcess.setId(id); CustomElement.autoStart.of(adHocSubProcess).set(Boolean.FALSE); tested = new AdHocSubProcessPropertyReader(adHocSubProcess, definitionResolverReal.getDiagram(), definitionResolverReal); assertFalse(tested.isAdHocAutostart()); }
### Question: AdHocSubProcessPropertyReader extends SubProcessPropertyReader { public String getAdHocActivationCondition() { return CustomElement.customActivationCondition.of(element).get(); } AdHocSubProcessPropertyReader(AdHocSubProcess element, BPMNDiagram diagram, DefinitionResolver definitionResolver); String getAdHocActivationCondition(); ScriptTypeValue getAdHocCompletionCondition(); String getAdHocOrdering(); boolean isAdHocAutostart(); }### Answer: @Test public void testIsAdHocActivationCondition() { AdHocSubProcess adHocSubProcess = bpmn2.createAdHocSubProcess(); CustomElement.customActivationCondition.of(adHocSubProcess).set("some condition"); tested = new AdHocSubProcessPropertyReader(adHocSubProcess, definitionResolverReal.getDiagram(), definitionResolverReal); assertEquals(asCData("some condition"), tested.getAdHocActivationCondition()); }
### Question: ActivityPropertyReader extends FlowElementPropertyReader { public ScriptTypeListValue getOnEntryAction() { return Scripts.onEntry(element.getExtensionValues()); } ActivityPropertyReader(Activity activity, BPMNDiagram diagram, DefinitionResolver definitionResolver); ScriptTypeListValue getOnEntryAction(); ScriptTypeListValue getOnExitAction(); SimulationSet getSimulationSet(); AssignmentsInfo getAssignmentsInfo(); }### Answer: @Test public void testGetOnEntryScript() { OnEntryScriptType onEntryScript = Mockito.mock(OnEntryScriptType.class); when(onEntryScript.getScript()).thenReturn(SCRIPT); when(onEntryScript.getScriptFormat()).thenReturn(JAVA_FORMAT); List<OnEntryScriptType> onEntryScripts = Collections.singletonList(onEntryScript); List<ExtensionAttributeValue> extensions = mockExtensions(DroolsPackage.Literals.DOCUMENT_ROOT__ON_ENTRY_SCRIPT, onEntryScripts); when(activity.getExtensionValues()).thenReturn(extensions); assertScript(JAVA, SCRIPT, reader.getOnEntryAction()); } @Test public void testGetOnEntryScript() { OnEntryScriptType onEntryScript = Mockito.mock(OnEntryScriptType.class); when(onEntryScript.getScript()).thenReturn(SCRIPT); when(onEntryScript.getScriptFormat()).thenReturn(JAVA_FORMAT); List<OnEntryScriptType> onEntryScripts = Collections.singletonList(onEntryScript); EList<ExtensionAttributeValue> extensions = mockExtensions(DroolsPackage.Literals.DOCUMENT_ROOT__ON_ENTRY_SCRIPT, onEntryScripts); when(activity.getExtensionValues()).thenReturn(extensions); assertScript(JAVA, SCRIPT, reader.getOnEntryAction()); }
### Question: ActivityPropertyReader extends FlowElementPropertyReader { public ScriptTypeListValue getOnExitAction() { return Scripts.onExit(element.getExtensionValues()); } ActivityPropertyReader(Activity activity, BPMNDiagram diagram, DefinitionResolver definitionResolver); ScriptTypeListValue getOnEntryAction(); ScriptTypeListValue getOnExitAction(); SimulationSet getSimulationSet(); AssignmentsInfo getAssignmentsInfo(); }### Answer: @Test public void testGetOnExitScript() { OnExitScriptType onExitScript = Mockito.mock(OnExitScriptType.class); when(onExitScript.getScript()).thenReturn(SCRIPT); when(onExitScript.getScriptFormat()).thenReturn(JAVA_FORMAT); List<OnExitScriptType> onExitScripts = Collections.singletonList(onExitScript); List<ExtensionAttributeValue> extensions = mockExtensions(DroolsPackage.Literals.DOCUMENT_ROOT__ON_EXIT_SCRIPT, onExitScripts); when(activity.getExtensionValues()).thenReturn(extensions); assertScript(JAVA, SCRIPT, reader.getOnExitAction()); } @Test public void testGetOnExitScript() { OnExitScriptType onExitScript = Mockito.mock(OnExitScriptType.class); when(onExitScript.getScript()).thenReturn(SCRIPT); when(onExitScript.getScriptFormat()).thenReturn(JAVA_FORMAT); List<OnExitScriptType> onExitScripts = Collections.singletonList(onExitScript); EList<ExtensionAttributeValue> extensions = mockExtensions(DroolsPackage.Literals.DOCUMENT_ROOT__ON_EXIT_SCRIPT, onExitScripts); when(activity.getExtensionValues()).thenReturn(extensions); assertScript(JAVA, SCRIPT, reader.getOnExitAction()); }
### Question: DecisionComponents { void applyDrgElementFilterFilter(final String value) { getFilter().setDrgElement(value); applyFilter(); } DecisionComponents(); @Inject DecisionComponents(final View view, final DMNIncludeModelsClient client, final ManagedInstance<DecisionComponentsItem> itemManagedInstance, final DecisionComponentFilter filter, final DMNDiagramsSession dmnDiagramsSession, final DMNGraphUtils dmnGraphUtils); @PostConstruct void init(); View getView(); void refresh(); void removeAllItems(); }### Answer: @Test public void testApplyDrgElementFilterFilter() { final String value = "value"; doNothing().when(decisionComponents).applyFilter(); decisionComponents.applyDrgElementFilterFilter(value); verify(filter).setDrgElement(value); verify(decisionComponents).applyFilter(); }
### Question: DefinitionResolver { static double obtainResolutionFactor() { final String resolution = System.getProperty(BPMN_DIAGRAM_RESOLUTION_PROPERTY); if (null != resolution && resolution.trim().length() > 0) { try { return Double.parseDouble(resolution); } catch (NumberFormatException e) { LOG.error("Error parsing the BPMN diagram's resolution - marshalling factor... " + "Using as default [" + DEFAULT_RESOLUTION + "].", e); } } return DEFAULT_RESOLUTION; } DefinitionResolver( Definitions definitions, Collection<WorkItemDefinition> workItemDefinitions, boolean jbpm, Mode mode); DefinitionResolver(Definitions definitions, Collection<WorkItemDefinition> workItemDefinitions); BPMNDiagram getDiagram(); double getResolutionFactor(); boolean isJbpm(); Definitions getDefinitions(); Process getProcess(); Mode getMode(); Collection<WorkItemDefinition> getWorkItemDefinitions(); Optional<Signal> resolveSignal(String id); String resolveSignalName(String id); Optional<ElementParameters> resolveSimulationParameters(String id); BPMNShape getShape(String elementId); BPMNEdge getEdge(String elementId); }### Answer: @Test public void testObtainResolutionFactor() { double factor = DefinitionResolver.obtainResolutionFactor(); assertEquals(DefinitionResolver.DEFAULT_RESOLUTION, factor, 0d); System.setProperty(DefinitionResolver.BPMN_DIAGRAM_RESOLUTION_PROPERTY, "0.25"); factor = DefinitionResolver.obtainResolutionFactor(); assertEquals(0.25d, factor, 0d); System.clearProperty(DefinitionResolver.BPMN_DIAGRAM_RESOLUTION_PROPERTY); }
### Question: DefinitionResolver { static double calculateResolutionFactor(final BPMNDiagram diagram) { final float resolution = diagram.getResolution(); return resolution == 0 ? 1 : obtainResolutionFactor() / resolution; } DefinitionResolver( Definitions definitions, Collection<WorkItemDefinition> workItemDefinitions, boolean jbpm, Mode mode); DefinitionResolver(Definitions definitions, Collection<WorkItemDefinition> workItemDefinitions); BPMNDiagram getDiagram(); double getResolutionFactor(); boolean isJbpm(); Definitions getDefinitions(); Process getProcess(); Mode getMode(); Collection<WorkItemDefinition> getWorkItemDefinitions(); Optional<Signal> resolveSignal(String id); String resolveSignalName(String id); Optional<ElementParameters> resolveSimulationParameters(String id); BPMNShape getShape(String elementId); BPMNEdge getEdge(String elementId); }### Answer: @Test public void testCalculateResolutionFactor() { BPMNDiagram diagram = mock(BPMNDiagram.class); when(diagram.getResolution()).thenReturn(0f); double factor = DefinitionResolver.calculateResolutionFactor(diagram); assertEquals(1d, factor, 0d); when(diagram.getResolution()).thenReturn(250f); factor = DefinitionResolver.calculateResolutionFactor(diagram); assertEquals(0.45d, factor, 0d); }
### Question: DefinitionResolver { public BPMNShape getShape(String elementId) { return definitions.getDiagrams().stream() .map(BPMNDiagram::getPlane) .map(plane -> getShape(plane, elementId)) .filter(Objects::nonNull) .findFirst().orElse(null); } DefinitionResolver( Definitions definitions, Collection<WorkItemDefinition> workItemDefinitions, boolean jbpm, Mode mode); DefinitionResolver(Definitions definitions, Collection<WorkItemDefinition> workItemDefinitions); BPMNDiagram getDiagram(); double getResolutionFactor(); boolean isJbpm(); Definitions getDefinitions(); Process getProcess(); Mode getMode(); Collection<WorkItemDefinition> getWorkItemDefinitions(); Optional<Signal> resolveSignal(String id); String resolveSignalName(String id); Optional<ElementParameters> resolveSimulationParameters(String id); BPMNShape getShape(String elementId); BPMNEdge getEdge(String elementId); }### Answer: @Test public void testGetShape() { BPMNShape shape = mock(BPMNShape.class); BaseElement bpmnElement = mock(BaseElement.class); when(shape.getBpmnElement()).thenReturn(bpmnElement); when(bpmnElement.getId()).thenReturn(ID); planeElement.add(shape); assertEquals(shape, definitionResolver.getShape(ID)); } @Test public void testGetShape() { BPMNShape shape = mock(BPMNShape.class); BaseElement bpmnElement = mock(BaseElement.class); when(shape.getBpmnElement()).thenReturn(bpmnElement); when(bpmnElement.getId()).thenReturn(ID); planeElements.add(shape); assertEquals(shape, definitionResolver.getShape(ID)); }
### Question: DefinitionResolver { public BPMNEdge getEdge(String elementId) { return definitions.getDiagrams().stream() .map(BPMNDiagram::getPlane) .map(plane -> getEdge(plane, elementId)) .filter(Objects::nonNull) .findFirst().orElse(null); } DefinitionResolver( Definitions definitions, Collection<WorkItemDefinition> workItemDefinitions, boolean jbpm, Mode mode); DefinitionResolver(Definitions definitions, Collection<WorkItemDefinition> workItemDefinitions); BPMNDiagram getDiagram(); double getResolutionFactor(); boolean isJbpm(); Definitions getDefinitions(); Process getProcess(); Mode getMode(); Collection<WorkItemDefinition> getWorkItemDefinitions(); Optional<Signal> resolveSignal(String id); String resolveSignalName(String id); Optional<ElementParameters> resolveSimulationParameters(String id); BPMNShape getShape(String elementId); BPMNEdge getEdge(String elementId); }### Answer: @Test public void testGetEdge() { BPMNEdge edge = mock(BPMNEdge.class); BaseElement bpmnElement = mock(BaseElement.class); when(edge.getBpmnElement()).thenReturn(bpmnElement); when(bpmnElement.getId()).thenReturn(ID); planeElement.add(edge); assertEquals(edge, definitionResolver.getEdge(ID)); } @Test public void testGetEdge() { BPMNEdge edge = mock(BPMNEdge.class); BaseElement bpmnElement = mock(BaseElement.class); when(edge.getBpmnElement()).thenReturn(bpmnElement); when(bpmnElement.getId()).thenReturn(ID); planeElements.add(edge); assertEquals(edge, definitionResolver.getEdge(ID)); }
### Question: DecisionComponents { void applyFilter() { hideAllItems(); showFilteredItems(); } DecisionComponents(); @Inject DecisionComponents(final View view, final DMNIncludeModelsClient client, final ManagedInstance<DecisionComponentsItem> itemManagedInstance, final DecisionComponentFilter filter, final DMNDiagramsSession dmnDiagramsSession, final DMNGraphUtils dmnGraphUtils); @PostConstruct void init(); View getView(); void refresh(); void removeAllItems(); }### Answer: @Test public void testApplyFilter() { final DecisionComponentsItem item1 = mock(DecisionComponentsItem.class); final DecisionComponentsItem item2 = mock(DecisionComponentsItem.class); final DecisionComponentsItem item3 = mock(DecisionComponentsItem.class); final DecisionComponent component1 = mock(DecisionComponent.class); final DecisionComponent component2 = mock(DecisionComponent.class); final DecisionComponent component3 = mock(DecisionComponent.class); final List<DecisionComponentsItem> decisionComponentsItems = asList(item1, item2, item3); doReturn(new DecisionComponentFilter()).when(decisionComponents).getFilter(); doReturn(decisionComponentsItems).when(decisionComponents).getDecisionComponentsItems(); when(item1.getDecisionComponent()).thenReturn(component1); when(item2.getDecisionComponent()).thenReturn(component2); when(item3.getDecisionComponent()).thenReturn(component3); when(component1.getName()).thenReturn("name3"); when(component2.getName()).thenReturn("nome!!!"); when(component3.getName()).thenReturn("name1"); decisionComponents.getFilter().setTerm("name"); decisionComponents.applyFilter(); verify(item1).hide(); verify(item2).hide(); verify(item3).hide(); verify(item3).show(); verify(item1).show(); }
### Question: BoundaryEventConverter implements EdgeConverter<BoundaryEvent> { @Override public Result<BpmnEdge> convertEdge(BoundaryEvent event, Map<String, BpmnNode> nodes) { String parentId = event.getAttachedToRef().getId(); String childId = event.getId(); return valid(nodes, parentId, childId) ? Result.success(BpmnEdge.docked(nodes.get(parentId), nodes.get(childId))) : Result.ignored("Boundary ignored", MarshallingMessage.builder() .message("Boundary ignored") .messageKey(MarshallingMessageKeys.boundaryIgnored) .messageArguments(childId, parentId) .type(Violation.Type.WARNING) .build()); } @Override Result<BpmnEdge> convertEdge(BoundaryEvent event, Map<String, BpmnNode> nodes); }### Answer: @Test public void convertEdge() { Map<String, BpmnNode> nodes = new Maps.Builder<String, BpmnNode>() .put(PARENT_ID, node1) .put(CHILD_ID, node2) .build(); Result<BpmnEdge> result = tested.convertEdge(event, nodes); BpmnEdge value = result.value(); assertTrue(result.isSuccess()); assertEquals(node1, value.getSource()); assertEquals(node2, value.getTarget()); assertTrue(value.isDocked()); } @Test public void convertMissingNodes() { Map<String, BpmnNode> nodes = new HashMap<>(); Result<BpmnEdge> result = tested.convertEdge(event, nodes); BpmnEdge value = result.value(); assertTrue(result.isIgnored()); assertNull(value); }
### Question: RootProcessConverter extends BaseRootProcessConverter<BPMNDiagramImpl, DiagramSet, ProcessData, AdvancedData> { @Override protected Node<View<BPMNDiagramImpl>, Edge> createNode(String id) { return delegate.factoryManager.newNode(id, BPMNDiagramImpl.class); } RootProcessConverter(TypedFactoryManager typedFactoryManager, PropertyReaderFactory propertyReaderFactory, DefinitionResolver definitionResolver, BaseConverterFactory factory); }### Answer: @Test public void testCreateNode() { assertTrue(tested.createNode("id").getContent().getDefinition() instanceof BPMNDiagramImpl); }
### Question: RootProcessConverter extends BaseRootProcessConverter<BPMNDiagramImpl, DiagramSet, ProcessData, AdvancedData> { @Override protected ProcessData createProcessData(String processVariables) { return new ProcessData(new ProcessVariables(processVariables)); } RootProcessConverter(TypedFactoryManager typedFactoryManager, PropertyReaderFactory propertyReaderFactory, DefinitionResolver definitionResolver, BaseConverterFactory factory); }### Answer: @Test public void testCreateProcessData() { assertNotNull(tested.createProcessData("id")); }
### Question: RootProcessConverter extends BaseRootProcessConverter<BPMNDiagramImpl, DiagramSet, ProcessData, AdvancedData> { @Override protected DiagramSet createDiagramSet(Process process, ProcessPropertyReader p, DefinitionsPropertyReader d) { return new DiagramSet(new Name(revertIllegalCharsAttribute(process.getName())), new Documentation(p.getDocumentation()), new Id(revertIllegalCharsAttribute(process.getId())), new Package(p.getPackage()), new ProcessType(p.getProcessType()), new Version(p.getVersion()), new AdHoc(p.isAdHoc()), new ProcessInstanceDescription(p.getDescription()), new Imports(new ImportsValue(p.getDefaultImports(), d.getWSDLImports())), new Executable(process.isIsExecutable()), new SLADueDate(p.getSlaDueDate())); } RootProcessConverter(TypedFactoryManager typedFactoryManager, PropertyReaderFactory propertyReaderFactory, DefinitionResolver definitionResolver, BaseConverterFactory factory); }### Answer: @Test public void testCreateDiagramSet() { DiagramSet diagramSet = createDiagramSet(); assertNotNull(diagramSet); } @Test public void testImports() { DiagramSet diagramSet = createDiagramSet(); Imports imports = diagramSet.getImports(); assertNotNull(imports); ImportsValue importsValue = imports.getValue(); assertNotNull(importsValue); List<DefaultImport> defaultImports = importsValue.getDefaultImports(); assertNotNull(defaultImports); assertFalse(defaultImports.isEmpty()); DefaultImport defaultImport = defaultImports.get(0); assertNotNull(defaultImport); assertEquals(getClass().getName(), defaultImport.getClassName()); }
### Question: RootProcessConverter extends BaseRootProcessConverter<BPMNDiagramImpl, DiagramSet, ProcessData, AdvancedData> { @Override protected AdvancedData createAdvancedData(String globalVariables, String metaDataAttributes) { return new AdvancedData(new GlobalVariables(globalVariables), new MetaDataAttributes(metaDataAttributes)); } RootProcessConverter(TypedFactoryManager typedFactoryManager, PropertyReaderFactory propertyReaderFactory, DefinitionResolver definitionResolver, BaseConverterFactory factory); }### Answer: @Test public void createAdvancedData() { assertTrue(AdvancedData.class.isInstance(tested.createAdvancedData("id", "testßval"))); } @Test public void convertAdvancedData() { tested.createAdvancedData("id", "testßval"); assertTrue(tested.convertProcess().isSuccess()); }
### Question: DecisionComponents { public void removeAllItems() { clearDecisionComponents(); } DecisionComponents(); @Inject DecisionComponents(final View view, final DMNIncludeModelsClient client, final ManagedInstance<DecisionComponentsItem> itemManagedInstance, final DecisionComponentFilter filter, final DMNDiagramsSession dmnDiagramsSession, final DMNGraphUtils dmnGraphUtils); @PostConstruct void init(); View getView(); void refresh(); void removeAllItems(); }### Answer: @Test public void testRemoveAllItems() { decisionComponents.removeAllItems(); verify(decisionComponents).clearDecisionComponents(); }
### Question: ProcessConverterDelegate { Result<Boolean> convertEdges(BpmnNode processRoot, List<BaseElement> flowElements, Map<String, BpmnNode> nodes) { List<Result<BpmnEdge>> results = flowElements.stream() .map(e -> converterFactory.edgeConverter().convertEdge(e, nodes)) .filter(Result::isSuccess) .collect(Collectors.toList()); boolean value = results.size() > 0 ? results.stream() .map(Result::value) .filter(Objects::nonNull) .map(processRoot::addEdge) .allMatch(Boolean.TRUE::equals) : false; return ResultComposer.compose(value, results); } ProcessConverterDelegate( TypedFactoryManager typedFactoryManager, PropertyReaderFactory propertyReaderFactory, DefinitionResolver definitionResolver, BaseConverterFactory factory); }### Answer: @Test public void testConvertEdges() { Task task1 = mockTask("1"); Task task2 = mockTask("2"); BpmnNode task1Node = mockTaskNode(task1); BpmnNode task2Node = mockTaskNode(task2); SequenceFlow sequenceFlow = mockSequenceFlow("seq1", task1, task2); List<BaseElement> elements = Arrays.asList(sequenceFlow, task1, task2); assertFalse(converterDelegate.convertEdges(parentNode, elements, new HashMap<>()).value()); Map<String, BpmnNode> nodes = new Maps.Builder<String, BpmnNode>().put(task1.getId(), task1Node).put(task2.getId(), task2Node).build(); assertTrue(converterDelegate.convertEdges(parentNode, elements, nodes).value()); } @Test public void testConvertEdgesIgnoredNonEdgeElement() { Map<String, BpmnNode> nodes = new HashMap<>(); List<BaseElement> elements = Arrays.asList(mockTask("1")); assertFalse(converterDelegate.convertEdges(parentNode, elements, nodes).value()); }
### Question: SubProcessConverter extends BaseSubProcessConverter<AdHocSubprocess, ProcessData, AdHocSubprocessTaskExecutionSet> { @Override protected Node<View<AdHocSubprocess>, Edge> createNode(String id) { return delegate.factoryManager.newNode(id, AdHocSubprocess.class); } SubProcessConverter(TypedFactoryManager typedFactoryManager, PropertyReaderFactory propertyReaderFactory, DefinitionResolver definitionResolver, ConverterFactory converterFactory); }### Answer: @Test public void createNode() { assertTrue(AdHocSubprocess.class.isInstance(tested.createNode("id").getContent().getDefinition())); }
### Question: SubProcessConverter extends BaseSubProcessConverter<AdHocSubprocess, ProcessData, AdHocSubprocessTaskExecutionSet> { @Override protected ProcessData createProcessData(String processVariables) { return new ProcessData(new ProcessVariables(processVariables)); } SubProcessConverter(TypedFactoryManager typedFactoryManager, PropertyReaderFactory propertyReaderFactory, DefinitionResolver definitionResolver, ConverterFactory converterFactory); }### Answer: @Test public void createProcessData() { assertTrue(ProcessData.class.isInstance(tested.createProcessData("id"))); }
### Question: SubProcessConverter extends BaseSubProcessConverter<AdHocSubprocess, ProcessData, AdHocSubprocessTaskExecutionSet> { @Override protected AdHocSubprocessTaskExecutionSet createAdHocSubprocessTaskExecutionSet(AdHocSubProcessPropertyReader p) { return new AdHocSubprocessTaskExecutionSet(new AdHocActivationCondition(p.getAdHocActivationCondition()), new AdHocCompletionCondition(p.getAdHocCompletionCondition()), new AdHocOrdering(p.getAdHocOrdering()), new AdHocAutostart(p.isAdHocAutostart()), new OnEntryAction(p.getOnEntryAction()), new OnExitAction(p.getOnExitAction()), new IsAsync(p.isAsync()), new SLADueDate(p.getSlaDueDate())); } SubProcessConverter(TypedFactoryManager typedFactoryManager, PropertyReaderFactory propertyReaderFactory, DefinitionResolver definitionResolver, ConverterFactory converterFactory); }### Answer: @Test public void testCreateAdHocSubprocessTaskExecutionSet() { AdHocSubProcess adHocSubProcess = mock(AdHocSubProcess.class); when(adHocSubProcess.getCompletionCondition()).thenReturn(mock(FormalExpression.class)); when(adHocSubProcess.getOrdering()).thenReturn(AdHocOrdering.SEQUENTIAL); assertTrue(AdHocSubprocessTaskExecutionSet.class.isInstance(tested.createAdHocSubprocessTaskExecutionSet( new AdHocSubProcessPropertyReader(adHocSubProcess, definitionResolver.getDiagram(), definitionResolver)))); }
### Question: ResultComposer { public static <T, R> Result compose(T value, Collection<Result<R>>... results) { List<MarshallingMessage> messages = Stream.of(results).flatMap(Collection::stream) .map(Result::messages) .flatMap(List::stream) .collect(Collectors.toList()); return Result.success(value, messages.stream().toArray(MarshallingMessage[]::new)); } static Result compose(T value, Collection<Result<R>>... results); static Result compose(T value, Result... result); }### Answer: @Test public void compose() { final Result result = ResultComposer.compose(value, result1, result2, result3); assertResult(result); } @Test public void composeList() { final Result result = ResultComposer.compose(value, Arrays.asList(result1, result2, result3)); assertResult(result); }
### Question: DecisionComponents { DMNIncludedModel asDMNIncludedModel(final Import anImport) { final String modelName = anImport.getName().getValue(); final String namespace = anImport.getNamespace(); final String importType = anImport.getImportType(); final String path = FileUtils.getFileName(anImport.getLocationURI().getValue()); return new DMNIncludedModel(modelName, "", path, namespace, importType, 0, 0); } DecisionComponents(); @Inject DecisionComponents(final View view, final DMNIncludeModelsClient client, final ManagedInstance<DecisionComponentsItem> itemManagedInstance, final DecisionComponentFilter filter, final DMNDiagramsSession dmnDiagramsSession, final DMNGraphUtils dmnGraphUtils); @PostConstruct void init(); View getView(); void refresh(); void removeAllItems(); }### Answer: @Test public void testAsDMNIncludedModel() { final String modelName = "Model Name"; final String namespace = "The Namespace"; final String type = "The type"; final String file = "my file.dmn"; final String filePath = " final Import anImport = new Import(); anImport.setName(new Name(modelName)); anImport.setNamespace(namespace); anImport.setImportType(type); anImport.setLocationURI(new LocationURI(filePath)); final DMNIncludedModel includedModel = decisionComponents.asDMNIncludedModel(anImport); assertEquals(modelName, includedModel.getModelName()); assertEquals(namespace, includedModel.getNamespace()); assertEquals(type, includedModel.getImportType()); assertEquals(file, includedModel.getPath()); }
### Question: CustomElement { public T get() { return elementDefinition.getValue(element); } CustomElement(ElementDefinition<T> elementDefinition, BaseElement element); T get(); void set(T value); static final MetadataTypeDefinition<Boolean> async; static final MetadataTypeDefinition<Boolean> autoStart; static final MetadataTypeDefinition<Boolean> autoConnectionSource; static final MetadataTypeDefinition<Boolean> autoConnectionTarget; static final MetadataTypeDefinition<String> customTags; static final MetadataTypeDefinition<String> description; static final MetadataTypeDefinition<String> scope; static final MetadataTypeDefinition<String> name; static final MetadataTypeDefinition<String> caseIdPrefix; static final MetadataTypeDefinition<String> caseRole; static final MetadataTypeDefinition<String> slaDueDate; static final GlobalVariablesElement globalVariables; static final MetaDataAttributesElement metaDataAttributes; static final MetadataTypeDefinition<Boolean> isCase; static final MetadataTypeDefinition<String> customActivationCondition; static final MetadataTypeDefinition<Boolean> abortParent; static final DefaultImportsElement defaultImports; }### Answer: @Test public void testGet() { Object value = new Object(); elementDefinition.setValue(baseElement, value); assertEquals(value, new CustomElement<>(elementDefinition, baseElement).get()); }
### Question: CustomElement { public void set(T value) { if (value != null && !value.equals(elementDefinition.getDefaultValue())) { elementDefinition.setValue(element, value); } } CustomElement(ElementDefinition<T> elementDefinition, BaseElement element); T get(); void set(T value); static final MetadataTypeDefinition<Boolean> async; static final MetadataTypeDefinition<Boolean> autoStart; static final MetadataTypeDefinition<Boolean> autoConnectionSource; static final MetadataTypeDefinition<Boolean> autoConnectionTarget; static final MetadataTypeDefinition<String> customTags; static final MetadataTypeDefinition<String> description; static final MetadataTypeDefinition<String> scope; static final MetadataTypeDefinition<String> name; static final MetadataTypeDefinition<String> caseIdPrefix; static final MetadataTypeDefinition<String> caseRole; static final MetadataTypeDefinition<String> slaDueDate; static final GlobalVariablesElement globalVariables; static final MetaDataAttributesElement metaDataAttributes; static final MetadataTypeDefinition<Boolean> isCase; static final MetadataTypeDefinition<String> customActivationCondition; static final MetadataTypeDefinition<Boolean> abortParent; static final DefaultImportsElement defaultImports; }### Answer: @Test public void testSetNonDefaultValue() { Object newValue = new Object(); CustomElement<Object> customElement = new CustomElement<>(elementDefinition, baseElement); customElement.set(newValue); assertEquals(newValue, elementDefinition.getValue(baseElement)); }
### Question: CustomInputDefinition { public CustomInput<T> of(Task element) { return new CustomInput<>(this, element); } CustomInputDefinition(String name, String type, T defaultValue); String name(); String type(); abstract T getValue(Task element); CustomInput<T> of(Task element); }### Answer: @Test public void shouldReuseInputSet() { Task task = bpmn2.createTask(); StringInput stringInput = new StringInput("BLAH", "ATYPE", "DEFAULTVAL"); stringInput.of(task).set("VALUE"); StringInput stringInput2 = new StringInput("BLAH2", "ATYPE", "DEFAULTVAL"); stringInput.of(task).set("VALUE"); InputOutputSpecification ioSpecification = task.getIoSpecification(); List<InputSet> inputSets = ioSpecification.getInputSets(); assertEquals(1, inputSets.size()); }
### Question: DefaultImportsElement extends ElementDefinition<List<DefaultImport>> { @Override public List<DefaultImport> getValue(BaseElement element) { List<ExtensionAttributeValue> extValues = element.getExtensionValues(); List<DefaultImport> defaultImports = extValues.stream() .map(ExtensionAttributeValue::getValue) .flatMap((Function<FeatureMap, Stream<?>>) extensionElements -> { List o = (List) extensionElements.get(DOCUMENT_ROOT__IMPORT, true); return o.stream(); }) .map(m -> new DefaultImport(((ImportType) m).getName())) .collect(Collectors.toList()); return defaultImports; } DefaultImportsElement(String name); @Override List<DefaultImport> getValue(BaseElement element); @Override void setValue(BaseElement element, List<DefaultImport> value); static FeatureMap.Entry extensionOf(DefaultImport defaultImport); static ImportType importTypeDataOf(DefaultImport defaultImport); }### Answer: @Test public void testGetValue() { BaseElement baseElement = bpmn2.createProcess(); assertEquals(new ArrayList<>(), CustomElement.defaultImports.of(baseElement).get()); }
### Question: DefaultImportsElement extends ElementDefinition<List<DefaultImport>> { @Override public void setValue(BaseElement element, List<DefaultImport> value) { value.stream() .map(DefaultImportsElement::extensionOf) .forEach(getExtensionElements(element)::add); } DefaultImportsElement(String name); @Override List<DefaultImport> getValue(BaseElement element); @Override void setValue(BaseElement element, List<DefaultImport> value); static FeatureMap.Entry extensionOf(DefaultImport defaultImport); static ImportType importTypeDataOf(DefaultImport defaultImport); }### Answer: @Test public void testSetValue() { List<DefaultImport> defaultImports = new ArrayList<>(); defaultImports.add(new DefaultImport(CLASS_NAME + 1)); defaultImports.add(new DefaultImport(CLASS_NAME + 2)); defaultImports.add(new DefaultImport(CLASS_NAME + 3)); BaseElement baseElement = bpmn2.createProcess(); CustomElement.defaultImports.of(baseElement).set(defaultImports); List<DefaultImport> result = CustomElement.defaultImports.of(baseElement).get(); assertEquals(3, result.size()); assertEquals(CLASS_NAME + 1, result.get(0).getClassName()); assertEquals(CLASS_NAME + 2, result.get(1).getClassName()); assertEquals(CLASS_NAME + 3, result.get(2).getClassName()); }
### Question: DefaultImportsElement extends ElementDefinition<List<DefaultImport>> { public static FeatureMap.Entry extensionOf(DefaultImport defaultImport) { return new EStructuralFeatureImpl.SimpleFeatureMapEntry( (EStructuralFeature.Internal) DOCUMENT_ROOT__IMPORT, importTypeDataOf(defaultImport)); } DefaultImportsElement(String name); @Override List<DefaultImport> getValue(BaseElement element); @Override void setValue(BaseElement element, List<DefaultImport> value); static FeatureMap.Entry extensionOf(DefaultImport defaultImport); static ImportType importTypeDataOf(DefaultImport defaultImport); }### Answer: @Test public void extensionOf() { DefaultImportsElement defaultImportsElement = new DefaultImportsElement(NAME); DefaultImport defaultImport = new DefaultImport(CLASS_NAME); ImportType importType = defaultImportsElement.importTypeDataOf(defaultImport); FeatureMap.Entry entry = defaultImportsElement.extensionOf(defaultImport); assertNotNull(entry); assertTrue(entry instanceof EStructuralFeatureImpl.SimpleFeatureMapEntry); assertEquals(DOCUMENT_ROOT__IMPORT, entry.getEStructuralFeature()); assertNotNull((ImportType) entry.getValue()); assertEquals(importType.getName(), ((ImportType) entry.getValue()).getName()); }
### Question: DefaultImportsElement extends ElementDefinition<List<DefaultImport>> { public static ImportType importTypeDataOf(DefaultImport defaultImport) { ImportType importType = DroolsFactory.eINSTANCE.createImportType(); importType.setName(defaultImport.getClassName()); return importType; } DefaultImportsElement(String name); @Override List<DefaultImport> getValue(BaseElement element); @Override void setValue(BaseElement element, List<DefaultImport> value); static FeatureMap.Entry extensionOf(DefaultImport defaultImport); static ImportType importTypeDataOf(DefaultImport defaultImport); }### Answer: @Test public void importTypeDataOf() { DefaultImportsElement defaultImportsElement = new DefaultImportsElement(NAME); DefaultImport defaultImport = new DefaultImport(CLASS_NAME); ImportType importType = defaultImportsElement.importTypeDataOf(defaultImport); assertEquals(CLASS_NAME, importType.getName()); }
### Question: MetaDataAttributesElement extends ElementDefinition<String> { @Override public void setValue(BaseElement element, String value) { setStringValue(element, value); } MetaDataAttributesElement(String name); @Override String getValue(BaseElement element); @Override void setValue(BaseElement element, String value); static final String DELIMITER; static final String SEPARATOR; }### Answer: @Test public void testSetValue() { BaseElement baseElement = bpmn2.createProcess(); CustomElement.metaDataAttributes.of(baseElement).set(ATTRIBUTES); assertEquals("att1ß<![CDATA[val1]]>Øatt2ß<![CDATA[val2]]>Øatt3ß<![CDATA[val3]]>", CustomElement.metaDataAttributes.of(baseElement).get()); }
### Question: MetaDataAttributesElement extends ElementDefinition<String> { protected FeatureMap.Entry extensionOf(String metaData) { return new EStructuralFeatureImpl.SimpleFeatureMapEntry( (EStructuralFeature.Internal) DOCUMENT_ROOT__META_DATA, metaDataTypeDataOf(metaData)); } MetaDataAttributesElement(String name); @Override String getValue(BaseElement element); @Override void setValue(BaseElement element, String value); static final String DELIMITER; static final String SEPARATOR; }### Answer: @Test public void testExtensionOf() { MetaDataAttributesElement metaDataAttributesElement = new MetaDataAttributesElement(NAME); MetaDataType metaDataType = metaDataAttributesElement.metaDataTypeDataOf(ATTRIBUTE); FeatureMap.Entry entry = metaDataAttributesElement.extensionOf(ATTRIBUTE); assertNotNull(entry); assertTrue(entry instanceof EStructuralFeatureImpl.SimpleFeatureMapEntry); assertEquals(DOCUMENT_ROOT__META_DATA, entry.getEStructuralFeature()); assertNotNull(entry.getValue()); assertEquals(metaDataType.getName(), ((MetaDataType) entry.getValue()).getName()); assertEquals(metaDataType.getMetaValue(), ((MetaDataType) entry.getValue()).getMetaValue()); }
### Question: MetaDataAttributesElement extends ElementDefinition<String> { protected MetaDataType metaDataTypeDataOf(String metaData) { MetaDataType metaDataType = DroolsFactory.eINSTANCE.createMetaDataType(); String[] properties = metaData.split(SEPARATOR); metaDataType.setName(properties[0]); metaDataType.setMetaValue(properties.length > 1 ? asCData(properties[1]) : null); return metaDataType; } MetaDataAttributesElement(String name); @Override String getValue(BaseElement element); @Override void setValue(BaseElement element, String value); static final String DELIMITER; static final String SEPARATOR; }### Answer: @Test public void testImportTypeDataOf() { MetaDataAttributesElement metaDataAttributesElement = new MetaDataAttributesElement(NAME); MetaDataType metaDataType = metaDataAttributesElement.metaDataTypeDataOf(ATTRIBUTE); assertTrue("att1ß<![CDATA[val1]]>".startsWith(metaDataType.getName())); assertTrue("att1ß<![CDATA[val1]]>".endsWith(metaDataType.getMetaValue())); }
### Question: DecisionComponents { void createDecisionComponentItem(final DecisionComponent component) { final DecisionComponentsItem item = itemManagedInstance.get(); item.setDecisionComponent(component); getDecisionComponentsItems().add(item); view.addListItem(item.getView().getElement()); } DecisionComponents(); @Inject DecisionComponents(final View view, final DMNIncludeModelsClient client, final ManagedInstance<DecisionComponentsItem> itemManagedInstance, final DecisionComponentFilter filter, final DMNDiagramsSession dmnDiagramsSession, final DMNGraphUtils dmnGraphUtils); @PostConstruct void init(); View getView(); void refresh(); void removeAllItems(); }### Answer: @Test public void testCreateDecisionComponentItem() { final DecisionComponentsItem item = mock(DecisionComponentsItem.class); final List<DecisionComponentsItem> decisionComponentsItems = spy(new ArrayList<>()); final DecisionComponentsItem.View decisionComponentsView = mock(DecisionComponentsItem.View.class); final HTMLElement htmlElement = mock(HTMLElement.class); final DecisionComponent component = mock(DecisionComponent.class); when(decisionComponentsView.getElement()).thenReturn(htmlElement); when(itemManagedInstance.get()).thenReturn(item); when(item.getView()).thenReturn(decisionComponentsView); doReturn(decisionComponentsItems).when(decisionComponents).getDecisionComponentsItems(); decisionComponents.createDecisionComponentItem(component); verify(item).setDecisionComponent(any(DecisionComponent.class)); verify(decisionComponentsItems).add(item); verify(view).addListItem(htmlElement); }
### Question: GlobalVariablesElement extends ElementDefinition<String> { @Override public String getValue(BaseElement element) { return getStringValue(element) .orElse(getDefaultValue()); } GlobalVariablesElement(String name); @Override String getValue(BaseElement element); @Override void setValue(BaseElement element, String value); }### Answer: @Test public void testGetValue() { BaseElement baseElement = bpmn2.createProcess(); CustomElement.globalVariables.of(baseElement).set(GLOBAL_VARIABLES); assertEquals(GLOBAL_VARIABLES, CustomElement.globalVariables.of(baseElement).get()); }
### Question: GlobalVariablesElement extends ElementDefinition<String> { @Override public void setValue(BaseElement element, String value) { setStringValue(element, value); } GlobalVariablesElement(String name); @Override String getValue(BaseElement element); @Override void setValue(BaseElement element, String value); }### Answer: @Test public void testSetValue() { BaseElement baseElement = bpmn2.createProcess(); CustomElement.globalVariables.of(baseElement).set(GLOBAL_VARIABLES); assertEquals(GLOBAL_VARIABLES, CustomElement.globalVariables.of(baseElement).get()); }
### Question: GlobalVariablesElement extends ElementDefinition<String> { static FeatureMap.Entry extensionOf(String variable) { return new EStructuralFeatureImpl.SimpleFeatureMapEntry( (EStructuralFeature.Internal) DOCUMENT_ROOT__GLOBAL, globalTypeDataOf(variable)); } GlobalVariablesElement(String name); @Override String getValue(BaseElement element); @Override void setValue(BaseElement element, String value); }### Answer: @Test public void testExtensionOf() { GlobalVariablesElement globalVariablesElement = new GlobalVariablesElement(NAME); GlobalType globalType = globalVariablesElement.globalTypeDataOf(GLOBAL_VARIABLE); FeatureMap.Entry entry = globalVariablesElement.extensionOf(GLOBAL_VARIABLE); assertNotNull(entry); assertTrue(entry instanceof EStructuralFeatureImpl.SimpleFeatureMapEntry); assertEquals(DOCUMENT_ROOT__GLOBAL, entry.getEStructuralFeature()); assertNotNull(entry.getValue()); assertEquals(globalType.getIdentifier(), ((GlobalType) entry.getValue()).getIdentifier()); assertEquals(globalType.getType(), ((GlobalType) entry.getValue()).getType()); }