target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void shouldAddFailureMessageOnNoValueForFormComponent() { FormComponent state = mock(FormComponent.class); ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class); given(state.getFieldValue()).willReturn(null); given(state.getLocale()).willReturn(Locale.ENGLISH); qualityControlService.closeQualityControl(viewDefinitionState, state, new String[] { "qualityControls" }); verify(state).addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } | public void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { if (state instanceof FormComponent) { FieldComponent controlResult = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_CONTROL_RESULT); String qualityControlType = ((FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL)).getFieldValue().toString(); if (hasControlResult(qualityControlType) && controlResult != null && (controlResult.getFieldValue() == null || ((String) controlResult.getFieldValue()).isEmpty())) { controlResult.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResult != null && ((controlResult.getFieldValue() != null) || !((String) controlResult .getFieldValue()).isEmpty()))) { FieldComponent closed = (FieldComponent) viewDefinitionState.getComponentByReference(CLOSED_LITERAL); FieldComponent staff = (FieldComponent) viewDefinitionState.getComponentByReference(STAFF_LITERAL); FieldComponent date = (FieldComponent) viewDefinitionState.getComponentByReference(DATE_LITERAL); staff.setFieldValue(securityService.getCurrentUserName()); date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_FORMAT, LocaleContextHolder.getLocale()) .format(new Date())); closed.setFieldValue(true); ((FormComponent) state).performEvent(viewDefinitionState, "save", new String[0]); } } else if (state instanceof GridComponent) { DataDefinition qualityControlDD = dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL); Entity qualityControl = qualityControlDD.get((Long) state.getFieldValue()); FieldDefinition controlResultField = qualityControlDD.getField(FIELD_CONTROL_RESULT); Object controlResult = qualityControl.getField(FIELD_CONTROL_RESULT); String qualityControlType = qualityControl.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasControlResult(qualityControlType) && controlResultField != null && (controlResult == null || controlResult.toString().isEmpty())) { state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResultField == null || (controlResult != null && !controlResult.toString().isEmpty()))) { qualityControl.setField(STAFF_LITERAL, securityService.getCurrentUserName()); qualityControl.setField(DATE_LITERAL, new Date()); qualityControl.setField(CLOSED_LITERAL, true); qualityControlDD.save(qualityControl); state.performEvent(viewDefinitionState, "refresh", new String[0]); } } state.addMessage("qualityControls.quality.control.closed.success", MessageType.SUCCESS); } } | QualityControlService { public void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { if (state instanceof FormComponent) { FieldComponent controlResult = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_CONTROL_RESULT); String qualityControlType = ((FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL)).getFieldValue().toString(); if (hasControlResult(qualityControlType) && controlResult != null && (controlResult.getFieldValue() == null || ((String) controlResult.getFieldValue()).isEmpty())) { controlResult.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResult != null && ((controlResult.getFieldValue() != null) || !((String) controlResult .getFieldValue()).isEmpty()))) { FieldComponent closed = (FieldComponent) viewDefinitionState.getComponentByReference(CLOSED_LITERAL); FieldComponent staff = (FieldComponent) viewDefinitionState.getComponentByReference(STAFF_LITERAL); FieldComponent date = (FieldComponent) viewDefinitionState.getComponentByReference(DATE_LITERAL); staff.setFieldValue(securityService.getCurrentUserName()); date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_FORMAT, LocaleContextHolder.getLocale()) .format(new Date())); closed.setFieldValue(true); ((FormComponent) state).performEvent(viewDefinitionState, "save", new String[0]); } } else if (state instanceof GridComponent) { DataDefinition qualityControlDD = dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL); Entity qualityControl = qualityControlDD.get((Long) state.getFieldValue()); FieldDefinition controlResultField = qualityControlDD.getField(FIELD_CONTROL_RESULT); Object controlResult = qualityControl.getField(FIELD_CONTROL_RESULT); String qualityControlType = qualityControl.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasControlResult(qualityControlType) && controlResultField != null && (controlResult == null || controlResult.toString().isEmpty())) { state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResultField == null || (controlResult != null && !controlResult.toString().isEmpty()))) { qualityControl.setField(STAFF_LITERAL, securityService.getCurrentUserName()); qualityControl.setField(DATE_LITERAL, new Date()); qualityControl.setField(CLOSED_LITERAL, true); qualityControlDD.save(qualityControl); state.performEvent(viewDefinitionState, "refresh", new String[0]); } } state.addMessage("qualityControls.quality.control.closed.success", MessageType.SUCCESS); } } } | QualityControlService { public void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { if (state instanceof FormComponent) { FieldComponent controlResult = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_CONTROL_RESULT); String qualityControlType = ((FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL)).getFieldValue().toString(); if (hasControlResult(qualityControlType) && controlResult != null && (controlResult.getFieldValue() == null || ((String) controlResult.getFieldValue()).isEmpty())) { controlResult.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResult != null && ((controlResult.getFieldValue() != null) || !((String) controlResult .getFieldValue()).isEmpty()))) { FieldComponent closed = (FieldComponent) viewDefinitionState.getComponentByReference(CLOSED_LITERAL); FieldComponent staff = (FieldComponent) viewDefinitionState.getComponentByReference(STAFF_LITERAL); FieldComponent date = (FieldComponent) viewDefinitionState.getComponentByReference(DATE_LITERAL); staff.setFieldValue(securityService.getCurrentUserName()); date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_FORMAT, LocaleContextHolder.getLocale()) .format(new Date())); closed.setFieldValue(true); ((FormComponent) state).performEvent(viewDefinitionState, "save", new String[0]); } } else if (state instanceof GridComponent) { DataDefinition qualityControlDD = dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL); Entity qualityControl = qualityControlDD.get((Long) state.getFieldValue()); FieldDefinition controlResultField = qualityControlDD.getField(FIELD_CONTROL_RESULT); Object controlResult = qualityControl.getField(FIELD_CONTROL_RESULT); String qualityControlType = qualityControl.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasControlResult(qualityControlType) && controlResultField != null && (controlResult == null || controlResult.toString().isEmpty())) { state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResultField == null || (controlResult != null && !controlResult.toString().isEmpty()))) { qualityControl.setField(STAFF_LITERAL, securityService.getCurrentUserName()); qualityControl.setField(DATE_LITERAL, new Date()); qualityControl.setField(CLOSED_LITERAL, true); qualityControlDD.save(qualityControl); state.performEvent(viewDefinitionState, "refresh", new String[0]); } } state.addMessage("qualityControls.quality.control.closed.success", MessageType.SUCCESS); } } } | QualityControlService { public void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { if (state instanceof FormComponent) { FieldComponent controlResult = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_CONTROL_RESULT); String qualityControlType = ((FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL)).getFieldValue().toString(); if (hasControlResult(qualityControlType) && controlResult != null && (controlResult.getFieldValue() == null || ((String) controlResult.getFieldValue()).isEmpty())) { controlResult.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResult != null && ((controlResult.getFieldValue() != null) || !((String) controlResult .getFieldValue()).isEmpty()))) { FieldComponent closed = (FieldComponent) viewDefinitionState.getComponentByReference(CLOSED_LITERAL); FieldComponent staff = (FieldComponent) viewDefinitionState.getComponentByReference(STAFF_LITERAL); FieldComponent date = (FieldComponent) viewDefinitionState.getComponentByReference(DATE_LITERAL); staff.setFieldValue(securityService.getCurrentUserName()); date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_FORMAT, LocaleContextHolder.getLocale()) .format(new Date())); closed.setFieldValue(true); ((FormComponent) state).performEvent(viewDefinitionState, "save", new String[0]); } } else if (state instanceof GridComponent) { DataDefinition qualityControlDD = dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL); Entity qualityControl = qualityControlDD.get((Long) state.getFieldValue()); FieldDefinition controlResultField = qualityControlDD.getField(FIELD_CONTROL_RESULT); Object controlResult = qualityControl.getField(FIELD_CONTROL_RESULT); String qualityControlType = qualityControl.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasControlResult(qualityControlType) && controlResultField != null && (controlResult == null || controlResult.toString().isEmpty())) { state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResultField == null || (controlResult != null && !controlResult.toString().isEmpty()))) { qualityControl.setField(STAFF_LITERAL, securityService.getCurrentUserName()); qualityControl.setField(DATE_LITERAL, new Date()); qualityControl.setField(CLOSED_LITERAL, true); qualityControlDD.save(qualityControl); state.performEvent(viewDefinitionState, "refresh", new String[0]); } } state.addMessage("qualityControls.quality.control.closed.success", MessageType.SUCCESS); } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { if (state instanceof FormComponent) { FieldComponent controlResult = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_CONTROL_RESULT); String qualityControlType = ((FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL)).getFieldValue().toString(); if (hasControlResult(qualityControlType) && controlResult != null && (controlResult.getFieldValue() == null || ((String) controlResult.getFieldValue()).isEmpty())) { controlResult.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResult != null && ((controlResult.getFieldValue() != null) || !((String) controlResult .getFieldValue()).isEmpty()))) { FieldComponent closed = (FieldComponent) viewDefinitionState.getComponentByReference(CLOSED_LITERAL); FieldComponent staff = (FieldComponent) viewDefinitionState.getComponentByReference(STAFF_LITERAL); FieldComponent date = (FieldComponent) viewDefinitionState.getComponentByReference(DATE_LITERAL); staff.setFieldValue(securityService.getCurrentUserName()); date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_FORMAT, LocaleContextHolder.getLocale()) .format(new Date())); closed.setFieldValue(true); ((FormComponent) state).performEvent(viewDefinitionState, "save", new String[0]); } } else if (state instanceof GridComponent) { DataDefinition qualityControlDD = dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL); Entity qualityControl = qualityControlDD.get((Long) state.getFieldValue()); FieldDefinition controlResultField = qualityControlDD.getField(FIELD_CONTROL_RESULT); Object controlResult = qualityControl.getField(FIELD_CONTROL_RESULT); String qualityControlType = qualityControl.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasControlResult(qualityControlType) && controlResultField != null && (controlResult == null || controlResult.toString().isEmpty())) { state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResultField == null || (controlResult != null && !controlResult.toString().isEmpty()))) { qualityControl.setField(STAFF_LITERAL, securityService.getCurrentUserName()); qualityControl.setField(DATE_LITERAL, new Date()); qualityControl.setField(CLOSED_LITERAL, true); qualityControlDD.save(qualityControl); state.performEvent(viewDefinitionState, "refresh", new String[0]); } } state.addMessage("qualityControls.quality.control.closed.success", MessageType.SUCCESS); } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldAddFailureMessageOnNoValueForNonFormComponent() { GridComponent state = mock(GridComponent.class); ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class); given(state.getFieldValue()).willReturn(null); given(state.getLocale()).willReturn(Locale.ENGLISH); qualityControlService.closeQualityControl(viewDefinitionState, state, new String[] { "qualityControls" }); verify(state).addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } | public void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { if (state instanceof FormComponent) { FieldComponent controlResult = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_CONTROL_RESULT); String qualityControlType = ((FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL)).getFieldValue().toString(); if (hasControlResult(qualityControlType) && controlResult != null && (controlResult.getFieldValue() == null || ((String) controlResult.getFieldValue()).isEmpty())) { controlResult.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResult != null && ((controlResult.getFieldValue() != null) || !((String) controlResult .getFieldValue()).isEmpty()))) { FieldComponent closed = (FieldComponent) viewDefinitionState.getComponentByReference(CLOSED_LITERAL); FieldComponent staff = (FieldComponent) viewDefinitionState.getComponentByReference(STAFF_LITERAL); FieldComponent date = (FieldComponent) viewDefinitionState.getComponentByReference(DATE_LITERAL); staff.setFieldValue(securityService.getCurrentUserName()); date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_FORMAT, LocaleContextHolder.getLocale()) .format(new Date())); closed.setFieldValue(true); ((FormComponent) state).performEvent(viewDefinitionState, "save", new String[0]); } } else if (state instanceof GridComponent) { DataDefinition qualityControlDD = dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL); Entity qualityControl = qualityControlDD.get((Long) state.getFieldValue()); FieldDefinition controlResultField = qualityControlDD.getField(FIELD_CONTROL_RESULT); Object controlResult = qualityControl.getField(FIELD_CONTROL_RESULT); String qualityControlType = qualityControl.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasControlResult(qualityControlType) && controlResultField != null && (controlResult == null || controlResult.toString().isEmpty())) { state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResultField == null || (controlResult != null && !controlResult.toString().isEmpty()))) { qualityControl.setField(STAFF_LITERAL, securityService.getCurrentUserName()); qualityControl.setField(DATE_LITERAL, new Date()); qualityControl.setField(CLOSED_LITERAL, true); qualityControlDD.save(qualityControl); state.performEvent(viewDefinitionState, "refresh", new String[0]); } } state.addMessage("qualityControls.quality.control.closed.success", MessageType.SUCCESS); } } | QualityControlService { public void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { if (state instanceof FormComponent) { FieldComponent controlResult = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_CONTROL_RESULT); String qualityControlType = ((FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL)).getFieldValue().toString(); if (hasControlResult(qualityControlType) && controlResult != null && (controlResult.getFieldValue() == null || ((String) controlResult.getFieldValue()).isEmpty())) { controlResult.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResult != null && ((controlResult.getFieldValue() != null) || !((String) controlResult .getFieldValue()).isEmpty()))) { FieldComponent closed = (FieldComponent) viewDefinitionState.getComponentByReference(CLOSED_LITERAL); FieldComponent staff = (FieldComponent) viewDefinitionState.getComponentByReference(STAFF_LITERAL); FieldComponent date = (FieldComponent) viewDefinitionState.getComponentByReference(DATE_LITERAL); staff.setFieldValue(securityService.getCurrentUserName()); date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_FORMAT, LocaleContextHolder.getLocale()) .format(new Date())); closed.setFieldValue(true); ((FormComponent) state).performEvent(viewDefinitionState, "save", new String[0]); } } else if (state instanceof GridComponent) { DataDefinition qualityControlDD = dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL); Entity qualityControl = qualityControlDD.get((Long) state.getFieldValue()); FieldDefinition controlResultField = qualityControlDD.getField(FIELD_CONTROL_RESULT); Object controlResult = qualityControl.getField(FIELD_CONTROL_RESULT); String qualityControlType = qualityControl.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasControlResult(qualityControlType) && controlResultField != null && (controlResult == null || controlResult.toString().isEmpty())) { state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResultField == null || (controlResult != null && !controlResult.toString().isEmpty()))) { qualityControl.setField(STAFF_LITERAL, securityService.getCurrentUserName()); qualityControl.setField(DATE_LITERAL, new Date()); qualityControl.setField(CLOSED_LITERAL, true); qualityControlDD.save(qualityControl); state.performEvent(viewDefinitionState, "refresh", new String[0]); } } state.addMessage("qualityControls.quality.control.closed.success", MessageType.SUCCESS); } } } | QualityControlService { public void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { if (state instanceof FormComponent) { FieldComponent controlResult = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_CONTROL_RESULT); String qualityControlType = ((FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL)).getFieldValue().toString(); if (hasControlResult(qualityControlType) && controlResult != null && (controlResult.getFieldValue() == null || ((String) controlResult.getFieldValue()).isEmpty())) { controlResult.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResult != null && ((controlResult.getFieldValue() != null) || !((String) controlResult .getFieldValue()).isEmpty()))) { FieldComponent closed = (FieldComponent) viewDefinitionState.getComponentByReference(CLOSED_LITERAL); FieldComponent staff = (FieldComponent) viewDefinitionState.getComponentByReference(STAFF_LITERAL); FieldComponent date = (FieldComponent) viewDefinitionState.getComponentByReference(DATE_LITERAL); staff.setFieldValue(securityService.getCurrentUserName()); date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_FORMAT, LocaleContextHolder.getLocale()) .format(new Date())); closed.setFieldValue(true); ((FormComponent) state).performEvent(viewDefinitionState, "save", new String[0]); } } else if (state instanceof GridComponent) { DataDefinition qualityControlDD = dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL); Entity qualityControl = qualityControlDD.get((Long) state.getFieldValue()); FieldDefinition controlResultField = qualityControlDD.getField(FIELD_CONTROL_RESULT); Object controlResult = qualityControl.getField(FIELD_CONTROL_RESULT); String qualityControlType = qualityControl.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasControlResult(qualityControlType) && controlResultField != null && (controlResult == null || controlResult.toString().isEmpty())) { state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResultField == null || (controlResult != null && !controlResult.toString().isEmpty()))) { qualityControl.setField(STAFF_LITERAL, securityService.getCurrentUserName()); qualityControl.setField(DATE_LITERAL, new Date()); qualityControl.setField(CLOSED_LITERAL, true); qualityControlDD.save(qualityControl); state.performEvent(viewDefinitionState, "refresh", new String[0]); } } state.addMessage("qualityControls.quality.control.closed.success", MessageType.SUCCESS); } } } | QualityControlService { public void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { if (state instanceof FormComponent) { FieldComponent controlResult = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_CONTROL_RESULT); String qualityControlType = ((FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL)).getFieldValue().toString(); if (hasControlResult(qualityControlType) && controlResult != null && (controlResult.getFieldValue() == null || ((String) controlResult.getFieldValue()).isEmpty())) { controlResult.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResult != null && ((controlResult.getFieldValue() != null) || !((String) controlResult .getFieldValue()).isEmpty()))) { FieldComponent closed = (FieldComponent) viewDefinitionState.getComponentByReference(CLOSED_LITERAL); FieldComponent staff = (FieldComponent) viewDefinitionState.getComponentByReference(STAFF_LITERAL); FieldComponent date = (FieldComponent) viewDefinitionState.getComponentByReference(DATE_LITERAL); staff.setFieldValue(securityService.getCurrentUserName()); date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_FORMAT, LocaleContextHolder.getLocale()) .format(new Date())); closed.setFieldValue(true); ((FormComponent) state).performEvent(viewDefinitionState, "save", new String[0]); } } else if (state instanceof GridComponent) { DataDefinition qualityControlDD = dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL); Entity qualityControl = qualityControlDD.get((Long) state.getFieldValue()); FieldDefinition controlResultField = qualityControlDD.getField(FIELD_CONTROL_RESULT); Object controlResult = qualityControl.getField(FIELD_CONTROL_RESULT); String qualityControlType = qualityControl.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasControlResult(qualityControlType) && controlResultField != null && (controlResult == null || controlResult.toString().isEmpty())) { state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResultField == null || (controlResult != null && !controlResult.toString().isEmpty()))) { qualityControl.setField(STAFF_LITERAL, securityService.getCurrentUserName()); qualityControl.setField(DATE_LITERAL, new Date()); qualityControl.setField(CLOSED_LITERAL, true); qualityControlDD.save(qualityControl); state.performEvent(viewDefinitionState, "refresh", new String[0]); } } state.addMessage("qualityControls.quality.control.closed.success", MessageType.SUCCESS); } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { if (state instanceof FormComponent) { FieldComponent controlResult = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_CONTROL_RESULT); String qualityControlType = ((FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL)).getFieldValue().toString(); if (hasControlResult(qualityControlType) && controlResult != null && (controlResult.getFieldValue() == null || ((String) controlResult.getFieldValue()).isEmpty())) { controlResult.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResult != null && ((controlResult.getFieldValue() != null) || !((String) controlResult .getFieldValue()).isEmpty()))) { FieldComponent closed = (FieldComponent) viewDefinitionState.getComponentByReference(CLOSED_LITERAL); FieldComponent staff = (FieldComponent) viewDefinitionState.getComponentByReference(STAFF_LITERAL); FieldComponent date = (FieldComponent) viewDefinitionState.getComponentByReference(DATE_LITERAL); staff.setFieldValue(securityService.getCurrentUserName()); date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_FORMAT, LocaleContextHolder.getLocale()) .format(new Date())); closed.setFieldValue(true); ((FormComponent) state).performEvent(viewDefinitionState, "save", new String[0]); } } else if (state instanceof GridComponent) { DataDefinition qualityControlDD = dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL); Entity qualityControl = qualityControlDD.get((Long) state.getFieldValue()); FieldDefinition controlResultField = qualityControlDD.getField(FIELD_CONTROL_RESULT); Object controlResult = qualityControl.getField(FIELD_CONTROL_RESULT); String qualityControlType = qualityControl.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasControlResult(qualityControlType) && controlResultField != null && (controlResult == null || controlResult.toString().isEmpty())) { state.addMessage("qualityControls.quality.control.result.missing", MessageType.FAILURE); return; } else if (!hasControlResult(qualityControlType) || (controlResultField == null || (controlResult != null && !controlResult.toString().isEmpty()))) { qualityControl.setField(STAFF_LITERAL, securityService.getCurrentUserName()); qualityControl.setField(DATE_LITERAL, new Date()); qualityControl.setField(CLOSED_LITERAL, true); qualityControlDD.save(qualityControl); state.performEvent(viewDefinitionState, "refresh", new String[0]); } } state.addMessage("qualityControls.quality.control.closed.success", MessageType.SUCCESS); } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldGenerateQualityControlForBatch() { DataDefinition genealogyDataDefinition = mock(DataDefinition.class); List<Entity> genealogies = new ArrayList<Entity>(); Entity genealogy = new DefaultEntity(genealogyDataDefinition); genealogy.setField("batch", "1"); genealogies.add(genealogy); GridComponent state = mock(GridComponent.class); ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class); DataDefinition orderDataDefinition = mock(DataDefinition.class); DataDefinition qualityForBatchDataDefinition = mock(DataDefinition.class); Entity order = mock(Entity.class); Entity technology = mock(Entity.class); SearchCriteriaBuilder searchCriteria = mock(SearchCriteriaBuilder.class); given(dataDefinitionService.get("orders", "order")).willReturn(orderDataDefinition); given( dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL)).willReturn(qualityForBatchDataDefinition); given(orderDataDefinition.get(7L)).willReturn(order); given(order.getBelongsToField("technology")).willReturn(technology); given(technology.getStringField("qualityControlType")).willReturn("01forBatch"); given(state.getLocale()).willReturn(Locale.ENGLISH); given(state.getFieldValue()).willReturn(7L); given(dataDefinitionService.get("genealogies", "genealogy")).willReturn(genealogyDataDefinition); given(genealogyDataDefinition.find()).willReturn(searchCriteria); given(searchCriteria.add(any(SearchCriterion.class))).willReturn(searchCriteria); SearchResult searchResult = mock(SearchResult.class); given(searchCriteria.list()).willReturn(searchResult); given(searchResult.getEntities()).willReturn(genealogies); given( qualityControlForNumber.generateNumber(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL, DIGITS_NUMBER, "qualityControlForBatch")).willReturn("1"); given(order.getDecimalField("plannedQuantity")).willReturn(new BigDecimal("1")); given(order.getBelongsToField("technology")).willReturn(technology); given(order.getBelongsToField("technology").getField("qualityControlInstruction")).willReturn("test"); DataAccessService dataAccessService = mock(DataAccessService.class); given(dataAccessService.convertToDatabaseEntity(any(Entity.class))).willReturn(new Object()); DataDefinition qualityControlDD = mock(DataDefinition.class); Entity newlyCreatedQualityControl = mockEntity(qualityControlDD); given(qualityControlDD.create()).willReturn(newlyCreatedQualityControl); given( dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL)).willReturn(qualityControlDD); SearchCriteriaBuilder scb = mock(SearchCriteriaBuilder.class); given(qualityControlDD.find()).willReturn(scb); given(scb.add(any(SearchCriterion.class))).willReturn(scb); given(scb.list()).willReturn(searchResult); given(searchResult.getTotalNumberOfEntities()).willReturn(0); SearchRestrictions searchRestrictions = new SearchRestrictions(); ReflectionTestUtils.setField(searchRestrictions, "dataAccessService", dataAccessService); qualityControlService.generateQualityControl(viewDefinitionState, state, new String[] { "qualityControls" }); verify(state).addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } | public void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { DataDefinition orderDataDefinition = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER); Entity order = orderDataDefinition.get((Long) state.getFieldValue()); Entity technology = order.getBelongsToField(TECHNOLOGY_LITERAL); if (technology == null) { return; } String qualityControlType = technology.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (qualityControlType == null) { state.addMessage("qualityControls.qualityControls.qualityType.missing", MessageType.FAILURE); } else { if (isQualityControlForOrderExists(order)) { state.addMessage("qualityControls.qualityControls.generated.failure", MessageType.FAILURE); } else { generateQualityControlForGivenType(qualityControlType, technology, order); state.addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } state.performEvent(viewDefinitionState, "refresh", new String[0]); } } } | QualityControlService { public void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { DataDefinition orderDataDefinition = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER); Entity order = orderDataDefinition.get((Long) state.getFieldValue()); Entity technology = order.getBelongsToField(TECHNOLOGY_LITERAL); if (technology == null) { return; } String qualityControlType = technology.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (qualityControlType == null) { state.addMessage("qualityControls.qualityControls.qualityType.missing", MessageType.FAILURE); } else { if (isQualityControlForOrderExists(order)) { state.addMessage("qualityControls.qualityControls.generated.failure", MessageType.FAILURE); } else { generateQualityControlForGivenType(qualityControlType, technology, order); state.addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } state.performEvent(viewDefinitionState, "refresh", new String[0]); } } } } | QualityControlService { public void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { DataDefinition orderDataDefinition = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER); Entity order = orderDataDefinition.get((Long) state.getFieldValue()); Entity technology = order.getBelongsToField(TECHNOLOGY_LITERAL); if (technology == null) { return; } String qualityControlType = technology.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (qualityControlType == null) { state.addMessage("qualityControls.qualityControls.qualityType.missing", MessageType.FAILURE); } else { if (isQualityControlForOrderExists(order)) { state.addMessage("qualityControls.qualityControls.generated.failure", MessageType.FAILURE); } else { generateQualityControlForGivenType(qualityControlType, technology, order); state.addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } state.performEvent(viewDefinitionState, "refresh", new String[0]); } } } } | QualityControlService { public void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { DataDefinition orderDataDefinition = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER); Entity order = orderDataDefinition.get((Long) state.getFieldValue()); Entity technology = order.getBelongsToField(TECHNOLOGY_LITERAL); if (technology == null) { return; } String qualityControlType = technology.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (qualityControlType == null) { state.addMessage("qualityControls.qualityControls.qualityType.missing", MessageType.FAILURE); } else { if (isQualityControlForOrderExists(order)) { state.addMessage("qualityControls.qualityControls.generated.failure", MessageType.FAILURE); } else { generateQualityControlForGivenType(qualityControlType, technology, order); state.addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } state.performEvent(viewDefinitionState, "refresh", new String[0]); } } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { DataDefinition orderDataDefinition = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER); Entity order = orderDataDefinition.get((Long) state.getFieldValue()); Entity technology = order.getBelongsToField(TECHNOLOGY_LITERAL); if (technology == null) { return; } String qualityControlType = technology.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (qualityControlType == null) { state.addMessage("qualityControls.qualityControls.qualityType.missing", MessageType.FAILURE); } else { if (isQualityControlForOrderExists(order)) { state.addMessage("qualityControls.qualityControls.generated.failure", MessageType.FAILURE); } else { generateQualityControlForGivenType(qualityControlType, technology, order); state.addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } state.performEvent(viewDefinitionState, "refresh", new String[0]); } } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public final void shouldDisableDeleteButtonWhenAnyOfWorkPlansIsGeneratedAndRelatesToAtLeastOneCompletedOrder() { stubGridSelectedEntities(mockWorkPlanEntity(false, OrderState.PENDING, OrderState.PENDING, OrderState.COMPLETED), mockWorkPlanEntity(true, OrderState.ABANDONED, OrderState.COMPLETED)); workPlansListHooks.setGridGenerateButtonState(workPlansListView); verify(workPlansListView).setUpDeleteButton(false, "orders.ribbon.message.selectedRecordCannotBeDeleted"); } | public void setGridGenerateButtonState(final ViewDefinitionState viewDefinitionState) { setGridGenerateButtonState(WorkPlansListView.from(viewDefinitionState)); } | WorkPlansListHooks { public void setGridGenerateButtonState(final ViewDefinitionState viewDefinitionState) { setGridGenerateButtonState(WorkPlansListView.from(viewDefinitionState)); } } | WorkPlansListHooks { public void setGridGenerateButtonState(final ViewDefinitionState viewDefinitionState) { setGridGenerateButtonState(WorkPlansListView.from(viewDefinitionState)); } } | WorkPlansListHooks { public void setGridGenerateButtonState(final ViewDefinitionState viewDefinitionState) { setGridGenerateButtonState(WorkPlansListView.from(viewDefinitionState)); } void setGridGenerateButtonState(final ViewDefinitionState viewDefinitionState); void setGridGenerateButtonState(final WorkPlansListView view); } | WorkPlansListHooks { public void setGridGenerateButtonState(final ViewDefinitionState viewDefinitionState) { setGridGenerateButtonState(WorkPlansListView.from(viewDefinitionState)); } void setGridGenerateButtonState(final ViewDefinitionState viewDefinitionState); void setGridGenerateButtonState(final WorkPlansListView view); } |
@Test public void shouldGenerateQualityControlForUnit() { GridComponent state = mock(GridComponent.class); ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class); DataDefinition orderDataDefinition = mock(DataDefinition.class); Entity order = mock(Entity.class); Entity technology = mock(Entity.class); given(dataDefinitionService.get("orders", "order")).willReturn(orderDataDefinition); given(orderDataDefinition.get(7L)).willReturn(order); given(order.getBelongsToField("technology")).willReturn(technology); given(technology.getStringField("qualityControlType")).willReturn("02forUnit"); given(state.getLocale()).willReturn(Locale.ENGLISH); given(state.getFieldValue()).willReturn(7L); given(technology.getDecimalField("unitSamplingNr")).willReturn(new BigDecimal("2")); given(order.getDecimalField("plannedQuantity")).willReturn(new BigDecimal("5")); given( qualityControlForNumber.generateNumber(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL, DIGITS_NUMBER, "qualityControlForUnit")).willReturn("1"); given(order.getBelongsToField("technology")).willReturn(technology); given(order.getBelongsToField("technology").getStringField("qualityControlInstruction")).willReturn("test"); DataAccessService dataAccessService = mock(DataAccessService.class); given(dataAccessService.convertToDatabaseEntity(any(Entity.class))).willReturn(new Object()); DataDefinition qualityControlDD = mock(DataDefinition.class); Entity newlyCreatedQualityControl = mockEntity(qualityControlDD); given(qualityControlDD.create()).willReturn(newlyCreatedQualityControl); given( dataDefinitionService.get(QualityControlsConstants.PLUGIN_IDENTIFIER, QualityControlsConstants.MODEL_QUALITY_CONTROL)).willReturn(qualityControlDD); SearchCriteriaBuilder scb = mock(SearchCriteriaBuilder.class); given(qualityControlDD.find()).willReturn(scb); given(scb.add(any(SearchCriterion.class))).willReturn(scb); SearchResult searchResults = mock(SearchResult.class); given(scb.list()).willReturn(searchResults); given(searchResults.getTotalNumberOfEntities()).willReturn(0); SearchRestrictions searchRestrictions = new SearchRestrictions(); ReflectionTestUtils.setField(searchRestrictions, "dataAccessService", dataAccessService); qualityControlService.generateQualityControl(viewDefinitionState, state, new String[] { "qualityControls" }); verify(state).addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } | public void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { DataDefinition orderDataDefinition = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER); Entity order = orderDataDefinition.get((Long) state.getFieldValue()); Entity technology = order.getBelongsToField(TECHNOLOGY_LITERAL); if (technology == null) { return; } String qualityControlType = technology.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (qualityControlType == null) { state.addMessage("qualityControls.qualityControls.qualityType.missing", MessageType.FAILURE); } else { if (isQualityControlForOrderExists(order)) { state.addMessage("qualityControls.qualityControls.generated.failure", MessageType.FAILURE); } else { generateQualityControlForGivenType(qualityControlType, technology, order); state.addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } state.performEvent(viewDefinitionState, "refresh", new String[0]); } } } | QualityControlService { public void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { DataDefinition orderDataDefinition = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER); Entity order = orderDataDefinition.get((Long) state.getFieldValue()); Entity technology = order.getBelongsToField(TECHNOLOGY_LITERAL); if (technology == null) { return; } String qualityControlType = technology.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (qualityControlType == null) { state.addMessage("qualityControls.qualityControls.qualityType.missing", MessageType.FAILURE); } else { if (isQualityControlForOrderExists(order)) { state.addMessage("qualityControls.qualityControls.generated.failure", MessageType.FAILURE); } else { generateQualityControlForGivenType(qualityControlType, technology, order); state.addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } state.performEvent(viewDefinitionState, "refresh", new String[0]); } } } } | QualityControlService { public void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { DataDefinition orderDataDefinition = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER); Entity order = orderDataDefinition.get((Long) state.getFieldValue()); Entity technology = order.getBelongsToField(TECHNOLOGY_LITERAL); if (technology == null) { return; } String qualityControlType = technology.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (qualityControlType == null) { state.addMessage("qualityControls.qualityControls.qualityType.missing", MessageType.FAILURE); } else { if (isQualityControlForOrderExists(order)) { state.addMessage("qualityControls.qualityControls.generated.failure", MessageType.FAILURE); } else { generateQualityControlForGivenType(qualityControlType, technology, order); state.addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } state.performEvent(viewDefinitionState, "refresh", new String[0]); } } } } | QualityControlService { public void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { DataDefinition orderDataDefinition = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER); Entity order = orderDataDefinition.get((Long) state.getFieldValue()); Entity technology = order.getBelongsToField(TECHNOLOGY_LITERAL); if (technology == null) { return; } String qualityControlType = technology.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (qualityControlType == null) { state.addMessage("qualityControls.qualityControls.qualityType.missing", MessageType.FAILURE); } else { if (isQualityControlForOrderExists(order)) { state.addMessage("qualityControls.qualityControls.generated.failure", MessageType.FAILURE); } else { generateQualityControlForGivenType(qualityControlType, technology, order); state.addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } state.performEvent(viewDefinitionState, "refresh", new String[0]); } } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (state.getFieldValue() == null) { if (state instanceof FormComponent) { state.addMessage("smartView.form.entityWithoutIdentifier", MessageType.FAILURE); } else { state.addMessage("smartView.grid.noRowSelectedError", MessageType.FAILURE); } } else { DataDefinition orderDataDefinition = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER); Entity order = orderDataDefinition.get((Long) state.getFieldValue()); Entity technology = order.getBelongsToField(TECHNOLOGY_LITERAL); if (technology == null) { return; } String qualityControlType = technology.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (qualityControlType == null) { state.addMessage("qualityControls.qualityControls.qualityType.missing", MessageType.FAILURE); } else { if (isQualityControlForOrderExists(order)) { state.addMessage("qualityControls.qualityControls.generated.failure", MessageType.FAILURE); } else { generateQualityControlForGivenType(qualityControlType, technology, order); state.addMessage("qualityControls.qualityControls.generated.success", MessageType.SUCCESS); } state.performEvent(viewDefinitionState, "refresh", new String[0]); } } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldEnableCalendarsOnPreRender() { FieldComponent dateFrom = mock(FieldComponent.class); FieldComponent dateTo = mock(FieldComponent.class); ViewDefinitionState state = mock(ViewDefinitionState.class); given(state.getComponentByReference("dateFrom")).willReturn(dateFrom); given(state.getComponentByReference("dateTo")).willReturn(dateTo); qualityControlService.enableCalendarsOnRender(state); verify(dateFrom).setEnabled(true); verify(dateTo).setEnabled(true); } | public void enableCalendarsOnRender(final ViewDefinitionState state) { FieldComponent dateFrom = (FieldComponent) state.getComponentByReference(DATE_FROM_LITERAL); FieldComponent dateTo = (FieldComponent) state.getComponentByReference(DATE_TO_LITERAL); dateFrom.setEnabled(true); dateTo.setEnabled(true); } | QualityControlService { public void enableCalendarsOnRender(final ViewDefinitionState state) { FieldComponent dateFrom = (FieldComponent) state.getComponentByReference(DATE_FROM_LITERAL); FieldComponent dateTo = (FieldComponent) state.getComponentByReference(DATE_TO_LITERAL); dateFrom.setEnabled(true); dateTo.setEnabled(true); } } | QualityControlService { public void enableCalendarsOnRender(final ViewDefinitionState state) { FieldComponent dateFrom = (FieldComponent) state.getComponentByReference(DATE_FROM_LITERAL); FieldComponent dateTo = (FieldComponent) state.getComponentByReference(DATE_TO_LITERAL); dateFrom.setEnabled(true); dateTo.setEnabled(true); } } | QualityControlService { public void enableCalendarsOnRender(final ViewDefinitionState state) { FieldComponent dateFrom = (FieldComponent) state.getComponentByReference(DATE_FROM_LITERAL); FieldComponent dateTo = (FieldComponent) state.getComponentByReference(DATE_TO_LITERAL); dateFrom.setEnabled(true); dateTo.setEnabled(true); } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public void enableCalendarsOnRender(final ViewDefinitionState state) { FieldComponent dateFrom = (FieldComponent) state.getComponentByReference(DATE_FROM_LITERAL); FieldComponent dateTo = (FieldComponent) state.getComponentByReference(DATE_TO_LITERAL); dateFrom.setEnabled(true); dateTo.setEnabled(true); } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldSetQuantitiesToDefaultsIfEmpty() { FormComponent form = mock(FormComponent.class); FieldComponent takenForControl = mock(FieldComponent.class); FieldComponent rejectedQuantity = mock(FieldComponent.class); FieldComponent acceptedDefectsQuantity = mock(FieldComponent.class); ViewDefinitionState state = mock(ViewDefinitionState.class); given(state.getComponentByReference("form")).willReturn(form); given(state.getComponentByReference("takenForControlQuantity")).willReturn(takenForControl); given(state.getComponentByReference("takenForControlQuantity").getFieldValue()).willReturn(null); given(state.getComponentByReference("rejectedQuantity")).willReturn(rejectedQuantity); given(state.getComponentByReference("rejectedQuantity").getFieldValue()).willReturn(null); given(state.getComponentByReference("acceptedDefectsQuantity")).willReturn(acceptedDefectsQuantity); given(state.getComponentByReference("acceptedDefectsQuantity").getFieldValue()).willReturn(null); qualityControlService.setQuantitiesToDefaulIfEmpty(state); verify(takenForControl).setFieldValue(BigDecimal.ONE); verify(rejectedQuantity).setFieldValue(BigDecimal.ZERO); verify(acceptedDefectsQuantity).setFieldValue(BigDecimal.ZERO); } | public void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state) { FieldComponent takenForControlQuantity = (FieldComponent) state .getComponentByReference(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); FieldComponent rejectedQuantity = (FieldComponent) state.getComponentByReference(REJECTED_QUANTITY_LITERAL); FieldComponent acceptedDefectsQuantity = (FieldComponent) state .getComponentByReference(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (takenForControlQuantity.getFieldValue() == null || takenForControlQuantity.getFieldValue().toString().isEmpty()) { takenForControlQuantity.setFieldValue(BigDecimal.ONE); } if (rejectedQuantity.getFieldValue() == null || rejectedQuantity.getFieldValue().toString().isEmpty()) { rejectedQuantity.setFieldValue(BigDecimal.ZERO); } if (acceptedDefectsQuantity.getFieldValue() == null || acceptedDefectsQuantity.getFieldValue().toString().isEmpty()) { acceptedDefectsQuantity.setFieldValue(BigDecimal.ZERO); } } | QualityControlService { public void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state) { FieldComponent takenForControlQuantity = (FieldComponent) state .getComponentByReference(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); FieldComponent rejectedQuantity = (FieldComponent) state.getComponentByReference(REJECTED_QUANTITY_LITERAL); FieldComponent acceptedDefectsQuantity = (FieldComponent) state .getComponentByReference(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (takenForControlQuantity.getFieldValue() == null || takenForControlQuantity.getFieldValue().toString().isEmpty()) { takenForControlQuantity.setFieldValue(BigDecimal.ONE); } if (rejectedQuantity.getFieldValue() == null || rejectedQuantity.getFieldValue().toString().isEmpty()) { rejectedQuantity.setFieldValue(BigDecimal.ZERO); } if (acceptedDefectsQuantity.getFieldValue() == null || acceptedDefectsQuantity.getFieldValue().toString().isEmpty()) { acceptedDefectsQuantity.setFieldValue(BigDecimal.ZERO); } } } | QualityControlService { public void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state) { FieldComponent takenForControlQuantity = (FieldComponent) state .getComponentByReference(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); FieldComponent rejectedQuantity = (FieldComponent) state.getComponentByReference(REJECTED_QUANTITY_LITERAL); FieldComponent acceptedDefectsQuantity = (FieldComponent) state .getComponentByReference(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (takenForControlQuantity.getFieldValue() == null || takenForControlQuantity.getFieldValue().toString().isEmpty()) { takenForControlQuantity.setFieldValue(BigDecimal.ONE); } if (rejectedQuantity.getFieldValue() == null || rejectedQuantity.getFieldValue().toString().isEmpty()) { rejectedQuantity.setFieldValue(BigDecimal.ZERO); } if (acceptedDefectsQuantity.getFieldValue() == null || acceptedDefectsQuantity.getFieldValue().toString().isEmpty()) { acceptedDefectsQuantity.setFieldValue(BigDecimal.ZERO); } } } | QualityControlService { public void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state) { FieldComponent takenForControlQuantity = (FieldComponent) state .getComponentByReference(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); FieldComponent rejectedQuantity = (FieldComponent) state.getComponentByReference(REJECTED_QUANTITY_LITERAL); FieldComponent acceptedDefectsQuantity = (FieldComponent) state .getComponentByReference(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (takenForControlQuantity.getFieldValue() == null || takenForControlQuantity.getFieldValue().toString().isEmpty()) { takenForControlQuantity.setFieldValue(BigDecimal.ONE); } if (rejectedQuantity.getFieldValue() == null || rejectedQuantity.getFieldValue().toString().isEmpty()) { rejectedQuantity.setFieldValue(BigDecimal.ZERO); } if (acceptedDefectsQuantity.getFieldValue() == null || acceptedDefectsQuantity.getFieldValue().toString().isEmpty()) { acceptedDefectsQuantity.setFieldValue(BigDecimal.ZERO); } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state) { FieldComponent takenForControlQuantity = (FieldComponent) state .getComponentByReference(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); FieldComponent rejectedQuantity = (FieldComponent) state.getComponentByReference(REJECTED_QUANTITY_LITERAL); FieldComponent acceptedDefectsQuantity = (FieldComponent) state .getComponentByReference(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (takenForControlQuantity.getFieldValue() == null || takenForControlQuantity.getFieldValue().toString().isEmpty()) { takenForControlQuantity.setFieldValue(BigDecimal.ONE); } if (rejectedQuantity.getFieldValue() == null || rejectedQuantity.getFieldValue().toString().isEmpty()) { rejectedQuantity.setFieldValue(BigDecimal.ZERO); } if (acceptedDefectsQuantity.getFieldValue() == null || acceptedDefectsQuantity.getFieldValue().toString().isEmpty()) { acceptedDefectsQuantity.setFieldValue(BigDecimal.ZERO); } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldSetCommentAsRequiredOnPositiveDefectsQuantity() { ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class); FieldComponent acceptedDefectsQuantity = mock(FieldComponent.class); FieldComponent comment = mock(FieldComponent.class); given(viewDefinitionState.getComponentByReference("comment")).willReturn(comment); given(acceptedDefectsQuantity.getFieldValue()).willReturn("1"); given(acceptedDefectsQuantity.getFieldValue().toString()).willReturn("1"); qualityControlService.checkAcceptedDefectsQuantity(viewDefinitionState, acceptedDefectsQuantity, new String[] {}); verify(comment).setRequired(true); } | public void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { throw new IllegalStateException("component is not input"); } FieldComponent acceptedDefectsQuantity = (FieldComponent) state; FieldComponent comment = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_COMMENT); if (acceptedDefectsQuantity.getFieldValue() != null) { if (isNumber(acceptedDefectsQuantity.getFieldValue().toString()) && (new BigDecimal(acceptedDefectsQuantity.getFieldValue().toString())).compareTo(BigDecimal.ZERO) > 0) { comment.setRequired(true); } else { comment.setRequired(false); } } } | QualityControlService { public void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { throw new IllegalStateException("component is not input"); } FieldComponent acceptedDefectsQuantity = (FieldComponent) state; FieldComponent comment = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_COMMENT); if (acceptedDefectsQuantity.getFieldValue() != null) { if (isNumber(acceptedDefectsQuantity.getFieldValue().toString()) && (new BigDecimal(acceptedDefectsQuantity.getFieldValue().toString())).compareTo(BigDecimal.ZERO) > 0) { comment.setRequired(true); } else { comment.setRequired(false); } } } } | QualityControlService { public void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { throw new IllegalStateException("component is not input"); } FieldComponent acceptedDefectsQuantity = (FieldComponent) state; FieldComponent comment = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_COMMENT); if (acceptedDefectsQuantity.getFieldValue() != null) { if (isNumber(acceptedDefectsQuantity.getFieldValue().toString()) && (new BigDecimal(acceptedDefectsQuantity.getFieldValue().toString())).compareTo(BigDecimal.ZERO) > 0) { comment.setRequired(true); } else { comment.setRequired(false); } } } } | QualityControlService { public void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { throw new IllegalStateException("component is not input"); } FieldComponent acceptedDefectsQuantity = (FieldComponent) state; FieldComponent comment = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_COMMENT); if (acceptedDefectsQuantity.getFieldValue() != null) { if (isNumber(acceptedDefectsQuantity.getFieldValue().toString()) && (new BigDecimal(acceptedDefectsQuantity.getFieldValue().toString())).compareTo(BigDecimal.ZERO) > 0) { comment.setRequired(true); } else { comment.setRequired(false); } } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { throw new IllegalStateException("component is not input"); } FieldComponent acceptedDefectsQuantity = (FieldComponent) state; FieldComponent comment = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_COMMENT); if (acceptedDefectsQuantity.getFieldValue() != null) { if (isNumber(acceptedDefectsQuantity.getFieldValue().toString()) && (new BigDecimal(acceptedDefectsQuantity.getFieldValue().toString())).compareTo(BigDecimal.ZERO) > 0) { comment.setRequired(true); } else { comment.setRequired(false); } } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldSetCommentAsNotRequiredOnPositiveDefectsQuantity() { ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class); FieldComponent state = mock(FieldComponent.class); FieldComponent comment = mock(FieldComponent.class); given(viewDefinitionState.getComponentByReference("comment")).willReturn(comment); given(state.getFieldValue()).willReturn("0"); given(state.getFieldValue().toString()).willReturn("0"); qualityControlService.checkAcceptedDefectsQuantity(viewDefinitionState, state, new String[] {}); verify(comment).setRequired(false); } | public void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { throw new IllegalStateException("component is not input"); } FieldComponent acceptedDefectsQuantity = (FieldComponent) state; FieldComponent comment = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_COMMENT); if (acceptedDefectsQuantity.getFieldValue() != null) { if (isNumber(acceptedDefectsQuantity.getFieldValue().toString()) && (new BigDecimal(acceptedDefectsQuantity.getFieldValue().toString())).compareTo(BigDecimal.ZERO) > 0) { comment.setRequired(true); } else { comment.setRequired(false); } } } | QualityControlService { public void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { throw new IllegalStateException("component is not input"); } FieldComponent acceptedDefectsQuantity = (FieldComponent) state; FieldComponent comment = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_COMMENT); if (acceptedDefectsQuantity.getFieldValue() != null) { if (isNumber(acceptedDefectsQuantity.getFieldValue().toString()) && (new BigDecimal(acceptedDefectsQuantity.getFieldValue().toString())).compareTo(BigDecimal.ZERO) > 0) { comment.setRequired(true); } else { comment.setRequired(false); } } } } | QualityControlService { public void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { throw new IllegalStateException("component is not input"); } FieldComponent acceptedDefectsQuantity = (FieldComponent) state; FieldComponent comment = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_COMMENT); if (acceptedDefectsQuantity.getFieldValue() != null) { if (isNumber(acceptedDefectsQuantity.getFieldValue().toString()) && (new BigDecimal(acceptedDefectsQuantity.getFieldValue().toString())).compareTo(BigDecimal.ZERO) > 0) { comment.setRequired(true); } else { comment.setRequired(false); } } } } | QualityControlService { public void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { throw new IllegalStateException("component is not input"); } FieldComponent acceptedDefectsQuantity = (FieldComponent) state; FieldComponent comment = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_COMMENT); if (acceptedDefectsQuantity.getFieldValue() != null) { if (isNumber(acceptedDefectsQuantity.getFieldValue().toString()) && (new BigDecimal(acceptedDefectsQuantity.getFieldValue().toString())).compareTo(BigDecimal.ZERO) > 0) { comment.setRequired(true); } else { comment.setRequired(false); } } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { throw new IllegalStateException("component is not input"); } FieldComponent acceptedDefectsQuantity = (FieldComponent) state; FieldComponent comment = (FieldComponent) viewDefinitionState.getComponentByReference(FIELD_COMMENT); if (acceptedDefectsQuantity.getFieldValue() != null) { if (isNumber(acceptedDefectsQuantity.getFieldValue().toString()) && (new BigDecimal(acceptedDefectsQuantity.getFieldValue().toString())).compareTo(BigDecimal.ZERO) > 0) { comment.setRequired(true); } else { comment.setRequired(false); } } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldSetQualityControlInstructionToDefaultFromTechnology() { ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class); FieldComponent state = mock(FieldComponent.class); FieldComponent controlInstruction = mock(FieldComponent.class); DataDefinition orderDD = mock(DataDefinition.class); SearchCriteriaBuilder searchCriteria = mock(SearchCriteriaBuilder.class); Entity technology = mock(Entity.class); given(technology.getField("qualityControlInstruction")).willReturn("test"); given(technology.getStringField("qualityControlInstruction")).willReturn("test"); List<Entity> orders = new ArrayList<Entity>(); Entity genealogy = mock(Entity.class); given(genealogy.getBelongsToField("technology")).willReturn(technology); orders.add(genealogy); given(viewDefinitionState.getComponentByReference("controlInstruction")).willReturn(controlInstruction); given(state.getFieldValue()).willReturn(1L); given(dataDefinitionService.get("orders", "order")).willReturn(orderDD); given(orderDD.find()).willReturn(searchCriteria); given(searchCriteria.setMaxResults(anyInt())).willReturn(searchCriteria); given(searchCriteria.add(any(SearchCriterion.class))).willReturn(searchCriteria); SearchResult searchResult = mock(SearchResult.class); given(searchCriteria.list()).willReturn(searchResult); given(searchResult.getEntities()).willReturn(orders); qualityControlService.setQualityControlInstruction(viewDefinitionState, state, new String[] {}); verify(controlInstruction).setFieldValue(""); verify(controlInstruction).setFieldValue("test"); } | public void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { return; } FieldComponent order = (FieldComponent) state; FieldComponent controlInstruction = (FieldComponent) viewDefinitionState .getComponentByReference(CONTROL_INSTRUCTION_LITERAL); if (controlInstruction == null) { return; } else { controlInstruction.setFieldValue(""); } if (order.getFieldValue() != null) { String qualityControlInstruction = getInstructionForOrder((Long) order.getFieldValue()); if (qualityControlInstruction != null) { controlInstruction.setFieldValue(qualityControlInstruction); } } } | QualityControlService { public void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { return; } FieldComponent order = (FieldComponent) state; FieldComponent controlInstruction = (FieldComponent) viewDefinitionState .getComponentByReference(CONTROL_INSTRUCTION_LITERAL); if (controlInstruction == null) { return; } else { controlInstruction.setFieldValue(""); } if (order.getFieldValue() != null) { String qualityControlInstruction = getInstructionForOrder((Long) order.getFieldValue()); if (qualityControlInstruction != null) { controlInstruction.setFieldValue(qualityControlInstruction); } } } } | QualityControlService { public void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { return; } FieldComponent order = (FieldComponent) state; FieldComponent controlInstruction = (FieldComponent) viewDefinitionState .getComponentByReference(CONTROL_INSTRUCTION_LITERAL); if (controlInstruction == null) { return; } else { controlInstruction.setFieldValue(""); } if (order.getFieldValue() != null) { String qualityControlInstruction = getInstructionForOrder((Long) order.getFieldValue()); if (qualityControlInstruction != null) { controlInstruction.setFieldValue(qualityControlInstruction); } } } } | QualityControlService { public void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { return; } FieldComponent order = (FieldComponent) state; FieldComponent controlInstruction = (FieldComponent) viewDefinitionState .getComponentByReference(CONTROL_INSTRUCTION_LITERAL); if (controlInstruction == null) { return; } else { controlInstruction.setFieldValue(""); } if (order.getFieldValue() != null) { String qualityControlInstruction = getInstructionForOrder((Long) order.getFieldValue()); if (qualityControlInstruction != null) { controlInstruction.setFieldValue(qualityControlInstruction); } } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { if (!(state instanceof FieldComponent)) { return; } FieldComponent order = (FieldComponent) state; FieldComponent controlInstruction = (FieldComponent) viewDefinitionState .getComponentByReference(CONTROL_INSTRUCTION_LITERAL); if (controlInstruction == null) { return; } else { controlInstruction.setFieldValue(""); } if (order.getFieldValue() != null) { String qualityControlInstruction = getInstructionForOrder((Long) order.getFieldValue()); if (qualityControlInstruction != null) { controlInstruction.setFieldValue(qualityControlInstruction); } } } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldSetOperationAsRequired() { ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class); FieldComponent operation = mock(FieldComponent.class); given(viewDefinitionState.getComponentByReference("operation")).willReturn(operation); qualityControlService.setOperationAsRequired(viewDefinitionState); verify(operation).setRequired(true); } | public void setOperationAsRequired(final ViewDefinitionState state) { FieldComponent operation = (FieldComponent) state.getComponentByReference(OPERATION_LITERAL); operation.setRequired(true); } | QualityControlService { public void setOperationAsRequired(final ViewDefinitionState state) { FieldComponent operation = (FieldComponent) state.getComponentByReference(OPERATION_LITERAL); operation.setRequired(true); } } | QualityControlService { public void setOperationAsRequired(final ViewDefinitionState state) { FieldComponent operation = (FieldComponent) state.getComponentByReference(OPERATION_LITERAL); operation.setRequired(true); } } | QualityControlService { public void setOperationAsRequired(final ViewDefinitionState state) { FieldComponent operation = (FieldComponent) state.getComponentByReference(OPERATION_LITERAL); operation.setRequired(true); } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public void setOperationAsRequired(final ViewDefinitionState state) { FieldComponent operation = (FieldComponent) state.getComponentByReference(OPERATION_LITERAL); operation.setRequired(true); } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldSetQualityControlTypeHiddenFieldToQualityControlsForBatch() { ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class); FormComponent qualityControlsForm = mock(FormComponent.class); FieldComponent qualityControlType = mock(FieldComponent.class); FieldComponent closed = mock(FieldComponent.class); given(viewDefinitionState.getComponentByReference("form")).willReturn(qualityControlsForm); given(qualityControlsForm.getName()).willReturn("qualityControlForBatch"); given(viewDefinitionState.getComponentByReference("qualityControlType")).willReturn(qualityControlType); given(viewDefinitionState.getComponentByReference("closed")).willReturn(closed); qualityControlService.setQualityControlTypeHiddenField(viewDefinitionState); verify(qualityControlType).setFieldValue("qualityControlsForBatch"); } | public void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState) { FormComponent qualityControlsForm = (FormComponent) viewDefinitionState.getComponentByReference(FORM_LITERAL); String qualityControlTypeString = qualityControlsForm.getName().replace("Control", "Controls"); FieldComponent qualityControlType = (FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL); qualityControlType.setFieldValue(qualityControlTypeString); } | QualityControlService { public void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState) { FormComponent qualityControlsForm = (FormComponent) viewDefinitionState.getComponentByReference(FORM_LITERAL); String qualityControlTypeString = qualityControlsForm.getName().replace("Control", "Controls"); FieldComponent qualityControlType = (FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL); qualityControlType.setFieldValue(qualityControlTypeString); } } | QualityControlService { public void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState) { FormComponent qualityControlsForm = (FormComponent) viewDefinitionState.getComponentByReference(FORM_LITERAL); String qualityControlTypeString = qualityControlsForm.getName().replace("Control", "Controls"); FieldComponent qualityControlType = (FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL); qualityControlType.setFieldValue(qualityControlTypeString); } } | QualityControlService { public void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState) { FormComponent qualityControlsForm = (FormComponent) viewDefinitionState.getComponentByReference(FORM_LITERAL); String qualityControlTypeString = qualityControlsForm.getName().replace("Control", "Controls"); FieldComponent qualityControlType = (FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL); qualityControlType.setFieldValue(qualityControlTypeString); } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState) { FormComponent qualityControlsForm = (FormComponent) viewDefinitionState.getComponentByReference(FORM_LITERAL); String qualityControlTypeString = qualityControlsForm.getName().replace("Control", "Controls"); FieldComponent qualityControlType = (FieldComponent) viewDefinitionState .getComponentByReference(QUALITY_CONTROL_TYPE_LITERAL); qualityControlType.setFieldValue(qualityControlTypeString); } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldSetErrorMessageOnEmptyOperationField() { DataDefinition qualityControlDD = mock(DataDefinition.class); FieldDefinition operation = mock(FieldDefinition.class); Entity qualityControl = mock(Entity.class); given(qualityControl.getStringField("qualityControlType")).willReturn("qualityControlsForOperation"); given(qualityControl.getBelongsToField("operation")).willReturn(null); given(qualityControlDD.getField("operation")).willReturn(operation); qualityControlService.checkIfOperationIsRequired(qualityControlDD, qualityControl); verify(qualityControl).addGlobalError("smartView.validate.global.error.custom"); verify(qualityControl).addError(qualityControlDD.getField("operation"), "qualityControls.quality.control.validate.global.error.operation"); } | public boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (QUALITY_CONTROLS_FOR_OPERATION_LITERAL.equals(qualityControlType)) { Object operation = entity.getField(OPERATION_LITERAL); if (operation == null) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(OPERATION_LITERAL), "qualityControls.quality.control.validate.global.error.operation"); return false; } } return true; } | QualityControlService { public boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (QUALITY_CONTROLS_FOR_OPERATION_LITERAL.equals(qualityControlType)) { Object operation = entity.getField(OPERATION_LITERAL); if (operation == null) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(OPERATION_LITERAL), "qualityControls.quality.control.validate.global.error.operation"); return false; } } return true; } } | QualityControlService { public boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (QUALITY_CONTROLS_FOR_OPERATION_LITERAL.equals(qualityControlType)) { Object operation = entity.getField(OPERATION_LITERAL); if (operation == null) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(OPERATION_LITERAL), "qualityControls.quality.control.validate.global.error.operation"); return false; } } return true; } } | QualityControlService { public boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (QUALITY_CONTROLS_FOR_OPERATION_LITERAL.equals(qualityControlType)) { Object operation = entity.getField(OPERATION_LITERAL); if (operation == null) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(OPERATION_LITERAL), "qualityControls.quality.control.validate.global.error.operation"); return false; } } return true; } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (QUALITY_CONTROLS_FOR_OPERATION_LITERAL.equals(qualityControlType)) { Object operation = entity.getField(OPERATION_LITERAL); if (operation == null) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(OPERATION_LITERAL), "qualityControls.quality.control.validate.global.error.operation"); return false; } } return true; } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldSetQuantitiesToDefaultValues() { DataDefinition qualityControlDD = mock(DataDefinition.class); Entity entity = mock(Entity.class); given(entity.getStringField("qualityControlType")).willReturn("qualityControlsForUnit"); given(entity.getDecimalField("controlledQuantity")).willReturn(null); given(entity.getDecimalField("takenForControlQuantity")).willReturn(null); given(entity.getDecimalField("rejectedQuantity")).willReturn(null); given(entity.getDecimalField("acceptedDefectsQuantity")).willReturn(null); qualityControlService.checkIfQuantitiesAreCorrect(qualityControlDD, entity); verify(entity).setField("controlledQuantity", BigDecimal.ZERO); verify(entity).setField("takenForControlQuantity", BigDecimal.ZERO); verify(entity).setField("rejectedQuantity", BigDecimal.ZERO); verify(entity).setField("acceptedDefectsQuantity", BigDecimal.ZERO); } | public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldClearGeneratedOnCopy() { workPlanHooks.onCopy(workPlanDD, workPlan); verify(workPlan).setField(WorkPlanFields.FILE_NAME, null); verify(workPlan).setField(WorkPlanFields.GENERATED, false); verify(workPlan).setField(WorkPlanFields.DATE, null); verify(workPlan).setField(WorkPlanFields.WORKER, null); } | public void onCopy(final DataDefinition workPlanDD, final Entity workPlan) { clearGeneratedOnCopy(workPlan); } | WorkPlanHooks { public void onCopy(final DataDefinition workPlanDD, final Entity workPlan) { clearGeneratedOnCopy(workPlan); } } | WorkPlanHooks { public void onCopy(final DataDefinition workPlanDD, final Entity workPlan) { clearGeneratedOnCopy(workPlan); } } | WorkPlanHooks { public void onCopy(final DataDefinition workPlanDD, final Entity workPlan) { clearGeneratedOnCopy(workPlan); } void onCreate(final DataDefinition workPlanDD, final Entity workPlan); void onCopy(final DataDefinition workPlanDD, final Entity workPlan); } | WorkPlanHooks { public void onCopy(final DataDefinition workPlanDD, final Entity workPlan) { clearGeneratedOnCopy(workPlan); } void onCreate(final DataDefinition workPlanDD, final Entity workPlan); void onCopy(final DataDefinition workPlanDD, final Entity workPlan); } |
@Test public void shouldSetFieldsVisibleAndRequiredWhenChangeoverTypeIsForTechnology() { given(changeoverType.getFieldValue()).willReturn(FOR_TECHNOLOGY.getStringValue()); hooks.setFieldsVisibleAndRequired(view, null, null); verify(fromTechnology).setVisible(true); verify(fromTechnology).setRequired(true); verify(toTechnology).setVisible(true); verify(toTechnology).setRequired(true); verify(fromTechnologyGroup).setVisible(false); verify(fromTechnologyGroup).setRequired(false); verify(fromTechnologyGroup).setFieldValue(null); verify(toTechnologyGroup).setVisible(false); verify(toTechnologyGroup).setRequired(false); verify(toTechnologyGroup).setFieldValue(null); } | public void setFieldsVisibleAndRequired(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { setFieldsVisibleAndRequired(view); } | LineChangeoverNormsDetailsHooks { public void setFieldsVisibleAndRequired(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { setFieldsVisibleAndRequired(view); } } | LineChangeoverNormsDetailsHooks { public void setFieldsVisibleAndRequired(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { setFieldsVisibleAndRequired(view); } } | LineChangeoverNormsDetailsHooks { public void setFieldsVisibleAndRequired(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { setFieldsVisibleAndRequired(view); } final void onBeforeRender(final ViewDefinitionState view); void setLineChangeoverNormsName(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void setFieldsVisibleAndRequired(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void setFieldsVisibleAndRequired(final ViewDefinitionState view); } | LineChangeoverNormsDetailsHooks { public void setFieldsVisibleAndRequired(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { setFieldsVisibleAndRequired(view); } final void onBeforeRender(final ViewDefinitionState view); void setLineChangeoverNormsName(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void setFieldsVisibleAndRequired(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void setFieldsVisibleAndRequired(final ViewDefinitionState view); } |
@Test public void shouldAddErrorMessageOnTooLargeRejectedQuantity() { DataDefinition qualityControlDD = mock(DataDefinition.class); Entity entity = mock(Entity.class); given(entity.getStringField("qualityControlType")).willReturn("qualityControlsForUnit"); given(entity.getDecimalField("controlledQuantity")).willReturn(null); given(entity.getDecimalField("takenForControlQuantity")).willReturn(new BigDecimal("1")); given(entity.getDecimalField("rejectedQuantity")).willReturn(new BigDecimal("5")); given(entity.getDecimalField("acceptedDefectsQuantity")).willReturn(null); qualityControlService.checkIfQuantitiesAreCorrect(qualityControlDD, entity); verify(entity).addGlobalError("smartView.validate.global.error.custom"); verify(entity).addError(qualityControlDD.getField("rejectedQuantity"), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); } | public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldAddErrorMessageOnTooLargeAcceptedDefectsQuantity() { DataDefinition qualityControlDD = mock(DataDefinition.class); Entity entity = mock(Entity.class); given(entity.getStringField("qualityControlType")).willReturn("qualityControlsForUnit"); given(entity.getDecimalField("controlledQuantity")).willReturn(null); given(entity.getDecimalField("takenForControlQuantity")).willReturn(new BigDecimal("5")); given(entity.getDecimalField("rejectedQuantity")).willReturn(new BigDecimal("5")); given(entity.getDecimalField("acceptedDefectsQuantity")).willReturn(new BigDecimal("10")); qualityControlService.checkIfQuantitiesAreCorrect(qualityControlDD, entity); verify(entity).addGlobalError("smartView.validate.global.error.custom"); verify(entity).addError(qualityControlDD.getField("acceptedDefectsQuantity"), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); } | public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } | QualityControlService { public boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity) { String qualityControlType = entity.getStringField(QUALITY_CONTROL_TYPE_LITERAL); if (hasQuantitiesToBeChecked(qualityControlType)) { BigDecimal controlledQuantity = entity.getDecimalField(CONTROLLED_QUANTITY_LITERAL); BigDecimal takenForControlQuantity = entity.getDecimalField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL); BigDecimal rejectedQuantity = entity.getDecimalField(REJECTED_QUANTITY_LITERAL); BigDecimal acceptedDefectsQuantity = entity.getDecimalField(ACCEPTED_DEFECTS_QUANTITY_LITERAL); if (controlledQuantity == null) { controlledQuantity = BigDecimal.ZERO; } if (takenForControlQuantity == null) { takenForControlQuantity = BigDecimal.ZERO; } if (rejectedQuantity == null) { rejectedQuantity = BigDecimal.ZERO; } if (acceptedDefectsQuantity == null) { acceptedDefectsQuantity = BigDecimal.ZERO; } if (rejectedQuantity.compareTo(takenForControlQuantity) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(REJECTED_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.rejectedQuantity.tooLarge"); return false; } if (acceptedDefectsQuantity.compareTo(takenForControlQuantity.subtract(rejectedQuantity, numberService.getMathContext())) > 0) { entity.addGlobalError(QCADOO_VIEW_VALIDATE_GLOBAL_ERROR_CUSTOM); entity.addError(dataDefinition.getField(ACCEPTED_DEFECTS_QUANTITY_LITERAL), "qualityControls.quality.control.validate.global.error.acceptedDefectsQuantity.tooLarge"); return false; } entity.setField(CONTROLLED_QUANTITY_LITERAL, controlledQuantity); entity.setField(TAKEN_FOR_CONTROL_QUANTITY_LITERAL, takenForControlQuantity); entity.setField(REJECTED_QUANTITY_LITERAL, rejectedQuantity); entity.setField(ACCEPTED_DEFECTS_QUANTITY_LITERAL, acceptedDefectsQuantity); } return true; } void setTechnology(final ViewDefinitionState view); void checkIfCommentIsRequiredBasedOnResult(final ViewDefinitionState state); void setQualityControlTypeForTechnology(final DataDefinition dataDefinition, final Entity entity); void checkIfCommentIsRequiredBasedOnDefects(final ViewDefinitionState state); boolean checkIfCommentForResultOrQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForResultIsReq(final DataDefinition dataDefinition, final Entity entity); boolean checkIfCommentForQuantityIsReq(final DataDefinition dataDefinition, final Entity entity); void checkQualityControlResult(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void closeQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args); void autoGenerateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void generateQualityControl(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void checkAcceptedDefectsQuantity(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void setQualityControlInstruction(final ViewDefinitionState viewDefinitionState, final ComponentState state,
final String[] args); void enableCalendarsOnRender(final ViewDefinitionState state); void setQuantitiesToDefaulIfEmpty(final ViewDefinitionState state); void addRestrictionToQualityControlGrid(final ViewDefinitionState viewDefinitionState); void setQualityControlTypeHiddenField(final ViewDefinitionState viewDefinitionState); void setOperationAsRequired(final ViewDefinitionState state); boolean checkIfOperationIsRequired(final DataDefinition dataDefinition, final Entity entity); boolean checkIfQuantitiesAreCorrect(final DataDefinition dataDefinition, final Entity entity); void disableFormForClosedControl(final ViewDefinitionState state); boolean clearQualityControlOnCopy(final DataDefinition dataDefinition, final Entity entity); boolean setStaffAndDateIfClosed(final DataDefinition dataDefinition, final Entity entity); void changeQualityControlType(final ViewDefinitionState state); } |
@Test public void shouldReturnFalseWhenUserNotLoggedIn() { given(securityService.getCurrentUserId()).willReturn(null); boolean result = draftDocumentsNotificationService.shouldNotifyCurrentUser(); verify(securityService).getCurrentUserId(); verify(securityService, never()).hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION); assertFalse(result); } | public boolean shouldNotifyCurrentUser() { Long currentUserId = securityService.getCurrentUserId(); return currentUserId != null && securityService.hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION) && countDraftDocumentsForUser(currentUserId) > 0; } | DraftDocumentsNotificationService { public boolean shouldNotifyCurrentUser() { Long currentUserId = securityService.getCurrentUserId(); return currentUserId != null && securityService.hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION) && countDraftDocumentsForUser(currentUserId) > 0; } } | DraftDocumentsNotificationService { public boolean shouldNotifyCurrentUser() { Long currentUserId = securityService.getCurrentUserId(); return currentUserId != null && securityService.hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION) && countDraftDocumentsForUser(currentUserId) > 0; } @Autowired DraftDocumentsNotificationService(SecurityService securityService, DataDefinitionService dataDefinitionService); } | DraftDocumentsNotificationService { public boolean shouldNotifyCurrentUser() { Long currentUserId = securityService.getCurrentUserId(); return currentUserId != null && securityService.hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION) && countDraftDocumentsForUser(currentUserId) > 0; } @Autowired DraftDocumentsNotificationService(SecurityService securityService, DataDefinitionService dataDefinitionService); boolean shouldNotifyCurrentUser(); } | DraftDocumentsNotificationService { public boolean shouldNotifyCurrentUser() { Long currentUserId = securityService.getCurrentUserId(); return currentUserId != null && securityService.hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION) && countDraftDocumentsForUser(currentUserId) > 0; } @Autowired DraftDocumentsNotificationService(SecurityService securityService, DataDefinitionService dataDefinitionService); boolean shouldNotifyCurrentUser(); } |
@Test public void shouldReturnFalseWhenUserHasNoRole() { given(securityService.getCurrentUserId()).willReturn(CURRENT_USER_ID); given(securityService.hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION)).willReturn(Boolean.FALSE); boolean result = draftDocumentsNotificationService.shouldNotifyCurrentUser(); verify(securityService).getCurrentUserId(); verify(securityService).hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION); assertFalse(result); } | public boolean shouldNotifyCurrentUser() { Long currentUserId = securityService.getCurrentUserId(); return currentUserId != null && securityService.hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION) && countDraftDocumentsForUser(currentUserId) > 0; } | DraftDocumentsNotificationService { public boolean shouldNotifyCurrentUser() { Long currentUserId = securityService.getCurrentUserId(); return currentUserId != null && securityService.hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION) && countDraftDocumentsForUser(currentUserId) > 0; } } | DraftDocumentsNotificationService { public boolean shouldNotifyCurrentUser() { Long currentUserId = securityService.getCurrentUserId(); return currentUserId != null && securityService.hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION) && countDraftDocumentsForUser(currentUserId) > 0; } @Autowired DraftDocumentsNotificationService(SecurityService securityService, DataDefinitionService dataDefinitionService); } | DraftDocumentsNotificationService { public boolean shouldNotifyCurrentUser() { Long currentUserId = securityService.getCurrentUserId(); return currentUserId != null && securityService.hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION) && countDraftDocumentsForUser(currentUserId) > 0; } @Autowired DraftDocumentsNotificationService(SecurityService securityService, DataDefinitionService dataDefinitionService); boolean shouldNotifyCurrentUser(); } | DraftDocumentsNotificationService { public boolean shouldNotifyCurrentUser() { Long currentUserId = securityService.getCurrentUserId(); return currentUserId != null && securityService.hasCurrentUserRole(ROLE_DOCUMENTS_NOTIFICATION) && countDraftDocumentsForUser(currentUserId) > 0; } @Autowired DraftDocumentsNotificationService(SecurityService securityService, DataDefinitionService dataDefinitionService); boolean shouldNotifyCurrentUser(); } |
@Test public void shouldEnabledButtonWhenProductOnTreeIsSelected() throws Exception { when(view.getComponentByReference("window")).thenReturn((ComponentState) windowComponent); when(windowComponent.getRibbon()).thenReturn(ribbon); when(ribbon.getGroupByName("edit")).thenReturn(ribbonGroup); when(ribbonGroup.getItemByName("editSelectedProduct")).thenReturn(actionItem); productsFamiliesListeners.enabledEditButton(view, state, new String[0]); Mockito.verify(actionItem).setEnabled(true); } | public final void enabledEditButton(final ViewDefinitionState view, final ComponentState state, final String[] args) { setEditButtonEnabled(view, true); } | ProductsFamiliesListeners { public final void enabledEditButton(final ViewDefinitionState view, final ComponentState state, final String[] args) { setEditButtonEnabled(view, true); } } | ProductsFamiliesListeners { public final void enabledEditButton(final ViewDefinitionState view, final ComponentState state, final String[] args) { setEditButtonEnabled(view, true); } } | ProductsFamiliesListeners { public final void enabledEditButton(final ViewDefinitionState view, final ComponentState state, final String[] args) { setEditButtonEnabled(view, true); } final void generateHierarchyTree(final ViewDefinitionState view, final ComponentState state, final String[] args); final void editSelectedProduct(final ViewDefinitionState view, final ComponentState state, final String[] args); final void enabledEditButton(final ViewDefinitionState view, final ComponentState state, final String[] args); } | ProductsFamiliesListeners { public final void enabledEditButton(final ViewDefinitionState view, final ComponentState state, final String[] args) { setEditButtonEnabled(view, true); } final void generateHierarchyTree(final ViewDefinitionState view, final ComponentState state, final String[] args); final void editSelectedProduct(final ViewDefinitionState view, final ComponentState state, final String[] args); final void enabledEditButton(final ViewDefinitionState view, final ComponentState state, final String[] args); } |
@Test public void shouldPrepareViewForParameters() throws Exception { Map<String, String> arguments = ImmutableMap.of("context", "{\"form.id\":\"13\"}"); ModelAndView expectedMav = mock(ModelAndView.class); CrudService crudController = mock(CrudService.class); given( crudController.prepareView(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.VIEW_PARAMETERS, arguments, Locale.ENGLISH)).willReturn(expectedMav); ParameterService parameterService = mock(ParameterService.class); given(parameterService.getParameterId()).willReturn(13L); BasicController basicController = new BasicController(); setField(basicController, "crudService", crudController); setField(basicController, "parameterService", parameterService); ModelAndView mav = basicController.getParameterPageView(Locale.ENGLISH); assertEquals(expectedMav, mav); } | @RequestMapping(value = "parameters", method = RequestMethod.GET) public ModelAndView getParameterPageView(final Locale locale) { JSONObject json = new JSONObject(ImmutableMap.of("form.id", parameterService.getParameterId().toString())); Map<String, String> arguments = ImmutableMap.of("context", json.toString()); return crudService.prepareView(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.VIEW_PARAMETERS, arguments, locale); } | BasicController { @RequestMapping(value = "parameters", method = RequestMethod.GET) public ModelAndView getParameterPageView(final Locale locale) { JSONObject json = new JSONObject(ImmutableMap.of("form.id", parameterService.getParameterId().toString())); Map<String, String> arguments = ImmutableMap.of("context", json.toString()); return crudService.prepareView(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.VIEW_PARAMETERS, arguments, locale); } } | BasicController { @RequestMapping(value = "parameters", method = RequestMethod.GET) public ModelAndView getParameterPageView(final Locale locale) { JSONObject json = new JSONObject(ImmutableMap.of("form.id", parameterService.getParameterId().toString())); Map<String, String> arguments = ImmutableMap.of("context", json.toString()); return crudService.prepareView(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.VIEW_PARAMETERS, arguments, locale); } } | BasicController { @RequestMapping(value = "parameters", method = RequestMethod.GET) public ModelAndView getParameterPageView(final Locale locale) { JSONObject json = new JSONObject(ImmutableMap.of("form.id", parameterService.getParameterId().toString())); Map<String, String> arguments = ImmutableMap.of("context", json.toString()); return crudService.prepareView(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.VIEW_PARAMETERS, arguments, locale); } @RequestMapping(value = "parameters", method = RequestMethod.GET) ModelAndView getParameterPageView(final Locale locale); } | BasicController { @RequestMapping(value = "parameters", method = RequestMethod.GET) public ModelAndView getParameterPageView(final Locale locale) { JSONObject json = new JSONObject(ImmutableMap.of("form.id", parameterService.getParameterId().toString())); Map<String, String> arguments = ImmutableMap.of("context", json.toString()); return crudService.prepareView(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.VIEW_PARAMETERS, arguments, locale); } @RequestMapping(value = "parameters", method = RequestMethod.GET) ModelAndView getParameterPageView(final Locale locale); } |
@Test public void shouldDisabledFormWhenExternalNumberIsNotNull() throws Exception { Long productId = 1L; given(view.getComponentByReference(L_FORM)).willReturn(productForm); given(view.getComponentByReference(ProductFields.PARENT)).willReturn(parentField); given(view.getComponentByReference(ProductFields.ENTITY_TYPE)).willReturn(entityTypeField); given(view.getComponentByReference(ProductFields.ASSORTMENT)).willReturn(assortmentLookup); given(productForm.getEntityId()).willReturn(L_ID); given(dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT)).willReturn(productDD); given(productDD.get(productId)).willReturn(product); given(product.getStringField(ProductFields.EXTERNAL_NUMBER)).willReturn(L_EXTERNAL_NUMBER); productDetailsHooks.disableProductFormForExternalItems(view); verify(productForm).setFormEnabled(false); verify(entityTypeField).setEnabled(true); verify(parentField).setEnabled(true); } | public void disableProductFormForExternalItems(final ViewDefinitionState state) { FormComponent productForm = (FormComponent) state.getComponentByReference(L_FORM); FieldComponent entityTypeField = (FieldComponent) state.getComponentByReference(ProductFields.ENTITY_TYPE); FieldComponent parentField = (FieldComponent) state.getComponentByReference(ProductFields.PARENT); LookupComponent assortmentLookup = (LookupComponent) state.getComponentByReference(ProductFields.ASSORTMENT); Long productId = productForm.getEntityId(); if (productId == null) { productForm.setFormEnabled(true); return; } Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(productId); if (product == null) { return; } String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER); if (StringUtils.isEmpty(externalNumber)) { productForm.setFormEnabled(true); } else { productForm.setFormEnabled(false); entityTypeField.setEnabled(true); parentField.setEnabled(true); assortmentLookup.setEnabled(true); } } | ProductDetailsHooks { public void disableProductFormForExternalItems(final ViewDefinitionState state) { FormComponent productForm = (FormComponent) state.getComponentByReference(L_FORM); FieldComponent entityTypeField = (FieldComponent) state.getComponentByReference(ProductFields.ENTITY_TYPE); FieldComponent parentField = (FieldComponent) state.getComponentByReference(ProductFields.PARENT); LookupComponent assortmentLookup = (LookupComponent) state.getComponentByReference(ProductFields.ASSORTMENT); Long productId = productForm.getEntityId(); if (productId == null) { productForm.setFormEnabled(true); return; } Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(productId); if (product == null) { return; } String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER); if (StringUtils.isEmpty(externalNumber)) { productForm.setFormEnabled(true); } else { productForm.setFormEnabled(false); entityTypeField.setEnabled(true); parentField.setEnabled(true); assortmentLookup.setEnabled(true); } } } | ProductDetailsHooks { public void disableProductFormForExternalItems(final ViewDefinitionState state) { FormComponent productForm = (FormComponent) state.getComponentByReference(L_FORM); FieldComponent entityTypeField = (FieldComponent) state.getComponentByReference(ProductFields.ENTITY_TYPE); FieldComponent parentField = (FieldComponent) state.getComponentByReference(ProductFields.PARENT); LookupComponent assortmentLookup = (LookupComponent) state.getComponentByReference(ProductFields.ASSORTMENT); Long productId = productForm.getEntityId(); if (productId == null) { productForm.setFormEnabled(true); return; } Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(productId); if (product == null) { return; } String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER); if (StringUtils.isEmpty(externalNumber)) { productForm.setFormEnabled(true); } else { productForm.setFormEnabled(false); entityTypeField.setEnabled(true); parentField.setEnabled(true); assortmentLookup.setEnabled(true); } } } | ProductDetailsHooks { public void disableProductFormForExternalItems(final ViewDefinitionState state) { FormComponent productForm = (FormComponent) state.getComponentByReference(L_FORM); FieldComponent entityTypeField = (FieldComponent) state.getComponentByReference(ProductFields.ENTITY_TYPE); FieldComponent parentField = (FieldComponent) state.getComponentByReference(ProductFields.PARENT); LookupComponent assortmentLookup = (LookupComponent) state.getComponentByReference(ProductFields.ASSORTMENT); Long productId = productForm.getEntityId(); if (productId == null) { productForm.setFormEnabled(true); return; } Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(productId); if (product == null) { return; } String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER); if (StringUtils.isEmpty(externalNumber)) { productForm.setFormEnabled(true); } else { productForm.setFormEnabled(false); entityTypeField.setEnabled(true); parentField.setEnabled(true); assortmentLookup.setEnabled(true); } } void generateProductNumber(final ViewDefinitionState view); void fillUnit(final ViewDefinitionState view); void disableUnitFromWhenFormIsSaved(final ViewDefinitionState view); void disableProductFormForExternalItems(final ViewDefinitionState state); void updateRibbonState(final ViewDefinitionState view); } | ProductDetailsHooks { public void disableProductFormForExternalItems(final ViewDefinitionState state) { FormComponent productForm = (FormComponent) state.getComponentByReference(L_FORM); FieldComponent entityTypeField = (FieldComponent) state.getComponentByReference(ProductFields.ENTITY_TYPE); FieldComponent parentField = (FieldComponent) state.getComponentByReference(ProductFields.PARENT); LookupComponent assortmentLookup = (LookupComponent) state.getComponentByReference(ProductFields.ASSORTMENT); Long productId = productForm.getEntityId(); if (productId == null) { productForm.setFormEnabled(true); return; } Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(productId); if (product == null) { return; } String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER); if (StringUtils.isEmpty(externalNumber)) { productForm.setFormEnabled(true); } else { productForm.setFormEnabled(false); entityTypeField.setEnabled(true); parentField.setEnabled(true); assortmentLookup.setEnabled(true); } } void generateProductNumber(final ViewDefinitionState view); void fillUnit(final ViewDefinitionState view); void disableUnitFromWhenFormIsSaved(final ViewDefinitionState view); void disableProductFormForExternalItems(final ViewDefinitionState state); void updateRibbonState(final ViewDefinitionState view); } |
@Test public void shouldntDisabledFormWhenExternalNumberIsNull() throws Exception { Long productId = 1L; given(view.getComponentByReference(L_FORM)).willReturn(productForm); given(view.getComponentByReference(ProductFields.PARENT)).willReturn(parentField); given(view.getComponentByReference(ProductFields.ENTITY_TYPE)).willReturn(entityTypeField); given(productForm.getEntityId()).willReturn(L_ID); given(dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT)).willReturn(productDD); given(productDD.get(productId)).willReturn(product); given(product.getStringField(ProductFields.EXTERNAL_NUMBER)).willReturn(null); productDetailsHooks.disableProductFormForExternalItems(view); verify(productForm).setFormEnabled(true); } | public void disableProductFormForExternalItems(final ViewDefinitionState state) { FormComponent productForm = (FormComponent) state.getComponentByReference(L_FORM); FieldComponent entityTypeField = (FieldComponent) state.getComponentByReference(ProductFields.ENTITY_TYPE); FieldComponent parentField = (FieldComponent) state.getComponentByReference(ProductFields.PARENT); LookupComponent assortmentLookup = (LookupComponent) state.getComponentByReference(ProductFields.ASSORTMENT); Long productId = productForm.getEntityId(); if (productId == null) { productForm.setFormEnabled(true); return; } Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(productId); if (product == null) { return; } String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER); if (StringUtils.isEmpty(externalNumber)) { productForm.setFormEnabled(true); } else { productForm.setFormEnabled(false); entityTypeField.setEnabled(true); parentField.setEnabled(true); assortmentLookup.setEnabled(true); } } | ProductDetailsHooks { public void disableProductFormForExternalItems(final ViewDefinitionState state) { FormComponent productForm = (FormComponent) state.getComponentByReference(L_FORM); FieldComponent entityTypeField = (FieldComponent) state.getComponentByReference(ProductFields.ENTITY_TYPE); FieldComponent parentField = (FieldComponent) state.getComponentByReference(ProductFields.PARENT); LookupComponent assortmentLookup = (LookupComponent) state.getComponentByReference(ProductFields.ASSORTMENT); Long productId = productForm.getEntityId(); if (productId == null) { productForm.setFormEnabled(true); return; } Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(productId); if (product == null) { return; } String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER); if (StringUtils.isEmpty(externalNumber)) { productForm.setFormEnabled(true); } else { productForm.setFormEnabled(false); entityTypeField.setEnabled(true); parentField.setEnabled(true); assortmentLookup.setEnabled(true); } } } | ProductDetailsHooks { public void disableProductFormForExternalItems(final ViewDefinitionState state) { FormComponent productForm = (FormComponent) state.getComponentByReference(L_FORM); FieldComponent entityTypeField = (FieldComponent) state.getComponentByReference(ProductFields.ENTITY_TYPE); FieldComponent parentField = (FieldComponent) state.getComponentByReference(ProductFields.PARENT); LookupComponent assortmentLookup = (LookupComponent) state.getComponentByReference(ProductFields.ASSORTMENT); Long productId = productForm.getEntityId(); if (productId == null) { productForm.setFormEnabled(true); return; } Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(productId); if (product == null) { return; } String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER); if (StringUtils.isEmpty(externalNumber)) { productForm.setFormEnabled(true); } else { productForm.setFormEnabled(false); entityTypeField.setEnabled(true); parentField.setEnabled(true); assortmentLookup.setEnabled(true); } } } | ProductDetailsHooks { public void disableProductFormForExternalItems(final ViewDefinitionState state) { FormComponent productForm = (FormComponent) state.getComponentByReference(L_FORM); FieldComponent entityTypeField = (FieldComponent) state.getComponentByReference(ProductFields.ENTITY_TYPE); FieldComponent parentField = (FieldComponent) state.getComponentByReference(ProductFields.PARENT); LookupComponent assortmentLookup = (LookupComponent) state.getComponentByReference(ProductFields.ASSORTMENT); Long productId = productForm.getEntityId(); if (productId == null) { productForm.setFormEnabled(true); return; } Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(productId); if (product == null) { return; } String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER); if (StringUtils.isEmpty(externalNumber)) { productForm.setFormEnabled(true); } else { productForm.setFormEnabled(false); entityTypeField.setEnabled(true); parentField.setEnabled(true); assortmentLookup.setEnabled(true); } } void generateProductNumber(final ViewDefinitionState view); void fillUnit(final ViewDefinitionState view); void disableUnitFromWhenFormIsSaved(final ViewDefinitionState view); void disableProductFormForExternalItems(final ViewDefinitionState state); void updateRibbonState(final ViewDefinitionState view); } | ProductDetailsHooks { public void disableProductFormForExternalItems(final ViewDefinitionState state) { FormComponent productForm = (FormComponent) state.getComponentByReference(L_FORM); FieldComponent entityTypeField = (FieldComponent) state.getComponentByReference(ProductFields.ENTITY_TYPE); FieldComponent parentField = (FieldComponent) state.getComponentByReference(ProductFields.PARENT); LookupComponent assortmentLookup = (LookupComponent) state.getComponentByReference(ProductFields.ASSORTMENT); Long productId = productForm.getEntityId(); if (productId == null) { productForm.setFormEnabled(true); return; } Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(productId); if (product == null) { return; } String externalNumber = product.getStringField(ProductFields.EXTERNAL_NUMBER); if (StringUtils.isEmpty(externalNumber)) { productForm.setFormEnabled(true); } else { productForm.setFormEnabled(false); entityTypeField.setEnabled(true); parentField.setEnabled(true); assortmentLookup.setEnabled(true); } } void generateProductNumber(final ViewDefinitionState view); void fillUnit(final ViewDefinitionState view); void disableUnitFromWhenFormIsSaved(final ViewDefinitionState view); void disableProductFormForExternalItems(final ViewDefinitionState state); void updateRibbonState(final ViewDefinitionState view); } |
@Test public void shouldntFillUnitIfFormIsSaved() { given(view.getComponentByReference(L_FORM)).willReturn(productForm); given(view.getComponentByReference(UNIT)).willReturn(unitField); given(productForm.getEntityId()).willReturn(L_ID); productDetailsHooks.fillUnit(view); verify(unitField, never()).setFieldValue(Mockito.anyString()); } | public void fillUnit(final ViewDefinitionState view) { FormComponent productForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent unitField = (FieldComponent) view.getComponentByReference(UNIT); if ((productForm.getEntityId() == null) && (unitField.getFieldValue() == null)) { unitField.setFieldValue(unitService.getDefaultUnitFromSystemParameters()); unitField.requestComponentUpdateState(); } } | ProductDetailsHooks { public void fillUnit(final ViewDefinitionState view) { FormComponent productForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent unitField = (FieldComponent) view.getComponentByReference(UNIT); if ((productForm.getEntityId() == null) && (unitField.getFieldValue() == null)) { unitField.setFieldValue(unitService.getDefaultUnitFromSystemParameters()); unitField.requestComponentUpdateState(); } } } | ProductDetailsHooks { public void fillUnit(final ViewDefinitionState view) { FormComponent productForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent unitField = (FieldComponent) view.getComponentByReference(UNIT); if ((productForm.getEntityId() == null) && (unitField.getFieldValue() == null)) { unitField.setFieldValue(unitService.getDefaultUnitFromSystemParameters()); unitField.requestComponentUpdateState(); } } } | ProductDetailsHooks { public void fillUnit(final ViewDefinitionState view) { FormComponent productForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent unitField = (FieldComponent) view.getComponentByReference(UNIT); if ((productForm.getEntityId() == null) && (unitField.getFieldValue() == null)) { unitField.setFieldValue(unitService.getDefaultUnitFromSystemParameters()); unitField.requestComponentUpdateState(); } } void generateProductNumber(final ViewDefinitionState view); void fillUnit(final ViewDefinitionState view); void disableUnitFromWhenFormIsSaved(final ViewDefinitionState view); void disableProductFormForExternalItems(final ViewDefinitionState state); void updateRibbonState(final ViewDefinitionState view); } | ProductDetailsHooks { public void fillUnit(final ViewDefinitionState view) { FormComponent productForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent unitField = (FieldComponent) view.getComponentByReference(UNIT); if ((productForm.getEntityId() == null) && (unitField.getFieldValue() == null)) { unitField.setFieldValue(unitService.getDefaultUnitFromSystemParameters()); unitField.requestComponentUpdateState(); } } void generateProductNumber(final ViewDefinitionState view); void fillUnit(final ViewDefinitionState view); void disableUnitFromWhenFormIsSaved(final ViewDefinitionState view); void disableProductFormForExternalItems(final ViewDefinitionState state); void updateRibbonState(final ViewDefinitionState view); } |
@Test public void shouldFillUnitIfFormIsntSaved() { given(view.getComponentByReference(L_FORM)).willReturn(productForm); given(view.getComponentByReference(UNIT)).willReturn(unitField); given(productForm.getEntityId()).willReturn(null); given(unitField.getFieldValue()).willReturn(null); given(unitService.getDefaultUnitFromSystemParameters()).willReturn(L_SZT); productDetailsHooks.fillUnit(view); verify(unitField).setFieldValue(L_SZT); } | public void fillUnit(final ViewDefinitionState view) { FormComponent productForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent unitField = (FieldComponent) view.getComponentByReference(UNIT); if ((productForm.getEntityId() == null) && (unitField.getFieldValue() == null)) { unitField.setFieldValue(unitService.getDefaultUnitFromSystemParameters()); unitField.requestComponentUpdateState(); } } | ProductDetailsHooks { public void fillUnit(final ViewDefinitionState view) { FormComponent productForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent unitField = (FieldComponent) view.getComponentByReference(UNIT); if ((productForm.getEntityId() == null) && (unitField.getFieldValue() == null)) { unitField.setFieldValue(unitService.getDefaultUnitFromSystemParameters()); unitField.requestComponentUpdateState(); } } } | ProductDetailsHooks { public void fillUnit(final ViewDefinitionState view) { FormComponent productForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent unitField = (FieldComponent) view.getComponentByReference(UNIT); if ((productForm.getEntityId() == null) && (unitField.getFieldValue() == null)) { unitField.setFieldValue(unitService.getDefaultUnitFromSystemParameters()); unitField.requestComponentUpdateState(); } } } | ProductDetailsHooks { public void fillUnit(final ViewDefinitionState view) { FormComponent productForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent unitField = (FieldComponent) view.getComponentByReference(UNIT); if ((productForm.getEntityId() == null) && (unitField.getFieldValue() == null)) { unitField.setFieldValue(unitService.getDefaultUnitFromSystemParameters()); unitField.requestComponentUpdateState(); } } void generateProductNumber(final ViewDefinitionState view); void fillUnit(final ViewDefinitionState view); void disableUnitFromWhenFormIsSaved(final ViewDefinitionState view); void disableProductFormForExternalItems(final ViewDefinitionState state); void updateRibbonState(final ViewDefinitionState view); } | ProductDetailsHooks { public void fillUnit(final ViewDefinitionState view) { FormComponent productForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent unitField = (FieldComponent) view.getComponentByReference(UNIT); if ((productForm.getEntityId() == null) && (unitField.getFieldValue() == null)) { unitField.setFieldValue(unitService.getDefaultUnitFromSystemParameters()); unitField.requestComponentUpdateState(); } } void generateProductNumber(final ViewDefinitionState view); void fillUnit(final ViewDefinitionState view); void disableUnitFromWhenFormIsSaved(final ViewDefinitionState view); void disableProductFormForExternalItems(final ViewDefinitionState state); void updateRibbonState(final ViewDefinitionState view); } |
@Test public final void shouldGetSelectedEntities() { List<Entity> entities = ImmutableList.of(mockEntity(), mockEntity(), mockEntity(), mockEntity()); given(workPlansGrid.getSelectedEntities()).willReturn(entities); List<Entity> result = workPlansListView.getSelectedWorkPlans(); assertEquals(entities, result); } | public List<Entity> getSelectedWorkPlans() { return workPlansGrid.getSelectedEntities(); } | WorkPlansListView { public List<Entity> getSelectedWorkPlans() { return workPlansGrid.getSelectedEntities(); } } | WorkPlansListView { public List<Entity> getSelectedWorkPlans() { return workPlansGrid.getSelectedEntities(); } WorkPlansListView(final WindowComponent window, final RibbonActionItem deleteButton, final GridComponent workPlansGrid); } | WorkPlansListView { public List<Entity> getSelectedWorkPlans() { return workPlansGrid.getSelectedEntities(); } WorkPlansListView(final WindowComponent window, final RibbonActionItem deleteButton, final GridComponent workPlansGrid); static WorkPlansListView from(final ViewDefinitionState view); void setUpDeleteButton(final boolean isEnabled, final String message); List<Entity> getSelectedWorkPlans(); @Override boolean equals(final Object obj); @Override int hashCode(); } | WorkPlansListView { public List<Entity> getSelectedWorkPlans() { return workPlansGrid.getSelectedEntities(); } WorkPlansListView(final WindowComponent window, final RibbonActionItem deleteButton, final GridComponent workPlansGrid); static WorkPlansListView from(final ViewDefinitionState view); void setUpDeleteButton(final boolean isEnabled, final String message); List<Entity> getSelectedWorkPlans(); @Override boolean equals(final Object obj); @Override int hashCode(); } |
@Test public void sholudReturnTrueIfProductIsNull() { given(unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT)).willReturn(null); boolean result = unitConversionItemValidatorsB.validateUnitOnConversionWithProduct(dataDefinition, unitConversionItem); assertTrue(result); } | public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem); } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem); } |
@Test public void sholudReturnTrueIfProductUnitIsEqualFieldUnit() { stubConversionSourceUnit(SOME_UNIT); stubProductUnit(SOME_UNIT); boolean result = unitConversionItemValidatorsB.validateUnitOnConversionWithProduct(dataDefinition, unitConversionItem); assertTrue(result); verify(unitConversionItem, Mockito.never()).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem); } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem); } |
@Test public void sholudReturnErrorIfProductUnitIsNotEqualFieldUnit() { stubConversionSourceUnit(SOME_UNIT); stubProductUnit("otherNotEqualSzt"); boolean result = unitConversionItemValidatorsB.validateUnitOnConversionWithProduct(dataDefinition, unitConversionItem); assertFalse(result); verify(unitConversionItem).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem); } | UnitConversionItemValidatorsB { public boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem) { final Entity product = unitConversionItem.getBelongsToField(UnitConversionItemFieldsB.PRODUCT); final String unitFrom = unitConversionItem.getStringField(UnitConversionItemFields.UNIT_FROM); if (product == null || product.getStringField(ProductFields.UNIT).equals(unitFrom)) { return true; } final String errorMsg = "basic.product.validateError.unitFrom.doesNotMatchUnitConversionItem"; unitConversionItem.addError(dataDefinition.getField(UnitConversionItemFields.UNIT_FROM), errorMsg); return false; } boolean validateUnitOnConversionWithProduct(final DataDefinition dataDefinition, final Entity unitConversionItem); } |
@Test public void shouldReturnWhenEntityIdIsNull() throws Exception { when(entity.getId()).thenReturn(null); productHooks.clearFamilyFromProductWhenTypeIsChanged(dataDefinition, entity); } | public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } void generateNodeNumber(final DataDefinition productDD, final Entity product); void updateNodeNumber(final DataDefinition productDD, final Entity product); void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product); boolean checkIfNotBelongsToSameFamily(final DataDefinition productDD, final Entity product); boolean checkIfParentIsFamily(final DataDefinition productDD, final Entity product); void clearFieldsOnCopy(final DataDefinition dataDefinition, final Entity product); void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity); void calculateConversionIfUnitChanged(final DataDefinition productDD, final Entity product); void calculateConversionOnCreate(final DataDefinition productDD, final Entity product); boolean validateAdditionalUnit(final DataDefinition productDD, final Entity product); boolean validateCodeUniqueness(final DataDefinition productDD, final Entity product); } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } void generateNodeNumber(final DataDefinition productDD, final Entity product); void updateNodeNumber(final DataDefinition productDD, final Entity product); void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product); boolean checkIfNotBelongsToSameFamily(final DataDefinition productDD, final Entity product); boolean checkIfParentIsFamily(final DataDefinition productDD, final Entity product); void clearFieldsOnCopy(final DataDefinition dataDefinition, final Entity product); void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity); void calculateConversionIfUnitChanged(final DataDefinition productDD, final Entity product); void calculateConversionOnCreate(final DataDefinition productDD, final Entity product); boolean validateAdditionalUnit(final DataDefinition productDD, final Entity product); boolean validateCodeUniqueness(final DataDefinition productDD, final Entity product); } |
@Test public void shouldReturnWhenSavingEntityIsFamily() throws Exception { Long entityId = 1L; when(entity.getId()).thenReturn(entityId); when(entity.getStringField(ProductFields.ENTITY_TYPE)).thenReturn("02productsFamily"); when(entity.getDataDefinition()).thenReturn(dataDefinition); when(dataDefinition.get(entityId)).thenReturn(product); productHooks.clearFamilyFromProductWhenTypeIsChanged(dataDefinition, entity); } | public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } void generateNodeNumber(final DataDefinition productDD, final Entity product); void updateNodeNumber(final DataDefinition productDD, final Entity product); void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product); boolean checkIfNotBelongsToSameFamily(final DataDefinition productDD, final Entity product); boolean checkIfParentIsFamily(final DataDefinition productDD, final Entity product); void clearFieldsOnCopy(final DataDefinition dataDefinition, final Entity product); void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity); void calculateConversionIfUnitChanged(final DataDefinition productDD, final Entity product); void calculateConversionOnCreate(final DataDefinition productDD, final Entity product); boolean validateAdditionalUnit(final DataDefinition productDD, final Entity product); boolean validateCodeUniqueness(final DataDefinition productDD, final Entity product); } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } void generateNodeNumber(final DataDefinition productDD, final Entity product); void updateNodeNumber(final DataDefinition productDD, final Entity product); void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product); boolean checkIfNotBelongsToSameFamily(final DataDefinition productDD, final Entity product); boolean checkIfParentIsFamily(final DataDefinition productDD, final Entity product); void clearFieldsOnCopy(final DataDefinition dataDefinition, final Entity product); void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity); void calculateConversionIfUnitChanged(final DataDefinition productDD, final Entity product); void calculateConversionOnCreate(final DataDefinition productDD, final Entity product); boolean validateAdditionalUnit(final DataDefinition productDD, final Entity product); boolean validateCodeUniqueness(final DataDefinition productDD, final Entity product); } |
@Test public void shouldDeleteFamilyFromProductsWhenEntityTypeIsChanged() throws Exception { Long entityId = 1L; when(entity.getId()).thenReturn(entityId); when(entity.getStringField(ProductFields.ENTITY_TYPE)).thenReturn("01particularProduct"); when(dataDefinition.get(entityId)).thenReturn(product); when(product.getStringField(ProductFields.ENTITY_TYPE)).thenReturn("02productsFamily"); searchProductLikeParent(product); EntityList products = mockEntityListIterator(asList(prod1, prod2)); when(searchCriteria.list()).thenReturn(result); when(result.getEntities()).thenReturn(products); productHooks.clearFamilyFromProductWhenTypeIsChanged(dataDefinition, entity); Assert.assertEquals(null, prod1.getBelongsToField("parent")); Assert.assertEquals(null, prod2.getBelongsToField("parent")); } | public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } void generateNodeNumber(final DataDefinition productDD, final Entity product); void updateNodeNumber(final DataDefinition productDD, final Entity product); void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product); boolean checkIfNotBelongsToSameFamily(final DataDefinition productDD, final Entity product); boolean checkIfParentIsFamily(final DataDefinition productDD, final Entity product); void clearFieldsOnCopy(final DataDefinition dataDefinition, final Entity product); void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity); void calculateConversionIfUnitChanged(final DataDefinition productDD, final Entity product); void calculateConversionOnCreate(final DataDefinition productDD, final Entity product); boolean validateAdditionalUnit(final DataDefinition productDD, final Entity product); boolean validateCodeUniqueness(final DataDefinition productDD, final Entity product); } | ProductHooks { public void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product) { if (product.getId() == null) { return; } String entityType = product.getStringField(ENTITY_TYPE); Entity productFromDB = product.getDataDefinition().get(product.getId()); if (entityType.equals(PARTICULAR_PRODUCT.getStringValue()) && !entityType.equals(productFromDB.getStringField(ENTITY_TYPE))) { deleteProductFamily(productFromDB); } } void generateNodeNumber(final DataDefinition productDD, final Entity product); void updateNodeNumber(final DataDefinition productDD, final Entity product); void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product); boolean checkIfNotBelongsToSameFamily(final DataDefinition productDD, final Entity product); boolean checkIfParentIsFamily(final DataDefinition productDD, final Entity product); void clearFieldsOnCopy(final DataDefinition dataDefinition, final Entity product); void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity); void calculateConversionIfUnitChanged(final DataDefinition productDD, final Entity product); void calculateConversionOnCreate(final DataDefinition productDD, final Entity product); boolean validateAdditionalUnit(final DataDefinition productDD, final Entity product); boolean validateCodeUniqueness(final DataDefinition productDD, final Entity product); } |
@Test public void shouldClearExternalIdOnCopy() throws Exception { productHooks.clearExternalIdOnCopy(dataDefinition, entity); Mockito.verify(entity).setField("externalNumber", null); } | public void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity) { if (entity == null) { return; } entity.setField("externalNumber", null); } | ProductHooks { public void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity) { if (entity == null) { return; } entity.setField("externalNumber", null); } } | ProductHooks { public void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity) { if (entity == null) { return; } entity.setField("externalNumber", null); } } | ProductHooks { public void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity) { if (entity == null) { return; } entity.setField("externalNumber", null); } void generateNodeNumber(final DataDefinition productDD, final Entity product); void updateNodeNumber(final DataDefinition productDD, final Entity product); void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product); boolean checkIfNotBelongsToSameFamily(final DataDefinition productDD, final Entity product); boolean checkIfParentIsFamily(final DataDefinition productDD, final Entity product); void clearFieldsOnCopy(final DataDefinition dataDefinition, final Entity product); void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity); void calculateConversionIfUnitChanged(final DataDefinition productDD, final Entity product); void calculateConversionOnCreate(final DataDefinition productDD, final Entity product); boolean validateAdditionalUnit(final DataDefinition productDD, final Entity product); boolean validateCodeUniqueness(final DataDefinition productDD, final Entity product); } | ProductHooks { public void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity) { if (entity == null) { return; } entity.setField("externalNumber", null); } void generateNodeNumber(final DataDefinition productDD, final Entity product); void updateNodeNumber(final DataDefinition productDD, final Entity product); void clearFamilyFromProductWhenTypeIsChanged(final DataDefinition productDD, final Entity product); boolean checkIfNotBelongsToSameFamily(final DataDefinition productDD, final Entity product); boolean checkIfParentIsFamily(final DataDefinition productDD, final Entity product); void clearFieldsOnCopy(final DataDefinition dataDefinition, final Entity product); void clearExternalIdOnCopy(final DataDefinition dataDefinition, final Entity entity); void calculateConversionIfUnitChanged(final DataDefinition productDD, final Entity product); void calculateConversionOnCreate(final DataDefinition productDD, final Entity product); boolean validateAdditionalUnit(final DataDefinition productDD, final Entity product); boolean validateCodeUniqueness(final DataDefinition productDD, final Entity product); } |
@Test public void shouldParseCorrectlyGivenExampleDocument() throws Exception { Map<String, BigDecimal> map = service.parse(inputStream, ExchangeRatesNbpService.NbpProperties.LAST_C); assertTrue(map.containsKey("USD")); assertTrue(map.containsKey("CAD")); assertTrue(map.containsKey("AUD")); assertTrue(map.containsValue(new BigDecimal("0.3076"))); assertTrue(map.containsValue(new BigDecimal("2.8927"))); assertTrue(map.containsValue(new BigDecimal("2.8732"))); } | @Override public Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties) { Map<String, BigDecimal> exRates = new HashMap<>(); try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader sr = inputFactory.createXMLStreamReader(inputStream); sr.nextTag(); sr.nextTag(); String currencyCode = ""; BigDecimal exRate = null; BigDecimal factor = BigDecimal.ONE; String exchangeRateField = nbpProperties.fieldName(); while (sr.hasNext()) { if (sr.getEventType() == XMLStreamConstants.END_DOCUMENT) { sr.close(); } if (sr.isStartElement()) { String s = sr.getLocalName(); if (s.equals("przelicznik")) { factor = new BigDecimal(sr.getElementText().replace(',', '.')); } else if (s.equals("kod_waluty")) { currencyCode = sr.getElementText(); } else if (s.equals(exchangeRateField)) { exRate = new BigDecimal(sr.getElementText().replace(',', '.')); } if (exRate != null) { exRates.put(currencyCode, exRate.divide(factor, RoundingMode.HALF_UP)); exRate = null; } } sr.next(); } } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { closeStream(inputStream); } return exRates; } | ExchangeRatesNbpServiceImpl implements ExchangeRatesNbpService { @Override public Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties) { Map<String, BigDecimal> exRates = new HashMap<>(); try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader sr = inputFactory.createXMLStreamReader(inputStream); sr.nextTag(); sr.nextTag(); String currencyCode = ""; BigDecimal exRate = null; BigDecimal factor = BigDecimal.ONE; String exchangeRateField = nbpProperties.fieldName(); while (sr.hasNext()) { if (sr.getEventType() == XMLStreamConstants.END_DOCUMENT) { sr.close(); } if (sr.isStartElement()) { String s = sr.getLocalName(); if (s.equals("przelicznik")) { factor = new BigDecimal(sr.getElementText().replace(',', '.')); } else if (s.equals("kod_waluty")) { currencyCode = sr.getElementText(); } else if (s.equals(exchangeRateField)) { exRate = new BigDecimal(sr.getElementText().replace(',', '.')); } if (exRate != null) { exRates.put(currencyCode, exRate.divide(factor, RoundingMode.HALF_UP)); exRate = null; } } sr.next(); } } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { closeStream(inputStream); } return exRates; } } | ExchangeRatesNbpServiceImpl implements ExchangeRatesNbpService { @Override public Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties) { Map<String, BigDecimal> exRates = new HashMap<>(); try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader sr = inputFactory.createXMLStreamReader(inputStream); sr.nextTag(); sr.nextTag(); String currencyCode = ""; BigDecimal exRate = null; BigDecimal factor = BigDecimal.ONE; String exchangeRateField = nbpProperties.fieldName(); while (sr.hasNext()) { if (sr.getEventType() == XMLStreamConstants.END_DOCUMENT) { sr.close(); } if (sr.isStartElement()) { String s = sr.getLocalName(); if (s.equals("przelicznik")) { factor = new BigDecimal(sr.getElementText().replace(',', '.')); } else if (s.equals("kod_waluty")) { currencyCode = sr.getElementText(); } else if (s.equals(exchangeRateField)) { exRate = new BigDecimal(sr.getElementText().replace(',', '.')); } if (exRate != null) { exRates.put(currencyCode, exRate.divide(factor, RoundingMode.HALF_UP)); exRate = null; } } sr.next(); } } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { closeStream(inputStream); } return exRates; } } | ExchangeRatesNbpServiceImpl implements ExchangeRatesNbpService { @Override public Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties) { Map<String, BigDecimal> exRates = new HashMap<>(); try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader sr = inputFactory.createXMLStreamReader(inputStream); sr.nextTag(); sr.nextTag(); String currencyCode = ""; BigDecimal exRate = null; BigDecimal factor = BigDecimal.ONE; String exchangeRateField = nbpProperties.fieldName(); while (sr.hasNext()) { if (sr.getEventType() == XMLStreamConstants.END_DOCUMENT) { sr.close(); } if (sr.isStartElement()) { String s = sr.getLocalName(); if (s.equals("przelicznik")) { factor = new BigDecimal(sr.getElementText().replace(',', '.')); } else if (s.equals("kod_waluty")) { currencyCode = sr.getElementText(); } else if (s.equals(exchangeRateField)) { exRate = new BigDecimal(sr.getElementText().replace(',', '.')); } if (exRate != null) { exRates.put(currencyCode, exRate.divide(factor, RoundingMode.HALF_UP)); exRate = null; } } sr.next(); } } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { closeStream(inputStream); } return exRates; } @Override Map<String, BigDecimal> get(NbpProperties nbpProperties); @Override Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties); } | ExchangeRatesNbpServiceImpl implements ExchangeRatesNbpService { @Override public Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties) { Map<String, BigDecimal> exRates = new HashMap<>(); try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader sr = inputFactory.createXMLStreamReader(inputStream); sr.nextTag(); sr.nextTag(); String currencyCode = ""; BigDecimal exRate = null; BigDecimal factor = BigDecimal.ONE; String exchangeRateField = nbpProperties.fieldName(); while (sr.hasNext()) { if (sr.getEventType() == XMLStreamConstants.END_DOCUMENT) { sr.close(); } if (sr.isStartElement()) { String s = sr.getLocalName(); if (s.equals("przelicznik")) { factor = new BigDecimal(sr.getElementText().replace(',', '.')); } else if (s.equals("kod_waluty")) { currencyCode = sr.getElementText(); } else if (s.equals(exchangeRateField)) { exRate = new BigDecimal(sr.getElementText().replace(',', '.')); } if (exRate != null) { exRates.put(currencyCode, exRate.divide(factor, RoundingMode.HALF_UP)); exRate = null; } } sr.next(); } } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { closeStream(inputStream); } return exRates; } @Override Map<String, BigDecimal> get(NbpProperties nbpProperties); @Override Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties); } |
@Test public void shouldParseAlwaysCloseInputStream() throws Exception { InputStream inputStreamSpied = spy(inputStream); service.parse(inputStreamSpied, ExchangeRatesNbpService.NbpProperties.LAST_C); verify(inputStreamSpied, atLeastOnce()).close(); } | @Override public Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties) { Map<String, BigDecimal> exRates = new HashMap<>(); try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader sr = inputFactory.createXMLStreamReader(inputStream); sr.nextTag(); sr.nextTag(); String currencyCode = ""; BigDecimal exRate = null; BigDecimal factor = BigDecimal.ONE; String exchangeRateField = nbpProperties.fieldName(); while (sr.hasNext()) { if (sr.getEventType() == XMLStreamConstants.END_DOCUMENT) { sr.close(); } if (sr.isStartElement()) { String s = sr.getLocalName(); if (s.equals("przelicznik")) { factor = new BigDecimal(sr.getElementText().replace(',', '.')); } else if (s.equals("kod_waluty")) { currencyCode = sr.getElementText(); } else if (s.equals(exchangeRateField)) { exRate = new BigDecimal(sr.getElementText().replace(',', '.')); } if (exRate != null) { exRates.put(currencyCode, exRate.divide(factor, RoundingMode.HALF_UP)); exRate = null; } } sr.next(); } } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { closeStream(inputStream); } return exRates; } | ExchangeRatesNbpServiceImpl implements ExchangeRatesNbpService { @Override public Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties) { Map<String, BigDecimal> exRates = new HashMap<>(); try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader sr = inputFactory.createXMLStreamReader(inputStream); sr.nextTag(); sr.nextTag(); String currencyCode = ""; BigDecimal exRate = null; BigDecimal factor = BigDecimal.ONE; String exchangeRateField = nbpProperties.fieldName(); while (sr.hasNext()) { if (sr.getEventType() == XMLStreamConstants.END_DOCUMENT) { sr.close(); } if (sr.isStartElement()) { String s = sr.getLocalName(); if (s.equals("przelicznik")) { factor = new BigDecimal(sr.getElementText().replace(',', '.')); } else if (s.equals("kod_waluty")) { currencyCode = sr.getElementText(); } else if (s.equals(exchangeRateField)) { exRate = new BigDecimal(sr.getElementText().replace(',', '.')); } if (exRate != null) { exRates.put(currencyCode, exRate.divide(factor, RoundingMode.HALF_UP)); exRate = null; } } sr.next(); } } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { closeStream(inputStream); } return exRates; } } | ExchangeRatesNbpServiceImpl implements ExchangeRatesNbpService { @Override public Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties) { Map<String, BigDecimal> exRates = new HashMap<>(); try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader sr = inputFactory.createXMLStreamReader(inputStream); sr.nextTag(); sr.nextTag(); String currencyCode = ""; BigDecimal exRate = null; BigDecimal factor = BigDecimal.ONE; String exchangeRateField = nbpProperties.fieldName(); while (sr.hasNext()) { if (sr.getEventType() == XMLStreamConstants.END_DOCUMENT) { sr.close(); } if (sr.isStartElement()) { String s = sr.getLocalName(); if (s.equals("przelicznik")) { factor = new BigDecimal(sr.getElementText().replace(',', '.')); } else if (s.equals("kod_waluty")) { currencyCode = sr.getElementText(); } else if (s.equals(exchangeRateField)) { exRate = new BigDecimal(sr.getElementText().replace(',', '.')); } if (exRate != null) { exRates.put(currencyCode, exRate.divide(factor, RoundingMode.HALF_UP)); exRate = null; } } sr.next(); } } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { closeStream(inputStream); } return exRates; } } | ExchangeRatesNbpServiceImpl implements ExchangeRatesNbpService { @Override public Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties) { Map<String, BigDecimal> exRates = new HashMap<>(); try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader sr = inputFactory.createXMLStreamReader(inputStream); sr.nextTag(); sr.nextTag(); String currencyCode = ""; BigDecimal exRate = null; BigDecimal factor = BigDecimal.ONE; String exchangeRateField = nbpProperties.fieldName(); while (sr.hasNext()) { if (sr.getEventType() == XMLStreamConstants.END_DOCUMENT) { sr.close(); } if (sr.isStartElement()) { String s = sr.getLocalName(); if (s.equals("przelicznik")) { factor = new BigDecimal(sr.getElementText().replace(',', '.')); } else if (s.equals("kod_waluty")) { currencyCode = sr.getElementText(); } else if (s.equals(exchangeRateField)) { exRate = new BigDecimal(sr.getElementText().replace(',', '.')); } if (exRate != null) { exRates.put(currencyCode, exRate.divide(factor, RoundingMode.HALF_UP)); exRate = null; } } sr.next(); } } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { closeStream(inputStream); } return exRates; } @Override Map<String, BigDecimal> get(NbpProperties nbpProperties); @Override Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties); } | ExchangeRatesNbpServiceImpl implements ExchangeRatesNbpService { @Override public Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties) { Map<String, BigDecimal> exRates = new HashMap<>(); try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader sr = inputFactory.createXMLStreamReader(inputStream); sr.nextTag(); sr.nextTag(); String currencyCode = ""; BigDecimal exRate = null; BigDecimal factor = BigDecimal.ONE; String exchangeRateField = nbpProperties.fieldName(); while (sr.hasNext()) { if (sr.getEventType() == XMLStreamConstants.END_DOCUMENT) { sr.close(); } if (sr.isStartElement()) { String s = sr.getLocalName(); if (s.equals("przelicznik")) { factor = new BigDecimal(sr.getElementText().replace(',', '.')); } else if (s.equals("kod_waluty")) { currencyCode = sr.getElementText(); } else if (s.equals(exchangeRateField)) { exRate = new BigDecimal(sr.getElementText().replace(',', '.')); } if (exRate != null) { exRates.put(currencyCode, exRate.divide(factor, RoundingMode.HALF_UP)); exRate = null; } } sr.next(); } } catch (XMLStreamException e) { throw new RuntimeException(e); } finally { closeStream(inputStream); } return exRates; } @Override Map<String, BigDecimal> get(NbpProperties nbpProperties); @Override Map<String, BigDecimal> parse(InputStream inputStream, NbpProperties nbpProperties); } |
@Test public final void shouldCheckEanUniquenessJustReturnTrueIfNewEanIsEmpty() { String oldVal = "123456"; String newVal = ""; boolean isValid = productValidators.checkEanUniqueness(dataDefinition, fieldDefinition, entity, oldVal, newVal); assertTrue(isValid); verify(entity, never()).addError(any(FieldDefinition.class), anyString()); } | public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition,
final Entity product, final Object eanOldValue, final Object eanNewValue); } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition,
final Entity product, final Object eanOldValue, final Object eanNewValue); } |
@Test public final void shouldSetUpDeleteButton() { boolean isEnabled = true; String message = "some arbitrary mesage"; workPlansListView.setUpDeleteButton(isEnabled, message); verify(deleteButton).setEnabled(isEnabled); verify(deleteButton).setMessage(message); verify(deleteButton).requestUpdate(true); verify(windowComponent).requestRibbonRender(); } | public void setUpDeleteButton(final boolean isEnabled, final String message) { deleteButton.setEnabled(isEnabled); deleteButton.setMessage(message); deleteButton.requestUpdate(true); window.requestRibbonRender(); } | WorkPlansListView { public void setUpDeleteButton(final boolean isEnabled, final String message) { deleteButton.setEnabled(isEnabled); deleteButton.setMessage(message); deleteButton.requestUpdate(true); window.requestRibbonRender(); } } | WorkPlansListView { public void setUpDeleteButton(final boolean isEnabled, final String message) { deleteButton.setEnabled(isEnabled); deleteButton.setMessage(message); deleteButton.requestUpdate(true); window.requestRibbonRender(); } WorkPlansListView(final WindowComponent window, final RibbonActionItem deleteButton, final GridComponent workPlansGrid); } | WorkPlansListView { public void setUpDeleteButton(final boolean isEnabled, final String message) { deleteButton.setEnabled(isEnabled); deleteButton.setMessage(message); deleteButton.requestUpdate(true); window.requestRibbonRender(); } WorkPlansListView(final WindowComponent window, final RibbonActionItem deleteButton, final GridComponent workPlansGrid); static WorkPlansListView from(final ViewDefinitionState view); void setUpDeleteButton(final boolean isEnabled, final String message); List<Entity> getSelectedWorkPlans(); @Override boolean equals(final Object obj); @Override int hashCode(); } | WorkPlansListView { public void setUpDeleteButton(final boolean isEnabled, final String message) { deleteButton.setEnabled(isEnabled); deleteButton.setMessage(message); deleteButton.requestUpdate(true); window.requestRibbonRender(); } WorkPlansListView(final WindowComponent window, final RibbonActionItem deleteButton, final GridComponent workPlansGrid); static WorkPlansListView from(final ViewDefinitionState view); void setUpDeleteButton(final boolean isEnabled, final String message); List<Entity> getSelectedWorkPlans(); @Override boolean equals(final Object obj); @Override int hashCode(); } |
@Test public final void shouldCheckEanUniquenessJustReturnTrueIfNewEanIsNull() { String oldVal = "123456"; String newVal = null; boolean isValid = productValidators.checkEanUniqueness(dataDefinition, fieldDefinition, entity, oldVal, newVal); assertTrue(isValid); verify(entity, never()).addError(any(FieldDefinition.class), anyString()); } | public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition,
final Entity product, final Object eanOldValue, final Object eanNewValue); } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition,
final Entity product, final Object eanOldValue, final Object eanNewValue); } |
@Test public final void shouldCheckEanUniquenessReturnTrueIfThereIsNoExistingProductsWithGivenId() { String oldVal = "123456"; String newVal = "654321"; ArgumentCaptor<SearchCriterion> criterionCaptor = ArgumentCaptor.forClass(SearchCriterion.class); stubSearchCriteriaWith(null); boolean isValid = productValidators.checkEanUniqueness(dataDefinition, fieldDefinition, entity, oldVal, newVal); assertTrue(isValid); verify(entity, never()).addError(any(FieldDefinition.class), anyString()); verify(scb).add(criterionCaptor.capture()); assertEquals(SearchRestrictions.eq(ProductFields.EAN, newVal), criterionCaptor.getValue()); } | public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition,
final Entity product, final Object eanOldValue, final Object eanNewValue); } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition,
final Entity product, final Object eanOldValue, final Object eanNewValue); } |
@Test public final void shouldCheckEanUniquenessReturnFalsAndMarkFieldAsInvalidIfProductsWithGivenIdExists() { String oldVal = "123456"; String newVal = "654321"; ArgumentCaptor<SearchCriterion> criterionCaptor = ArgumentCaptor.forClass(SearchCriterion.class); Entity resultEntity = mock(Entity.class); stubSearchCriteriaWith(resultEntity); boolean isValid = productValidators.checkEanUniqueness(dataDefinition, fieldDefinition, entity, oldVal, newVal); assertFalse(isValid); verify(entity).addError(fieldDefinition, "smartView.validate.field.error.duplicated"); verify(scb).add(criterionCaptor.capture()); assertEquals(SearchRestrictions.eq(ProductFields.EAN, newVal), criterionCaptor.getValue()); } | public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition,
final Entity product, final Object eanOldValue, final Object eanNewValue); } | ProductValidators { public boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition, final Entity product, final Object eanOldValue, final Object eanNewValue) { String ean = (String) eanNewValue; if (StringUtils.isEmpty(ean) || ObjectUtils.equals(eanOldValue, ean)) { return true; } if (productWithEanAlreadyExists(productDD, ean)) { product.addError(eanFieldDefinition, "smartView.validate.field.error.duplicated"); return false; } return true; } boolean checkEanUniqueness(final DataDefinition productDD, final FieldDefinition eanFieldDefinition,
final Entity product, final Object eanOldValue, final Object eanNewValue); } |
@Test public void shouldReturnExistingCompanyEntityId() throws Exception { Entity company = Mockito.mock(Entity.class); given(company.getId()).willReturn(13L); given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBelongsToField(ParameterFields.COMPANY)).willReturn(company); Long id = companyService.getCompanyId(); assertEquals(Long.valueOf(13L), id); } | public Long getCompanyId() { if (getCompany() == null) { return null; } else { return getCompany().getId(); } } | CompanyService { public Long getCompanyId() { if (getCompany() == null) { return null; } else { return getCompany().getId(); } } } | CompanyService { public Long getCompanyId() { if (getCompany() == null) { return null; } else { return getCompany().getId(); } } } | CompanyService { public Long getCompanyId() { if (getCompany() == null) { return null; } else { return getCompany().getId(); } } Long getCompanyId(); @Transactional Entity getCompany(); @Transactional Entity getCompany(final Long companyId); final Boolean isCompanyOwner(final Entity company); void disabledGridWhenCompanyIsOwner(final ViewDefinitionState view, final String... references); void disableButton(final ViewDefinitionState view, final String ribbonGroupName, final String ribbonActionItemName,
final boolean isEnabled, final String message); } | CompanyService { public Long getCompanyId() { if (getCompany() == null) { return null; } else { return getCompany().getId(); } } Long getCompanyId(); @Transactional Entity getCompany(); @Transactional Entity getCompany(final Long companyId); final Boolean isCompanyOwner(final Entity company); void disabledGridWhenCompanyIsOwner(final ViewDefinitionState view, final String... references); void disableButton(final ViewDefinitionState view, final String ribbonGroupName, final String ribbonActionItemName,
final boolean isEnabled, final String message); } |
@Test public void shouldReturnExistingCompanyEntity() throws Exception { given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBelongsToField(ParameterFields.COMPANY)).willReturn(company); given(company.isValid()).willReturn(true); Entity existingcompany = companyService.getCompany(); assertEquals(company, existingcompany); } | @Transactional public Entity getCompany() { Entity parameter = parameterService.getParameter(); return parameter.getBelongsToField(ParameterFields.COMPANY); } | CompanyService { @Transactional public Entity getCompany() { Entity parameter = parameterService.getParameter(); return parameter.getBelongsToField(ParameterFields.COMPANY); } } | CompanyService { @Transactional public Entity getCompany() { Entity parameter = parameterService.getParameter(); return parameter.getBelongsToField(ParameterFields.COMPANY); } } | CompanyService { @Transactional public Entity getCompany() { Entity parameter = parameterService.getParameter(); return parameter.getBelongsToField(ParameterFields.COMPANY); } Long getCompanyId(); @Transactional Entity getCompany(); @Transactional Entity getCompany(final Long companyId); final Boolean isCompanyOwner(final Entity company); void disabledGridWhenCompanyIsOwner(final ViewDefinitionState view, final String... references); void disableButton(final ViewDefinitionState view, final String ribbonGroupName, final String ribbonActionItemName,
final boolean isEnabled, final String message); } | CompanyService { @Transactional public Entity getCompany() { Entity parameter = parameterService.getParameter(); return parameter.getBelongsToField(ParameterFields.COMPANY); } Long getCompanyId(); @Transactional Entity getCompany(); @Transactional Entity getCompany(final Long companyId); final Boolean isCompanyOwner(final Entity company); void disabledGridWhenCompanyIsOwner(final ViewDefinitionState view, final String... references); void disableButton(final ViewDefinitionState view, final String ribbonGroupName, final String ribbonActionItemName,
final boolean isEnabled, final String message); } |
@Test public final void shouldReturnWorkingHoursForDay() { String hours = "6:00-12:00, 21:30-2:30"; given(shiftEntity.getStringField(ShiftFields.MONDAY_HOURS)).willReturn(hours); given(shiftEntity.getBooleanField(ShiftFields.MONDAY_WORKING)).willReturn(true); LocalDate mondayDate = new LocalDate(2013, 9, 2); Shift shift = new Shift(shiftEntity); List<TimeRange> timeRanges = shift.findWorkTimeAt(mondayDate); List<TimeRange> expectedTimeRanges = ImmutableList.of(new TimeRange(new LocalTime(6, 0), new LocalTime(12, 0)), new TimeRange(new LocalTime(21, 30), new LocalTime(2, 30))); assertEquals(expectedTimeRanges, timeRanges); } | public Optional<DateRange> findWorkTimeAt(final Date date) { if (timetableExceptions.hasFreeTimeAt(date)) { return Optional.absent(); } DateTime dateTime = new DateTime(date); Optional<TimeRange> maybeTimeRangeFromPlan = findWorkTimeAt(dateTime.getDayOfWeek(), dateTime.toLocalTime()); for (TimeRange timeRangeFromPlan : maybeTimeRangeFromPlan.asSet()) { return Optional.of(buildDateRangeFrom(timeRangeFromPlan, date)); } return timetableExceptions.findDateRangeFor(TimetableExceptionType.WORK_TIME, date); } | Shift { public Optional<DateRange> findWorkTimeAt(final Date date) { if (timetableExceptions.hasFreeTimeAt(date)) { return Optional.absent(); } DateTime dateTime = new DateTime(date); Optional<TimeRange> maybeTimeRangeFromPlan = findWorkTimeAt(dateTime.getDayOfWeek(), dateTime.toLocalTime()); for (TimeRange timeRangeFromPlan : maybeTimeRangeFromPlan.asSet()) { return Optional.of(buildDateRangeFrom(timeRangeFromPlan, date)); } return timetableExceptions.findDateRangeFor(TimetableExceptionType.WORK_TIME, date); } } | Shift { public Optional<DateRange> findWorkTimeAt(final Date date) { if (timetableExceptions.hasFreeTimeAt(date)) { return Optional.absent(); } DateTime dateTime = new DateTime(date); Optional<TimeRange> maybeTimeRangeFromPlan = findWorkTimeAt(dateTime.getDayOfWeek(), dateTime.toLocalTime()); for (TimeRange timeRangeFromPlan : maybeTimeRangeFromPlan.asSet()) { return Optional.of(buildDateRangeFrom(timeRangeFromPlan, date)); } return timetableExceptions.findDateRangeFor(TimetableExceptionType.WORK_TIME, date); } Shift(final Entity shiftEntity); Shift(final Entity shiftEntity, final DateTime day); Shift(final Entity shiftEntity, final DateTime day, final boolean checkWorking); } | Shift { public Optional<DateRange> findWorkTimeAt(final Date date) { if (timetableExceptions.hasFreeTimeAt(date)) { return Optional.absent(); } DateTime dateTime = new DateTime(date); Optional<TimeRange> maybeTimeRangeFromPlan = findWorkTimeAt(dateTime.getDayOfWeek(), dateTime.toLocalTime()); for (TimeRange timeRangeFromPlan : maybeTimeRangeFromPlan.asSet()) { return Optional.of(buildDateRangeFrom(timeRangeFromPlan, date)); } return timetableExceptions.findDateRangeFor(TimetableExceptionType.WORK_TIME, date); } Shift(final Entity shiftEntity); Shift(final Entity shiftEntity, final DateTime day); Shift(final Entity shiftEntity, final DateTime day, final boolean checkWorking); boolean worksAt(final int dayOfWeek, final LocalTime time); boolean worksAt(final int dayOfWeek); boolean worksAt(final LocalDate localDate); boolean worksAt(final DateTime dateTime); @Deprecated boolean worksAt(final Date date); Optional<DateRange> findWorkTimeAt(final Date date); Optional<TimeRange> findWorkTimeAt(final int dayOfWeek, final LocalTime time); Optional<TimeRange> findWorkTimeAt(final int dayOfWeek); List<TimeRange> findWorkTimeAt(final LocalDate localDate); Entity getEntity(); Long getId(); DateTime getShiftStartDate(); void setShiftStartDate(DateTime shiftStartDate); DateTime getShiftEndDate(); void setShiftEndDate(DateTime shiftEndDate); @Override int hashCode(); @Override boolean equals(final Object obj); } | Shift { public Optional<DateRange> findWorkTimeAt(final Date date) { if (timetableExceptions.hasFreeTimeAt(date)) { return Optional.absent(); } DateTime dateTime = new DateTime(date); Optional<TimeRange> maybeTimeRangeFromPlan = findWorkTimeAt(dateTime.getDayOfWeek(), dateTime.toLocalTime()); for (TimeRange timeRangeFromPlan : maybeTimeRangeFromPlan.asSet()) { return Optional.of(buildDateRangeFrom(timeRangeFromPlan, date)); } return timetableExceptions.findDateRangeFor(TimetableExceptionType.WORK_TIME, date); } Shift(final Entity shiftEntity); Shift(final Entity shiftEntity, final DateTime day); Shift(final Entity shiftEntity, final DateTime day, final boolean checkWorking); boolean worksAt(final int dayOfWeek, final LocalTime time); boolean worksAt(final int dayOfWeek); boolean worksAt(final LocalDate localDate); boolean worksAt(final DateTime dateTime); @Deprecated boolean worksAt(final Date date); Optional<DateRange> findWorkTimeAt(final Date date); Optional<TimeRange> findWorkTimeAt(final int dayOfWeek, final LocalTime time); Optional<TimeRange> findWorkTimeAt(final int dayOfWeek); List<TimeRange> findWorkTimeAt(final LocalDate localDate); Entity getEntity(); Long getId(); DateTime getShiftStartDate(); void setShiftStartDate(DateTime shiftStartDate); DateTime getShiftEndDate(); void setShiftEndDate(DateTime shiftEndDate); @Override int hashCode(); @Override boolean equals(final Object obj); } |
@Test public final void shouldBuildWorkingHoursFromSingleTimeRangeWithTwoDigitsHour() { String timeRangeString = "09:00-17:00"; WorkingHours workingHours = new WorkingHours(timeRangeString); assertEquals(1, workingHours.getTimeRanges().size()); TimeRange timeRange = workingHours.getTimeRanges().iterator().next(); assertEquals(new LocalTime(9, 0, 0), timeRange.getFrom()); assertEquals(new LocalTime(17, 0, 0), timeRange.getTo()); } | public Set<TimeRange> getTimeRanges() { return Collections.unmodifiableSet(hours); } | WorkingHours implements Comparable<WorkingHours> { public Set<TimeRange> getTimeRanges() { return Collections.unmodifiableSet(hours); } } | WorkingHours implements Comparable<WorkingHours> { public Set<TimeRange> getTimeRanges() { return Collections.unmodifiableSet(hours); } WorkingHours(final String hourRanges); } | WorkingHours implements Comparable<WorkingHours> { public Set<TimeRange> getTimeRanges() { return Collections.unmodifiableSet(hours); } WorkingHours(final String hourRanges); boolean isEmpty(); boolean contains(final LocalTime time); Optional<TimeRange> findRangeFor(final LocalTime time); Set<TimeRange> getTimeRanges(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override int compareTo(final WorkingHours other); } | WorkingHours implements Comparable<WorkingHours> { public Set<TimeRange> getTimeRanges() { return Collections.unmodifiableSet(hours); } WorkingHours(final String hourRanges); boolean isEmpty(); boolean contains(final LocalTime time); Optional<TimeRange> findRangeFor(final LocalTime time); Set<TimeRange> getTimeRanges(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override int compareTo(final WorkingHours other); } |
@Test public final void shouldBuildWorkingHoursFromSingleTimeRangeWithOneDigitsHour() { String timeRangeString = "9:00-17:00"; WorkingHours workingHours = new WorkingHours(timeRangeString); assertEquals(1, workingHours.getTimeRanges().size()); TimeRange timeRange = workingHours.getTimeRanges().iterator().next(); assertEquals(new LocalTime(9, 0, 0), timeRange.getFrom()); assertEquals(new LocalTime(17, 0, 0), timeRange.getTo()); } | public Set<TimeRange> getTimeRanges() { return Collections.unmodifiableSet(hours); } | WorkingHours implements Comparable<WorkingHours> { public Set<TimeRange> getTimeRanges() { return Collections.unmodifiableSet(hours); } } | WorkingHours implements Comparable<WorkingHours> { public Set<TimeRange> getTimeRanges() { return Collections.unmodifiableSet(hours); } WorkingHours(final String hourRanges); } | WorkingHours implements Comparable<WorkingHours> { public Set<TimeRange> getTimeRanges() { return Collections.unmodifiableSet(hours); } WorkingHours(final String hourRanges); boolean isEmpty(); boolean contains(final LocalTime time); Optional<TimeRange> findRangeFor(final LocalTime time); Set<TimeRange> getTimeRanges(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override int compareTo(final WorkingHours other); } | WorkingHours implements Comparable<WorkingHours> { public Set<TimeRange> getTimeRanges() { return Collections.unmodifiableSet(hours); } WorkingHours(final String hourRanges); boolean isEmpty(); boolean contains(final LocalTime time); Optional<TimeRange> findRangeFor(final LocalTime time); Set<TimeRange> getTimeRanges(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override int compareTo(final WorkingHours other); } |
@Test public void shouldReturnTreeWithoutChildrenWhenDoesnotExists() throws Exception { EntityList emptyList = mockEntityList(new LinkedList<Entity>()); when(productDsk.getHasManyField(PRODUCT_FAMILY_CHILDRENS)).thenReturn(emptyList); List<Entity> tree = productsFamiliesTreeService.getHierarchyProductsTree(productDsk); assertEquals(1, tree.size()); assertEquals(productDsk, tree.get(0)); } | public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } List<Entity> getHierarchyProductsTree(final Entity product); } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } List<Entity> getHierarchyProductsTree(final Entity product); } |
@Test public void shouldReturnTreeWithTwoLevel() throws Exception { List<Entity> tree = productsFamiliesTreeService.getHierarchyProductsTree(productDsk); assertEquals(4, tree.size()); assertEquals(productDsk3, tree.get(2)); assertEquals(productDsk2, tree.get(3)); } | public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } List<Entity> getHierarchyProductsTree(final Entity product); } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } List<Entity> getHierarchyProductsTree(final Entity product); } |
@Test public void shouldReturnNullWhenGetProductCatalogNumber() { given(productCatalogNumbersDD.find()).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.add(Mockito.any(SearchCriterion.class))).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.setMaxResults(1)).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.uniqueResult()).willReturn(null); Entity result = productCatalogNumbersService.getProductCatalogNumber(null, null); assertEquals(null, result); } | @Override public Entity getProductCatalogNumber(final Entity product, final Entity supplier) { return dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, product)).add(SearchRestrictions.belongsTo(COMPANY, supplier)) .setMaxResults(1).uniqueResult(); } | ProductCatalogNumbersServiceImpl implements ProductCatalogNumbersService { @Override public Entity getProductCatalogNumber(final Entity product, final Entity supplier) { return dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, product)).add(SearchRestrictions.belongsTo(COMPANY, supplier)) .setMaxResults(1).uniqueResult(); } } | ProductCatalogNumbersServiceImpl implements ProductCatalogNumbersService { @Override public Entity getProductCatalogNumber(final Entity product, final Entity supplier) { return dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, product)).add(SearchRestrictions.belongsTo(COMPANY, supplier)) .setMaxResults(1).uniqueResult(); } } | ProductCatalogNumbersServiceImpl implements ProductCatalogNumbersService { @Override public Entity getProductCatalogNumber(final Entity product, final Entity supplier) { return dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, product)).add(SearchRestrictions.belongsTo(COMPANY, supplier)) .setMaxResults(1).uniqueResult(); } @Override Entity getProductCatalogNumber(final Entity product, final Entity supplier); } | ProductCatalogNumbersServiceImpl implements ProductCatalogNumbersService { @Override public Entity getProductCatalogNumber(final Entity product, final Entity supplier) { return dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, product)).add(SearchRestrictions.belongsTo(COMPANY, supplier)) .setMaxResults(1).uniqueResult(); } @Override Entity getProductCatalogNumber(final Entity product, final Entity supplier); } |
@Test public void shouldReturnTreeWithOneLevel() throws Exception { EntityList emptyList = mockEntityList(new LinkedList<Entity>()); when(productDsk1.getHasManyField(PRODUCT_FAMILY_CHILDRENS)).thenReturn(emptyList); List<Entity> tree = productsFamiliesTreeService.getHierarchyProductsTree(productDsk); assertEquals(3, tree.size()); assertEquals(productDsk2, tree.get(2)); } | public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } List<Entity> getHierarchyProductsTree(final Entity product); } | ProductsFamiliesTreeService { public List<Entity> getHierarchyProductsTree(final Entity product) { List<Entity> tree = new ArrayList<Entity>(); addProduct(tree, product); generateTree(product, tree); return tree; } List<Entity> getHierarchyProductsTree(final Entity product); } |
@Test public void shouldReturnTrueWhenCheckIfProductEntityTypeIsCorrect() throws Exception { given(product.getStringField(ENTITY_TYPE)).willReturn(PARTICULAR_PRODUCT.getStringValue()); boolean result = productService.checkIfProductEntityTypeIsCorrect(product, PARTICULAR_PRODUCT); assertTrue(result); } | public boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType) { return entityType.getStringValue().equals(product.getStringField(ENTITY_TYPE)); } | ProductService { public boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType) { return entityType.getStringValue().equals(product.getStringField(ENTITY_TYPE)); } } | ProductService { public boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType) { return entityType.getStringValue().equals(product.getStringField(ENTITY_TYPE)); } } | ProductService { public boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType) { return entityType.getStringValue().equals(product.getStringField(ENTITY_TYPE)); } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } | ProductService { public boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType) { return entityType.getStringValue().equals(product.getStringField(ENTITY_TYPE)); } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } |
@Test public void shouldReturnFalseWhenCheckIfProductEntityTypeIsCorrect() throws Exception { given(product.getStringField(ENTITY_TYPE)).willReturn(PARTICULAR_PRODUCT.getStringValue()); boolean result = productService.checkIfProductEntityTypeIsCorrect(product, PRODUCTS_FAMILY); assertFalse(result); } | public boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType) { return entityType.getStringValue().equals(product.getStringField(ENTITY_TYPE)); } | ProductService { public boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType) { return entityType.getStringValue().equals(product.getStringField(ENTITY_TYPE)); } } | ProductService { public boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType) { return entityType.getStringValue().equals(product.getStringField(ENTITY_TYPE)); } } | ProductService { public boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType) { return entityType.getStringValue().equals(product.getStringField(ENTITY_TYPE)); } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } | ProductService { public boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType) { return entityType.getStringValue().equals(product.getStringField(ENTITY_TYPE)); } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } |
@Test public void shouldReturnTrueWhenProductIsNotRemoved() throws Exception { boolean result = productService.checkIfProductIsNotRemoved(productDD, product); assertTrue(result); } | public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } |
@Test public void shouldReturnFalseWhenEntityDoesnotExists() throws Exception { DataDefinition productDD = Mockito.mock(DataDefinition.class); Long productId = 1L; given(substitute.getBelongsToField(SubstituteFields.PRODUCT)).willReturn(product); given(dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT)).willReturn(productDD); given(product.getId()).willReturn(productId); given(productDD.get(productId)).willReturn(null); boolean result = productService.checkIfProductIsNotRemoved(substituteDD, substitute); assertFalse(result); } | public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } |
@Test public void shouldReturnTrueWhenProductExists() throws Exception { DataDefinition productDD = Mockito.mock(DataDefinition.class); Long productId = 1L; given(substitute.getBelongsToField(SubstituteFields.PRODUCT)).willReturn(product); given(dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT)).willReturn(productDD); given(product.getId()).willReturn(productId); given(productDD.get(productId)).willReturn(product); boolean result = productService.checkIfProductIsNotRemoved(substituteDD, substitute); assertTrue(result); } | public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } | ProductService { public boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute) { Entity product = substitute.getBelongsToField(SubstituteFields.PRODUCT); if (product == null || product.getId() == null) { return true; } Entity productEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get( product.getId()); if (productEntity == null) { substitute.addGlobalError("smartView.message.belongsToNotFound"); substitute.setField(SubstituteFields.PRODUCT, null); return false; } return true; } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } |
@Test public void shouldReturnFalseWhenSubstituteDoesnotExists() throws Exception { DataDefinition substituteDD = Mockito.mock(DataDefinition.class); Long substituteId = 1L; given(substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE)).willReturn(substitute); given(dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE)).willReturn( substituteDD); given(substitute.getId()).willReturn(substituteId); given(substituteDD.get(substituteId)).willReturn(null); boolean result = productService.checkIfSubstituteIsNotRemoved(substituteComponentDD, substituteComponent); assertFalse(result); } | public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } |
@Test public void shouldReturnTrueWhenEntityDoesnotHaveBTSubstitute() throws Exception { boolean result = productService.checkIfSubstituteIsNotRemoved(substituteComponentDD, substituteComponent); assertTrue(result); } | public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } |
@Test public void shouldReturnTrueWhenSubstitueExists() throws Exception { DataDefinition substituteDD = Mockito.mock(DataDefinition.class); Long substituteId = 1L; given(substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE)).willReturn(substitute); given(dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE)).willReturn( substituteDD); given(substitute.getId()).willReturn(substituteId); given(substituteDD.get(substituteId)).willReturn(substitute); boolean result = productService.checkIfSubstituteIsNotRemoved(substituteComponentDD, substituteComponent); assertTrue(result); } | public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } | ProductService { public boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent) { Entity substitute = substituteComponent.getBelongsToField(SubstituteComponentFields.SUBSTITUTE); if (substitute == null || substitute.getId() == null) { return true; } Entity substituteEntity = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_SUBSTITUTE) .get(substitute.getId()); if (substituteEntity == null) { substituteComponent.addGlobalError("smartView.message.belongsToNotFound"); substituteComponent.setField(SubstituteComponentFields.SUBSTITUTE, null); return false; } else { return true; } } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } |
@Test public void shouldntFillUnitIfUnitIsntNull() { Entity product = mock(Entity.class); DataDefinition productDD = mock(DataDefinition.class); given(product.getField(UNIT)).willReturn(L_SZT); productService.fillUnit(productDD, product); verify(product, never()).setField(Mockito.anyString(), Mockito.anyString()); } | public void fillUnit(final DataDefinition productDD, final Entity product) { if (product.getField(UNIT) == null) { product.setField(UNIT, unitService.getDefaultUnitFromSystemParameters()); } } | ProductService { public void fillUnit(final DataDefinition productDD, final Entity product) { if (product.getField(UNIT) == null) { product.setField(UNIT, unitService.getDefaultUnitFromSystemParameters()); } } } | ProductService { public void fillUnit(final DataDefinition productDD, final Entity product) { if (product.getField(UNIT) == null) { product.setField(UNIT, unitService.getDefaultUnitFromSystemParameters()); } } } | ProductService { public void fillUnit(final DataDefinition productDD, final Entity product) { if (product.getField(UNIT) == null) { product.setField(UNIT, unitService.getDefaultUnitFromSystemParameters()); } } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } | ProductService { public void fillUnit(final DataDefinition productDD, final Entity product) { if (product.getField(UNIT) == null) { product.setField(UNIT, unitService.getDefaultUnitFromSystemParameters()); } } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } |
@Test public void shouldReturnProductCatalogNumberWhenFetProductCatalogNumber() { given(productCatalogNumbersDD.find()).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.add(Mockito.any(SearchCriterion.class))).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.setMaxResults(1)).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.uniqueResult()).willReturn(productCatalogNumbers); Entity result = productCatalogNumbersService.getProductCatalogNumber(product, supplier); assertEquals(productCatalogNumbers, result); } | @Override public Entity getProductCatalogNumber(final Entity product, final Entity supplier) { return dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, product)).add(SearchRestrictions.belongsTo(COMPANY, supplier)) .setMaxResults(1).uniqueResult(); } | ProductCatalogNumbersServiceImpl implements ProductCatalogNumbersService { @Override public Entity getProductCatalogNumber(final Entity product, final Entity supplier) { return dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, product)).add(SearchRestrictions.belongsTo(COMPANY, supplier)) .setMaxResults(1).uniqueResult(); } } | ProductCatalogNumbersServiceImpl implements ProductCatalogNumbersService { @Override public Entity getProductCatalogNumber(final Entity product, final Entity supplier) { return dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, product)).add(SearchRestrictions.belongsTo(COMPANY, supplier)) .setMaxResults(1).uniqueResult(); } } | ProductCatalogNumbersServiceImpl implements ProductCatalogNumbersService { @Override public Entity getProductCatalogNumber(final Entity product, final Entity supplier) { return dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, product)).add(SearchRestrictions.belongsTo(COMPANY, supplier)) .setMaxResults(1).uniqueResult(); } @Override Entity getProductCatalogNumber(final Entity product, final Entity supplier); } | ProductCatalogNumbersServiceImpl implements ProductCatalogNumbersService { @Override public Entity getProductCatalogNumber(final Entity product, final Entity supplier) { return dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, product)).add(SearchRestrictions.belongsTo(COMPANY, supplier)) .setMaxResults(1).uniqueResult(); } @Override Entity getProductCatalogNumber(final Entity product, final Entity supplier); } |
@Test public void shouldFillUnitIfUnitIsNull() { Entity product = mock(Entity.class); DataDefinition productDD = mock(DataDefinition.class); given(product.getField(UNIT)).willReturn(null); given(unitService.getDefaultUnitFromSystemParameters()).willReturn(L_SZT); productService.fillUnit(productDD, product); verify(product).setField(UNIT, L_SZT); } | public void fillUnit(final DataDefinition productDD, final Entity product) { if (product.getField(UNIT) == null) { product.setField(UNIT, unitService.getDefaultUnitFromSystemParameters()); } } | ProductService { public void fillUnit(final DataDefinition productDD, final Entity product) { if (product.getField(UNIT) == null) { product.setField(UNIT, unitService.getDefaultUnitFromSystemParameters()); } } } | ProductService { public void fillUnit(final DataDefinition productDD, final Entity product) { if (product.getField(UNIT) == null) { product.setField(UNIT, unitService.getDefaultUnitFromSystemParameters()); } } } | ProductService { public void fillUnit(final DataDefinition productDD, final Entity product) { if (product.getField(UNIT) == null) { product.setField(UNIT, unitService.getDefaultUnitFromSystemParameters()); } } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } | ProductService { public void fillUnit(final DataDefinition productDD, final Entity product) { if (product.getField(UNIT) == null) { product.setField(UNIT, unitService.getDefaultUnitFromSystemParameters()); } } Entity find(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); List<Entity> findAll(final SearchProjection projection, final SearchCriterion criteria, final SearchOrder order); boolean checkIfProductEntityTypeIsCorrect(final Entity product, final ProductFamilyElementType entityType); void conversionForProductUnit(final Entity product); BigDecimal convertQuantityFromProductUnit(final Entity product, final BigDecimal quantity, final String targetUnit); boolean hasUnitChangedOnUpdate(final Entity product); void getDefaultConversions(final ViewDefinitionState view, final ComponentState state, final String[] args); void getDefaultConversionsForGrid(final ViewDefinitionState view, final ComponentState state, final String[] args); boolean checkIfSubstituteIsNotRemoved(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkSubstituteComponentUniqueness(final DataDefinition substituteComponentDD, final Entity substituteComponent); boolean checkIfProductIsNotRemoved(final DataDefinition substituteDD, final Entity substitute); void fillUnit(final DataDefinition productDD, final Entity product); } |
@Test public void shouldReturnWhenEntityIdIsNull() throws Exception { Long technologyOperationComponentId = null; String comment = "comment"; given(technologyOperationComponent.getId()).willReturn(technologyOperationComponentId); technologyOperationComponentHooksOTFO.changeDescriptionInOperationalTasksWhenChanged(technologyOperationComponentDD, technologyOperationComponent); Mockito.verify(operationalTask, Mockito.never()).setField(OperationalTaskFields.DESCRIPTION, comment); Mockito.verify(operationalTaskDD, Mockito.never()).save(operationalTask); } | public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD,
final Entity technologyOperationComponent); } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD,
final Entity technologyOperationComponent); } |
@Test public void shouldReturnWhenTechnologyOperationComponentCommentIsTheSame() throws Exception { Long technologyOperationComponentId = 1L; String comment = "comment"; String technologyOperationComponentComment = "comment"; given(technologyOperationComponent.getId()).willReturn(technologyOperationComponentId); given(technologyOperationComponentDD.get(technologyOperationComponentId)).willReturn(technologyOperationComponentFromDB); given(technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT)).willReturn(comment); given(technologyOperationComponentFromDB.getStringField(TechnologyOperationComponentFields.COMMENT)).willReturn( technologyOperationComponentComment); technologyOperationComponentHooksOTFO.changeDescriptionInOperationalTasksWhenChanged(technologyOperationComponentDD, technologyOperationComponent); Mockito.verify(operationalTask, Mockito.never()).setField(OperationalTaskFields.DESCRIPTION, comment); Mockito.verify(operationalTaskDD, Mockito.never()).save(operationalTask); } | public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD,
final Entity technologyOperationComponent); } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD,
final Entity technologyOperationComponent); } |
@Ignore @Test public void shouldChangeOperationalTasksDescriptionWhenTechnologyOperationComponentCommentWasChanged() throws Exception { Long technologyOperationComponentId = 1L; String comment = "comment"; String technologyOperationComponentComment = "comment2"; given(technologyOperationComponent.getId()).willReturn(technologyOperationComponentId); given(technologyOperationComponentDD.get(technologyOperationComponentId)).willReturn(technologyOperationComponentFromDB); given(technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT)).willReturn(comment); given(technologyOperationComponentFromDB.getStringField(TechnologyOperationComponentFields.COMMENT)).willReturn( technologyOperationComponentComment); EntityList techOperCompOperationalTasks = mockEntityList(Lists.newArrayList(techOperCompOperationalTask)); given( operationalTasksForOrdersService .getTechOperCompOperationalTasksForTechnologyOperationComponent(technologyOperationComponent)) .willReturn(techOperCompOperationalTasks); technologyOperationComponentHooksOTFO.changeDescriptionInOperationalTasksWhenChanged(technologyOperationComponentDD, technologyOperationComponent); Mockito.verify(operationalTask).setField(OperationalTaskFields.DESCRIPTION, comment); Mockito.verify(operationalTaskDD).save(operationalTask); } | public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD,
final Entity technologyOperationComponent); } | TechnologyOperationComponentHooksOTFO { public void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { Long technologyOperationComponentId = technologyOperationComponent.getId(); if (technologyOperationComponentId == null) { return; } Entity technologyOperationComponentFromDB = technologyOperationComponentDD.get(technologyOperationComponentId); String comment = (technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); String technologyOperationComponentComment = (technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT) == null) ? "" : technologyOperationComponentFromDB .getStringField(TechnologyOperationComponentFields.COMMENT); if (!comment.equals(technologyOperationComponentComment)) { changedDescriptionInOperationalTasks(technologyOperationComponent); } } void changeDescriptionInOperationalTasksWhenChanged(final DataDefinition technologyOperationComponentDD,
final Entity technologyOperationComponent); } |
@Test public void shouldReturnIfEntityIdIsNull() throws Exception { Long operationId = null; String name = "name"; given(operation.getId()).willReturn(operationId); operationHooksOTFO.changedNameInOperationalTasksWhenChanged(operationDD, operation); Mockito.verify(operationalTask, Mockito.never()).setField(OperationalTaskFields.NAME, name); Mockito.verify(operationalTaskDD, Mockito.never()).save(operationalTask); } | public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation); } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation); } |
@Test public void shouldReturnWhenEntityNameIsTheSame() throws Exception { Long operationId = 1L; String name = "name"; String operationName = "name"; given(operation.getId()).willReturn(operationId); given(operationDD.get(operationId)).willReturn(operationFromDB); given(operation.getStringField(OperationFields.NAME)).willReturn(name); given(operationFromDB.getStringField(OperationFields.NAME)).willReturn(operationName); operationHooksOTFO.changedNameInOperationalTasksWhenChanged(operationDD, operation); Mockito.verify(operationalTask, Mockito.never()).setField(OperationalTaskFields.NAME, name); Mockito.verify(operationalTaskDD, Mockito.never()).save(operationalTask); } | public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation); } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation); } |
@Ignore @Test public void shouldChangeOperationalTaskNameWhenOperationNameWasChanged() throws Exception { Long operationId = 1L; String name = "name"; String operationName = "name2"; given(operation.getId()).willReturn(operationId); given(operationDD.get(operationId)).willReturn(operationFromDB); given(operation.getStringField(OperationFields.NAME)).willReturn(name); given(operationFromDB.getStringField(OperationFields.NAME)).willReturn(operationName); EntityList technologyOperationComponents = mockEntityList(Lists.newArrayList(technologyOperationComponent)); given(operationalTasksForOrdersService.getTechnologyOperationComponentsForOperation(operation)).willReturn( technologyOperationComponents); operationHooksOTFO.changedNameInOperationalTasksWhenChanged(operationDD, operation); Mockito.verify(operationalTask).setField(OperationalTaskFields.NAME, name); Mockito.verify(operationalTaskDD).save(operationalTask); } | public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation); } | OperationHooksOTFO { public void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation) { Long operationId = operation.getId(); if (operationId == null) { return; } Entity operationFromDB = operationDD.get(operationId); String name = operation.getStringField(OperationFields.NAME); String operationName = operationFromDB.getStringField(OperationFields.NAME); if (!name.equals(operationName)) { changedNameInOperationalTasks(operation); } } void changedNameInOperationalTasksWhenChanged(final DataDefinition operationDD, final Entity operation); } |
@Test public void shouldDisabledFieldWhenTypeForOrderIsSelected() throws Exception { String typeTask = OperationalTaskTypeTaskOTFO.EXECUTION_OPERATION_IN_ORDER.getStringValue(); given(typeTaskField.getFieldValue()).willReturn(typeTask); given(operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)).willReturn(false); operationalTaskDetailsHooksOTFO.disableFieldsWhenOrderTypeIsSelected(view); Mockito.verify(nameField).setEnabled(false); Mockito.verify(descriptionField).setEnabled(false); Mockito.verify(productionLineField).setEnabled(false); Mockito.verify(orderField).setEnabled(true); Mockito.verify(technologyOperationComponentField).setEnabled(true); } | public void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view) { FieldComponent typeTaskField = (FieldComponent) view.getComponentByReference(OperationalTaskFields.TYPE_TASK); String typeTask = (String) typeTaskField.getFieldValue(); List<String> referenceBasicFields = Lists.newArrayList(OperationalTaskFields.NAME, OperationalTaskFields.PRODUCTION_LINE, OperationalTaskFields.DESCRIPTION); List<String> extendFields = Lists.newArrayList(OperationalTaskFieldsOTFO.ORDER, OperationalTaskFieldsOTFO.TECHNOLOGY_OPERATION_COMPONENT); if (operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)) { changedStateField(view, referenceBasicFields, true); changedStateField(view, extendFields, false); clearFieldValue(view, extendFields); } else { changedStateField(view, referenceBasicFields, false); changedStateField(view, extendFields, true); } } | OperationalTaskDetailsHooksOTFO { public void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view) { FieldComponent typeTaskField = (FieldComponent) view.getComponentByReference(OperationalTaskFields.TYPE_TASK); String typeTask = (String) typeTaskField.getFieldValue(); List<String> referenceBasicFields = Lists.newArrayList(OperationalTaskFields.NAME, OperationalTaskFields.PRODUCTION_LINE, OperationalTaskFields.DESCRIPTION); List<String> extendFields = Lists.newArrayList(OperationalTaskFieldsOTFO.ORDER, OperationalTaskFieldsOTFO.TECHNOLOGY_OPERATION_COMPONENT); if (operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)) { changedStateField(view, referenceBasicFields, true); changedStateField(view, extendFields, false); clearFieldValue(view, extendFields); } else { changedStateField(view, referenceBasicFields, false); changedStateField(view, extendFields, true); } } } | OperationalTaskDetailsHooksOTFO { public void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view) { FieldComponent typeTaskField = (FieldComponent) view.getComponentByReference(OperationalTaskFields.TYPE_TASK); String typeTask = (String) typeTaskField.getFieldValue(); List<String> referenceBasicFields = Lists.newArrayList(OperationalTaskFields.NAME, OperationalTaskFields.PRODUCTION_LINE, OperationalTaskFields.DESCRIPTION); List<String> extendFields = Lists.newArrayList(OperationalTaskFieldsOTFO.ORDER, OperationalTaskFieldsOTFO.TECHNOLOGY_OPERATION_COMPONENT); if (operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)) { changedStateField(view, referenceBasicFields, true); changedStateField(view, extendFields, false); clearFieldValue(view, extendFields); } else { changedStateField(view, referenceBasicFields, false); changedStateField(view, extendFields, true); } } } | OperationalTaskDetailsHooksOTFO { public void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view) { FieldComponent typeTaskField = (FieldComponent) view.getComponentByReference(OperationalTaskFields.TYPE_TASK); String typeTask = (String) typeTaskField.getFieldValue(); List<String> referenceBasicFields = Lists.newArrayList(OperationalTaskFields.NAME, OperationalTaskFields.PRODUCTION_LINE, OperationalTaskFields.DESCRIPTION); List<String> extendFields = Lists.newArrayList(OperationalTaskFieldsOTFO.ORDER, OperationalTaskFieldsOTFO.TECHNOLOGY_OPERATION_COMPONENT); if (operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)) { changedStateField(view, referenceBasicFields, true); changedStateField(view, extendFields, false); clearFieldValue(view, extendFields); } else { changedStateField(view, referenceBasicFields, false); changedStateField(view, extendFields, true); } } void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view); void disableButtons(final ViewDefinitionState view); void setTechnology(final ViewDefinitionState view); void setTechnologyOperationComponent(final ViewDefinitionState view); } | OperationalTaskDetailsHooksOTFO { public void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view) { FieldComponent typeTaskField = (FieldComponent) view.getComponentByReference(OperationalTaskFields.TYPE_TASK); String typeTask = (String) typeTaskField.getFieldValue(); List<String> referenceBasicFields = Lists.newArrayList(OperationalTaskFields.NAME, OperationalTaskFields.PRODUCTION_LINE, OperationalTaskFields.DESCRIPTION); List<String> extendFields = Lists.newArrayList(OperationalTaskFieldsOTFO.ORDER, OperationalTaskFieldsOTFO.TECHNOLOGY_OPERATION_COMPONENT); if (operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)) { changedStateField(view, referenceBasicFields, true); changedStateField(view, extendFields, false); clearFieldValue(view, extendFields); } else { changedStateField(view, referenceBasicFields, false); changedStateField(view, extendFields, true); } } void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view); void disableButtons(final ViewDefinitionState view); void setTechnology(final ViewDefinitionState view); void setTechnologyOperationComponent(final ViewDefinitionState view); } |
@Test public void shouldEnabledFieldWhenTypeOtherCaseIsSelected() throws Exception { String typeTask = OperationalTaskTypeTask.OTHER_CASE.getStringValue(); given(typeTaskField.getFieldValue()).willReturn(typeTask); given(operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)).willReturn(true); operationalTaskDetailsHooksOTFO.disableFieldsWhenOrderTypeIsSelected(view); Mockito.verify(nameField).setEnabled(true); Mockito.verify(descriptionField).setEnabled(true); Mockito.verify(productionLineField).setEnabled(true); Mockito.verify(orderField).setEnabled(false); Mockito.verify(technologyOperationComponentField).setEnabled(false); } | public void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view) { FieldComponent typeTaskField = (FieldComponent) view.getComponentByReference(OperationalTaskFields.TYPE_TASK); String typeTask = (String) typeTaskField.getFieldValue(); List<String> referenceBasicFields = Lists.newArrayList(OperationalTaskFields.NAME, OperationalTaskFields.PRODUCTION_LINE, OperationalTaskFields.DESCRIPTION); List<String> extendFields = Lists.newArrayList(OperationalTaskFieldsOTFO.ORDER, OperationalTaskFieldsOTFO.TECHNOLOGY_OPERATION_COMPONENT); if (operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)) { changedStateField(view, referenceBasicFields, true); changedStateField(view, extendFields, false); clearFieldValue(view, extendFields); } else { changedStateField(view, referenceBasicFields, false); changedStateField(view, extendFields, true); } } | OperationalTaskDetailsHooksOTFO { public void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view) { FieldComponent typeTaskField = (FieldComponent) view.getComponentByReference(OperationalTaskFields.TYPE_TASK); String typeTask = (String) typeTaskField.getFieldValue(); List<String> referenceBasicFields = Lists.newArrayList(OperationalTaskFields.NAME, OperationalTaskFields.PRODUCTION_LINE, OperationalTaskFields.DESCRIPTION); List<String> extendFields = Lists.newArrayList(OperationalTaskFieldsOTFO.ORDER, OperationalTaskFieldsOTFO.TECHNOLOGY_OPERATION_COMPONENT); if (operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)) { changedStateField(view, referenceBasicFields, true); changedStateField(view, extendFields, false); clearFieldValue(view, extendFields); } else { changedStateField(view, referenceBasicFields, false); changedStateField(view, extendFields, true); } } } | OperationalTaskDetailsHooksOTFO { public void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view) { FieldComponent typeTaskField = (FieldComponent) view.getComponentByReference(OperationalTaskFields.TYPE_TASK); String typeTask = (String) typeTaskField.getFieldValue(); List<String> referenceBasicFields = Lists.newArrayList(OperationalTaskFields.NAME, OperationalTaskFields.PRODUCTION_LINE, OperationalTaskFields.DESCRIPTION); List<String> extendFields = Lists.newArrayList(OperationalTaskFieldsOTFO.ORDER, OperationalTaskFieldsOTFO.TECHNOLOGY_OPERATION_COMPONENT); if (operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)) { changedStateField(view, referenceBasicFields, true); changedStateField(view, extendFields, false); clearFieldValue(view, extendFields); } else { changedStateField(view, referenceBasicFields, false); changedStateField(view, extendFields, true); } } } | OperationalTaskDetailsHooksOTFO { public void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view) { FieldComponent typeTaskField = (FieldComponent) view.getComponentByReference(OperationalTaskFields.TYPE_TASK); String typeTask = (String) typeTaskField.getFieldValue(); List<String> referenceBasicFields = Lists.newArrayList(OperationalTaskFields.NAME, OperationalTaskFields.PRODUCTION_LINE, OperationalTaskFields.DESCRIPTION); List<String> extendFields = Lists.newArrayList(OperationalTaskFieldsOTFO.ORDER, OperationalTaskFieldsOTFO.TECHNOLOGY_OPERATION_COMPONENT); if (operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)) { changedStateField(view, referenceBasicFields, true); changedStateField(view, extendFields, false); clearFieldValue(view, extendFields); } else { changedStateField(view, referenceBasicFields, false); changedStateField(view, extendFields, true); } } void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view); void disableButtons(final ViewDefinitionState view); void setTechnology(final ViewDefinitionState view); void setTechnologyOperationComponent(final ViewDefinitionState view); } | OperationalTaskDetailsHooksOTFO { public void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view) { FieldComponent typeTaskField = (FieldComponent) view.getComponentByReference(OperationalTaskFields.TYPE_TASK); String typeTask = (String) typeTaskField.getFieldValue(); List<String> referenceBasicFields = Lists.newArrayList(OperationalTaskFields.NAME, OperationalTaskFields.PRODUCTION_LINE, OperationalTaskFields.DESCRIPTION); List<String> extendFields = Lists.newArrayList(OperationalTaskFieldsOTFO.ORDER, OperationalTaskFieldsOTFO.TECHNOLOGY_OPERATION_COMPONENT); if (operationalTasksForOrdersService.isOperationalTaskTypeTaskOtherCase(typeTask)) { changedStateField(view, referenceBasicFields, true); changedStateField(view, extendFields, false); clearFieldValue(view, extendFields); } else { changedStateField(view, referenceBasicFields, false); changedStateField(view, extendFields, true); } } void disableFieldsWhenOrderTypeIsSelected(final ViewDefinitionState view); void disableButtons(final ViewDefinitionState view); void setTechnology(final ViewDefinitionState view); void setTechnologyOperationComponent(final ViewDefinitionState view); } |
@Test public void shouldReturnWhenEntityIdIsNull() throws Exception { Long orderId = null; given(order.getId()).willReturn(orderId); orderHooksOTFO.changedProductionLineInOperationalTasksWhenChanged(orderDD, order); } | public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order); } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order); } |
@Test public void shouldReturnTrueWhenEntityWithGivenNumberAndCompanyDoesnotExistsInDB() throws Exception { SearchCriterion criterion1 = SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER)); SearchCriterion criterion2 = SearchRestrictions.belongsTo(ProductCatalogNumberFields.COMPANY, company); given(entity.getId()).willReturn(null); given(criteria.add(criterion1)).willReturn(criteria); given(criteria.add(criterion2)).willReturn(criteria); given(criteria.list()).willReturn(searchResult); given(searchResult.getEntities()).willReturn(productCatalogNumbers); given(productCatalogNumbers.isEmpty()).willReturn(true); boolean result = productCatalogNumbersHooks.checkIfExistsCatalogNumberWithNumberAndCompany(dataDefinition, entity); Assert.assertTrue(result); } | public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany"); return false; } } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany"); return false; } } } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany"); return false; } } } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany"); return false; } } boolean checkIfExistsCatalogNumberWithProductAndCompany(final DataDefinition dataDefinition, final Entity entity); boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity); } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany"); return false; } } boolean checkIfExistsCatalogNumberWithProductAndCompany(final DataDefinition dataDefinition, final Entity entity); boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity); } |
@Test public void shouldReturnWhenProductionLineIsTheSame() throws Exception { Long orderId = 1L; Long productionLineId = 1L; given(order.getId()).willReturn(orderId); given(orderDD.get(orderId)).willReturn(orderFromDB); given(order.getBelongsToField(OrderFields.PRODUCTION_LINE)).willReturn(productionLine); given(orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE)).willReturn(productionLine); given(productionLine.getId()).willReturn(productionLineId); orderHooksOTFO.changedProductionLineInOperationalTasksWhenChanged(orderDD, order); Mockito.verify(operationalTask, Mockito.never()).setField(OrderFields.PRODUCTION_LINE, null); Mockito.verify(operationalTaskDD, Mockito.never()).save(operationalTask); } | public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order); } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order); } |
@Test public void shouldReturneWhenProductionLineIsNull() throws Exception { Long orderId = 1L; Long productionLineId = 1L; given(order.getId()).willReturn(orderId); given(orderDD.get(orderId)).willReturn(orderFromDB); given(order.getBelongsToField(OrderFields.PRODUCTION_LINE)).willReturn(productionLine); given(orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE)).willReturn(null); given(productionLine.getId()).willReturn(productionLineId); orderHooksOTFO.changedProductionLineInOperationalTasksWhenChanged(orderDD, order); Mockito.verify(operationalTask, Mockito.never()).setField(OrderFields.PRODUCTION_LINE, productionLine); Mockito.verify(operationalTaskDD, Mockito.never()).save(operationalTask); } | public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order); } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order); } |
@Ignore @Test public void shouldChangeProductionLineWhenProductionLineWasChanged() throws Exception { Long orderId = 1L; Long productionLineId = 1L; Long orderProductionLineId = 2L; given(order.getId()).willReturn(orderId); given(orderDD.get(orderId)).willReturn(orderFromDB); given(order.getBelongsToField(OrderFields.PRODUCTION_LINE)).willReturn(productionLine); given(orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE)).willReturn(orderProductionLine); given(productionLine.getId()).willReturn(productionLineId); given(orderProductionLine.getId()).willReturn(orderProductionLineId); EntityList operationalTasks = mockEntityList(Lists.newArrayList(operationalTask)); given(operationalTasksForOrdersService.getOperationalTasksForOrder(order)).willReturn(operationalTasks); orderHooksOTFO.changedProductionLineInOperationalTasksWhenChanged(orderDD, order); Mockito.verify(operationalTask).setField(OrderFields.PRODUCTION_LINE, productionLine); Mockito.verify(operationalTaskDD).save(operationalTask); } | public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order); } | OrderHooksOTFO { public void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order) { Long orderId = order.getId(); if (orderId == null) { return; } Entity orderFromDB = orderDD.get(orderId); Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE); Entity orderProductionLine = orderFromDB.getBelongsToField(OrderFields.PRODUCTION_LINE); if ((productionLine == null) || (orderProductionLine == null)) { return; } else { if (!orderProductionLine.getId().equals(productionLine.getId())) { changedProductionLineInOperationalTasks(orderFromDB, productionLine); } } } void changedProductionLineInOperationalTasksWhenChanged(final DataDefinition orderDD, final Entity order); } |
@Test public void shouldEnableButtonWhenIsGeneratedAndOrderStateIsAccepted() throws Exception { String generatedEndDate = "01-02-2012"; given(generatedEndDateField.getFieldValue()).willReturn(generatedEndDate); given(order.getStringField(OrderFields.STATE)).willReturn(OrderStateStringValues.ACCEPTED); given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); operationDurationDetailsInOrderDetailsHooksOTFO.disableCreateButton(view); Mockito.verify(createOperationalTasks).setEnabled(true); } | public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } void disableCreateButton(final ViewDefinitionState view); } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } void disableCreateButton(final ViewDefinitionState view); } |
@Test public void shouldDisableButtonWhenIsNotGeneratedAndOrderStateIsInProgress() throws Exception { String generatedEndDate = ""; given(generatedEndDateField.getFieldValue()).willReturn(generatedEndDate); given(order.getStringField(OrderFields.STATE)).willReturn(OrderStateStringValues.IN_PROGRESS); given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); operationDurationDetailsInOrderDetailsHooksOTFO.disableCreateButton(view); Mockito.verify(createOperationalTasks).setEnabled(false); } | public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } void disableCreateButton(final ViewDefinitionState view); } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } void disableCreateButton(final ViewDefinitionState view); } |
@Test public void shouldDisableButtonWhenIsNotGeneratedAndOrderStateIsIncorrect() throws Exception { String generatedEndDate = ""; given(generatedEndDateField.getFieldValue()).willReturn(generatedEndDate); given(order.getStringField(OrderFields.STATE)).willReturn(OrderStateStringValues.ABANDONED); given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); operationDurationDetailsInOrderDetailsHooksOTFO.disableCreateButton(view); Mockito.verify(createOperationalTasks).setEnabled(false); } | public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } void disableCreateButton(final ViewDefinitionState view); } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } void disableCreateButton(final ViewDefinitionState view); } |
@Test public void shouldDisableFieldWhenIsGeneratedAndOrderStateIsIncorrect() throws Exception { String generatedEndDate = "01-02-2012"; given(generatedEndDateField.getFieldValue()).willReturn(generatedEndDate); given(order.getStringField(OrderFields.STATE)).willReturn(OrderStateStringValues.DECLINED); given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); operationDurationDetailsInOrderDetailsHooksOTFO.disableCreateButton(view); Mockito.verify(createOperationalTasks).setEnabled(false); } | public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } void disableCreateButton(final ViewDefinitionState view); } | OperationDurationDetailsInOrderDetailsHooksOTFO { public void disableCreateButton(final ViewDefinitionState view) { WindowComponent window = (WindowComponent) view.getComponentByReference(L_WINDOW); RibbonGroup operationalTasks = window.getRibbon().getGroupByName(L_OPERATIONAL_TASKS); RibbonActionItem createOperationalTasks = operationalTasks.getItemByName(L_CREATE_OPERATIONAL_TASKS); if (isGenerated(view) && orderHasTechnologyAndCorrectState(view)) { createOperationalTasks.setEnabled(true); } else { createOperationalTasks.setEnabled(false); } createOperationalTasks.requestUpdate(true); } void disableCreateButton(final ViewDefinitionState view); } |
@Test public void shouldReturnTrueWhenOrderIsNotSave() throws Exception { given(operationalTask.getBelongsToField(OperationalTaskFieldsOTFO.ORDER)).willReturn(null); boolean result = operationalTaskValidatorsOTFO.validatesWith(operationalTaskDD, operationalTask); Assert.assertTrue(result); } | public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask); } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask); } |
@Test public void shouldReturnFalseWhenOrderDoesNotHaveTechnology() throws Exception { given(operationalTask.getBelongsToField(OperationalTaskFieldsOTFO.ORDER)).willReturn(order); given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(null); boolean result = operationalTaskValidatorsOTFO.validatesWith(operationalTaskDD, operationalTask); Assert.assertFalse(result); Mockito.verify(operationalTask).addError(operationalTaskDD.getField(OperationalTaskFieldsOTFO.ORDER), "operationalTasks.operationalTask.order.error.technologyIsNull"); } | public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask); } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask); } |
@Test public void shouldReturnTrueWhenOrderHaveTechnology() throws Exception { when(operationalTask.getBelongsToField(OperationalTaskFieldsOTFO.ORDER)).thenReturn(order); when(order.getBelongsToField(OrderFields.TECHNOLOGY)).thenReturn(technology); boolean result = operationalTaskValidatorsOTFO.validatesWith(operationalTaskDD, operationalTask); Assert.assertTrue(result); } | public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask); } | OperationalTaskValidatorsOTFO { public boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask) { return checkIfOrderHasTechnology(operationalTaskDD, operationalTask); } boolean validatesWith(final DataDefinition operationalTaskDD, final Entity operationalTask); } |
@Test public void shouldReturnFalseWhenEntityWithGivenNumberAndCompanyDoesExistsInDB() throws Exception { SearchCriterion criterion1 = SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER)); SearchCriterion criterion2 = SearchRestrictions.belongsTo(ProductCatalogNumberFields.COMPANY, company); given(entity.getId()).willReturn(null); given(criteria.add(criterion1)).willReturn(criteria); given(criteria.add(criterion2)).willReturn(criteria); given(criteria.list()).willReturn(searchResult); given(searchResult.getEntities()).willReturn(productCatalogNumbers); given(productCatalogNumbers.isEmpty()).willReturn(false); boolean result = productCatalogNumbersHooks.checkIfExistsCatalogNumberWithNumberAndCompany(dataDefinition, entity); Assert.assertFalse(result); Mockito.verify(entity).addGlobalError( "productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany"); } | public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany"); return false; } } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany"); return false; } } } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany"); return false; } } } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany"); return false; } } boolean checkIfExistsCatalogNumberWithProductAndCompany(final DataDefinition dataDefinition, final Entity entity); boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity); } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany"); return false; } } boolean checkIfExistsCatalogNumberWithProductAndCompany(final DataDefinition dataDefinition, final Entity entity); boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity); } |
@Test public void shouldNotRedirectToPreviousOrderIfPreviousOrderIsNull() { stubLookup(previousOrderLookup, null); lineChangeoverNormsForOrderDetailsListeners.showPreviousOrder(view, null, null); verify(view, never()).redirectTo(anyString(), anyBoolean(), anyBoolean(), anyMap()); } | public final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); Long previousOrderId = (Long) previousOrderLookup.getFieldValue(); if (previousOrderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", previousOrderId); String url = "../page/orders/orderDetails.html"; view.redirectTo(url, false, true, parameters); } | LineChangeoverNormsForOrderDetailsListeners { public final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); Long previousOrderId = (Long) previousOrderLookup.getFieldValue(); if (previousOrderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", previousOrderId); String url = "../page/orders/orderDetails.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); Long previousOrderId = (Long) previousOrderLookup.getFieldValue(); if (previousOrderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", previousOrderId); String url = "../page/orders/orderDetails.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); Long previousOrderId = (Long) previousOrderLookup.getFieldValue(); if (previousOrderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", previousOrderId); String url = "../page/orders/orderDetails.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); Long previousOrderId = (Long) previousOrderLookup.getFieldValue(); if (previousOrderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", previousOrderId); String url = "../page/orders/orderDetails.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldRedirectToPreviousOrderIfPreviousOrderIsNotNull() { stubLookup(previousOrderLookup, entityWithId); lineChangeoverNormsForOrderDetailsListeners.showPreviousOrder(view, null, null); String url = "../page/orders/orderDetails.html"; verify(view).redirectTo(eq(url), anyBoolean(), anyBoolean(), parametersCaptor.capture()); Map<String, Object> usedParameters = parametersCaptor.getValue(); assertEquals(L_ID, usedParameters.get("form.id")); } | public final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); Long previousOrderId = (Long) previousOrderLookup.getFieldValue(); if (previousOrderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", previousOrderId); String url = "../page/orders/orderDetails.html"; view.redirectTo(url, false, true, parameters); } | LineChangeoverNormsForOrderDetailsListeners { public final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); Long previousOrderId = (Long) previousOrderLookup.getFieldValue(); if (previousOrderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", previousOrderId); String url = "../page/orders/orderDetails.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); Long previousOrderId = (Long) previousOrderLookup.getFieldValue(); if (previousOrderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", previousOrderId); String url = "../page/orders/orderDetails.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); Long previousOrderId = (Long) previousOrderLookup.getFieldValue(); if (previousOrderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", previousOrderId); String url = "../page/orders/orderDetails.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); Long previousOrderId = (Long) previousOrderLookup.getFieldValue(); if (previousOrderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", previousOrderId); String url = "../page/orders/orderDetails.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldNotRedirectToBestFittingLineChangeoverNormIfLineChangeoverIsNull() { stubLookup(lineChangeoverNormLookup, null); lineChangeoverNormsForOrderDetailsListeners.showBestFittingLineChangeoverNorm(view, null, null); verify(view, never()).redirectTo(anyString(), anyBoolean(), anyBoolean(), anyMap()); } | public final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent lineChangeoverNormField = (FieldComponent) view .getComponentByReference(OrderFieldsLCNFO.LINE_CHANGEOVER_NORM); Long lineChangeoverNormId = (Long) lineChangeoverNormField.getFieldValue(); if (lineChangeoverNormId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", lineChangeoverNormId); String url = "../page/lineChangeoverNorms/lineChangeoverNormsDetails.html"; view.redirectTo(url, false, true, parameters); } | LineChangeoverNormsForOrderDetailsListeners { public final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent lineChangeoverNormField = (FieldComponent) view .getComponentByReference(OrderFieldsLCNFO.LINE_CHANGEOVER_NORM); Long lineChangeoverNormId = (Long) lineChangeoverNormField.getFieldValue(); if (lineChangeoverNormId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", lineChangeoverNormId); String url = "../page/lineChangeoverNorms/lineChangeoverNormsDetails.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent lineChangeoverNormField = (FieldComponent) view .getComponentByReference(OrderFieldsLCNFO.LINE_CHANGEOVER_NORM); Long lineChangeoverNormId = (Long) lineChangeoverNormField.getFieldValue(); if (lineChangeoverNormId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", lineChangeoverNormId); String url = "../page/lineChangeoverNorms/lineChangeoverNormsDetails.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent lineChangeoverNormField = (FieldComponent) view .getComponentByReference(OrderFieldsLCNFO.LINE_CHANGEOVER_NORM); Long lineChangeoverNormId = (Long) lineChangeoverNormField.getFieldValue(); if (lineChangeoverNormId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", lineChangeoverNormId); String url = "../page/lineChangeoverNorms/lineChangeoverNormsDetails.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent lineChangeoverNormField = (FieldComponent) view .getComponentByReference(OrderFieldsLCNFO.LINE_CHANGEOVER_NORM); Long lineChangeoverNormId = (Long) lineChangeoverNormField.getFieldValue(); if (lineChangeoverNormId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", lineChangeoverNormId); String url = "../page/lineChangeoverNorms/lineChangeoverNormsDetails.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldRedirectToBestFittingLineChangeoverNormIfLineChangeoverNormIsNotNull() { stubLookup(lineChangeoverNormLookup, entityWithId); lineChangeoverNormsForOrderDetailsListeners.showBestFittingLineChangeoverNorm(view, null, null); String url = "../page/lineChangeoverNorms/lineChangeoverNormsDetails.html"; verify(view).redirectTo(eq(url), anyBoolean(), anyBoolean(), parametersCaptor.capture()); Map<String, Object> usedParameters = parametersCaptor.getValue(); assertEquals(L_ID, usedParameters.get("form.id")); } | public final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent lineChangeoverNormField = (FieldComponent) view .getComponentByReference(OrderFieldsLCNFO.LINE_CHANGEOVER_NORM); Long lineChangeoverNormId = (Long) lineChangeoverNormField.getFieldValue(); if (lineChangeoverNormId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", lineChangeoverNormId); String url = "../page/lineChangeoverNorms/lineChangeoverNormsDetails.html"; view.redirectTo(url, false, true, parameters); } | LineChangeoverNormsForOrderDetailsListeners { public final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent lineChangeoverNormField = (FieldComponent) view .getComponentByReference(OrderFieldsLCNFO.LINE_CHANGEOVER_NORM); Long lineChangeoverNormId = (Long) lineChangeoverNormField.getFieldValue(); if (lineChangeoverNormId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", lineChangeoverNormId); String url = "../page/lineChangeoverNorms/lineChangeoverNormsDetails.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent lineChangeoverNormField = (FieldComponent) view .getComponentByReference(OrderFieldsLCNFO.LINE_CHANGEOVER_NORM); Long lineChangeoverNormId = (Long) lineChangeoverNormField.getFieldValue(); if (lineChangeoverNormId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", lineChangeoverNormId); String url = "../page/lineChangeoverNorms/lineChangeoverNormsDetails.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent lineChangeoverNormField = (FieldComponent) view .getComponentByReference(OrderFieldsLCNFO.LINE_CHANGEOVER_NORM); Long lineChangeoverNormId = (Long) lineChangeoverNormField.getFieldValue(); if (lineChangeoverNormId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", lineChangeoverNormId); String url = "../page/lineChangeoverNorms/lineChangeoverNormsDetails.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent lineChangeoverNormField = (FieldComponent) view .getComponentByReference(OrderFieldsLCNFO.LINE_CHANGEOVER_NORM); Long lineChangeoverNormId = (Long) lineChangeoverNormField.getFieldValue(); if (lineChangeoverNormId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", lineChangeoverNormId); String url = "../page/lineChangeoverNorms/lineChangeoverNormsDetails.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldNotRedirectToLineChangeoverNormForGroupIfTechnologyGroupNumbersAreEmpty() { given(previousOrderTechnologyGroupNumberField.getFieldValue()).willReturn(null); given(technologyGroupNumberField.getFieldValue()).willReturn(null); lineChangeoverNormsForOrderDetailsListeners.showLineChangeoverNormForGroup(view, null, null); verify(view, never()).redirectTo(anyString(), anyBoolean(), anyBoolean(), anyMap()); } | public final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyGroupNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyGroupNumber"); FieldComponent technologyGroupNumberField = (FieldComponent) view.getComponentByReference("technologyGroupNumber"); String previousOrderTechnologyGroupNumber = (String) previousOrderTechnologyGroupNumberField.getFieldValue(); String technologyGroupNumber = (String) technologyGroupNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyGroupNumber) || StringUtils.isEmpty(technologyGroupNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnologyGroup", previousOrderTechnologyGroupNumber); filters.put("toTechnologyGroup", technologyGroupNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyGroupNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyGroupNumber"); FieldComponent technologyGroupNumberField = (FieldComponent) view.getComponentByReference("technologyGroupNumber"); String previousOrderTechnologyGroupNumber = (String) previousOrderTechnologyGroupNumberField.getFieldValue(); String technologyGroupNumber = (String) technologyGroupNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyGroupNumber) || StringUtils.isEmpty(technologyGroupNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnologyGroup", previousOrderTechnologyGroupNumber); filters.put("toTechnologyGroup", technologyGroupNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyGroupNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyGroupNumber"); FieldComponent technologyGroupNumberField = (FieldComponent) view.getComponentByReference("technologyGroupNumber"); String previousOrderTechnologyGroupNumber = (String) previousOrderTechnologyGroupNumberField.getFieldValue(); String technologyGroupNumber = (String) technologyGroupNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyGroupNumber) || StringUtils.isEmpty(technologyGroupNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnologyGroup", previousOrderTechnologyGroupNumber); filters.put("toTechnologyGroup", technologyGroupNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyGroupNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyGroupNumber"); FieldComponent technologyGroupNumberField = (FieldComponent) view.getComponentByReference("technologyGroupNumber"); String previousOrderTechnologyGroupNumber = (String) previousOrderTechnologyGroupNumberField.getFieldValue(); String technologyGroupNumber = (String) technologyGroupNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyGroupNumber) || StringUtils.isEmpty(technologyGroupNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnologyGroup", previousOrderTechnologyGroupNumber); filters.put("toTechnologyGroup", technologyGroupNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyGroupNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyGroupNumber"); FieldComponent technologyGroupNumberField = (FieldComponent) view.getComponentByReference("technologyGroupNumber"); String previousOrderTechnologyGroupNumber = (String) previousOrderTechnologyGroupNumberField.getFieldValue(); String technologyGroupNumber = (String) technologyGroupNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyGroupNumber) || StringUtils.isEmpty(technologyGroupNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnologyGroup", previousOrderTechnologyGroupNumber); filters.put("toTechnologyGroup", technologyGroupNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldRedirectToLineChangeoverNormForGroupIfTechnologyGroupNumbersAreNotEmpty() { given(previousOrderTechnologyGroupNumberField.getFieldValue()).willReturn(L_TECHNOLOGY_GROUP_NUMBER); given(technologyGroupNumberField.getFieldValue()).willReturn(L_TECHNOLOGY_GROUP_NUMBER); lineChangeoverNormsForOrderDetailsListeners.showLineChangeoverNormForGroup(view, null, null); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; verify(view).redirectTo(eq(url), anyBoolean(), anyBoolean(), parametersCaptor.capture()); Map<String, Object> usedParameters = parametersCaptor.getValue(); assertEquals(2, usedParameters.size()); assertEquals("technology.lineChangeoverNorms", usedParameters.get(L_WINDOW_ACTIVE_MENU)); Map<String, Object> gridOptions = (Map<String, Object>) usedParameters.get(L_GRID_OPTIONS); assertEquals(1, gridOptions.size()); Map<String, Object> filters = (Map<String, Object>) gridOptions.get(L_FILTERS); assertEquals(2, filters.size()); assertEquals(L_TECHNOLOGY_GROUP_NUMBER, filters.get("fromTechnologyGroup")); assertEquals(L_TECHNOLOGY_GROUP_NUMBER, filters.get("toTechnologyGroup")); } | public final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyGroupNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyGroupNumber"); FieldComponent technologyGroupNumberField = (FieldComponent) view.getComponentByReference("technologyGroupNumber"); String previousOrderTechnologyGroupNumber = (String) previousOrderTechnologyGroupNumberField.getFieldValue(); String technologyGroupNumber = (String) technologyGroupNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyGroupNumber) || StringUtils.isEmpty(technologyGroupNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnologyGroup", previousOrderTechnologyGroupNumber); filters.put("toTechnologyGroup", technologyGroupNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyGroupNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyGroupNumber"); FieldComponent technologyGroupNumberField = (FieldComponent) view.getComponentByReference("technologyGroupNumber"); String previousOrderTechnologyGroupNumber = (String) previousOrderTechnologyGroupNumberField.getFieldValue(); String technologyGroupNumber = (String) technologyGroupNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyGroupNumber) || StringUtils.isEmpty(technologyGroupNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnologyGroup", previousOrderTechnologyGroupNumber); filters.put("toTechnologyGroup", technologyGroupNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyGroupNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyGroupNumber"); FieldComponent technologyGroupNumberField = (FieldComponent) view.getComponentByReference("technologyGroupNumber"); String previousOrderTechnologyGroupNumber = (String) previousOrderTechnologyGroupNumberField.getFieldValue(); String technologyGroupNumber = (String) technologyGroupNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyGroupNumber) || StringUtils.isEmpty(technologyGroupNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnologyGroup", previousOrderTechnologyGroupNumber); filters.put("toTechnologyGroup", technologyGroupNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyGroupNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyGroupNumber"); FieldComponent technologyGroupNumberField = (FieldComponent) view.getComponentByReference("technologyGroupNumber"); String previousOrderTechnologyGroupNumber = (String) previousOrderTechnologyGroupNumberField.getFieldValue(); String technologyGroupNumber = (String) technologyGroupNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyGroupNumber) || StringUtils.isEmpty(technologyGroupNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnologyGroup", previousOrderTechnologyGroupNumber); filters.put("toTechnologyGroup", technologyGroupNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyGroupNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyGroupNumber"); FieldComponent technologyGroupNumberField = (FieldComponent) view.getComponentByReference("technologyGroupNumber"); String previousOrderTechnologyGroupNumber = (String) previousOrderTechnologyGroupNumberField.getFieldValue(); String technologyGroupNumber = (String) technologyGroupNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyGroupNumber) || StringUtils.isEmpty(technologyGroupNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnologyGroup", previousOrderTechnologyGroupNumber); filters.put("toTechnologyGroup", technologyGroupNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldNotRedirectToLineChangeoverNormsForTechnologyIfTechnologyNumbersAreEmpty() { given(previousOrderTechnologyNumberField.getFieldValue()).willReturn(null); given(technologyNumberField.getFieldValue()).willReturn(null); lineChangeoverNormsForOrderDetailsListeners.showLineChangeoverNormForTechnology(view, null, null); verify(view, never()).redirectTo(anyString(), anyBoolean(), anyBoolean(), anyMap()); } | public final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyNumber"); FieldComponent technologyNumberField = (FieldComponent) view.getComponentByReference("technologyNumber"); String previousOrderTechnologyNumber = (String) previousOrderTechnologyNumberField.getFieldValue(); String technologyNumber = (String) technologyNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyNumber) || StringUtils.isEmpty(technologyNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnology", previousOrderTechnologyNumber); filters.put("toTechnology", technologyNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyNumber"); FieldComponent technologyNumberField = (FieldComponent) view.getComponentByReference("technologyNumber"); String previousOrderTechnologyNumber = (String) previousOrderTechnologyNumberField.getFieldValue(); String technologyNumber = (String) technologyNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyNumber) || StringUtils.isEmpty(technologyNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnology", previousOrderTechnologyNumber); filters.put("toTechnology", technologyNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyNumber"); FieldComponent technologyNumberField = (FieldComponent) view.getComponentByReference("technologyNumber"); String previousOrderTechnologyNumber = (String) previousOrderTechnologyNumberField.getFieldValue(); String technologyNumber = (String) technologyNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyNumber) || StringUtils.isEmpty(technologyNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnology", previousOrderTechnologyNumber); filters.put("toTechnology", technologyNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyNumber"); FieldComponent technologyNumberField = (FieldComponent) view.getComponentByReference("technologyNumber"); String previousOrderTechnologyNumber = (String) previousOrderTechnologyNumberField.getFieldValue(); String technologyNumber = (String) technologyNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyNumber) || StringUtils.isEmpty(technologyNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnology", previousOrderTechnologyNumber); filters.put("toTechnology", technologyNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyNumber"); FieldComponent technologyNumberField = (FieldComponent) view.getComponentByReference("technologyNumber"); String previousOrderTechnologyNumber = (String) previousOrderTechnologyNumberField.getFieldValue(); String technologyNumber = (String) technologyNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyNumber) || StringUtils.isEmpty(technologyNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnology", previousOrderTechnologyNumber); filters.put("toTechnology", technologyNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldRedirectToLineChangeoverNormsForTechnologyIfTechnologyNumbersAreNotEmpty() { given(previousOrderTechnologyNumberField.getFieldValue()).willReturn(L_TECHNOLOGY_NUMBER); given(technologyNumberField.getFieldValue()).willReturn(L_TECHNOLOGY_NUMBER); lineChangeoverNormsForOrderDetailsListeners.showLineChangeoverNormForTechnology(view, null, null); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; verify(view).redirectTo(eq(url), anyBoolean(), anyBoolean(), parametersCaptor.capture()); Map<String, Object> usedParameters = parametersCaptor.getValue(); assertEquals(2, usedParameters.size()); assertEquals("technology.lineChangeoverNorms", usedParameters.get(L_WINDOW_ACTIVE_MENU)); Map<String, Object> gridOptions = (Map<String, Object>) usedParameters.get(L_GRID_OPTIONS); assertEquals(1, gridOptions.size()); Map<String, Object> filters = (Map<String, Object>) gridOptions.get(L_FILTERS); assertEquals(2, filters.size()); assertEquals(L_TECHNOLOGY_GROUP_NUMBER, filters.get("fromTechnology")); assertEquals(L_TECHNOLOGY_GROUP_NUMBER, filters.get("toTechnology")); } | public final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyNumber"); FieldComponent technologyNumberField = (FieldComponent) view.getComponentByReference("technologyNumber"); String previousOrderTechnologyNumber = (String) previousOrderTechnologyNumberField.getFieldValue(); String technologyNumber = (String) technologyNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyNumber) || StringUtils.isEmpty(technologyNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnology", previousOrderTechnologyNumber); filters.put("toTechnology", technologyNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyNumber"); FieldComponent technologyNumberField = (FieldComponent) view.getComponentByReference("technologyNumber"); String previousOrderTechnologyNumber = (String) previousOrderTechnologyNumberField.getFieldValue(); String technologyNumber = (String) technologyNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyNumber) || StringUtils.isEmpty(technologyNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnology", previousOrderTechnologyNumber); filters.put("toTechnology", technologyNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyNumber"); FieldComponent technologyNumberField = (FieldComponent) view.getComponentByReference("technologyNumber"); String previousOrderTechnologyNumber = (String) previousOrderTechnologyNumberField.getFieldValue(); String technologyNumber = (String) technologyNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyNumber) || StringUtils.isEmpty(technologyNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnology", previousOrderTechnologyNumber); filters.put("toTechnology", technologyNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyNumber"); FieldComponent technologyNumberField = (FieldComponent) view.getComponentByReference("technologyNumber"); String previousOrderTechnologyNumber = (String) previousOrderTechnologyNumberField.getFieldValue(); String technologyNumber = (String) technologyNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyNumber) || StringUtils.isEmpty(technologyNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnology", previousOrderTechnologyNumber); filters.put("toTechnology", technologyNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FieldComponent previousOrderTechnologyNumberField = (FieldComponent) view .getComponentByReference("previousOrderTechnologyNumber"); FieldComponent technologyNumberField = (FieldComponent) view.getComponentByReference("technologyNumber"); String previousOrderTechnologyNumber = (String) previousOrderTechnologyNumberField.getFieldValue(); String technologyNumber = (String) technologyNumberField.getFieldValue(); if (StringUtils.isEmpty(previousOrderTechnologyNumber) || StringUtils.isEmpty(technologyNumber)) { return; } Map<String, String> filters = Maps.newHashMap(); filters.put("fromTechnology", previousOrderTechnologyNumber); filters.put("toTechnology", technologyNumber); Map<String, Object> gridOptions = Maps.newHashMap(); gridOptions.put(L_FILTERS, filters); Map<String, Object> parameters = Maps.newHashMap(); parameters.put(L_GRID_OPTIONS, gridOptions); parameters.put(L_WINDOW_ACTIVE_MENU, "technology.lineChangeoverNorms"); String url = "../page/lineChangeoverNorms/lineChangeoverNormsList.html"; view.redirectTo(url, false, true, parameters); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldNotAddMessageWhenOrdersAreNotSpecified() { stubLookup(previousOrderLookup, null); stubLookup(orderLookup, null); given(lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(null, null)).willReturn(true); lineChangeoverNormsForOrderDetailsListeners.checkIfOrderHasCorrectStateAndIsPrevious(view, null, null); verify(previousOrderLookup, never()).addMessage(anyString(), eq(ComponentState.MessageType.FAILURE)); } | public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldNotAddMessageWhenPreviousOrderIsCorrect() { stubLookup(previousOrderLookup, entityWithId); stubLookup(orderLookup, entityWithId); given(lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(entityWithId, entityWithId)).willReturn( true); lineChangeoverNormsForOrderDetailsListeners.checkIfOrderHasCorrectStateAndIsPrevious(view, null, null); verify(previousOrderLookup, never()).addMessage(anyString(), eq(ComponentState.MessageType.FAILURE)); } | public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldReturnTrueWhenEntityWithGivenProductAndCompanyDoesnotExistsInDB() throws Exception { SearchCriterion criterion1 = SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER)); SearchCriterion criterion2 = SearchRestrictions.belongsTo(PRODUCT, entity.getBelongsToField(PRODUCT)); given(entity.getId()).willReturn(null); given(criteria.add(criterion1)).willReturn(criteria); given(criteria.add(criterion2)).willReturn(criteria); given(criteria.list()).willReturn(searchResult); given(searchResult.getEntities()).willReturn(productCatalogNumbers); given(productCatalogNumbers.isEmpty()).willReturn(true); boolean result = productCatalogNumbersHooks.checkIfExistsCatalogNumberWithProductAndCompany(dataDefinition, entity); Assert.assertTrue(result); } | public boolean checkIfExistsCatalogNumberWithProductAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, entity.getBelongsToField(PRODUCT))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsProductForCompany"); return false; } } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithProductAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, entity.getBelongsToField(PRODUCT))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsProductForCompany"); return false; } } } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithProductAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, entity.getBelongsToField(PRODUCT))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsProductForCompany"); return false; } } } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithProductAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, entity.getBelongsToField(PRODUCT))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsProductForCompany"); return false; } } boolean checkIfExistsCatalogNumberWithProductAndCompany(final DataDefinition dataDefinition, final Entity entity); boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity); } | ProductCatalogNumbersHooks { public boolean checkIfExistsCatalogNumberWithProductAndCompany(final DataDefinition dataDefinition, final Entity entity) { SearchCriteriaBuilder criteria = dataDefinitionService .get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find() .add(SearchRestrictions.belongsTo(PRODUCT, entity.getBelongsToField(PRODUCT))) .add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY))); if (entity.getId() != null) { criteria.add(SearchRestrictions.ne("id", entity.getId())); } List<Entity> catalogsNumbers = criteria.list().getEntities(); if (catalogsNumbers.isEmpty()) { return true; } else { entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsProductForCompany"); return false; } } boolean checkIfExistsCatalogNumberWithProductAndCompany(final DataDefinition dataDefinition, final Entity entity); boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity); } |
@Test public void shouldAddMessageWhenPreviousOrderIsIncorrect() { stubLookup(previousOrderLookup, entityWithId); stubLookup(orderLookup, entityWithId); given(lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(entityWithId, entityWithId)).willReturn( false); lineChangeoverNormsForOrderDetailsListeners.checkIfOrderHasCorrectStateAndIsPrevious(view, null, null); verify(previousOrderLookup).addMessage(anyString(), eq(ComponentState.MessageType.FAILURE)); } | public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { LookupComponent previousOrderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.PREVIOUS_ORDER); LookupComponent orderLookup = (LookupComponent) view.getComponentByReference(OrderFieldsLCNFO.ORDER); Entity previousOrder = previousOrderLookup.getEntity(); Entity order = orderLookup.getEntity(); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrder, order)) { previousOrderLookup.addMessage("orders.order.previousOrder.message.orderIsIncorrect", ComponentState.MessageType.FAILURE); } } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public final void shouldFillPreviousOrderForm() { lineChangeoverNormsForOrderDetailsListeners.fillPreviousOrderForm(view, null, null); verify(lineChangeoverNormsForOrdersService).fillOrderForm(view, PREVIOUS_ORDER_FIELDS); } | public final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { lineChangeoverNormsForOrdersService.fillOrderForm(view, LineChangeoverNormsForOrdersConstants.PREVIOUS_ORDER_FIELDS); } | LineChangeoverNormsForOrderDetailsListeners { public final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { lineChangeoverNormsForOrdersService.fillOrderForm(view, LineChangeoverNormsForOrdersConstants.PREVIOUS_ORDER_FIELDS); } } | LineChangeoverNormsForOrderDetailsListeners { public final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { lineChangeoverNormsForOrdersService.fillOrderForm(view, LineChangeoverNormsForOrdersConstants.PREVIOUS_ORDER_FIELDS); } } | LineChangeoverNormsForOrderDetailsListeners { public final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { lineChangeoverNormsForOrdersService.fillOrderForm(view, LineChangeoverNormsForOrdersConstants.PREVIOUS_ORDER_FIELDS); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { lineChangeoverNormsForOrdersService.fillOrderForm(view, LineChangeoverNormsForOrdersConstants.PREVIOUS_ORDER_FIELDS); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldShowOwnLineChangeoverDurationField() { lineChangeoverNormsForOrderDetailsListeners.showOwnLineChangeoverDurationField(view, null, null); verify(orderService).changeFieldState(view, OWN_LINE_CHANGEOVER, OWN_LINE_CHANGEOVER_DURATION); } | public void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { orderService.changeFieldState(view, OrderFieldsLCNFO.OWN_LINE_CHANGEOVER, OrderFieldsLCNFO.OWN_LINE_CHANGEOVER_DURATION); } | LineChangeoverNormsForOrderDetailsListeners { public void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { orderService.changeFieldState(view, OrderFieldsLCNFO.OWN_LINE_CHANGEOVER, OrderFieldsLCNFO.OWN_LINE_CHANGEOVER_DURATION); } } | LineChangeoverNormsForOrderDetailsListeners { public void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { orderService.changeFieldState(view, OrderFieldsLCNFO.OWN_LINE_CHANGEOVER, OrderFieldsLCNFO.OWN_LINE_CHANGEOVER_DURATION); } } | LineChangeoverNormsForOrderDetailsListeners { public void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { orderService.changeFieldState(view, OrderFieldsLCNFO.OWN_LINE_CHANGEOVER, OrderFieldsLCNFO.OWN_LINE_CHANGEOVER_DURATION); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | LineChangeoverNormsForOrderDetailsListeners { public void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { orderService.changeFieldState(view, OrderFieldsLCNFO.OWN_LINE_CHANGEOVER, OrderFieldsLCNFO.OWN_LINE_CHANGEOVER_DURATION); } final void showPreviousOrder(final ViewDefinitionState view, final ComponentState componentState, final String[] args); final void showBestFittingLineChangeoverNorm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForGroup(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void showLineChangeoverNormForTechnology(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); final void checkIfOrderHasCorrectStateAndIsPrevious(final ViewDefinitionState view,
final ComponentState componentState, final String[] args); final void fillPreviousOrderForm(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); void showOwnLineChangeoverDurationField(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldntShowChangeoverIfOrderIdIsNull() { given(componentState.getFieldValue()).willReturn(null); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; orderDetailsListenersLCNFO.showChangeover(view, componentState, null); verify(view, never()).redirectTo(url, false, true, parameters); } | public final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args) { Long orderId = (Long) componentState.getFieldValue(); if (orderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", orderId); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; viewState.redirectTo(url, false, true, parameters); } | OrderDetailsListenersLCNFO { public final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args) { Long orderId = (Long) componentState.getFieldValue(); if (orderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", orderId); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; viewState.redirectTo(url, false, true, parameters); } } | OrderDetailsListenersLCNFO { public final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args) { Long orderId = (Long) componentState.getFieldValue(); if (orderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", orderId); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; viewState.redirectTo(url, false, true, parameters); } } | OrderDetailsListenersLCNFO { public final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args) { Long orderId = (Long) componentState.getFieldValue(); if (orderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", orderId); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; viewState.redirectTo(url, false, true, parameters); } final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args); } | OrderDetailsListenersLCNFO { public final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args) { Long orderId = (Long) componentState.getFieldValue(); if (orderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", orderId); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; viewState.redirectTo(url, false, true, parameters); } final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args); } |
@Test public void shouldShowChangeoverIfOrderIdIsntNull() { given(componentState.getFieldValue()).willReturn(L_ID); parameters.put("form.id", L_ID); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; orderDetailsListenersLCNFO.showChangeover(view, componentState, null); verify(view).redirectTo(url, false, true, parameters); } | public final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args) { Long orderId = (Long) componentState.getFieldValue(); if (orderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", orderId); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; viewState.redirectTo(url, false, true, parameters); } | OrderDetailsListenersLCNFO { public final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args) { Long orderId = (Long) componentState.getFieldValue(); if (orderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", orderId); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; viewState.redirectTo(url, false, true, parameters); } } | OrderDetailsListenersLCNFO { public final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args) { Long orderId = (Long) componentState.getFieldValue(); if (orderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", orderId); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; viewState.redirectTo(url, false, true, parameters); } } | OrderDetailsListenersLCNFO { public final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args) { Long orderId = (Long) componentState.getFieldValue(); if (orderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", orderId); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; viewState.redirectTo(url, false, true, parameters); } final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args); } | OrderDetailsListenersLCNFO { public final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args) { Long orderId = (Long) componentState.getFieldValue(); if (orderId == null) { return; } Map<String, Object> parameters = Maps.newHashMap(); parameters.put("form.id", orderId); String url = "/page/lineChangeoverNormsForOrders/lineChangeoverNormsForOrderDetails.html"; viewState.redirectTo(url, false, true, parameters); } final void showChangeover(final ViewDefinitionState viewState, final ComponentState componentState, final String[] args); } |
@Test public void shouldReturnFalseWhenPreviousOrderIsNotCorrect() { given(lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)).willReturn( false); boolean result = orderModelValidatorsLCNFO.checkIfOrderHasCorrectStateAndIsPrevious(orderDD, order); assertFalse(result); verify(order).addError(Mockito.eq(orderDD.getField(PREVIOUS_ORDER)), Mockito.anyString()); } | public final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order) { Entity previousOrderDB = order.getBelongsToField(OrderFieldsLCNFO.PREVIOUS_ORDER); Entity orderDB = order.getBelongsToField(OrderFieldsLCNFO.ORDER); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)) { order.addError(orderDD.getField(OrderFieldsLCNFO.PREVIOUS_ORDER), "orders.order.previousOrder.message.orderIsIncorrect"); return false; } return true; } | OrderModelValidatorsLCNFO { public final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order) { Entity previousOrderDB = order.getBelongsToField(OrderFieldsLCNFO.PREVIOUS_ORDER); Entity orderDB = order.getBelongsToField(OrderFieldsLCNFO.ORDER); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)) { order.addError(orderDD.getField(OrderFieldsLCNFO.PREVIOUS_ORDER), "orders.order.previousOrder.message.orderIsIncorrect"); return false; } return true; } } | OrderModelValidatorsLCNFO { public final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order) { Entity previousOrderDB = order.getBelongsToField(OrderFieldsLCNFO.PREVIOUS_ORDER); Entity orderDB = order.getBelongsToField(OrderFieldsLCNFO.ORDER); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)) { order.addError(orderDD.getField(OrderFieldsLCNFO.PREVIOUS_ORDER), "orders.order.previousOrder.message.orderIsIncorrect"); return false; } return true; } } | OrderModelValidatorsLCNFO { public final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order) { Entity previousOrderDB = order.getBelongsToField(OrderFieldsLCNFO.PREVIOUS_ORDER); Entity orderDB = order.getBelongsToField(OrderFieldsLCNFO.ORDER); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)) { order.addError(orderDD.getField(OrderFieldsLCNFO.PREVIOUS_ORDER), "orders.order.previousOrder.message.orderIsIncorrect"); return false; } return true; } final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order); } | OrderModelValidatorsLCNFO { public final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order) { Entity previousOrderDB = order.getBelongsToField(OrderFieldsLCNFO.PREVIOUS_ORDER); Entity orderDB = order.getBelongsToField(OrderFieldsLCNFO.ORDER); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)) { order.addError(orderDD.getField(OrderFieldsLCNFO.PREVIOUS_ORDER), "orders.order.previousOrder.message.orderIsIncorrect"); return false; } return true; } final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order); } |
@Test public void shouldReturnTrueWhenPreviousOrderIsCorrect() { given(lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)).willReturn( true); boolean result = orderModelValidatorsLCNFO.checkIfOrderHasCorrectStateAndIsPrevious(orderDD, order); assertTrue(result); verify(order, never()).addError(Mockito.eq(orderDD.getField(PREVIOUS_ORDER)), Mockito.anyString()); } | public final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order) { Entity previousOrderDB = order.getBelongsToField(OrderFieldsLCNFO.PREVIOUS_ORDER); Entity orderDB = order.getBelongsToField(OrderFieldsLCNFO.ORDER); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)) { order.addError(orderDD.getField(OrderFieldsLCNFO.PREVIOUS_ORDER), "orders.order.previousOrder.message.orderIsIncorrect"); return false; } return true; } | OrderModelValidatorsLCNFO { public final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order) { Entity previousOrderDB = order.getBelongsToField(OrderFieldsLCNFO.PREVIOUS_ORDER); Entity orderDB = order.getBelongsToField(OrderFieldsLCNFO.ORDER); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)) { order.addError(orderDD.getField(OrderFieldsLCNFO.PREVIOUS_ORDER), "orders.order.previousOrder.message.orderIsIncorrect"); return false; } return true; } } | OrderModelValidatorsLCNFO { public final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order) { Entity previousOrderDB = order.getBelongsToField(OrderFieldsLCNFO.PREVIOUS_ORDER); Entity orderDB = order.getBelongsToField(OrderFieldsLCNFO.ORDER); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)) { order.addError(orderDD.getField(OrderFieldsLCNFO.PREVIOUS_ORDER), "orders.order.previousOrder.message.orderIsIncorrect"); return false; } return true; } } | OrderModelValidatorsLCNFO { public final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order) { Entity previousOrderDB = order.getBelongsToField(OrderFieldsLCNFO.PREVIOUS_ORDER); Entity orderDB = order.getBelongsToField(OrderFieldsLCNFO.ORDER); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)) { order.addError(orderDD.getField(OrderFieldsLCNFO.PREVIOUS_ORDER), "orders.order.previousOrder.message.orderIsIncorrect"); return false; } return true; } final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order); } | OrderModelValidatorsLCNFO { public final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order) { Entity previousOrderDB = order.getBelongsToField(OrderFieldsLCNFO.PREVIOUS_ORDER); Entity orderDB = order.getBelongsToField(OrderFieldsLCNFO.ORDER); if (!lineChangeoverNormsForOrdersService.previousOrderEndsBeforeOrIsWithdrawed(previousOrderDB, orderDB)) { order.addError(orderDD.getField(OrderFieldsLCNFO.PREVIOUS_ORDER), "orders.order.previousOrder.message.orderIsIncorrect"); return false; } return true; } final boolean checkIfOrderHasCorrectStateAndIsPrevious(final DataDefinition orderDD, final Entity order); } |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.