Search in sources :

Example 11 with HasVariable

use of org.kie.workbench.common.dmn.api.definition.HasVariable in project kie-wb-common by kiegroup.

the class ExpressionContainerGrid method spyHasName.

/**
 * Proxy {@link HasName} to be able intercept interactions with the original to update the
 * navigation label in {@link ExpressionEditorView#setExpressionNameText(Optional)} when the {@link Name}
 * changes. The {@link Name} changes by a {@link SetHasValueCommand#execute(AbstractCanvasHandler)} or
 * {@link SetHasValueCommand#undo(AbstractCanvasHandler)} that ensures the {@link HasName#setName(Name)}
 * method is called.
 * @param hasName A {@link HasName} to be proxied.
 * @return A proxy that intercepts interactions with the wrapped {@link HasName}
 */
Optional<HasName> spyHasName(final Optional<HasName> hasName) {
    final HasName spy = new HasName() {

        @Override
        public Name getName() {
            return hasName.orElse(HasName.NOP).getName();
        }

        @Override
        public void setName(final Name name) {
            hasName.ifPresent(hn -> {
                hn.setName(name);
                if (hn instanceof HasVariable) {
                    final HasVariable hv = (HasVariable) hn;
                    hv.getVariable().setName(name);
                }
                onHasNameChanged.execute(hasName);
            });
        }
    };
    return Optional.of(spy);
}
Also used : HasName(org.kie.workbench.common.dmn.api.definition.HasName) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) HasName(org.kie.workbench.common.dmn.api.definition.HasName)

Example 12 with HasVariable

use of org.kie.workbench.common.dmn.api.definition.HasVariable in project kie-wb-common by kiegroup.

the class DMNIncludedNodeFactoryTest method testDrgElementWithNamespace.

@Test
public void testDrgElementWithNamespace() {
    final DRGElement drgElement = mock(DRGElement.class, withSettings().extraInterfaces(HasVariable.class));
    final IncludedModel includedModel = mock(IncludedModel.class);
    final DMNIncludedNodeFactory factory = mock(DMNIncludedNodeFactory.class);
    final Id elementId = mock(Id.class);
    final String theId = "theId";
    final String theName = "theName";
    final String tType = "tType";
    final String namespaceUri = "namespaceUri";
    final String prefix = "prefix";
    final String modelName = "Model Name";
    final Name elementName = mock(Name.class);
    final IsInformationItem informationItem = mock(IsInformationItem.class);
    final QName qName = mock(QName.class);
    final Name createdName = mock(Name.class);
    final QName typeRef = mock(QName.class);
    when(includedModel.getModelName()).thenReturn(modelName);
    when(elementId.getValue()).thenReturn(theId);
    when(elementName.getValue()).thenReturn(theName);
    when(drgElement.getName()).thenReturn(elementName);
    when(drgElement.getId()).thenReturn(elementId);
    when(((HasVariable) drgElement).getVariable()).thenReturn(informationItem);
    when(qName.getLocalPart()).thenReturn(tType);
    when(informationItem.getTypeRef()).thenReturn(qName);
    when(qName.getPrefix()).thenReturn(prefix);
    when(qName.getNamespaceURI()).thenReturn(namespaceUri);
    when(factory.createName(drgElement, modelName)).thenReturn(createdName);
    when(factory.createTypeRef(modelName, qName)).thenReturn(typeRef);
    doCallRealMethod().when(factory).drgElementWithNamespace(drgElement, includedModel);
    factory.drgElementWithNamespace(drgElement, includedModel);
    verify(drgElement).setName(createdName);
    verify(drgElement).setAllowOnlyVisualChange(true);
    verify(factory).setVariable((HasVariable) drgElement, informationItem, typeRef);
}
Also used : HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Aggregations

HasVariable (org.kie.workbench.common.dmn.api.definition.HasVariable)12 IsInformationItem (org.kie.workbench.common.dmn.api.definition.model.IsInformationItem)9 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)4 Test (org.junit.Test)3 HasName (org.kie.workbench.common.dmn.api.definition.HasName)3 DMNModelInstrumentedBase (org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase)3 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)3 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)3 HasTypeRef (org.kie.workbench.common.dmn.api.definition.HasTypeRef)2 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)2 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)2 DMNElement (org.kie.workbench.common.dmn.api.definition.model.DMNElement)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 View (org.kie.workbench.common.stunner.core.graph.content.view.View)2 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)1 HasText (org.kie.workbench.common.dmn.api.definition.HasText)1 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)1 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)1 IncludedModel (org.kie.workbench.common.dmn.api.editors.included.IncludedModel)1 DynamicReadOnly (org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly)1