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