use of org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly in project kie-wb-common by kiegroup.
the class NoInputNodesInImportedDecisionRuleTest method testEvaluate.
@Test
@SuppressWarnings("unchecked")
public void testEvaluate() {
final Node source = mock(Node.class);
final Node target = mock(Node.class);
final View content = mock(View.class);
final DynamicReadOnly dynamicReadonly = mock(DynamicReadOnly.class);
when(dynamicReadonly.isAllowOnlyVisualChange()).thenReturn(true);
when(content.getDefinition()).thenReturn(dynamicReadonly);
when(target.getContent()).thenReturn(content);
when(context.getSource()).thenReturn(Optional.of(source));
when(context.getTarget()).thenReturn(Optional.of(target));
final RuleViolations result = check.evaluate(rule, context);
assertNotNull(result);
final RuleViolation violation = result.violations().iterator().next();
assertNotNull(violation);
assertTrue(violation.getArguments().isPresent());
assertEquals(1, violation.getArguments().get().length);
assertEquals(NoInputNodesInImportedDecisionRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
use of org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly in project kie-wb-common by kiegroup.
the class NoInputNodesInImportedDecisionRuleTest method testIsReadOnly.
@Test
@SuppressWarnings("unchecked")
public void testIsReadOnly() {
final Node target = mock(Node.class);
final View content = mock(View.class);
final DynamicReadOnly dynamicReadonly = mock(DynamicReadOnly.class);
when(dynamicReadonly.isAllowOnlyVisualChange()).thenReturn(true);
when(content.getDefinition()).thenReturn(dynamicReadonly);
when(target.getContent()).thenReturn(content);
when(context.getTarget()).thenReturn(Optional.of(target));
final boolean actual = check.isReadOnly(Optional.of(target));
assertTrue(actual);
verify(check).isReadOnly(any(Optional.class));
}
use of org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly in project kie-wb-common by kiegroup.
the class ObserverBuilderControl method updateElementFromDefinition.
@Override
@SuppressWarnings("unchecked")
protected void updateElementFromDefinition(final Element element, final Object definition) {
final Object content = element.getContent();
if (!(content instanceof View)) {
return;
}
final Object newDefinition = ((View) content).getDefinition();
if (newDefinition instanceof HasName && definition instanceof HasName) {
((HasName) newDefinition).getName().setValue(((HasName) definition).getName().getValue());
}
if (newDefinition instanceof DynamicReadOnly && definition instanceof DynamicReadOnly) {
((DynamicReadOnly) newDefinition).setAllowOnlyVisualChange(((DynamicReadOnly) definition).isAllowOnlyVisualChange());
}
if (newDefinition instanceof HasVariable && definition instanceof HasVariable) {
((HasVariable) newDefinition).setVariable(((HasVariable) definition).getVariable());
}
if (newDefinition instanceof BusinessKnowledgeModel && definition instanceof BusinessKnowledgeModel) {
((BusinessKnowledgeModel) newDefinition).setEncapsulatedLogic(((BusinessKnowledgeModel) definition).getEncapsulatedLogic());
}
if (newDefinition instanceof HasExpression && definition instanceof HasExpression) {
((HasExpression) newDefinition).setExpression(((HasExpression) definition).getExpression());
}
if (newDefinition instanceof DMNElement && definition instanceof DMNElement) {
final DMNElement dmnElement = (DMNElement) definition;
if (!StringUtils.isEmpty(dmnElement.getId().getValue())) {
((DMNElement) newDefinition).getId().setValue(dmnElement.getId().getValue());
}
}
final Optional<DMNDiagramElement> currentDMNDiagramElement = getDMNDiagramsSession().getCurrentDMNDiagramElement();
if (currentDMNDiagramElement.isPresent() && newDefinition instanceof HasContentDefinitionId) {
((HasContentDefinitionId) newDefinition).setDiagramId(currentDMNDiagramElement.get().getId().getValue());
}
}
use of org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly in project kie-wb-common by kiegroup.
the class AbstractCanvasInlineTextEditorControlTest method testAllowOnlyVisualChanges.
@Test
public void testAllowOnlyVisualChanges() {
final Element element = mock(Element.class);
final Definition definition = mock(Definition.class);
final DynamicReadOnly dynamicReadOnly = mock(DynamicReadOnly.class);
when(element.getContent()).thenReturn(definition);
when(definition.getDefinition()).thenReturn(dynamicReadOnly);
boolean actual = control.allowOnlyVisualChanges(element);
assertFalse(actual);
when(dynamicReadOnly.isAllowOnlyVisualChange()).thenReturn(true);
actual = control.allowOnlyVisualChanges(element);
assertTrue(actual);
}
use of org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly in project kie-wb-common by kiegroup.
the class ObserverBuilderControlTest method testUpdateDynamicReadOnlyFromDefinition.
private void testUpdateDynamicReadOnlyFromDefinition(final boolean expectedDynamicReadOnlyValue) {
final Element element = mock(Element.class);
final View elementContent = mock(View.class);
final DynamicReadOnly newDefinition = mock(DynamicReadOnly.class);
final DynamicReadOnly definition = mock(DynamicReadOnly.class);
when(element.getContent()).thenReturn(elementContent);
when(elementContent.getDefinition()).thenReturn(newDefinition);
when(definition.isAllowOnlyVisualChange()).thenReturn(expectedDynamicReadOnlyValue);
observerBuilderControl.updateElementFromDefinition(element, definition);
verify(newDefinition).setAllowOnlyVisualChange(expectedDynamicReadOnlyValue);
}
Aggregations