use of com.qcadoo.view.api.ViewDefinitionState in project qcadoo by qcadoo.
the class DefaultEventHandlerTest method shouldCallEventMethod.
@Test
public void shouldCallEventMethod() throws Exception {
// given
ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
FormComponentState component = new FormComponentState(pattern);
component.setFieldValue(13L);
// when
component.performEvent(viewDefinitionState, "clear");
// then
assertNull("value is " + component.getFieldValue(), component.getFieldValue());
}
use of com.qcadoo.view.api.ViewDefinitionState in project qcadoo by qcadoo.
the class DefaultEventHandlerTest method shouldCallCustomEventMethod.
@Test
public void shouldCallCustomEventMethod() throws Exception {
// given
ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
FormComponentState component = new FormComponentState(pattern);
ViewEventListenerHook eventListener = mock(ViewEventListenerHook.class);
given(eventListener.getEventName()).willReturn("custom");
component.registerCustomEvent(eventListener);
// when
component.performEvent(viewDefinitionState, "custom", "arg0", "arg1");
// then
Mockito.verify(eventListener).invokeEvent(viewDefinitionState, component, new String[] { "arg0", "arg1" });
}
use of com.qcadoo.view.api.ViewDefinitionState in project qcadoo by qcadoo.
the class DefaultEventHandlerTest method shouldNotThrowExceptionWhenEventNotExists.
@Test
public void shouldNotThrowExceptionWhenEventNotExists() throws Exception {
// given
ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
FormComponentState component = new FormComponentState(pattern);
component.setFieldValue(13L);
// when
component.performEvent(viewDefinitionState, "noSuchMethod");
}
use of com.qcadoo.view.api.ViewDefinitionState in project qcadoo by qcadoo.
the class FormComponentStateTest method init.
@Before
public void init() throws Exception {
entity = mock(Entity.class);
given(entity.getField("name")).willReturn("text");
viewDefinitionState = mock(ViewDefinitionState.class);
translationService = mock(TranslationService.class);
fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(new StringType());
given(fieldDefinition.getName()).willReturn("name");
dataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
given(dataDefinition.get(12L)).willReturn(null);
given(dataDefinition.get(13L)).willReturn(entity);
given(dataDefinition.getPluginIdentifier()).willReturn("plugin");
given(dataDefinition.getName()).willReturn("name");
given(dataDefinition.getField("name")).willReturn(fieldDefinition);
given(dataDefinition.delete(any(Long.class))).willReturn(EntityOpResult.successfull());
given(dataDefinition.create(anyLong())).willAnswer(new Answer<Entity>() {
@Override
public Entity answer(final InvocationOnMock invocation) throws Throwable {
Long id = (Long) invocation.getArguments()[0];
return new DefaultEntity(dataDefinition, id);
}
});
FieldComponentPattern namePattern = mock(FieldComponentPattern.class);
given(namePattern.isRequired()).willReturn(false);
given(namePattern.isPersistent()).willReturn(true);
name = new FieldComponentState(namePattern);
name.setTranslationService(translationService);
name.setName("name");
name.initialize(new JSONObject(), Locale.ENGLISH);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn("'static expression'");
applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
SecurityRolesService securityRolesService = mock(SecurityRolesService.class);
given(applicationContext.getBean(SecurityRolesService.class)).willReturn(securityRolesService);
form = new FormComponentState(pattern);
form.setDataDefinition(dataDefinition);
form.setTranslationService(translationService);
form.addFieldEntityIdChangeListener("name", name);
form.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
new ExpressionServiceImpl().init();
}
use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.
the class ProductsToIssueDetailsHooks method sortIssuesBasedOnFilter.
private List<Entity> sortIssuesBasedOnFilter(final ViewDefinitionState view, final List<Entity> createdIssues) {
try {
sortEntries: {
String jsonKeyName = "window.mainTab.form.gridProductNumberFilter";
final String gridProductNumberFilter;
JSONObject jsonContext = view.getJsonContext();
if (jsonContext.has(jsonKeyName) && isNotBlank(gridProductNumberFilter = jsonContext.getString(jsonKeyName))) {
String[] productsNumbers = gridProductNumberFilter.substring(1, gridProductNumberFilter.length() - 1).split(",");
List<String> productNumbersList = new ArrayList<>(Arrays.stream(productsNumbers).map(String::trim).filter(s -> !s.isEmpty()).map(String::toUpperCase).collect(Collectors.toCollection(LinkedHashSet::new)));
if (productNumbersList.isEmpty()) {
break sortEntries;
}
Comparator<Entity> comparator = Comparator.comparing(e -> productNumbersList.indexOf(e.getBelongsToField(ProductsToIssueFields.PRODUCT).getStringField(ProductFields.NUMBER).toUpperCase()));
createdIssues.sort(comparator);
}
}
return createdIssues;
} catch (JSONException e) {
throw new IllegalStateException(e);
}
}
Aggregations