Search in sources :

Example 6 with DropDownData

use of org.kie.soup.project.datamodel.oracle.DropDownData in project drools-wb by kiegroup.

the class GuidedDecisionTablePresenterTest method getEnumLookupsWithQueryExpressionDefinition.

@Test
@SuppressWarnings("unchecked")
public void getEnumLookupsWithQueryExpressionDefinition() {
    final DependentEnumsUtilities.Context context = mock(DependentEnumsUtilities.Context.class);
    final Callback<Map<String, String>> callback = mock(Callback.class);
    final DropDownData dd = DropDownData.create("query", new String[] { "one", "two" });
    when(oracle.getEnums(eq("FactType"), eq("field"), any(Map.class))).thenReturn(dd);
    when(enumDropdownService.loadDropDownExpression(any(Path.class), any(String[].class), any(String.class))).thenReturn(new String[] { "three", "four" });
    dtPresenter.getEnumLookups("FactType", "field", context, callback);
    verify(callback, times(1)).callback(callbackValueCaptor.capture());
    final Map<String, String> callbackValue = callbackValueCaptor.getValue();
    assertNotNull(callbackValue);
    assertFalse(callbackValue.isEmpty());
    assertTrue(callbackValue.containsKey("three"));
    assertTrue(callbackValue.containsKey("four"));
}
Also used : ObservablePath(org.uberfire.backend.vfs.ObservablePath) Path(org.uberfire.backend.vfs.Path) DependentEnumsUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.DependentEnumsUtilities) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Map(java.util.Map) Test(org.junit.Test)

Example 7 with DropDownData

use of org.kie.soup.project.datamodel.oracle.DropDownData in project drools-wb by kiegroup.

the class EnumLoaderUtilitiesTest method checkQueryExpressionDefinitionWithCaching.

@Test
public void checkQueryExpressionDefinitionWithCaching() {
    final Callback<Map<String, String>> callback = (result) -> {
        assertFalse(result.isEmpty());
        assertEquals(2, result.size());
        assertTrue(result.containsKey("one"));
        assertTrue(result.containsKey("two"));
    };
    final String[] fixedList = { "one", "two" };
    final String[] valuePairs = { "param1=a", "param2=b" };
    final DropDownData enumDefinition = DropDownData.create("expression", valuePairs);
    when(enumDropdownService.loadDropDownExpression(any(Path.class), any(String[].class), any(String.class))).thenReturn(fixedList);
    // Call twice to check caching
    enumLoaderUtilities.getEnums(enumDefinition, callback, presenter, onFetchCommand, onFetchCompleteCommand);
    enumLoaderUtilities.getEnums(enumDefinition, callback, presenter, onFetchCommand, onFetchCompleteCommand);
    verify(enumDropdownService, times(1)).loadDropDownExpression(any(Path.class), any(String[].class), any(String.class));
    verify(onFetchCommand, times(1)).execute();
    verify(onFetchCompleteCommand, times(1)).execute();
    verify(enumLoaderUtilities, times(1)).convertDropDownData(any(String[].class));
    verify(view, times(1)).batch();
}
Also used : GuidedDecisionTablePresenter(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter) EnumDropdownService(org.kie.workbench.common.services.shared.enums.EnumDropdownService) CallerMock(org.uberfire.mocks.CallerMock) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.spy(org.mockito.Mockito.spy) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Callback(org.uberfire.client.callbacks.Callback) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) Caller(org.jboss.errai.common.client.api.Caller) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) Mockito.any(org.mockito.Mockito.any) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Path(org.uberfire.backend.vfs.Path) Command(org.uberfire.mvp.Command) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Path(org.uberfire.backend.vfs.Path) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Map(java.util.Map) Test(org.junit.Test)

Example 8 with DropDownData

use of org.kie.soup.project.datamodel.oracle.DropDownData in project drools-wb by kiegroup.

the class EnumLoaderUtilitiesTest method checkFixedListDefinitionWithCaching.

@Test
public void checkFixedListDefinitionWithCaching() {
    final Callback<Map<String, String>> callback = (result) -> {
        assertFalse(result.isEmpty());
        assertEquals(2, result.size());
        assertTrue(result.containsKey("one"));
        assertTrue(result.containsKey("two"));
    };
    final String[] fixedList = { "one", "two" };
    final DropDownData enumDefinition = DropDownData.create(fixedList);
    // Call twice to check caching
    enumLoaderUtilities.getEnums(enumDefinition, callback, presenter, onFetchCommand, onFetchCompleteCommand);
    enumLoaderUtilities.getEnums(enumDefinition, callback, presenter, onFetchCommand, onFetchCompleteCommand);
    verify(enumDropdownService, never()).loadDropDownExpression(any(Path.class), any(String[].class), any(String.class));
    verify(onFetchCommand, never()).execute();
    verify(onFetchCompleteCommand, never()).execute();
    verify(enumLoaderUtilities, times(1)).convertDropDownData(any(String[].class));
}
Also used : GuidedDecisionTablePresenter(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter) EnumDropdownService(org.kie.workbench.common.services.shared.enums.EnumDropdownService) CallerMock(org.uberfire.mocks.CallerMock) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.spy(org.mockito.Mockito.spy) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Callback(org.uberfire.client.callbacks.Callback) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) Caller(org.jboss.errai.common.client.api.Caller) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) Mockito.any(org.mockito.Mockito.any) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Path(org.uberfire.backend.vfs.Path) Command(org.uberfire.mvp.Command) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Path(org.uberfire.backend.vfs.Path) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Map(java.util.Map) Test(org.junit.Test)

Example 9 with DropDownData

use of org.kie.soup.project.datamodel.oracle.DropDownData in project drools-wb by kiegroup.

the class ConstraintValueEditorHelperTest method isEnumEquivalentDifferentLength.

@Test
public void isEnumEquivalentDifferentLength() throws Exception {
    final DropDownData dropDownData = mock(DropDownData.class);
    doReturn(new String[0]).when(dropDownData).getFixedList();
    Assertions.assertThat(ConstraintValueEditorHelper.isEnumEquivalent(new String[1], dropDownData)).isFalse();
}
Also used : DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Test(org.junit.Test)

Example 10 with DropDownData

use of org.kie.soup.project.datamodel.oracle.DropDownData in project drools-wb by kiegroup.

the class ConstraintValueEditorHelperTest method isEnumEquivalentDifferentContent.

@Test
public void isEnumEquivalentDifferentContent() throws Exception {
    final DropDownData dropDownData = mock(DropDownData.class);
    doReturn(new String[] { "a" }).when(dropDownData).getFixedList();
    Assertions.assertThat(ConstraintValueEditorHelper.isEnumEquivalent(new String[] { "b" }, dropDownData)).isFalse();
}
Also used : DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Test(org.junit.Test)

Aggregations

DropDownData (org.kie.soup.project.datamodel.oracle.DropDownData)23 Test (org.junit.Test)18 Map (java.util.Map)7 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)5 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)5 ConstraintValueEditorHelper (org.drools.workbench.screens.guided.rule.client.editor.util.ConstraintValueEditorHelper)5 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)5 Path (org.uberfire.backend.vfs.Path)5 GuidedDecisionTablePresenter (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter)3 GuidedDecisionTableView (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView)3 DependentEnumsUtilities (org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.DependentEnumsUtilities)3 Caller (org.jboss.errai.common.client.api.Caller)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Before (org.junit.Before)3 RunWith (org.junit.runner.RunWith)3 EnumDropdownService (org.kie.workbench.common.services.shared.enums.EnumDropdownService)3 Mock (org.mockito.Mock)3 Mockito.any (org.mockito.Mockito.any)3