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);
}
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);
}
Aggregations