Search in sources :

Example 1 with EnumDropdownService

use of org.kie.workbench.common.services.shared.enums.EnumDropdownService 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 2 with EnumDropdownService

use of org.kie.workbench.common.services.shared.enums.EnumDropdownService 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 3 with EnumDropdownService

use of org.kie.workbench.common.services.shared.enums.EnumDropdownService in project drools-wb by kiegroup.

the class EnumDropDownServiceTest method testLoadDropDown.

@Test
public void testLoadDropDown() throws Exception {
    // Override code that converts Path to ClassLoader for test
    final ClassLoader cl = Thread.currentThread().getContextClassLoader();
    final EnumDropdownService service = new EnumDropdownServiceImpl() {

        @Override
        public String[] loadDropDownExpression(final Path resource, final String[] valuePairs, final String expression) {
            return super.loadDropDownExpression(cl, new RawMVELEvaluator(), valuePairs, expression);
        }
    };
    final String[] pairs = new String[] { "f1=x", "f2=2" };
    final String expression = "['@{f1}', '@{f2}']";
    final String[] r = service.loadDropDownExpression(mock(Path.class), pairs, expression);
    assertEquals(2, r.length);
    assertEquals("x", r[0]);
    assertEquals("2", r[1]);
}
Also used : Path(org.uberfire.backend.vfs.Path) EnumDropdownServiceImpl(org.kie.workbench.common.services.backend.enums.EnumDropdownServiceImpl) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) EnumDropdownService(org.kie.workbench.common.services.shared.enums.EnumDropdownService) Test(org.junit.Test)

Example 4 with EnumDropdownService

use of org.kie.workbench.common.services.shared.enums.EnumDropdownService in project drools-wb by kiegroup.

the class EnumDropDownServiceTest method testLoadDropDownNoValuePairs.

@Test
public void testLoadDropDownNoValuePairs() throws Exception {
    // Override code that converts Path to ClassLoader for test
    final ClassLoader cl = Thread.currentThread().getContextClassLoader();
    final EnumDropdownService service = new EnumDropdownServiceImpl() {

        @Override
        public String[] loadDropDownExpression(final Path resource, final String[] valuePairs, final String expression) {
            return super.loadDropDownExpression(cl, new RawMVELEvaluator(), valuePairs, expression);
        }
    };
    final String[] pairs = new String[] { null };
    final String expression = "['@{f1}', '@{f2}']";
    final String[] r = service.loadDropDownExpression(mock(Path.class), pairs, expression);
    assertEquals(0, r.length);
}
Also used : Path(org.uberfire.backend.vfs.Path) EnumDropdownServiceImpl(org.kie.workbench.common.services.backend.enums.EnumDropdownServiceImpl) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) EnumDropdownService(org.kie.workbench.common.services.shared.enums.EnumDropdownService) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 EnumDropdownService (org.kie.workbench.common.services.shared.enums.EnumDropdownService)4 Path (org.uberfire.backend.vfs.Path)4 Map (java.util.Map)2 GuidedDecisionTablePresenter (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter)2 GuidedDecisionTableView (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView)2 Caller (org.jboss.errai.common.client.api.Caller)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Before (org.junit.Before)2 RunWith (org.junit.runner.RunWith)2 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)2 DropDownData (org.kie.soup.project.datamodel.oracle.DropDownData)2 EnumDropdownServiceImpl (org.kie.workbench.common.services.backend.enums.EnumDropdownServiceImpl)2 Mock (org.mockito.Mock)2 Mockito.any (org.mockito.Mockito.any)2 Mockito.never (org.mockito.Mockito.never)2 Mockito.spy (org.mockito.Mockito.spy)2 Mockito.times (org.mockito.Mockito.times)2