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 shouldClearOrderFieldsOnCopy() throws Exception { Date startDate = new Date(); Date finishDate = new Date(); stubDateField(order, OrderFields.START_DATE, startDate); stubDateField(order, OrderFields.FINISH_DATE, finishDate); orderHooks.clearOrSetSpecyfiedValueOrderFieldsOnCopy(orderDD, order); verify(order).setField(OrderFields.STATE, OrderState.PENDING.getStringValue()); verify(order).setField(OrderFields.EFFECTIVE_DATE_TO, null); verify(order).setField(OrderFields.EFFECTIVE_DATE_FROM, null); verify(order).setField(OrderFields.CORRECTED_DATE_FROM, null); verify(order).setField(OrderFields.CORRECTED_DATE_TO, null); verify(order).setField(OrderFields.DONE_QUANTITY, null); verify(order).setField(OrderFields.DATE_FROM, startDate); verify(order).setField(OrderFields.DATE_TO, finishDate); } | public void clearOrSetSpecyfiedValueOrderFieldsOnCopy(final DataDefinition orderDD, final Entity order) { order.setField(OrderFields.STATE, OrderState.PENDING.getStringValue()); order.setField(OrderFields.EFFECTIVE_DATE_TO, null); order.setField(OrderFields.EFFECTIVE_DATE_FROM, null); order.setField(OrderFields.CORRECTED_DATE_FROM, null); order.setField(OrderFields.CORRECTED_DATE_TO, null); order.setField(OrderFields.DATE_FROM, order.getDateField(OrderFields.START_DATE)); order.setField(OrderFields.DATE_TO, order.getDateField(OrderFields.FINISH_DATE)); order.setField(OrderFields.DONE_QUANTITY, null); order.setField(OrderFields.WASTES_QUANTITY, null); order.setField(OrderFields.EXTERNAL_NUMBER, null); order.setField(OrderFields.EXTERNAL_SYNCHRONIZED, true); order.setField(OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, null); order.setField(OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, null); order.setField(OrderFields.COMMENT_REASON_DEVIATION_EFFECTIVE_END, null); order.setField(OrderFields.COMMENT_REASON_DEVIATION_EFFECTIVE_START, null); order.setField(OrderFields.COMMENT_REASON_TYPE_DEVIATIONS_QUANTITY, null); } | OrderHooks { public void clearOrSetSpecyfiedValueOrderFieldsOnCopy(final DataDefinition orderDD, final Entity order) { order.setField(OrderFields.STATE, OrderState.PENDING.getStringValue()); order.setField(OrderFields.EFFECTIVE_DATE_TO, null); order.setField(OrderFields.EFFECTIVE_DATE_FROM, null); order.setField(OrderFields.CORRECTED_DATE_FROM, null); order.setField(OrderFields.CORRECTED_DATE_TO, null); order.setField(OrderFields.DATE_FROM, order.getDateField(OrderFields.START_DATE)); order.setField(OrderFields.DATE_TO, order.getDateField(OrderFields.FINISH_DATE)); order.setField(OrderFields.DONE_QUANTITY, null); order.setField(OrderFields.WASTES_QUANTITY, null); order.setField(OrderFields.EXTERNAL_NUMBER, null); order.setField(OrderFields.EXTERNAL_SYNCHRONIZED, true); order.setField(OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, null); order.setField(OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, null); order.setField(OrderFields.COMMENT_REASON_DEVIATION_EFFECTIVE_END, null); order.setField(OrderFields.COMMENT_REASON_DEVIATION_EFFECTIVE_START, null); order.setField(OrderFields.COMMENT_REASON_TYPE_DEVIATIONS_QUANTITY, null); } } | OrderHooks { public void clearOrSetSpecyfiedValueOrderFieldsOnCopy(final DataDefinition orderDD, final Entity order) { order.setField(OrderFields.STATE, OrderState.PENDING.getStringValue()); order.setField(OrderFields.EFFECTIVE_DATE_TO, null); order.setField(OrderFields.EFFECTIVE_DATE_FROM, null); order.setField(OrderFields.CORRECTED_DATE_FROM, null); order.setField(OrderFields.CORRECTED_DATE_TO, null); order.setField(OrderFields.DATE_FROM, order.getDateField(OrderFields.START_DATE)); order.setField(OrderFields.DATE_TO, order.getDateField(OrderFields.FINISH_DATE)); order.setField(OrderFields.DONE_QUANTITY, null); order.setField(OrderFields.WASTES_QUANTITY, null); order.setField(OrderFields.EXTERNAL_NUMBER, null); order.setField(OrderFields.EXTERNAL_SYNCHRONIZED, true); order.setField(OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, null); order.setField(OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, null); order.setField(OrderFields.COMMENT_REASON_DEVIATION_EFFECTIVE_END, null); order.setField(OrderFields.COMMENT_REASON_DEVIATION_EFFECTIVE_START, null); order.setField(OrderFields.COMMENT_REASON_TYPE_DEVIATIONS_QUANTITY, null); } } | OrderHooks { public void clearOrSetSpecyfiedValueOrderFieldsOnCopy(final DataDefinition orderDD, final Entity order) { order.setField(OrderFields.STATE, OrderState.PENDING.getStringValue()); order.setField(OrderFields.EFFECTIVE_DATE_TO, null); order.setField(OrderFields.EFFECTIVE_DATE_FROM, null); order.setField(OrderFields.CORRECTED_DATE_FROM, null); order.setField(OrderFields.CORRECTED_DATE_TO, null); order.setField(OrderFields.DATE_FROM, order.getDateField(OrderFields.START_DATE)); order.setField(OrderFields.DATE_TO, order.getDateField(OrderFields.FINISH_DATE)); order.setField(OrderFields.DONE_QUANTITY, null); order.setField(OrderFields.WASTES_QUANTITY, null); order.setField(OrderFields.EXTERNAL_NUMBER, null); order.setField(OrderFields.EXTERNAL_SYNCHRONIZED, true); order.setField(OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, null); order.setField(OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, null); order.setField(OrderFields.COMMENT_REASON_DEVIATION_EFFECTIVE_END, null); order.setField(OrderFields.COMMENT_REASON_DEVIATION_EFFECTIVE_START, null); order.setField(OrderFields.COMMENT_REASON_TYPE_DEVIATIONS_QUANTITY, null); } boolean validatesWith(final DataDefinition orderDD, final Entity order); void onCreate(final DataDefinition orderDD, final Entity order); void onSave(final DataDefinition orderDD, final Entity order); void onCopy(final DataDefinition orderDD, final Entity order); void setRemainingQuantity(final Entity order); void onDelete(final DataDefinition orderDD, final Entity order); boolean setDateChanged(final DataDefinition dataDefinition, final FieldDefinition fieldDefinition, final Entity order,
final Object fieldOldValue, final Object fieldNewValue); void setInitialState(final DataDefinition orderDD, final Entity order); boolean checkOrderDates(final DataDefinition orderDD, final Entity order); boolean checkOrderPlannedQuantity(final DataDefinition orderDD, final Entity order); void copyStartDate(final DataDefinition orderDD, final Entity order); void copyEndDate(final DataDefinition orderDD, final Entity order); boolean validateDates(final DataDefinition orderDD, final Entity order); void copyProductQuantity(final DataDefinition orderDD, final Entity order); void onCorrectingTheRequestedVolume(final DataDefinition orderDD, final Entity order); boolean neededWhenCorrectingTheRequestedVolume(); void setCommissionedPlannedQuantity(final DataDefinition orderDD, final Entity order); void setProductQuantity(final DataDefinition orderDD, final Entity order); void clearOrSetSpecyfiedValueOrderFieldsOnCopy(final DataDefinition orderDD, final Entity order); } | OrderHooks { public void clearOrSetSpecyfiedValueOrderFieldsOnCopy(final DataDefinition orderDD, final Entity order) { order.setField(OrderFields.STATE, OrderState.PENDING.getStringValue()); order.setField(OrderFields.EFFECTIVE_DATE_TO, null); order.setField(OrderFields.EFFECTIVE_DATE_FROM, null); order.setField(OrderFields.CORRECTED_DATE_FROM, null); order.setField(OrderFields.CORRECTED_DATE_TO, null); order.setField(OrderFields.DATE_FROM, order.getDateField(OrderFields.START_DATE)); order.setField(OrderFields.DATE_TO, order.getDateField(OrderFields.FINISH_DATE)); order.setField(OrderFields.DONE_QUANTITY, null); order.setField(OrderFields.WASTES_QUANTITY, null); order.setField(OrderFields.EXTERNAL_NUMBER, null); order.setField(OrderFields.EXTERNAL_SYNCHRONIZED, true); order.setField(OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, null); order.setField(OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, null); order.setField(OrderFields.COMMENT_REASON_DEVIATION_EFFECTIVE_END, null); order.setField(OrderFields.COMMENT_REASON_DEVIATION_EFFECTIVE_START, null); order.setField(OrderFields.COMMENT_REASON_TYPE_DEVIATIONS_QUANTITY, null); } boolean validatesWith(final DataDefinition orderDD, final Entity order); void onCreate(final DataDefinition orderDD, final Entity order); void onSave(final DataDefinition orderDD, final Entity order); void onCopy(final DataDefinition orderDD, final Entity order); void setRemainingQuantity(final Entity order); void onDelete(final DataDefinition orderDD, final Entity order); boolean setDateChanged(final DataDefinition dataDefinition, final FieldDefinition fieldDefinition, final Entity order,
final Object fieldOldValue, final Object fieldNewValue); void setInitialState(final DataDefinition orderDD, final Entity order); boolean checkOrderDates(final DataDefinition orderDD, final Entity order); boolean checkOrderPlannedQuantity(final DataDefinition orderDD, final Entity order); void copyStartDate(final DataDefinition orderDD, final Entity order); void copyEndDate(final DataDefinition orderDD, final Entity order); boolean validateDates(final DataDefinition orderDD, final Entity order); void copyProductQuantity(final DataDefinition orderDD, final Entity order); void onCorrectingTheRequestedVolume(final DataDefinition orderDD, final Entity order); boolean neededWhenCorrectingTheRequestedVolume(); void setCommissionedPlannedQuantity(final DataDefinition orderDD, final Entity order); void setProductQuantity(final DataDefinition orderDD, final Entity order); void clearOrSetSpecyfiedValueOrderFieldsOnCopy(final DataDefinition orderDD, final Entity order); static final String L_TYPE_OF_PRODUCTION_RECORDING; static final String BACKUP_TECHNOLOGY_PREFIX; static final long SECOND_MILLIS; static final List<String> sourceDateFields; } |
@Test public final void shouldNotSetCopyOfTechnology() { given(orderService.isPktEnabled()).willReturn(true); stubBelongsToField(order, OrderFields.TECHNOLOGY, null); orderHooks.setCopyOfTechnology(order); verify(order, never()).setField(eq(OrderFields.TECHNOLOGY), notNull()); } | void setCopyOfTechnology(final Entity order) { if (orderService.isPktEnabled()) { order.setField(OrderFields.TECHNOLOGY, copyTechnology(order).orNull()); } else { Entity prototypeTechnology = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE); if (prototypeTechnology != null && TechnologyState.of(prototypeTechnology).compareTo(TechnologyState.ACCEPTED) == 0) { order.setField(OrderFields.TECHNOLOGY, prototypeTechnology); } else { order.setField(OrderFields.TECHNOLOGY, null); order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null); } } } | OrderHooks { void setCopyOfTechnology(final Entity order) { if (orderService.isPktEnabled()) { order.setField(OrderFields.TECHNOLOGY, copyTechnology(order).orNull()); } else { Entity prototypeTechnology = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE); if (prototypeTechnology != null && TechnologyState.of(prototypeTechnology).compareTo(TechnologyState.ACCEPTED) == 0) { order.setField(OrderFields.TECHNOLOGY, prototypeTechnology); } else { order.setField(OrderFields.TECHNOLOGY, null); order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null); } } } } | OrderHooks { void setCopyOfTechnology(final Entity order) { if (orderService.isPktEnabled()) { order.setField(OrderFields.TECHNOLOGY, copyTechnology(order).orNull()); } else { Entity prototypeTechnology = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE); if (prototypeTechnology != null && TechnologyState.of(prototypeTechnology).compareTo(TechnologyState.ACCEPTED) == 0) { order.setField(OrderFields.TECHNOLOGY, prototypeTechnology); } else { order.setField(OrderFields.TECHNOLOGY, null); order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null); } } } } | OrderHooks { void setCopyOfTechnology(final Entity order) { if (orderService.isPktEnabled()) { order.setField(OrderFields.TECHNOLOGY, copyTechnology(order).orNull()); } else { Entity prototypeTechnology = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE); if (prototypeTechnology != null && TechnologyState.of(prototypeTechnology).compareTo(TechnologyState.ACCEPTED) == 0) { order.setField(OrderFields.TECHNOLOGY, prototypeTechnology); } else { order.setField(OrderFields.TECHNOLOGY, null); order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null); } } } boolean validatesWith(final DataDefinition orderDD, final Entity order); void onCreate(final DataDefinition orderDD, final Entity order); void onSave(final DataDefinition orderDD, final Entity order); void onCopy(final DataDefinition orderDD, final Entity order); void setRemainingQuantity(final Entity order); void onDelete(final DataDefinition orderDD, final Entity order); boolean setDateChanged(final DataDefinition dataDefinition, final FieldDefinition fieldDefinition, final Entity order,
final Object fieldOldValue, final Object fieldNewValue); void setInitialState(final DataDefinition orderDD, final Entity order); boolean checkOrderDates(final DataDefinition orderDD, final Entity order); boolean checkOrderPlannedQuantity(final DataDefinition orderDD, final Entity order); void copyStartDate(final DataDefinition orderDD, final Entity order); void copyEndDate(final DataDefinition orderDD, final Entity order); boolean validateDates(final DataDefinition orderDD, final Entity order); void copyProductQuantity(final DataDefinition orderDD, final Entity order); void onCorrectingTheRequestedVolume(final DataDefinition orderDD, final Entity order); boolean neededWhenCorrectingTheRequestedVolume(); void setCommissionedPlannedQuantity(final DataDefinition orderDD, final Entity order); void setProductQuantity(final DataDefinition orderDD, final Entity order); void clearOrSetSpecyfiedValueOrderFieldsOnCopy(final DataDefinition orderDD, final Entity order); } | OrderHooks { void setCopyOfTechnology(final Entity order) { if (orderService.isPktEnabled()) { order.setField(OrderFields.TECHNOLOGY, copyTechnology(order).orNull()); } else { Entity prototypeTechnology = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE); if (prototypeTechnology != null && TechnologyState.of(prototypeTechnology).compareTo(TechnologyState.ACCEPTED) == 0) { order.setField(OrderFields.TECHNOLOGY, prototypeTechnology); } else { order.setField(OrderFields.TECHNOLOGY, null); order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null); } } } boolean validatesWith(final DataDefinition orderDD, final Entity order); void onCreate(final DataDefinition orderDD, final Entity order); void onSave(final DataDefinition orderDD, final Entity order); void onCopy(final DataDefinition orderDD, final Entity order); void setRemainingQuantity(final Entity order); void onDelete(final DataDefinition orderDD, final Entity order); boolean setDateChanged(final DataDefinition dataDefinition, final FieldDefinition fieldDefinition, final Entity order,
final Object fieldOldValue, final Object fieldNewValue); void setInitialState(final DataDefinition orderDD, final Entity order); boolean checkOrderDates(final DataDefinition orderDD, final Entity order); boolean checkOrderPlannedQuantity(final DataDefinition orderDD, final Entity order); void copyStartDate(final DataDefinition orderDD, final Entity order); void copyEndDate(final DataDefinition orderDD, final Entity order); boolean validateDates(final DataDefinition orderDD, final Entity order); void copyProductQuantity(final DataDefinition orderDD, final Entity order); void onCorrectingTheRequestedVolume(final DataDefinition orderDD, final Entity order); boolean neededWhenCorrectingTheRequestedVolume(); void setCommissionedPlannedQuantity(final DataDefinition orderDD, final Entity order); void setProductQuantity(final DataDefinition orderDD, final Entity order); void clearOrSetSpecyfiedValueOrderFieldsOnCopy(final DataDefinition orderDD, final Entity order); static final String L_TYPE_OF_PRODUCTION_RECORDING; static final String BACKUP_TECHNOLOGY_PREFIX; static final long SECOND_MILLIS; static final List<String> sourceDateFields; } |
@Test public final void shouldSetCopyOfTechnology() { final String generatedNumber = "NEWLY GENERATED NUM"; given(technologyServiceO.generateNumberForTechnologyInOrder(eq(order), any(Entity.class))).willReturn(generatedNumber); given(orderService.isPktEnabled()).willReturn(true); DataDefinition technologyDD = mock(DataDefinition.class); Entity technology = mockEntity(technologyDD); Entity technologyCopy = mockEntity(technologyDD); given(technologyDD.copy(any(Long[].class))).willReturn(ImmutableList.of(technologyCopy)); given(technologyDD.save(any(Entity.class))).willAnswer(new Answer<Entity>() { @Override public Entity answer(final InvocationOnMock invocation) throws Throwable { return (Entity) invocation.getArguments()[0]; } }); stubBelongsToField(order, OrderFields.TECHNOLOGY, technology); stubStringField(order, OrderFields.ORDER_TYPE, OrderType.WITH_OWN_TECHNOLOGY.getStringValue()); orderHooks.setCopyOfTechnology(order); verify(order).setField(OrderFields.TECHNOLOGY, technologyCopy); verify(order, never()).setField(OrderFields.TECHNOLOGY, technology); verify(technologyCopy).setField(TechnologyFields.NUMBER, generatedNumber); } | void setCopyOfTechnology(final Entity order) { if (orderService.isPktEnabled()) { order.setField(OrderFields.TECHNOLOGY, copyTechnology(order).orNull()); } else { Entity prototypeTechnology = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE); if (prototypeTechnology != null && TechnologyState.of(prototypeTechnology).compareTo(TechnologyState.ACCEPTED) == 0) { order.setField(OrderFields.TECHNOLOGY, prototypeTechnology); } else { order.setField(OrderFields.TECHNOLOGY, null); order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null); } } } | OrderHooks { void setCopyOfTechnology(final Entity order) { if (orderService.isPktEnabled()) { order.setField(OrderFields.TECHNOLOGY, copyTechnology(order).orNull()); } else { Entity prototypeTechnology = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE); if (prototypeTechnology != null && TechnologyState.of(prototypeTechnology).compareTo(TechnologyState.ACCEPTED) == 0) { order.setField(OrderFields.TECHNOLOGY, prototypeTechnology); } else { order.setField(OrderFields.TECHNOLOGY, null); order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null); } } } } | OrderHooks { void setCopyOfTechnology(final Entity order) { if (orderService.isPktEnabled()) { order.setField(OrderFields.TECHNOLOGY, copyTechnology(order).orNull()); } else { Entity prototypeTechnology = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE); if (prototypeTechnology != null && TechnologyState.of(prototypeTechnology).compareTo(TechnologyState.ACCEPTED) == 0) { order.setField(OrderFields.TECHNOLOGY, prototypeTechnology); } else { order.setField(OrderFields.TECHNOLOGY, null); order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null); } } } } | OrderHooks { void setCopyOfTechnology(final Entity order) { if (orderService.isPktEnabled()) { order.setField(OrderFields.TECHNOLOGY, copyTechnology(order).orNull()); } else { Entity prototypeTechnology = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE); if (prototypeTechnology != null && TechnologyState.of(prototypeTechnology).compareTo(TechnologyState.ACCEPTED) == 0) { order.setField(OrderFields.TECHNOLOGY, prototypeTechnology); } else { order.setField(OrderFields.TECHNOLOGY, null); order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null); } } } boolean validatesWith(final DataDefinition orderDD, final Entity order); void onCreate(final DataDefinition orderDD, final Entity order); void onSave(final DataDefinition orderDD, final Entity order); void onCopy(final DataDefinition orderDD, final Entity order); void setRemainingQuantity(final Entity order); void onDelete(final DataDefinition orderDD, final Entity order); boolean setDateChanged(final DataDefinition dataDefinition, final FieldDefinition fieldDefinition, final Entity order,
final Object fieldOldValue, final Object fieldNewValue); void setInitialState(final DataDefinition orderDD, final Entity order); boolean checkOrderDates(final DataDefinition orderDD, final Entity order); boolean checkOrderPlannedQuantity(final DataDefinition orderDD, final Entity order); void copyStartDate(final DataDefinition orderDD, final Entity order); void copyEndDate(final DataDefinition orderDD, final Entity order); boolean validateDates(final DataDefinition orderDD, final Entity order); void copyProductQuantity(final DataDefinition orderDD, final Entity order); void onCorrectingTheRequestedVolume(final DataDefinition orderDD, final Entity order); boolean neededWhenCorrectingTheRequestedVolume(); void setCommissionedPlannedQuantity(final DataDefinition orderDD, final Entity order); void setProductQuantity(final DataDefinition orderDD, final Entity order); void clearOrSetSpecyfiedValueOrderFieldsOnCopy(final DataDefinition orderDD, final Entity order); } | OrderHooks { void setCopyOfTechnology(final Entity order) { if (orderService.isPktEnabled()) { order.setField(OrderFields.TECHNOLOGY, copyTechnology(order).orNull()); } else { Entity prototypeTechnology = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE); if (prototypeTechnology != null && TechnologyState.of(prototypeTechnology).compareTo(TechnologyState.ACCEPTED) == 0) { order.setField(OrderFields.TECHNOLOGY, prototypeTechnology); } else { order.setField(OrderFields.TECHNOLOGY, null); order.setField(OrderFields.TECHNOLOGY_PROTOTYPE, null); } } } boolean validatesWith(final DataDefinition orderDD, final Entity order); void onCreate(final DataDefinition orderDD, final Entity order); void onSave(final DataDefinition orderDD, final Entity order); void onCopy(final DataDefinition orderDD, final Entity order); void setRemainingQuantity(final Entity order); void onDelete(final DataDefinition orderDD, final Entity order); boolean setDateChanged(final DataDefinition dataDefinition, final FieldDefinition fieldDefinition, final Entity order,
final Object fieldOldValue, final Object fieldNewValue); void setInitialState(final DataDefinition orderDD, final Entity order); boolean checkOrderDates(final DataDefinition orderDD, final Entity order); boolean checkOrderPlannedQuantity(final DataDefinition orderDD, final Entity order); void copyStartDate(final DataDefinition orderDD, final Entity order); void copyEndDate(final DataDefinition orderDD, final Entity order); boolean validateDates(final DataDefinition orderDD, final Entity order); void copyProductQuantity(final DataDefinition orderDD, final Entity order); void onCorrectingTheRequestedVolume(final DataDefinition orderDD, final Entity order); boolean neededWhenCorrectingTheRequestedVolume(); void setCommissionedPlannedQuantity(final DataDefinition orderDD, final Entity order); void setProductQuantity(final DataDefinition orderDD, final Entity order); void clearOrSetSpecyfiedValueOrderFieldsOnCopy(final DataDefinition orderDD, final Entity order); static final String L_TYPE_OF_PRODUCTION_RECORDING; static final String BACKUP_TECHNOLOGY_PREFIX; static final long SECOND_MILLIS; static final List<String> sourceDateFields; } |
@Test public void shouldSetAndDisableState() throws Exception { given(view.getComponentByReference(L_FORM)).willReturn(orderForm); given(orderForm.getEntityId()).willReturn(null); orderDetailsHooks.setAndDisableState(view); verify(stateField).setEnabled(false); verify(stateField).setFieldValue(OrderState.PENDING.getStringValue()); } | public void setAndDisableState(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(OrderFields.STATE); stateField.setEnabled(false); if (orderForm.getEntityId() != null) { return; } stateField.setFieldValue(OrderState.PENDING.getStringValue()); } | OrderDetailsHooks { public void setAndDisableState(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(OrderFields.STATE); stateField.setEnabled(false); if (orderForm.getEntityId() != null) { return; } stateField.setFieldValue(OrderState.PENDING.getStringValue()); } } | OrderDetailsHooks { public void setAndDisableState(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(OrderFields.STATE); stateField.setEnabled(false); if (orderForm.getEntityId() != null) { return; } stateField.setFieldValue(OrderState.PENDING.getStringValue()); } } | OrderDetailsHooks { public void setAndDisableState(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(OrderFields.STATE); stateField.setEnabled(false); if (orderForm.getEntityId() != null) { return; } stateField.setFieldValue(OrderState.PENDING.getStringValue()); } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void setAndDisableState(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(OrderFields.STATE); stateField.setEnabled(false); if (orderForm.getEntityId() != null) { return; } stateField.setFieldValue(OrderState.PENDING.getStringValue()); } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldReturnFalseWhenCheckMaterialFlowComponentUniquenessAndMaterialsInLocationOrLocationIsNull() { given(materialsInLocationComponent.getBelongsToField(LOCATION)).willReturn(null); given(materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION)).willReturn(null); boolean result = materialsInLocationComponentModelValidators.checkMaterialFlowComponentUniqueness( materialsInLocationComponentDD, materialsInLocationComponent); assertFalse(result); } | public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD,
final Entity materialsInLocationComponent); } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD,
final Entity materialsInLocationComponent); } |
@Test public void shouldDisableState() throws Exception { given(view.getComponentByReference(L_FORM)).willReturn(orderForm); given(orderForm.getEntityId()).willReturn(L_ID); orderDetailsHooks.setAndDisableState(view); verify(stateField).setEnabled(false); verify(stateField, never()).setFieldValue(OrderState.PENDING.getStringValue()); } | public void setAndDisableState(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(OrderFields.STATE); stateField.setEnabled(false); if (orderForm.getEntityId() != null) { return; } stateField.setFieldValue(OrderState.PENDING.getStringValue()); } | OrderDetailsHooks { public void setAndDisableState(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(OrderFields.STATE); stateField.setEnabled(false); if (orderForm.getEntityId() != null) { return; } stateField.setFieldValue(OrderState.PENDING.getStringValue()); } } | OrderDetailsHooks { public void setAndDisableState(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(OrderFields.STATE); stateField.setEnabled(false); if (orderForm.getEntityId() != null) { return; } stateField.setFieldValue(OrderState.PENDING.getStringValue()); } } | OrderDetailsHooks { public void setAndDisableState(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(OrderFields.STATE); stateField.setEnabled(false); if (orderForm.getEntityId() != null) { return; } stateField.setFieldValue(OrderState.PENDING.getStringValue()); } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void setAndDisableState(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); FieldComponent stateField = (FieldComponent) view.getComponentByReference(OrderFields.STATE); stateField.setEnabled(false); if (orderForm.getEntityId() != null) { return; } stateField.setFieldValue(OrderState.PENDING.getStringValue()); } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldGenerateOrderNumber() throws Exception { orderDetailsHooks.generateOrderNumber(view); verify(numberGeneratorService).generateAndInsertNumber(view, OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, L_FORM, OrderFields.NUMBER); } | public void generateOrderNumber(final ViewDefinitionState view) { numberGeneratorService.generateAndInsertNumber(view, OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, L_FORM, OrderFields.NUMBER); } | OrderDetailsHooks { public void generateOrderNumber(final ViewDefinitionState view) { numberGeneratorService.generateAndInsertNumber(view, OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, L_FORM, OrderFields.NUMBER); } } | OrderDetailsHooks { public void generateOrderNumber(final ViewDefinitionState view) { numberGeneratorService.generateAndInsertNumber(view, OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, L_FORM, OrderFields.NUMBER); } } | OrderDetailsHooks { public void generateOrderNumber(final ViewDefinitionState view) { numberGeneratorService.generateAndInsertNumber(view, OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, L_FORM, OrderFields.NUMBER); } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void generateOrderNumber(final ViewDefinitionState view) { numberGeneratorService.generateAndInsertNumber(view, OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, L_FORM, OrderFields.NUMBER); } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldNotFillDefaultTechnologyIfThereIsNoProduct() throws Exception { given(view.getComponentByReference(OrderFields.PRODUCT)).willReturn(productLookup); given(view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY)).willReturn(defaultTechnologyField); given(productLookup.getEntity()).willReturn(null); orderDetailsHooks.fillDefaultTechnology(view); verify(defaultTechnologyField, never()).setFieldValue(anyString()); } | public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldNotFillDefaultTechnologyIfThereIsNoDefaultTechnology() throws Exception { given(view.getComponentByReference(OrderFields.PRODUCT)).willReturn(productLookup); given(view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY)).willReturn(defaultTechnologyField); given(productLookup.getEntity()).willReturn(product); given(technologyServiceO.getDefaultTechnology(product)).willReturn(null); orderDetailsHooks.fillDefaultTechnology(view); verify(defaultTechnologyField, never()).setFieldValue(Mockito.anyString()); } | public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldFillDefaultTechnology() throws Exception { given(view.getComponentByReference(OrderFields.PRODUCT)).willReturn(productLookup); given(view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY)).willReturn(defaultTechnologyField); given(productLookup.getEntity()).willReturn(product); given(technologyServiceO.getDefaultTechnology(product)).willReturn(defaultTechnology); given(defaultTechnology.getId()).willReturn(1L); orderDetailsHooks.fillDefaultTechnology(view); verify(defaultTechnologyField).setFieldValue(anyString()); } | public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void fillDefaultTechnology(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); Entity product = productLookup.getEntity(); if (product != null) { Entity defaultTechnology = technologyServiceO.getDefaultTechnology(product); if (defaultTechnology != null) { String defaultTechnologyValue = expressionService.getValue(defaultTechnology, "#number + ' - ' + #name", view.getLocale()); defaultTechnologyField.setFieldValue(defaultTechnologyValue); } } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldDisableTechnologyIfThereIsNoProduct() throws Exception { given(view.getComponentByReference(OrderFields.PRODUCT)).willReturn(productLookup); given(view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY)).willReturn(defaultTechnologyField); given(view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE)).willReturn(technologyLookup); given(view.getComponentByReference(OrderFields.PLANNED_QUANTITY)).willReturn(plannedQuantityField); given(productLookup.getEntity()).willReturn(null); orderDetailsHooks.disableTechnologiesIfProductDoesNotAny(view); verify(defaultTechnologyField).setEnabled(false); verify(technologyLookup).setRequired(false); verify(plannedQuantityField).setRequired(false); } | public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldDisableTechnologyIfProductHasNoTechnologies() throws Exception { given(view.getComponentByReference(OrderFields.PRODUCT)).willReturn(productLookup); given(view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY)).willReturn(defaultTechnologyField); given(view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE)).willReturn(technologyLookup); given(view.getComponentByReference(OrderFields.PLANNED_QUANTITY)).willReturn(plannedQuantityField); given(productLookup.getEntity()).willReturn(product); given(dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY)) .willReturn(technologyDD); given(technologyDD.find()).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.add(Mockito.any(SearchCriterion.class))).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.setMaxResults(1)).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.list()).willReturn(searchResult); given(searchResult.getTotalNumberOfEntities()).willReturn(0); orderDetailsHooks.disableTechnologiesIfProductDoesNotAny(view); verify(defaultTechnologyField).setEnabled(false); verify(technologyLookup).setRequired(false); verify(plannedQuantityField).setRequired(false); } | public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldSetTechnologyAndPlannedQuantityAsRequired() throws Exception { given(view.getComponentByReference(OrderFields.PRODUCT)).willReturn(productLookup); given(view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY)).willReturn(defaultTechnologyField); given(view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE)).willReturn(technologyLookup); given(view.getComponentByReference(OrderFields.PLANNED_QUANTITY)).willReturn(plannedQuantityField); given(productLookup.getEntity()).willReturn(product); given(productLookup.getFieldValue()).willReturn("1"); given(dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY)) .willReturn(technologyDD); given(technologyDD.find()).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.add(Mockito.any(SearchCriterion.class))).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.setMaxResults(1)).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.list()).willReturn(searchResult); given(searchResult.getTotalNumberOfEntities()).willReturn(1); orderDetailsHooks.disableTechnologiesIfProductDoesNotAny(view); verify(defaultTechnologyField).setEnabled(false); verify(technologyLookup).setRequired(true); verify(plannedQuantityField).setRequired(true); } | public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderFields.PRODUCT); LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(OrderFields.TECHNOLOGY_PROTOTYPE); FieldComponent defaultTechnologyField = (FieldComponent) view.getComponentByReference(OrderFields.DEFAULT_TECHNOLOGY); FieldComponent plannedQuantity = (FieldComponent) view.getComponentByReference("plannedQuantity"); defaultTechnologyField.setEnabled(false); if (productLookup.getFieldValue() == null || !hasAnyTechnologies(productLookup.getEntity())) { technologyLookup.setRequired(false); plannedQuantity.setRequired(false); } else { technologyLookup.setRequired(true); plannedQuantity.setRequired(true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldNotDisableFormIfOrderIsNotDone() throws Exception { given(view.getComponentByReference(L_FORM)).willReturn(orderForm); given(orderForm.getEntityId()).willReturn(L_ID); given(orderService.getOrder(L_ID)).willReturn(order); given(orderForm.getEntity()).willReturn(order); given(order.getStringField(OrderFields.STATE)).willReturn(OrderState.PENDING.getStringValue()); given(order.getBelongsToField(OrderFields.COMPANY)).willReturn(company); orderDetailsHooks.disableFieldOrderForm(view); verify(orderForm).setFormEnabled(true); } | public void disableFieldOrderForm(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); boolean disabled = false; Long orderId = orderForm.getEntityId(); if (orderId != null) { Entity order = orderService.getOrder(orderId); if (order == null) { return; } String state = order.getStringField(OrderFields.STATE); if (!OrderState.PENDING.getStringValue().equals(state)) { disabled = true; } } orderForm.setFormEnabled(!disabled); Entity order = orderForm.getEntity(); Entity company = order.getBelongsToField(OrderFields.COMPANY); LookupComponent addressLookup = (LookupComponent) view.getComponentByReference(OrderFields.ADDRESS); if (company == null) { addressLookup.setFieldValue(null); addressLookup.setEnabled(false); } else { addressLookup.setEnabled(true); } } | OrderDetailsHooks { public void disableFieldOrderForm(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); boolean disabled = false; Long orderId = orderForm.getEntityId(); if (orderId != null) { Entity order = orderService.getOrder(orderId); if (order == null) { return; } String state = order.getStringField(OrderFields.STATE); if (!OrderState.PENDING.getStringValue().equals(state)) { disabled = true; } } orderForm.setFormEnabled(!disabled); Entity order = orderForm.getEntity(); Entity company = order.getBelongsToField(OrderFields.COMPANY); LookupComponent addressLookup = (LookupComponent) view.getComponentByReference(OrderFields.ADDRESS); if (company == null) { addressLookup.setFieldValue(null); addressLookup.setEnabled(false); } else { addressLookup.setEnabled(true); } } } | OrderDetailsHooks { public void disableFieldOrderForm(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); boolean disabled = false; Long orderId = orderForm.getEntityId(); if (orderId != null) { Entity order = orderService.getOrder(orderId); if (order == null) { return; } String state = order.getStringField(OrderFields.STATE); if (!OrderState.PENDING.getStringValue().equals(state)) { disabled = true; } } orderForm.setFormEnabled(!disabled); Entity order = orderForm.getEntity(); Entity company = order.getBelongsToField(OrderFields.COMPANY); LookupComponent addressLookup = (LookupComponent) view.getComponentByReference(OrderFields.ADDRESS); if (company == null) { addressLookup.setFieldValue(null); addressLookup.setEnabled(false); } else { addressLookup.setEnabled(true); } } } | OrderDetailsHooks { public void disableFieldOrderForm(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); boolean disabled = false; Long orderId = orderForm.getEntityId(); if (orderId != null) { Entity order = orderService.getOrder(orderId); if (order == null) { return; } String state = order.getStringField(OrderFields.STATE); if (!OrderState.PENDING.getStringValue().equals(state)) { disabled = true; } } orderForm.setFormEnabled(!disabled); Entity order = orderForm.getEntity(); Entity company = order.getBelongsToField(OrderFields.COMPANY); LookupComponent addressLookup = (LookupComponent) view.getComponentByReference(OrderFields.ADDRESS); if (company == null) { addressLookup.setFieldValue(null); addressLookup.setEnabled(false); } else { addressLookup.setEnabled(true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void disableFieldOrderForm(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); boolean disabled = false; Long orderId = orderForm.getEntityId(); if (orderId != null) { Entity order = orderService.getOrder(orderId); if (order == null) { return; } String state = order.getStringField(OrderFields.STATE); if (!OrderState.PENDING.getStringValue().equals(state)) { disabled = true; } } orderForm.setFormEnabled(!disabled); Entity order = orderForm.getEntity(); Entity company = order.getBelongsToField(OrderFields.COMPANY); LookupComponent addressLookup = (LookupComponent) view.getComponentByReference(OrderFields.ADDRESS); if (company == null) { addressLookup.setFieldValue(null); addressLookup.setEnabled(false); } else { addressLookup.setEnabled(true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldNotDisableFormForDoneOrder() throws Exception { given(view.getComponentByReference(L_FORM)).willReturn(orderForm); given(orderForm.getEntityId()).willReturn(L_ID); given(orderService.getOrder(L_ID)).willReturn(order); given(order.getStringField(OrderFields.STATE)).willReturn(OrderState.COMPLETED.getStringValue()); given(order.isValid()).willReturn(true); given(orderForm.getEntity()).willReturn(order); given(order.getBelongsToField(OrderFields.COMPANY)).willReturn(company); orderDetailsHooks.disableFieldOrderForm(view); verify(orderForm).setFormEnabled(false); } | public void disableFieldOrderForm(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); boolean disabled = false; Long orderId = orderForm.getEntityId(); if (orderId != null) { Entity order = orderService.getOrder(orderId); if (order == null) { return; } String state = order.getStringField(OrderFields.STATE); if (!OrderState.PENDING.getStringValue().equals(state)) { disabled = true; } } orderForm.setFormEnabled(!disabled); Entity order = orderForm.getEntity(); Entity company = order.getBelongsToField(OrderFields.COMPANY); LookupComponent addressLookup = (LookupComponent) view.getComponentByReference(OrderFields.ADDRESS); if (company == null) { addressLookup.setFieldValue(null); addressLookup.setEnabled(false); } else { addressLookup.setEnabled(true); } } | OrderDetailsHooks { public void disableFieldOrderForm(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); boolean disabled = false; Long orderId = orderForm.getEntityId(); if (orderId != null) { Entity order = orderService.getOrder(orderId); if (order == null) { return; } String state = order.getStringField(OrderFields.STATE); if (!OrderState.PENDING.getStringValue().equals(state)) { disabled = true; } } orderForm.setFormEnabled(!disabled); Entity order = orderForm.getEntity(); Entity company = order.getBelongsToField(OrderFields.COMPANY); LookupComponent addressLookup = (LookupComponent) view.getComponentByReference(OrderFields.ADDRESS); if (company == null) { addressLookup.setFieldValue(null); addressLookup.setEnabled(false); } else { addressLookup.setEnabled(true); } } } | OrderDetailsHooks { public void disableFieldOrderForm(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); boolean disabled = false; Long orderId = orderForm.getEntityId(); if (orderId != null) { Entity order = orderService.getOrder(orderId); if (order == null) { return; } String state = order.getStringField(OrderFields.STATE); if (!OrderState.PENDING.getStringValue().equals(state)) { disabled = true; } } orderForm.setFormEnabled(!disabled); Entity order = orderForm.getEntity(); Entity company = order.getBelongsToField(OrderFields.COMPANY); LookupComponent addressLookup = (LookupComponent) view.getComponentByReference(OrderFields.ADDRESS); if (company == null) { addressLookup.setFieldValue(null); addressLookup.setEnabled(false); } else { addressLookup.setEnabled(true); } } } | OrderDetailsHooks { public void disableFieldOrderForm(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); boolean disabled = false; Long orderId = orderForm.getEntityId(); if (orderId != null) { Entity order = orderService.getOrder(orderId); if (order == null) { return; } String state = order.getStringField(OrderFields.STATE); if (!OrderState.PENDING.getStringValue().equals(state)) { disabled = true; } } orderForm.setFormEnabled(!disabled); Entity order = orderForm.getEntity(); Entity company = order.getBelongsToField(OrderFields.COMPANY); LookupComponent addressLookup = (LookupComponent) view.getComponentByReference(OrderFields.ADDRESS); if (company == null) { addressLookup.setFieldValue(null); addressLookup.setEnabled(false); } else { addressLookup.setEnabled(true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void disableFieldOrderForm(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); boolean disabled = false; Long orderId = orderForm.getEntityId(); if (orderId != null) { Entity order = orderService.getOrder(orderId); if (order == null) { return; } String state = order.getStringField(OrderFields.STATE); if (!OrderState.PENDING.getStringValue().equals(state)) { disabled = true; } } orderForm.setFormEnabled(!disabled); Entity order = orderForm.getEntity(); Entity company = order.getBelongsToField(OrderFields.COMPANY); LookupComponent addressLookup = (LookupComponent) view.getComponentByReference(OrderFields.ADDRESS); if (company == null) { addressLookup.setFieldValue(null); addressLookup.setEnabled(false); } else { addressLookup.setEnabled(true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldReturnFalseAndAddErrorWhenCheckMaterialFlowComponentUniquenessAndMaterialFlowComponentIsntUnique() { given(materialsInLocationComponent.getBelongsToField(LOCATION)).willReturn(location); given(materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION)).willReturn(materialsInLocation); given(materialsInLocationComponentDD.find()).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.add(Mockito.any(SearchCriterion.class))).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.list()).willReturn(searchResult); given(searchResult.getTotalNumberOfEntities()).willReturn(1); given(searchResult.getEntities()).willReturn(entities); given(entities.get(0)).willReturn(materialsInLocationComponentOther); given(materialsInLocationComponent.getId()).willReturn(L_ID); given(materialsInLocationComponentOther.getId()).willReturn(L_ID_OTHER); boolean result = materialsInLocationComponentModelValidators.checkMaterialFlowComponentUniqueness( materialsInLocationComponentDD, materialsInLocationComponent); assertFalse(result); Mockito.verify(materialsInLocationComponent).addError(Mockito.eq(materialsInLocationComponentDD.getField(LOCATION)), Mockito.anyString()); } | public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD,
final Entity materialsInLocationComponent); } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD,
final Entity materialsInLocationComponent); } |
@Test public void shouldCheckEnabledFieldWhenOrderStateIsAccepted() throws Exception { given(order.getStringField(OrderFields.STATE)).willReturn(OrderState.ACCEPTED.getStringValue()); orderDetailsHooks.changedEnabledFieldForSpecificOrderState(view); Mockito.verify(correctDateFromField).setEnabled(true); Mockito.verify(correctDateToField).setEnabled(true); Mockito.verify(commentDateFromField).setEnabled(true); Mockito.verify(commentDateToField).setEnabled(true); Mockito.verify(reasonsDateFromField).setEnabled(true); Mockito.verify(reasonsDateToField).setEnabled(true); Mockito.verify(dateFromField).setEnabled(true); Mockito.verify(dateToField).setEnabled(true); } | public void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view) { final FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); Long orderId = orderForm.getEntityId(); if (orderId == null) { return; } final Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get( orderId); if (order == null) { return; } String orderState = order.getStringField(OrderFields.STATE); if (OrderState.PENDING.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.CORRECTED_DATE_FROM, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_FROM, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END, OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.EFFECTIVE_DATE_TO); changedEnabledFields(view, references, false); } if (OrderState.ACCEPTED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.CORRECTED_DATE_FROM, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_FROM, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.DATE_FROM, OrderFields.DATE_TO); changedEnabledFields(view, references, true); } if (OrderState.IN_PROGRESS.getStringValue().equals(orderState) || OrderState.INTERRUPTED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.DATE_FROM, OrderFields.DATE_TO, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } if (OrderState.COMPLETED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.EFFECTIVE_DATE_TO, OrderFields.DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } if (OrderState.ABANDONED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.EFFECTIVE_DATE_TO, OrderFields.DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } } | OrderDetailsHooks { public void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view) { final FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); Long orderId = orderForm.getEntityId(); if (orderId == null) { return; } final Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get( orderId); if (order == null) { return; } String orderState = order.getStringField(OrderFields.STATE); if (OrderState.PENDING.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.CORRECTED_DATE_FROM, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_FROM, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END, OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.EFFECTIVE_DATE_TO); changedEnabledFields(view, references, false); } if (OrderState.ACCEPTED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.CORRECTED_DATE_FROM, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_FROM, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.DATE_FROM, OrderFields.DATE_TO); changedEnabledFields(view, references, true); } if (OrderState.IN_PROGRESS.getStringValue().equals(orderState) || OrderState.INTERRUPTED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.DATE_FROM, OrderFields.DATE_TO, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } if (OrderState.COMPLETED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.EFFECTIVE_DATE_TO, OrderFields.DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } if (OrderState.ABANDONED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.EFFECTIVE_DATE_TO, OrderFields.DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } } } | OrderDetailsHooks { public void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view) { final FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); Long orderId = orderForm.getEntityId(); if (orderId == null) { return; } final Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get( orderId); if (order == null) { return; } String orderState = order.getStringField(OrderFields.STATE); if (OrderState.PENDING.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.CORRECTED_DATE_FROM, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_FROM, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END, OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.EFFECTIVE_DATE_TO); changedEnabledFields(view, references, false); } if (OrderState.ACCEPTED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.CORRECTED_DATE_FROM, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_FROM, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.DATE_FROM, OrderFields.DATE_TO); changedEnabledFields(view, references, true); } if (OrderState.IN_PROGRESS.getStringValue().equals(orderState) || OrderState.INTERRUPTED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.DATE_FROM, OrderFields.DATE_TO, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } if (OrderState.COMPLETED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.EFFECTIVE_DATE_TO, OrderFields.DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } if (OrderState.ABANDONED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.EFFECTIVE_DATE_TO, OrderFields.DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } } } | OrderDetailsHooks { public void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view) { final FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); Long orderId = orderForm.getEntityId(); if (orderId == null) { return; } final Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get( orderId); if (order == null) { return; } String orderState = order.getStringField(OrderFields.STATE); if (OrderState.PENDING.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.CORRECTED_DATE_FROM, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_FROM, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END, OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.EFFECTIVE_DATE_TO); changedEnabledFields(view, references, false); } if (OrderState.ACCEPTED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.CORRECTED_DATE_FROM, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_FROM, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.DATE_FROM, OrderFields.DATE_TO); changedEnabledFields(view, references, true); } if (OrderState.IN_PROGRESS.getStringValue().equals(orderState) || OrderState.INTERRUPTED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.DATE_FROM, OrderFields.DATE_TO, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } if (OrderState.COMPLETED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.EFFECTIVE_DATE_TO, OrderFields.DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } if (OrderState.ABANDONED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.EFFECTIVE_DATE_TO, OrderFields.DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } | OrderDetailsHooks { public void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view) { final FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); Long orderId = orderForm.getEntityId(); if (orderId == null) { return; } final Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get( orderId); if (order == null) { return; } String orderState = order.getStringField(OrderFields.STATE); if (OrderState.PENDING.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.CORRECTED_DATE_FROM, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_FROM, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END, OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.EFFECTIVE_DATE_TO); changedEnabledFields(view, references, false); } if (OrderState.ACCEPTED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.CORRECTED_DATE_FROM, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_FROM, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_FROM, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.DATE_FROM, OrderFields.DATE_TO); changedEnabledFields(view, references, true); } if (OrderState.IN_PROGRESS.getStringValue().equals(orderState) || OrderState.INTERRUPTED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.DATE_FROM, OrderFields.DATE_TO, OrderFields.CORRECTED_DATE_TO, OrderFields.REASON_TYPES_CORRECTION_DATE_TO, OrderFields.COMMENT_REASON_TYPE_CORRECTION_DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } if (OrderState.COMPLETED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.EFFECTIVE_DATE_TO, OrderFields.DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } if (OrderState.ABANDONED.getStringValue().equals(orderState)) { List<String> references = Lists.newArrayList(OrderFields.EFFECTIVE_DATE_TO, OrderFields.DATE_TO, OrderFields.EFFECTIVE_DATE_FROM, OrderFields.DATE_FROM, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_END, L_COMMENT_REASON_TYPE_DEVIATIONS_OF_EFFECTIVE_START); changedEnabledFields(view, references, true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_FROM), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_CORRECTION_DATE_TO), false); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_END), true); changedEnabledAwesomeDynamicListComponents(view, Lists.newArrayList(OrderFields.REASON_TYPES_DEVIATIONS_OF_EFFECTIVE_START), true); } } final void onBeforeRender(final ViewDefinitionState view); void fillRecipeFilterValue(final ViewDefinitionState view); final void fillProductionLine(final ViewDefinitionState view); void fillProductionLine(final LookupComponent productionLineLookup, final Entity technology,
final Entity defaultProductionLine); void generateOrderNumber(final ViewDefinitionState view); void fillDefaultTechnology(final ViewDefinitionState view); void disableFieldOrderForm(final ViewDefinitionState view); void disableTechnologiesIfProductDoesNotAny(final ViewDefinitionState view); void setAndDisableState(final ViewDefinitionState view); void changedEnabledFieldForSpecificOrderState(final ViewDefinitionState view); void disableOrderFormForExternalItems(final ViewDefinitionState state); void filterStateChangeHistory(final ViewDefinitionState view); void disabledRibbonWhenOrderIsSynchronized(final ViewDefinitionState view); void compareDeadlineAndEndDate(final ViewDefinitionState view); void compareDeadlineAndStartDate(final ViewDefinitionState view); void setFieldsVisibility(final ViewDefinitionState view); void setFieldsVisibilityAndFill(final ViewDefinitionState view); void fillOrderDescriptionIfTechnologyHasDescription(ViewDefinitionState view); } |
@Test public void shouldChangeFieldStateIfCheckboxIsSelected() { String booleanFieldComponentName = "booleanFieldComponentName"; String fieldComponentName = "fieldComponentName"; given(view.getComponentByReference(booleanFieldComponentName)).willReturn(booleanCheckBoxComponent); given(view.getComponentByReference(fieldComponentName)).willReturn(fieldComponent); given(booleanCheckBoxComponent.isChecked()).willReturn(true); orderService.changeFieldState(view, booleanFieldComponentName, fieldComponentName); verify(fieldComponent).setEnabled(true); } | @Override public void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName, final String fieldComponentName) { CheckBoxComponent booleanCheckBox = (CheckBoxComponent) view.getComponentByReference(booleanFieldComponentName); FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(fieldComponentName); if (booleanCheckBox.isChecked()) { fieldComponent.setEnabled(true); fieldComponent.requestComponentUpdateState(); } else { fieldComponent.setEnabled(false); fieldComponent.requestComponentUpdateState(); } } | OrderServiceImpl implements OrderService { @Override public void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName, final String fieldComponentName) { CheckBoxComponent booleanCheckBox = (CheckBoxComponent) view.getComponentByReference(booleanFieldComponentName); FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(fieldComponentName); if (booleanCheckBox.isChecked()) { fieldComponent.setEnabled(true); fieldComponent.requestComponentUpdateState(); } else { fieldComponent.setEnabled(false); fieldComponent.requestComponentUpdateState(); } } } | OrderServiceImpl implements OrderService { @Override public void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName, final String fieldComponentName) { CheckBoxComponent booleanCheckBox = (CheckBoxComponent) view.getComponentByReference(booleanFieldComponentName); FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(fieldComponentName); if (booleanCheckBox.isChecked()) { fieldComponent.setEnabled(true); fieldComponent.requestComponentUpdateState(); } else { fieldComponent.setEnabled(false); fieldComponent.requestComponentUpdateState(); } } } | OrderServiceImpl implements OrderService { @Override public void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName, final String fieldComponentName) { CheckBoxComponent booleanCheckBox = (CheckBoxComponent) view.getComponentByReference(booleanFieldComponentName); FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(fieldComponentName); if (booleanCheckBox.isChecked()) { fieldComponent.setEnabled(true); fieldComponent.requestComponentUpdateState(); } else { fieldComponent.setEnabled(false); fieldComponent.requestComponentUpdateState(); } } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName, final String fieldComponentName) { CheckBoxComponent booleanCheckBox = (CheckBoxComponent) view.getComponentByReference(booleanFieldComponentName); FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(fieldComponentName); if (booleanCheckBox.isChecked()) { fieldComponent.setEnabled(true); fieldComponent.requestComponentUpdateState(); } else { fieldComponent.setEnabled(false); fieldComponent.requestComponentUpdateState(); } } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldntChangeFieldStateIfCheckboxIsntSelected() { String booleanFieldComponentName = "booleanFieldComponentName"; String fieldComponentName = "fieldComponentName"; given(view.getComponentByReference(booleanFieldComponentName)).willReturn(booleanCheckBoxComponent); given(view.getComponentByReference(fieldComponentName)).willReturn(fieldComponent); given(booleanCheckBoxComponent.isChecked()).willReturn(false); orderService.changeFieldState(view, booleanFieldComponentName, fieldComponentName); verify(fieldComponent).setEnabled(false); } | @Override public void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName, final String fieldComponentName) { CheckBoxComponent booleanCheckBox = (CheckBoxComponent) view.getComponentByReference(booleanFieldComponentName); FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(fieldComponentName); if (booleanCheckBox.isChecked()) { fieldComponent.setEnabled(true); fieldComponent.requestComponentUpdateState(); } else { fieldComponent.setEnabled(false); fieldComponent.requestComponentUpdateState(); } } | OrderServiceImpl implements OrderService { @Override public void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName, final String fieldComponentName) { CheckBoxComponent booleanCheckBox = (CheckBoxComponent) view.getComponentByReference(booleanFieldComponentName); FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(fieldComponentName); if (booleanCheckBox.isChecked()) { fieldComponent.setEnabled(true); fieldComponent.requestComponentUpdateState(); } else { fieldComponent.setEnabled(false); fieldComponent.requestComponentUpdateState(); } } } | OrderServiceImpl implements OrderService { @Override public void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName, final String fieldComponentName) { CheckBoxComponent booleanCheckBox = (CheckBoxComponent) view.getComponentByReference(booleanFieldComponentName); FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(fieldComponentName); if (booleanCheckBox.isChecked()) { fieldComponent.setEnabled(true); fieldComponent.requestComponentUpdateState(); } else { fieldComponent.setEnabled(false); fieldComponent.requestComponentUpdateState(); } } } | OrderServiceImpl implements OrderService { @Override public void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName, final String fieldComponentName) { CheckBoxComponent booleanCheckBox = (CheckBoxComponent) view.getComponentByReference(booleanFieldComponentName); FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(fieldComponentName); if (booleanCheckBox.isChecked()) { fieldComponent.setEnabled(true); fieldComponent.requestComponentUpdateState(); } else { fieldComponent.setEnabled(false); fieldComponent.requestComponentUpdateState(); } } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName, final String fieldComponentName) { CheckBoxComponent booleanCheckBox = (CheckBoxComponent) view.getComponentByReference(booleanFieldComponentName); FieldComponent fieldComponent = (FieldComponent) view.getComponentByReference(fieldComponentName); if (booleanCheckBox.isChecked()) { fieldComponent.setEnabled(true); fieldComponent.requestComponentUpdateState(); } else { fieldComponent.setEnabled(false); fieldComponent.requestComponentUpdateState(); } } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldFailCheckingRequiredBatchForBatchRequired() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").isEmpty()).willReturn(true); given(technology.getBooleanField("batchRequired")).willReturn(true); boolean result = orderService.checkRequiredBatch(order); assertFalse(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldFailCheckingRequiredBatchForPostBatchRequired() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").isEmpty()).willReturn(true); given(technology.getBooleanField("batchRequired")).willReturn(false); given(technology.getBooleanField("shiftFeatureRequired")).willReturn(false); given(technology.getBooleanField("postFeatureRequired")).willReturn(true); boolean result = orderService.checkRequiredBatch(order); assertFalse(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldFailCheckingRequiredBatchForOtherBatchRequired() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").isEmpty()).willReturn(true); given(technology.getBooleanField("batchRequired")).willReturn(false); given(technology.getBooleanField("shiftFeatureRequired")).willReturn(false); given(technology.getBooleanField("postFeatureRequired")).willReturn(false); given(technology.getBooleanField("otherFeatureRequired")).willReturn(true); boolean result = orderService.checkRequiredBatch(order); assertFalse(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldFailCheckingRequiredBatchForOperationComponentBatchRequired() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").isEmpty()).willReturn(true); given(technology.getBooleanField("batchRequired")).willReturn(false); given(technology.getBooleanField("shiftFeatureRequired")).willReturn(false); given(technology.getBooleanField("postFeatureRequired")).willReturn(false); given(technology.getBooleanField("otherFeatureRequired")).willReturn(false); given(technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS).iterator()).willReturn(iterator); given(iterator.hasNext()).willReturn(true, false); given(iterator.next()).willReturn(operationComponent); given(operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS).iterator()) .willReturn(iterator2); given(iterator2.hasNext()).willReturn(true, false); given(iterator2.next()).willReturn(operationProductInComponent); given(operationProductInComponent.getBooleanField("batchRequired")).willReturn(true); boolean result = orderService.checkRequiredBatch(order); assertFalse(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldFailCheckingRequiredBatchForGenealogyBatchRequired() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").isEmpty()).willReturn(false); given(order.getHasManyField("genealogies").iterator()).willReturn(iterator); given(iterator.hasNext()).willReturn(true, false); given(iterator.next()).willReturn(genealogy); given(technology.getBooleanField("batchRequired")).willReturn(true); given(genealogy.getField("batch")).willReturn(null); boolean result = orderService.checkRequiredBatch(order); assertFalse(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldFailCheckingRequiredBatchForGenealogyShiftBatchRequired() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").isEmpty()).willReturn(false); given(order.getHasManyField("genealogies").iterator()).willReturn(iterator); given(iterator.hasNext()).willReturn(true, false); given(iterator.next()).willReturn(genealogy); given(technology.getBooleanField("batchRequired")).willReturn(true); given(technology.getBooleanField("shiftFeatureRequired")).willReturn(true); given(genealogy.getHasManyField("shiftFeatures").isEmpty()).willReturn(true); boolean result = orderService.checkRequiredBatch(order); assertFalse(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldFailCheckingRequiredBatchForGenealogyPostBatchRequired() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").isEmpty()).willReturn(false); given(order.getHasManyField("genealogies").iterator()).willReturn(iterator); given(iterator.hasNext()).willReturn(true, false); given(iterator.next()).willReturn(genealogy); given(technology.getBooleanField("batchRequired")).willReturn(false); given(technology.getBooleanField("shiftFeatureRequired")).willReturn(true); given(genealogy.getHasManyField("shiftFeatures").isEmpty()).willReturn(false); given(technology.getBooleanField("postFeatureRequired")).willReturn(true); given(genealogy.getHasManyField("postFeatures").isEmpty()).willReturn(true); boolean result = orderService.checkRequiredBatch(order); assertFalse(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldReturnTrueWhenCheckMaterialFlowComponentUniquenessAndMaterialFlowComponentIsUnique() { given(materialsInLocationComponent.getBelongsToField(LOCATION)).willReturn(location); given(materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION)).willReturn(materialsInLocation); given(materialsInLocationComponentDD.find()).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.add(Mockito.any(SearchCriterion.class))).willReturn(searchCriteriaBuilder); given(searchCriteriaBuilder.list()).willReturn(searchResult); given(searchResult.getTotalNumberOfEntities()).willReturn(0); boolean result = materialsInLocationComponentModelValidators.checkMaterialFlowComponentUniqueness( materialsInLocationComponentDD, materialsInLocationComponent); assertTrue(result); } | public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD,
final Entity materialsInLocationComponent); } | MaterialsInLocationComponentModelValidators { public boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD, final Entity materialsInLocationComponent) { Entity location = materialsInLocationComponent.getBelongsToField(LOCATION); Entity materialsInLocation = materialsInLocationComponent.getBelongsToField(MATERIALS_IN_LOCATION); if (materialsInLocation == null || location == null) { return false; } SearchResult searchResult = materialsInLocationComponentDD.find().add(SearchRestrictions.belongsTo(LOCATION, location)) .add(SearchRestrictions.belongsTo(MATERIALS_IN_LOCATION, materialsInLocation)).list(); if (searchResult.getTotalNumberOfEntities() == 1 && !searchResult.getEntities().get(0).getId().equals(materialsInLocationComponent.getId())) { materialsInLocationComponent.addError(materialsInLocationComponentDD.getField(LOCATION), "materialFlow.validate.global.error.materialsInLocationDuplicated"); return false; } else { return true; } } boolean checkMaterialFlowComponentUniqueness(final DataDefinition materialsInLocationComponentDD,
final Entity materialsInLocationComponent); } |
@Test public void shouldFailCheckingRequiredBatchForGenealogyOtherBatchRequired() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").size()).willReturn(1); given(order.getHasManyField("genealogies").iterator()).willReturn(iterator); given(iterator.hasNext()).willReturn(true, false); given(iterator.next()).willReturn(genealogy); given(technology.getBooleanField("batchRequired")).willReturn(false); given(technology.getBooleanField("shiftFeatureRequired")).willReturn(false); given(technology.getBooleanField("postFeatureRequired")).willReturn(true); given(genealogy.getHasManyField("postFeatures").isEmpty()).willReturn(false); given(technology.getBooleanField("otherFeatureRequired")).willReturn(true); given(genealogy.getHasManyField("otherFeatures").isEmpty()).willReturn(true); boolean result = orderService.checkRequiredBatch(order); assertFalse(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldFailCheckingRequiredBatchForGenealogyComponentsBatchRequired() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").isEmpty()).willReturn(false); given(order.getHasManyField("genealogies").iterator()).willReturn(iterator); given(iterator.hasNext()).willReturn(true, false); given(iterator.next()).willReturn(genealogy); given(technology.getBooleanField("batchRequired")).willReturn(false); given(technology.getBooleanField("shiftFeatureRequired")).willReturn(false); given(technology.getBooleanField("postFeatureRequired")).willReturn(false); given(technology.getBooleanField("otherFeatureRequired")).willReturn(true); given(genealogy.getHasManyField("otherFeatures").isEmpty()).willReturn(false); given(genealogy.getHasManyField("productInComponents").iterator()).willReturn(iterator2); given(iterator2.hasNext()).willReturn(true, false); given(iterator2.next()).willReturn(operationProductInComponent); given(operationProductInComponent.getBelongsToField("productInComponent").getBooleanField("batchRequired")).willReturn( true); given(operationProductInComponent.getHasManyField("batch").isEmpty()).willReturn(true); boolean result = orderService.checkRequiredBatch(order); assertFalse(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldFailCheckingRequiredBatchForGenealogyComponentsBatchRequired2() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").size()).willReturn(1); given(order.getHasManyField("genealogies").iterator()).willReturn(iterator); given(iterator.hasNext()).willReturn(true, false); given(iterator.next()).willReturn(genealogy); given(technology.getBooleanField("batchRequired")).willReturn(false); given(technology.getBooleanField("shiftFeatureRequired")).willReturn(false); given(technology.getBooleanField("postFeatureRequired")).willReturn(false); given(technology.getBooleanField("otherFeatureRequired")).willReturn(true); given(genealogy.getHasManyField("otherFeatures").size()).willReturn(1); given(genealogy.getHasManyField("productInComponents").iterator()).willReturn(iterator2); given(iterator2.hasNext()).willReturn(true, false); given(iterator2.next()).willReturn(operationProductInComponent); given(operationProductInComponent.getBelongsToField("productInComponent").getBooleanField("batchRequired")).willReturn( true); given(operationProductInComponent.getHasManyField("batch").size()).willReturn(1); boolean result = orderService.checkRequiredBatch(order); assertTrue(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldFailCheckingRequiredBatchForGenealogyComponentsBatchRequired3() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").size()).willReturn(1); given(order.getHasManyField("genealogies").iterator()).willReturn(iterator); given(iterator.hasNext()).willReturn(true, false); given(iterator.next()).willReturn(genealogy); given(technology.getBooleanField("batchRequired")).willReturn(false); given(technology.getBooleanField("shiftFeatureRequired")).willReturn(false); given(technology.getBooleanField("postFeatureRequired")).willReturn(false); given(technology.getBooleanField("otherFeatureRequired")).willReturn(true); given(genealogy.getHasManyField("otherFeatures").size()).willReturn(1); given(genealogy.getHasManyField("productInComponents").iterator()).willReturn(iterator2); given(iterator2.hasNext()).willReturn(true, false); given(iterator2.next()).willReturn(operationProductInComponent); given(operationProductInComponent.getBelongsToField("productInComponent").getBooleanField("batchRequired")).willReturn( false); boolean result = orderService.checkRequiredBatch(order); assertTrue(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldSuccessCheckingRequiredBatch() throws Exception { given(order.getBelongsToField(OrderFields.TECHNOLOGY)).willReturn(technology); given(order.getHasManyField("genealogies").size()).willReturn(1); boolean result = orderService.checkRequiredBatch(order); assertTrue(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test public void shouldSuccessCheckingRequiredBatchIfThereIsNoTechnology() throws Exception { given(order.getField(OrderFields.TECHNOLOGY)).willReturn(null); boolean result = orderService.checkRequiredBatch(order); assertTrue(result); } | @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } | OrderServiceImpl implements OrderService { @Override public boolean checkRequiredBatch(final Entity order) { Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY); if (technology != null) { if (order.getHasManyField("genealogies").isEmpty()) { if (technology.getBooleanField("batchRequired")) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { return false; } if (technology.getBooleanField("postFeatureRequired")) { return false; } if (technology.getBooleanField("otherFeatureRequired")) { return false; } for (Entity operationComponent : technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)) { for (Entity operationProductComponent : operationComponent .getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)) { if (operationProductComponent.getBooleanField("batchRequired")) { return false; } } } } for (Entity genealogy : order.getHasManyField("genealogies")) { if (technology.getBooleanField("batchRequired") && genealogy.getField("batch") == null) { return false; } if (technology.getBooleanField("shiftFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("shiftFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("postFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("postFeatures"); if (entityList.isEmpty()) { return false; } } if (technology.getBooleanField("otherFeatureRequired")) { List<Entity> entityList = genealogy.getHasManyField("otherFeatures"); if (entityList.isEmpty()) { return false; } } for (Entity genealogyProductIn : genealogy.getHasManyField("productInComponents")) { if (genealogyProductIn.getBelongsToField("productInComponent").getBooleanField("batchRequired")) { List<Entity> entityList = genealogyProductIn.getHasManyField("batch"); if (entityList.isEmpty()) { return false; } } } } } return true; } @Override Entity getOrder(final Long orderId); @Override boolean isOrderStarted(final String state); @Override Entity getDefaultProductionLine(); @Override String makeDefaultName(final Entity product, Entity technology, final Locale locale); @Override void changeFieldState(final ViewDefinitionState view, final String booleanFieldComponentName,
final String fieldComponentName); @Override boolean checkComponentOrderHasTechnology(final DataDefinition dataDefinition, final Entity entity); @Override boolean checkAutogenealogyRequired(); @Override boolean checkRequiredBatch(final Entity order); @Override boolean isPktEnabled(); @Override String buildOrderDescription(Entity masterOrder, Entity technology, boolean fillOrderDescriptionBasedOnTechnology); } |
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenEntityIsNullValidationAccepted() throws Exception { orderStateValidationService.validationOnAccepted(null); } | public void validationOnAccepted(final StateChangeContext stateChangeContext) { final List<String> references = Arrays.asList(DATE_TO, DATE_FROM, PRODUCTION_LINE); checkRequired(references, stateChangeContext); } | OrderStateValidationService { public void validationOnAccepted(final StateChangeContext stateChangeContext) { final List<String> references = Arrays.asList(DATE_TO, DATE_FROM, PRODUCTION_LINE); checkRequired(references, stateChangeContext); } } | OrderStateValidationService { public void validationOnAccepted(final StateChangeContext stateChangeContext) { final List<String> references = Arrays.asList(DATE_TO, DATE_FROM, PRODUCTION_LINE); checkRequired(references, stateChangeContext); } } | OrderStateValidationService { public void validationOnAccepted(final StateChangeContext stateChangeContext) { final List<String> references = Arrays.asList(DATE_TO, DATE_FROM, PRODUCTION_LINE); checkRequired(references, stateChangeContext); } void validationOnAccepted(final StateChangeContext stateChangeContext); void validationOnInProgress(final StateChangeContext stateChangeContext); void validationOnCompleted(final StateChangeContext stateChangeContext); } | OrderStateValidationService { public void validationOnAccepted(final StateChangeContext stateChangeContext) { final List<String> references = Arrays.asList(DATE_TO, DATE_FROM, PRODUCTION_LINE); checkRequired(references, stateChangeContext); } void validationOnAccepted(final StateChangeContext stateChangeContext); void validationOnInProgress(final StateChangeContext stateChangeContext); void validationOnCompleted(final StateChangeContext stateChangeContext); } |
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenEntityIsNullValidationInProgress() throws Exception { orderStateValidationService.validationOnInProgress(null); } | public void validationOnInProgress(final StateChangeContext stateChangeContext) { final List<String> references = Arrays.asList(DATE_TO, DATE_FROM); checkRequired(references, stateChangeContext); } | OrderStateValidationService { public void validationOnInProgress(final StateChangeContext stateChangeContext) { final List<String> references = Arrays.asList(DATE_TO, DATE_FROM); checkRequired(references, stateChangeContext); } } | OrderStateValidationService { public void validationOnInProgress(final StateChangeContext stateChangeContext) { final List<String> references = Arrays.asList(DATE_TO, DATE_FROM); checkRequired(references, stateChangeContext); } } | OrderStateValidationService { public void validationOnInProgress(final StateChangeContext stateChangeContext) { final List<String> references = Arrays.asList(DATE_TO, DATE_FROM); checkRequired(references, stateChangeContext); } void validationOnAccepted(final StateChangeContext stateChangeContext); void validationOnInProgress(final StateChangeContext stateChangeContext); void validationOnCompleted(final StateChangeContext stateChangeContext); } | OrderStateValidationService { public void validationOnInProgress(final StateChangeContext stateChangeContext) { final List<String> references = Arrays.asList(DATE_TO, DATE_FROM); checkRequired(references, stateChangeContext); } void validationOnAccepted(final StateChangeContext stateChangeContext); void validationOnInProgress(final StateChangeContext stateChangeContext); void validationOnCompleted(final StateChangeContext stateChangeContext); } |
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenEntityIsNullValidationCompleted() throws Exception { orderStateValidationService.validationOnCompleted(null); } | public void validationOnCompleted(final StateChangeContext stateChangeContext) { final List<String> fieldNames = Arrays.asList(DATE_TO, DATE_FROM, DONE_QUANTITY); checkRequired(fieldNames, stateChangeContext); } | OrderStateValidationService { public void validationOnCompleted(final StateChangeContext stateChangeContext) { final List<String> fieldNames = Arrays.asList(DATE_TO, DATE_FROM, DONE_QUANTITY); checkRequired(fieldNames, stateChangeContext); } } | OrderStateValidationService { public void validationOnCompleted(final StateChangeContext stateChangeContext) { final List<String> fieldNames = Arrays.asList(DATE_TO, DATE_FROM, DONE_QUANTITY); checkRequired(fieldNames, stateChangeContext); } } | OrderStateValidationService { public void validationOnCompleted(final StateChangeContext stateChangeContext) { final List<String> fieldNames = Arrays.asList(DATE_TO, DATE_FROM, DONE_QUANTITY); checkRequired(fieldNames, stateChangeContext); } void validationOnAccepted(final StateChangeContext stateChangeContext); void validationOnInProgress(final StateChangeContext stateChangeContext); void validationOnCompleted(final StateChangeContext stateChangeContext); } | OrderStateValidationService { public void validationOnCompleted(final StateChangeContext stateChangeContext) { final List<String> fieldNames = Arrays.asList(DATE_TO, DATE_FROM, DONE_QUANTITY); checkRequired(fieldNames, stateChangeContext); } void validationOnAccepted(final StateChangeContext stateChangeContext); void validationOnInProgress(final StateChangeContext stateChangeContext); void validationOnCompleted(final StateChangeContext stateChangeContext); } |
@Test public void shouldPerformValidationCompleted() throws Exception { given(order.getField(Mockito.anyString())).willReturn("fieldValue"); given(order.getField(EFFECTIVE_DATE_FROM)).willReturn(new Date(System.currentTimeMillis() - 10000)); orderStateValidationService.validationOnCompleted(stateChangeContext); verify(stateChangeContext, never()).addFieldValidationError(Mockito.anyString(), Mockito.eq(L_MISSING_MESSAGE)); verify(stateChangeContext, never()).addFieldValidationError(Mockito.anyString(), Mockito.eq(L_WRONG_EFFECTIVE_DATE_TO)); } | public void validationOnCompleted(final StateChangeContext stateChangeContext) { final List<String> fieldNames = Arrays.asList(DATE_TO, DATE_FROM, DONE_QUANTITY); checkRequired(fieldNames, stateChangeContext); } | OrderStateValidationService { public void validationOnCompleted(final StateChangeContext stateChangeContext) { final List<String> fieldNames = Arrays.asList(DATE_TO, DATE_FROM, DONE_QUANTITY); checkRequired(fieldNames, stateChangeContext); } } | OrderStateValidationService { public void validationOnCompleted(final StateChangeContext stateChangeContext) { final List<String> fieldNames = Arrays.asList(DATE_TO, DATE_FROM, DONE_QUANTITY); checkRequired(fieldNames, stateChangeContext); } } | OrderStateValidationService { public void validationOnCompleted(final StateChangeContext stateChangeContext) { final List<String> fieldNames = Arrays.asList(DATE_TO, DATE_FROM, DONE_QUANTITY); checkRequired(fieldNames, stateChangeContext); } void validationOnAccepted(final StateChangeContext stateChangeContext); void validationOnInProgress(final StateChangeContext stateChangeContext); void validationOnCompleted(final StateChangeContext stateChangeContext); } | OrderStateValidationService { public void validationOnCompleted(final StateChangeContext stateChangeContext) { final List<String> fieldNames = Arrays.asList(DATE_TO, DATE_FROM, DONE_QUANTITY); checkRequired(fieldNames, stateChangeContext); } void validationOnAccepted(final StateChangeContext stateChangeContext); void validationOnInProgress(final StateChangeContext stateChangeContext); void validationOnCompleted(final StateChangeContext stateChangeContext); } |
@Test public void shouldReturnFalseAndAddErrorWhenValidateTransferAndAllFieldsAreNull() { given(transfer.getStringField(TYPE)).willReturn(null); given(transfer.getField(TIME)).willReturn(null); given(transfer.getBelongsToField(LOCATION_FROM)).willReturn(null); given(transfer.getBelongsToField(LOCATION_TO)).willReturn(null); boolean result = transferModelValidators.validateTransfer(transferDD, transfer); assertFalse(result); verify(transfer, times(2)).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } boolean validateTransfer(final DataDefinition transferDD, final Entity transfer); boolean checkIfLocationFromOrLocationToHasExternalNumber(final DataDefinition transferDD, final Entity transfer); } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } boolean validateTransfer(final DataDefinition transferDD, final Entity transfer); boolean checkIfLocationFromOrLocationToHasExternalNumber(final DataDefinition transferDD, final Entity transfer); } |
@Test public void shouldReturnTrueIfIsReasonNeededWhenCorrectingDateFrom() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM)).willReturn(true); boolean result = orderStateChangeReasonService.neededWhenCorrectingDateFrom(); assertTrue(result); } | public boolean neededWhenCorrectingDateFrom() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM); } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateFrom() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM); } } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateFrom() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM); } } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateFrom() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateFrom() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnFalseIfIsReasonNeededWhenCorrectingDateFrom() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM)).willReturn(false); boolean result = orderStateChangeReasonService.neededWhenCorrectingDateFrom(); assertFalse(result); } | public boolean neededWhenCorrectingDateFrom() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM); } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateFrom() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM); } } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateFrom() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM); } } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateFrom() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateFrom() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_FROM); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnTrueIfIsReasonNeededWhenCorrectingDateTo() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO)).willReturn(true); boolean result = orderStateChangeReasonService.neededWhenCorrectingDateTo(); assertTrue(result); } | public boolean neededWhenCorrectingDateTo() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO); } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateTo() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO); } } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateTo() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO); } } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateTo() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateTo() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnFalseIfIsReasonNeededWhenCorrectingDateTo() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO)).willReturn(false); boolean result = orderStateChangeReasonService.neededWhenCorrectingDateTo(); assertFalse(result); } | public boolean neededWhenCorrectingDateTo() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO); } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateTo() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO); } } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateTo() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO); } } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateTo() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public boolean neededWhenCorrectingDateTo() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CORRECTING_DATE_TO); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnTrueIfIsReasonNeededWhenChangingStateToDeclined() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED)).willReturn(true); boolean result = orderStateChangeReasonService.neededForDecline(); assertTrue(result); } | public boolean neededForDecline() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED); } | OrderStateChangeReasonService { public boolean neededForDecline() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED); } } | OrderStateChangeReasonService { public boolean neededForDecline() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED); } } | OrderStateChangeReasonService { public boolean neededForDecline() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public boolean neededForDecline() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnFalseIfIsReasonNeededWhenChangingStateToDeclined() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED)).willReturn(false); boolean result = orderStateChangeReasonService.neededForDecline(); assertFalse(result); } | public boolean neededForDecline() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED); } | OrderStateChangeReasonService { public boolean neededForDecline() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED); } } | OrderStateChangeReasonService { public boolean neededForDecline() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED); } } | OrderStateChangeReasonService { public boolean neededForDecline() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public boolean neededForDecline() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_DECLINED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnTrueIfIsReasonNeededWhenChangingStateToInterrupted() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED)).willReturn(true); boolean result = orderStateChangeReasonService.neededForInterrupt(); assertTrue(result); } | public boolean neededForInterrupt() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED); } | OrderStateChangeReasonService { public boolean neededForInterrupt() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED); } } | OrderStateChangeReasonService { public boolean neededForInterrupt() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED); } } | OrderStateChangeReasonService { public boolean neededForInterrupt() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public boolean neededForInterrupt() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnFalseIfIsReasonNeededWhenChangingStateToInterrupted() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED)).willReturn(false); boolean result = orderStateChangeReasonService.neededForInterrupt(); assertFalse(result); } | public boolean neededForInterrupt() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED); } | OrderStateChangeReasonService { public boolean neededForInterrupt() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED); } } | OrderStateChangeReasonService { public boolean neededForInterrupt() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED); } } | OrderStateChangeReasonService { public boolean neededForInterrupt() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public boolean neededForInterrupt() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_INTERRUPTED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnTrueIfIsReasonNeededWhenChangingStateToAbandoned() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED)).willReturn(true); boolean result = orderStateChangeReasonService.neededForAbandon(); assertTrue(result); } | public boolean neededForAbandon() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED); } | OrderStateChangeReasonService { public boolean neededForAbandon() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED); } } | OrderStateChangeReasonService { public boolean neededForAbandon() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED); } } | OrderStateChangeReasonService { public boolean neededForAbandon() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public boolean neededForAbandon() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnFalseIfIsReasonNeededWhenChangingStateToAbandoned() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); given(parameter.getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED)).willReturn(false); boolean result = orderStateChangeReasonService.neededForAbandon(); assertFalse(result); } | public boolean neededForAbandon() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED); } | OrderStateChangeReasonService { public boolean neededForAbandon() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED); } } | OrderStateChangeReasonService { public boolean neededForAbandon() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED); } } | OrderStateChangeReasonService { public boolean neededForAbandon() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public boolean neededForAbandon() { return parameterService.getParameter().getBooleanField(REASON_NEEDED_WHEN_CHANGING_STATE_TO_ABANDONED); } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnFalseAndAddErrorWhenValidateTransferAndTypeIsNull() { given(transfer.getStringField(TYPE)).willReturn(null); given(transfer.getField(TIME)).willReturn(time); given(transfer.getBelongsToField(LOCATION_FROM)).willReturn(locationFrom); given(transfer.getBelongsToField(LOCATION_TO)).willReturn(locationTo); boolean result = transferModelValidators.validateTransfer(transferDD, transfer); assertFalse(result); verify(transfer, times(1)).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } boolean validateTransfer(final DataDefinition transferDD, final Entity transfer); boolean checkIfLocationFromOrLocationToHasExternalNumber(final DataDefinition transferDD, final Entity transfer); } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } boolean validateTransfer(final DataDefinition transferDD, final Entity transfer); boolean checkIfLocationFromOrLocationToHasExternalNumber(final DataDefinition transferDD, final Entity transfer); } |
@Test public void shouldReturnNonZeroIfIsReasonNeededWhenChangingEffectiveDateFrom() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); Entity order = mock(Entity.class); Date dateFrom = mock(Date.class); Date correctedDateFrom = null; Date effectiveDateFrom = mock(Date.class); long dateFromTime = 10000L; long effectiveDateFromTime = 15000L; Integer delayedDateFromTime = 2; Integer earlierDateFromTime = 2; given(order.getField(DATE_FROM)).willReturn(dateFrom); given(order.getField(CORRECTED_DATE_FROM)).willReturn(correctedDateFrom); given(order.getField(EFFECTIVE_DATE_FROM)).willReturn(effectiveDateFrom); given(dateFrom.getTime()).willReturn(dateFromTime); given(effectiveDateFrom.getTime()).willReturn(effectiveDateFromTime); given(parameter.getBooleanField(REASON_NEEDED_WHEN_DELAYED_EFFECTIVE_DATE_FROM)).willReturn(true); given(parameter.getBooleanField(REASON_NEEDED_WHEN_EARLIER_EFFECTIVE_DATE_FROM)).willReturn(true); given(parameter.getField(DELAYED_EFFECTIVE_DATE_FROM_TIME)).willReturn(delayedDateFromTime); given(parameter.getField(EARLIER_EFFECTIVE_DATE_FROM_TIME)).willReturn(earlierDateFromTime); long result = orderStateChangeReasonService.getEffectiveDateFromDifference(parameter, order); assertEquals(5L, result); } | public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnNonZeroIfIsReasonNeededWhenChangingEffectiveDateFromAndCorrectedDateFromIsntNull() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); Entity order = mock(Entity.class); Date dateFrom = mock(Date.class); Date correctedDateFrom = mock(Date.class); Date effectiveDateFrom = mock(Date.class); long dateFromTime = 10000L; long effectiveDateFromTime = 15000L; Integer delayedDateFromTime = 2; Integer earlierDateFromTime = 2; given(order.getField(DATE_FROM)).willReturn(dateFrom); given(order.getField(CORRECTED_DATE_FROM)).willReturn(correctedDateFrom); given(order.getField(EFFECTIVE_DATE_FROM)).willReturn(effectiveDateFrom); given(correctedDateFrom.getTime()).willReturn(dateFromTime); given(effectiveDateFrom.getTime()).willReturn(effectiveDateFromTime); given(parameter.getBooleanField(REASON_NEEDED_WHEN_DELAYED_EFFECTIVE_DATE_FROM)).willReturn(true); given(parameter.getBooleanField(REASON_NEEDED_WHEN_EARLIER_EFFECTIVE_DATE_FROM)).willReturn(true); given(parameter.getField(DELAYED_EFFECTIVE_DATE_FROM_TIME)).willReturn(delayedDateFromTime); given(parameter.getField(EARLIER_EFFECTIVE_DATE_FROM_TIME)).willReturn(earlierDateFromTime); long result = orderStateChangeReasonService.getEffectiveDateFromDifference(parameter, order); assertEquals(5L, result); } | public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnZeroIfIsReasonNeededWhenChangingEffectiveDateFromAndDateFromAndEffectiveDateFromIsNull() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); Entity order = mock(Entity.class); given(order.getField(DATE_FROM)).willReturn(null); given(order.getField(CORRECTED_DATE_FROM)).willReturn(null); given(order.getField(EFFECTIVE_DATE_FROM)).willReturn(null); long result = orderStateChangeReasonService.getEffectiveDateFromDifference(parameter, order); assertTrue(result == 0); } | public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnZeroIfIsReasonNeededWhenChangingEffectiveDateFromAndReasonsAreFalse() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); Entity order = mock(Entity.class); Date dateFrom = mock(Date.class); Date correctedDateFrom = null; Date effectiveDateFrom = mock(Date.class); long dateFromTime = 10000L; long effectiveDateFromTime = 15000L; Integer delayedDateFromTime = 2; Integer earlierDateFromTime = 2; given(order.getField(DATE_FROM)).willReturn(dateFrom); given(order.getField(CORRECTED_DATE_FROM)).willReturn(correctedDateFrom); given(order.getField(EFFECTIVE_DATE_FROM)).willReturn(effectiveDateFrom); given(dateFrom.getTime()).willReturn(dateFromTime); given(effectiveDateFrom.getTime()).willReturn(effectiveDateFromTime); given(parameter.getBooleanField(REASON_NEEDED_WHEN_DELAYED_EFFECTIVE_DATE_FROM)).willReturn(false); given(parameter.getBooleanField(REASON_NEEDED_WHEN_EARLIER_EFFECTIVE_DATE_FROM)).willReturn(false); given(parameter.getField(DELAYED_EFFECTIVE_DATE_FROM_TIME)).willReturn(delayedDateFromTime); given(parameter.getField(EARLIER_EFFECTIVE_DATE_FROM_TIME)).willReturn(earlierDateFromTime); long result = orderStateChangeReasonService.getEffectiveDateFromDifference(parameter, order); assertTrue(result == 0L); } | public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; } final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime(dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime(dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnNonZeroIfIsReasonNeededWhenChangingEffectiveDateTo() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); Entity order = mock(Entity.class); Date dateTo = mock(Date.class); Date correctedDateTo = null; Date effectiveDateTo = mock(Date.class); long dateToTime = 10000L; long effectiveDateToTime = 15000L; Integer delayedDateToTime = 2; Integer earlierDateToTime = 2; given(order.getField(DATE_TO)).willReturn(dateTo); given(order.getField(CORRECTED_DATE_TO)).willReturn(correctedDateTo); given(order.getField(EFFECTIVE_DATE_TO)).willReturn(effectiveDateTo); given(dateTo.getTime()).willReturn(dateToTime); given(effectiveDateTo.getTime()).willReturn(effectiveDateToTime); given(parameter.getBooleanField(REASON_NEEDED_WHEN_DELAYED_EFFECTIVE_DATE_TO)).willReturn(true); given(parameter.getBooleanField(REASON_NEEDED_WHEN_EARLIER_EFFECTIVE_DATE_TO)).willReturn(true); given(parameter.getField(DELAYED_EFFECTIVE_DATE_TO_TIME)).willReturn(delayedDateToTime); given(parameter.getField(EARLIER_EFFECTIVE_DATE_TO_TIME)).willReturn(earlierDateToTime); long result = orderStateChangeReasonService.getEffectiveDateToDifference(parameter, order); assertEquals(5L, result); } | public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnNonZeroIfIsReasonNeededWhenChangingEffectiveDateToAndCorrectedDateToIsntNull() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); Entity order = mock(Entity.class); Date dateTo = mock(Date.class); Date correctedDateTo = mock(Date.class); Date effectiveDateTo = mock(Date.class); long dateToTime = 10000L; long effectiveDateToTime = 15000L; Integer delayedDateToTime = 2; Integer earlierDateToTime = 2; given(order.getField(DATE_TO)).willReturn(dateTo); given(order.getField(CORRECTED_DATE_TO)).willReturn(correctedDateTo); given(order.getField(EFFECTIVE_DATE_TO)).willReturn(effectiveDateTo); given(correctedDateTo.getTime()).willReturn(dateToTime); given(effectiveDateTo.getTime()).willReturn(effectiveDateToTime); given(parameter.getBooleanField(REASON_NEEDED_WHEN_DELAYED_EFFECTIVE_DATE_TO)).willReturn(true); given(parameter.getBooleanField(REASON_NEEDED_WHEN_EARLIER_EFFECTIVE_DATE_TO)).willReturn(true); given(parameter.getField(DELAYED_EFFECTIVE_DATE_TO_TIME)).willReturn(delayedDateToTime); given(parameter.getField(EARLIER_EFFECTIVE_DATE_TO_TIME)).willReturn(earlierDateToTime); long result = orderStateChangeReasonService.getEffectiveDateToDifference(parameter, order); assertEquals(5L, result); } | public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnZeroIfIsReasonNeededWhenChangingEffectiveDateToAndDateToAndEffectiveDateToIsNull() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); Entity order = mock(Entity.class); given(order.getField(DATE_TO)).willReturn(null); given(order.getField(CORRECTED_DATE_TO)).willReturn(null); given(order.getField(EFFECTIVE_DATE_TO)).willReturn(null); long result = orderStateChangeReasonService.getEffectiveDateToDifference(parameter, order); assertTrue(result == 0L); } | public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldReturnZeroIfIsReasonNeededWhenChangingEffectiveDateToAndReasonsAreFalse() { Entity parameter = mock(Entity.class); given(parameterService.getParameter()).willReturn(parameter); Entity order = mock(Entity.class); Date dateTo = mock(Date.class); Date correctedDateTo = null; Date effectiveDateTo = mock(Date.class); long dateToTime = 10000L; long effectiveDateToTime = 15000L; Integer delayedDateToTime = 2; Integer earlierDateToTime = 2; given(order.getField(DATE_TO)).willReturn(dateTo); given(order.getField(CORRECTED_DATE_TO)).willReturn(correctedDateTo); given(order.getField(EFFECTIVE_DATE_TO)).willReturn(effectiveDateTo); given(dateTo.getTime()).willReturn(dateToTime); given(effectiveDateTo.getTime()).willReturn(effectiveDateToTime); given(parameter.getBooleanField(REASON_NEEDED_WHEN_DELAYED_EFFECTIVE_DATE_TO)).willReturn(false); given(parameter.getBooleanField(REASON_NEEDED_WHEN_EARLIER_EFFECTIVE_DATE_TO)).willReturn(false); given(parameter.getField(DELAYED_EFFECTIVE_DATE_TO_TIME)).willReturn(delayedDateToTime); given(parameter.getField(EARLIER_EFFECTIVE_DATE_TO_TIME)).willReturn(earlierDateToTime); long result = orderStateChangeReasonService.getEffectiveDateToDifference(parameter, order); assertTrue(result == 0L); } | public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } | OrderStateChangeReasonService { public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; } final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime(dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime(dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; } boolean neededWhenCorrectingDateFrom(); boolean neededWhenCorrectingDateTo(); boolean neededForDecline(); boolean neededForInterrupt(); boolean neededForAbandon(); boolean neededWhenChangingEffectiveDateFrom(); long getEffectiveDateFromDifference(final Entity parameter, final Entity order); long getEffectiveDateToDifference(final Entity parameter, final Entity order); void showReasonForm(final StateChangeContext stateChangeContext, final ViewContextHolder viewContext); } |
@Test public void shouldGenerateAssignmentToShiftReportNumber() { hooks.generateAssignmentToShiftReportNumber(view); verify(numberGeneratorService).generateAndInsertNumber(view, AssignmentToShiftConstants.PLUGIN_IDENTIFIER, AssignmentToShiftConstants.MODEL_ASSIGNMENT_TO_SHIFT_REPORT, L_FORM, AssignmentToShiftReportFields.NUMBER); } | public void generateAssignmentToShiftReportNumber(final ViewDefinitionState view) { numberGeneratorService.generateAndInsertNumber(view, AssignmentToShiftConstants.PLUGIN_IDENTIFIER, AssignmentToShiftConstants.MODEL_ASSIGNMENT_TO_SHIFT_REPORT, L_FORM, AssignmentToShiftReportFields.NUMBER); } | AssignmentToShiftReportDetailsHooks { public void generateAssignmentToShiftReportNumber(final ViewDefinitionState view) { numberGeneratorService.generateAndInsertNumber(view, AssignmentToShiftConstants.PLUGIN_IDENTIFIER, AssignmentToShiftConstants.MODEL_ASSIGNMENT_TO_SHIFT_REPORT, L_FORM, AssignmentToShiftReportFields.NUMBER); } } | AssignmentToShiftReportDetailsHooks { public void generateAssignmentToShiftReportNumber(final ViewDefinitionState view) { numberGeneratorService.generateAndInsertNumber(view, AssignmentToShiftConstants.PLUGIN_IDENTIFIER, AssignmentToShiftConstants.MODEL_ASSIGNMENT_TO_SHIFT_REPORT, L_FORM, AssignmentToShiftReportFields.NUMBER); } } | AssignmentToShiftReportDetailsHooks { public void generateAssignmentToShiftReportNumber(final ViewDefinitionState view) { numberGeneratorService.generateAndInsertNumber(view, AssignmentToShiftConstants.PLUGIN_IDENTIFIER, AssignmentToShiftConstants.MODEL_ASSIGNMENT_TO_SHIFT_REPORT, L_FORM, AssignmentToShiftReportFields.NUMBER); } void generateAssignmentToShiftReportNumber(final ViewDefinitionState view); void disableFields(final ViewDefinitionState view); } | AssignmentToShiftReportDetailsHooks { public void generateAssignmentToShiftReportNumber(final ViewDefinitionState view) { numberGeneratorService.generateAndInsertNumber(view, AssignmentToShiftConstants.PLUGIN_IDENTIFIER, AssignmentToShiftConstants.MODEL_ASSIGNMENT_TO_SHIFT_REPORT, L_FORM, AssignmentToShiftReportFields.NUMBER); } void generateAssignmentToShiftReportNumber(final ViewDefinitionState view); void disableFields(final ViewDefinitionState view); } |
@Test public void shouldntDisableFieldsWhenEntityIsntSaved() { given(view.getComponentByReference(L_FORM)).willReturn(assignmentToShiftReportForm); given(view.getComponentByReference(AssignmentToShiftReportFields.NUMBER)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.NAME)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.SHIFT)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.FACTORY)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.DATE_FROM)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.DATE_TO)).willReturn(fieldComponent); given(assignmentToShiftReportForm.getEntityId()).willReturn(null); hooks.disableFields(view); verify(fieldComponent, times(6)).setEnabled(true); } | public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } void generateAssignmentToShiftReportNumber(final ViewDefinitionState view); void disableFields(final ViewDefinitionState view); } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } void generateAssignmentToShiftReportNumber(final ViewDefinitionState view); void disableFields(final ViewDefinitionState view); } |
@Test public void shouldReturnFalseAndAddErrorWhenValidateTransferAndTimeIsNull() { given(transfer.getStringField(TYPE)).willReturn(TRANSPORT.getStringValue()); given(transfer.getField(TIME)).willReturn(null); given(transfer.getBelongsToField(LOCATION_FROM)).willReturn(locationFrom); given(transfer.getBelongsToField(LOCATION_TO)).willReturn(locationTo); boolean result = transferModelValidators.validateTransfer(transferDD, transfer); assertFalse(result); verify(transfer, times(1)).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } boolean validateTransfer(final DataDefinition transferDD, final Entity transfer); boolean checkIfLocationFromOrLocationToHasExternalNumber(final DataDefinition transferDD, final Entity transfer); } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } boolean validateTransfer(final DataDefinition transferDD, final Entity transfer); boolean checkIfLocationFromOrLocationToHasExternalNumber(final DataDefinition transferDD, final Entity transfer); } |
@Test public void shouldntDisableFieldsWhenEntityIsSavedAndReportIsntGenerated() { given(view.getComponentByReference(L_FORM)).willReturn(assignmentToShiftReportForm); given(view.getComponentByReference(AssignmentToShiftReportFields.NUMBER)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.NAME)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.SHIFT)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.FACTORY)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.DATE_FROM)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.DATE_TO)).willReturn(fieldComponent); given(assignmentToShiftReportForm.getEntityId()).willReturn(1L); given( dataDefinitionService.get(AssignmentToShiftConstants.PLUGIN_IDENTIFIER, AssignmentToShiftConstants.MODEL_ASSIGNMENT_TO_SHIFT_REPORT)).willReturn(assignmentToShiftReportDD); given(assignmentToShiftReportDD.get(1L)).willReturn(assignmentToShiftReport); given(assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED)).willReturn(false); hooks.disableFields(view); verify(fieldComponent, times(6)).setEnabled(true); } | public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } void generateAssignmentToShiftReportNumber(final ViewDefinitionState view); void disableFields(final ViewDefinitionState view); } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } void generateAssignmentToShiftReportNumber(final ViewDefinitionState view); void disableFields(final ViewDefinitionState view); } |
@Test public void shouldDisableFieldsWhenEntityIsSavedAndReportIsGenerated() { given(view.getComponentByReference(L_FORM)).willReturn(assignmentToShiftReportForm); given(view.getComponentByReference(AssignmentToShiftReportFields.NUMBER)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.NAME)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.SHIFT)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.FACTORY)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.DATE_FROM)).willReturn(fieldComponent); given(view.getComponentByReference(AssignmentToShiftReportFields.DATE_TO)).willReturn(fieldComponent); given(assignmentToShiftReportForm.getEntityId()).willReturn(1L); given( dataDefinitionService.get(AssignmentToShiftConstants.PLUGIN_IDENTIFIER, AssignmentToShiftConstants.MODEL_ASSIGNMENT_TO_SHIFT_REPORT)).willReturn(assignmentToShiftReportDD); given(assignmentToShiftReportDD.get(1L)).willReturn(assignmentToShiftReport); given(assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED)).willReturn(true); hooks.disableFields(view); verify(fieldComponent, times(6)).setEnabled(false); } | public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } void generateAssignmentToShiftReportNumber(final ViewDefinitionState view); void disableFields(final ViewDefinitionState view); } | AssignmentToShiftReportDetailsHooks { public void disableFields(final ViewDefinitionState view) { FormComponent assignmentToShiftReportForm = (FormComponent) view.getComponentByReference(L_FORM); Long assignmentToShiftReportId = assignmentToShiftReportForm.getEntityId(); if (assignmentToShiftReportId == null) { setFieldsState(view, L_REPORT_FIELDS, true); } else { Entity assignmentToShiftReport = getAssignmentToShiftReportFromDB(assignmentToShiftReportId); if (assignmentToShiftReport != null) { boolean generated = assignmentToShiftReport.getBooleanField(AssignmentToShiftReportFields.GENERATED); if (generated) { setFieldsState(view, L_REPORT_FIELDS, false); } else { setFieldsState(view, L_REPORT_FIELDS, true); } } } } void generateAssignmentToShiftReportNumber(final ViewDefinitionState view); void disableFields(final ViewDefinitionState view); } |
@Test public void shouldReturnFalseWhenCheckIfIsMoreThatFiveDays() { given(assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport)).willReturn(10); boolean result = hooks.checkIfIsMoreThatFiveDays(assignmentToShiftReportDD, assignmentToShiftReport); Assert.assertFalse(result); verify(assignmentToShiftReport, times(2)).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | public boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { int days = assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport); if (days > 5) { assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_FROM), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_TO), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); return false; } return true; } | AssignmentToShiftReportHooks { public boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { int days = assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport); if (days > 5) { assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_FROM), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_TO), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); return false; } return true; } } | AssignmentToShiftReportHooks { public boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { int days = assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport); if (days > 5) { assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_FROM), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_TO), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); return false; } return true; } } | AssignmentToShiftReportHooks { public boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { int days = assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport); if (days > 5) { assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_FROM), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_TO), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); return false; } return true; } boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); void clearGenerated(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); final boolean validateDates(final DataDefinition dataDefinition, final Entity assignmentToShiftReport); } | AssignmentToShiftReportHooks { public boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { int days = assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport); if (days > 5) { assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_FROM), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_TO), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); return false; } return true; } boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); void clearGenerated(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); final boolean validateDates(final DataDefinition dataDefinition, final Entity assignmentToShiftReport); } |
@Test public void shouldReturnTrueWhenCheckIfIsMoreThatFiveDays() { given(assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport)).willReturn(3); boolean result = hooks.checkIfIsMoreThatFiveDays(assignmentToShiftReportDD, assignmentToShiftReport); Assert.assertTrue(result); verify(assignmentToShiftReport, never()).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | public boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { int days = assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport); if (days > 5) { assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_FROM), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_TO), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); return false; } return true; } | AssignmentToShiftReportHooks { public boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { int days = assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport); if (days > 5) { assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_FROM), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_TO), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); return false; } return true; } } | AssignmentToShiftReportHooks { public boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { int days = assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport); if (days > 5) { assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_FROM), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_TO), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); return false; } return true; } } | AssignmentToShiftReportHooks { public boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { int days = assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport); if (days > 5) { assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_FROM), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_TO), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); return false; } return true; } boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); void clearGenerated(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); final boolean validateDates(final DataDefinition dataDefinition, final Entity assignmentToShiftReport); } | AssignmentToShiftReportHooks { public boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { int days = assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport); if (days > 5) { assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_FROM), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); assignmentToShiftReport.addError(assignmentToShiftReportDD.getField(DATE_TO), "assignmentToShift.assignmentToShift.report.onlyFiveDays"); return false; } return true; } boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); void clearGenerated(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); final boolean validateDates(final DataDefinition dataDefinition, final Entity assignmentToShiftReport); } |
@Test public void shouldClearGenerated() { hooks.clearGenerated(assignmentToShiftReportDD, assignmentToShiftReport); verify(assignmentToShiftReport, times(2)).setField(Mockito.anyString(), Mockito.any()); } | public void clearGenerated(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { assignmentToShiftReport.setField(GENERATED, false); assignmentToShiftReport.setField(FILE_NAME, null); } | AssignmentToShiftReportHooks { public void clearGenerated(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { assignmentToShiftReport.setField(GENERATED, false); assignmentToShiftReport.setField(FILE_NAME, null); } } | AssignmentToShiftReportHooks { public void clearGenerated(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { assignmentToShiftReport.setField(GENERATED, false); assignmentToShiftReport.setField(FILE_NAME, null); } } | AssignmentToShiftReportHooks { public void clearGenerated(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { assignmentToShiftReport.setField(GENERATED, false); assignmentToShiftReport.setField(FILE_NAME, null); } boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); void clearGenerated(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); final boolean validateDates(final DataDefinition dataDefinition, final Entity assignmentToShiftReport); } | AssignmentToShiftReportHooks { public void clearGenerated(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport) { assignmentToShiftReport.setField(GENERATED, false); assignmentToShiftReport.setField(FILE_NAME, null); } boolean checkIfIsMoreThatFiveDays(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); void clearGenerated(final DataDefinition assignmentToShiftReportDD, final Entity assignmentToShiftReport); final boolean validateDates(final DataDefinition dataDefinition, final Entity assignmentToShiftReport); } |
@Test public void shouldSaveOccupationTypeForGridValueWhenProductionLineIsSelected() { String technicalCode = "01workOnLine"; String occupationType = "Praca na linii"; String productionLineNumber = "00001"; String occupationTypeForGridValue = "info"; given(staffAssignmentToShift.getStringField(OCCUPATION_TYPE)).willReturn(occupationType); given(staffAssignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType)).willReturn(dictionary); given(dictionary.getStringField(TECHNICAL_CODE)).willReturn(technicalCode); given(staffAssignmentToShift.getBelongsToField(PRODUCTION_LINE)).willReturn(productionLine); given(productionLine.getStringField(NUMBER)).willReturn(productionLineNumber); hooks.setOccupationTypeForGridValue(staffAssignmentToShiftDD, staffAssignmentToShift); Assert.assertEquals("info", occupationTypeForGridValue); } | public void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift) { String occupationType = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE); Entity dictionaryItem = assignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType); String technicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (technicalCode != null && technicalCode.equals(WORK_ON_LINE.getStringValue())) { if (staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) == null) { staffAssignmentToShift.addError(staffAssignmentToShiftDD.getField(StaffAssignmentToShiftFields.PRODUCTION_LINE), "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty"); return; } staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) .getStringField(NUMBER)); } else if (technicalCode != null && technicalCode.equals(OTHER_CASE.getStringValue())) { String occupationTypeName = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_NAME); if (StringUtils.isEmpty(occupationTypeName)) { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + occupationTypeName); } } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } } | StaffAssignmentToShiftHooks { public void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift) { String occupationType = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE); Entity dictionaryItem = assignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType); String technicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (technicalCode != null && technicalCode.equals(WORK_ON_LINE.getStringValue())) { if (staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) == null) { staffAssignmentToShift.addError(staffAssignmentToShiftDD.getField(StaffAssignmentToShiftFields.PRODUCTION_LINE), "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty"); return; } staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) .getStringField(NUMBER)); } else if (technicalCode != null && technicalCode.equals(OTHER_CASE.getStringValue())) { String occupationTypeName = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_NAME); if (StringUtils.isEmpty(occupationTypeName)) { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + occupationTypeName); } } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } } } | StaffAssignmentToShiftHooks { public void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift) { String occupationType = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE); Entity dictionaryItem = assignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType); String technicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (technicalCode != null && technicalCode.equals(WORK_ON_LINE.getStringValue())) { if (staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) == null) { staffAssignmentToShift.addError(staffAssignmentToShiftDD.getField(StaffAssignmentToShiftFields.PRODUCTION_LINE), "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty"); return; } staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) .getStringField(NUMBER)); } else if (technicalCode != null && technicalCode.equals(OTHER_CASE.getStringValue())) { String occupationTypeName = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_NAME); if (StringUtils.isEmpty(occupationTypeName)) { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + occupationTypeName); } } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } } } | StaffAssignmentToShiftHooks { public void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift) { String occupationType = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE); Entity dictionaryItem = assignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType); String technicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (technicalCode != null && technicalCode.equals(WORK_ON_LINE.getStringValue())) { if (staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) == null) { staffAssignmentToShift.addError(staffAssignmentToShiftDD.getField(StaffAssignmentToShiftFields.PRODUCTION_LINE), "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty"); return; } staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) .getStringField(NUMBER)); } else if (technicalCode != null && technicalCode.equals(OTHER_CASE.getStringValue())) { String occupationTypeName = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_NAME); if (StringUtils.isEmpty(occupationTypeName)) { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + occupationTypeName); } } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } } void onSave(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); Boolean onCopy(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); void setOccupationTypeEnum(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); } | StaffAssignmentToShiftHooks { public void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift) { String occupationType = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE); Entity dictionaryItem = assignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType); String technicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (technicalCode != null && technicalCode.equals(WORK_ON_LINE.getStringValue())) { if (staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) == null) { staffAssignmentToShift.addError(staffAssignmentToShiftDD.getField(StaffAssignmentToShiftFields.PRODUCTION_LINE), "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty"); return; } staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) .getStringField(NUMBER)); } else if (technicalCode != null && technicalCode.equals(OTHER_CASE.getStringValue())) { String occupationTypeName = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_NAME); if (StringUtils.isEmpty(occupationTypeName)) { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + occupationTypeName); } } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } } void onSave(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); Boolean onCopy(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); void setOccupationTypeEnum(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); } |
@Test public void shouldAddErrorForEntityWhenProductionLineIsNull() { String technicalCode = "01workOnLine"; String occupationType = "Praca na linii"; given(staffAssignmentToShift.getStringField(OCCUPATION_TYPE)).willReturn(occupationType); given(staffAssignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType)).willReturn(dictionary); given(dictionary.getStringField(TECHNICAL_CODE)).willReturn(technicalCode); given(staffAssignmentToShift.getBelongsToField(PRODUCTION_LINE)).willReturn(null); hooks.setOccupationTypeForGridValue(staffAssignmentToShiftDD, staffAssignmentToShift); verify(staffAssignmentToShift).addError(staffAssignmentToShiftDD.getField(StaffAssignmentToShiftFields.PRODUCTION_LINE), "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty"); } | public void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift) { String occupationType = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE); Entity dictionaryItem = assignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType); String technicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (technicalCode != null && technicalCode.equals(WORK_ON_LINE.getStringValue())) { if (staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) == null) { staffAssignmentToShift.addError(staffAssignmentToShiftDD.getField(StaffAssignmentToShiftFields.PRODUCTION_LINE), "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty"); return; } staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) .getStringField(NUMBER)); } else if (technicalCode != null && technicalCode.equals(OTHER_CASE.getStringValue())) { String occupationTypeName = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_NAME); if (StringUtils.isEmpty(occupationTypeName)) { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + occupationTypeName); } } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } } | StaffAssignmentToShiftHooks { public void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift) { String occupationType = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE); Entity dictionaryItem = assignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType); String technicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (technicalCode != null && technicalCode.equals(WORK_ON_LINE.getStringValue())) { if (staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) == null) { staffAssignmentToShift.addError(staffAssignmentToShiftDD.getField(StaffAssignmentToShiftFields.PRODUCTION_LINE), "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty"); return; } staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) .getStringField(NUMBER)); } else if (technicalCode != null && technicalCode.equals(OTHER_CASE.getStringValue())) { String occupationTypeName = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_NAME); if (StringUtils.isEmpty(occupationTypeName)) { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + occupationTypeName); } } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } } } | StaffAssignmentToShiftHooks { public void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift) { String occupationType = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE); Entity dictionaryItem = assignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType); String technicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (technicalCode != null && technicalCode.equals(WORK_ON_LINE.getStringValue())) { if (staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) == null) { staffAssignmentToShift.addError(staffAssignmentToShiftDD.getField(StaffAssignmentToShiftFields.PRODUCTION_LINE), "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty"); return; } staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) .getStringField(NUMBER)); } else if (technicalCode != null && technicalCode.equals(OTHER_CASE.getStringValue())) { String occupationTypeName = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_NAME); if (StringUtils.isEmpty(occupationTypeName)) { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + occupationTypeName); } } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } } } | StaffAssignmentToShiftHooks { public void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift) { String occupationType = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE); Entity dictionaryItem = assignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType); String technicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (technicalCode != null && technicalCode.equals(WORK_ON_LINE.getStringValue())) { if (staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) == null) { staffAssignmentToShift.addError(staffAssignmentToShiftDD.getField(StaffAssignmentToShiftFields.PRODUCTION_LINE), "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty"); return; } staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) .getStringField(NUMBER)); } else if (technicalCode != null && technicalCode.equals(OTHER_CASE.getStringValue())) { String occupationTypeName = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_NAME); if (StringUtils.isEmpty(occupationTypeName)) { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + occupationTypeName); } } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } } void onSave(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); Boolean onCopy(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); void setOccupationTypeEnum(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); } | StaffAssignmentToShiftHooks { public void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift) { String occupationType = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE); Entity dictionaryItem = assignmentToShiftDetailsHooks.findDictionaryItemByName(occupationType); String technicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (technicalCode != null && technicalCode.equals(WORK_ON_LINE.getStringValue())) { if (staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) == null) { staffAssignmentToShift.addError(staffAssignmentToShiftDD.getField(StaffAssignmentToShiftFields.PRODUCTION_LINE), "assignmentToShift.staffAssignmentToShift.productionLine.isEmpty"); return; } staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + staffAssignmentToShift.getBelongsToField(StaffAssignmentToShiftFields.PRODUCTION_LINE) .getStringField(NUMBER)); } else if (technicalCode != null && technicalCode.equals(OTHER_CASE.getStringValue())) { String occupationTypeName = staffAssignmentToShift.getStringField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_NAME); if (StringUtils.isEmpty(occupationTypeName)) { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType + ": " + occupationTypeName); } } else { staffAssignmentToShift.setField(StaffAssignmentToShiftFields.OCCUPATION_TYPE_VALUE_FOR_GRID, occupationType); } } void onSave(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); Boolean onCopy(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); void setOccupationTypeForGridValue(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); void setOccupationTypeEnum(final DataDefinition staffAssignmentToShiftDD, final Entity staffAssignmentToShift); } |
@Test public void shouldSetInitialState() { assignmentToShiftHooks.setInitialState(assignmentToShift); verify(stateChangeEntityBuilder).buildInitial(describer, assignmentToShift, AssignmentToShiftState.DRAFT); } | void setInitialState(final Entity assignmentToShift) { stateChangeEntityBuilder.buildInitial(describer, assignmentToShift, AssignmentToShiftState.DRAFT); } | AssignmentToShiftHooks { void setInitialState(final Entity assignmentToShift) { stateChangeEntityBuilder.buildInitial(describer, assignmentToShift, AssignmentToShiftState.DRAFT); } } | AssignmentToShiftHooks { void setInitialState(final Entity assignmentToShift) { stateChangeEntityBuilder.buildInitial(describer, assignmentToShift, AssignmentToShiftState.DRAFT); } } | AssignmentToShiftHooks { void setInitialState(final Entity assignmentToShift) { stateChangeEntityBuilder.buildInitial(describer, assignmentToShift, AssignmentToShiftState.DRAFT); } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } | AssignmentToShiftHooks { void setInitialState(final Entity assignmentToShift) { stateChangeEntityBuilder.buildInitial(describer, assignmentToShift, AssignmentToShiftState.DRAFT); } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } |
@Test public void shouldReturnTrueWhenCheckUniqueEntityIfEntityIsNotSaved() { boolean result = assignmentToShiftHooks.checkUniqueEntity(assignmentToShift); Assert.assertTrue(result); verify(assignmentToShift, never()).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } |
@Test public void shouldReturnFalseWhenCheckUniqueEntityIfEntityIsntSaved() { stubFind(mockEntity()); boolean result = assignmentToShiftHooks.checkUniqueEntity(assignmentToShift); Assert.assertFalse(result); verify(assignmentToShift, times(4)).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } |
@Test public void shouldReturnFalseAndAddErrorWhenValidateTransferAndLocationsAreNull() { given(transfer.getStringField(TYPE)).willReturn(TRANSPORT.getStringValue()); given(transfer.getField(TIME)).willReturn(time); given(transfer.getBelongsToField(LOCATION_FROM)).willReturn(null); given(transfer.getBelongsToField(LOCATION_TO)).willReturn(null); boolean result = transferModelValidators.validateTransfer(transferDD, transfer); assertFalse(result); verify(transfer, times(2)).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } boolean validateTransfer(final DataDefinition transferDD, final Entity transfer); boolean checkIfLocationFromOrLocationToHasExternalNumber(final DataDefinition transferDD, final Entity transfer); } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } boolean validateTransfer(final DataDefinition transferDD, final Entity transfer); boolean checkIfLocationFromOrLocationToHasExternalNumber(final DataDefinition transferDD, final Entity transfer); } |
@Test public void shouldReturnFalseWhenCheckUniqueEntityIfEntityIsSaved() { stubFind(mockEntity()); boolean result = assignmentToShiftHooks.checkUniqueEntity(assignmentToShift); Assert.assertFalse(result); verify(assignmentToShift, times(4)).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } | AssignmentToShiftHooks { boolean checkUniqueEntity(final Entity assignmentToShift) { Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE); Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT); Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY); Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW); AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty(); SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate); criteria.withShiftCriteria(idEq(shift.getId())); criteria.withFactoryCriteria(idEq(factory.getId())); if (crew != null) { criteria.withCrewCriteria(idEq(crew.getId())); } else { additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW)); } if (assignmentToShift.getId() != null) { additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId())); } criteria.withCriteria(additionalCriteria); for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) { addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift); return false; } return true; } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } |
@Test public final void shouldPickUpNextDay() { Entity startProjection1 = mockStartDateProjection(START_DATE.plusDays(1)); Entity startProjection2 = mockStartDateProjection(START_DATE.plusDays(2)); Entity startProjection3 = mockStartDateProjection(START_DATE.plusDays(3)); stubFindAll(Lists.newArrayList(startProjection1, startProjection2, startProjection3)); given(shiftPojo.worksAt(START_DATE)).willReturn(true); given(shiftPojo.worksAt(START_DATE.plusDays(1))).willReturn(false); given(shiftPojo.worksAt(START_DATE.plusDays(2))).willReturn(true); given(shiftPojo.worksAt(START_DATE.plusDays(3))).willReturn(false); given(shiftPojo.worksAt(START_DATE.plusDays(4))).willReturn(false); given(shiftPojo.worksAt(START_DATE.plusDays(5))).willReturn(true); assignmentToShiftHooks.setNextDay(assignmentToShift); ArgumentCaptor<Date> dateCaptor = ArgumentCaptor.forClass(Date.class); verify(assignmentToShift).setField(eq(AssignmentToShiftFields.START_DATE), dateCaptor.capture()); Date pickedUpNextStartDate = dateCaptor.getValue(); Assert.assertTrue(START_DATE.plusDays(5).toDate().compareTo(pickedUpNextStartDate) == 0); } | void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } |
@Test public final void shouldPickUpNextDayIfThereIsNoOccupiedDates() { given(shiftPojo.worksAt(START_DATE)).willReturn(true); given(shiftPojo.worksAt(START_DATE.plusDays(1))).willReturn(false); given(shiftPojo.worksAt(START_DATE.plusDays(2))).willReturn(true); given(shiftPojo.worksAt(START_DATE.plusDays(3))).willReturn(false); given(shiftPojo.worksAt(START_DATE.plusDays(4))).willReturn(false); given(shiftPojo.worksAt(START_DATE.plusDays(5))).willReturn(true); assignmentToShiftHooks.setNextDay(assignmentToShift); ArgumentCaptor<Date> dateCaptor = ArgumentCaptor.forClass(Date.class); verify(assignmentToShift).setField(eq(AssignmentToShiftFields.START_DATE), dateCaptor.capture()); Date pickedUpNextStartDate = dateCaptor.getValue(); Assert.assertTrue(START_DATE.plusDays(2).toDate().compareTo(pickedUpNextStartDate) == 0); } | void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } |
@Test public final void shouldNotPickUpAnyDateIfShiftNeverWork() { Entity startProjection1 = mockStartDateProjection(START_DATE.plusDays(1)); Entity startProjection2 = mockStartDateProjection(START_DATE.plusDays(2)); Entity startProjection3 = mockStartDateProjection(START_DATE.plusDays(3)); stubFindAll(Lists.newArrayList(startProjection1, startProjection2, startProjection3)); assignmentToShiftHooks.setNextDay(assignmentToShift); verify(assignmentToShift).setField(eq(AssignmentToShiftFields.START_DATE), refEq(null)); } | void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } | AssignmentToShiftHooks { void setNextDay(final Entity assignmentToShift) { Optional<LocalDate> maybeNewDate = resolveNextStartDate(assignmentToShift); assignmentToShift.setField(AssignmentToShiftFields.START_DATE, maybeNewDate.transform(TO_DATE).orNull()); } void onCreate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); void onCopy(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); boolean onValidate(final DataDefinition assignmentToShiftDD, final Entity assignmentToShift); } |
@Test public void shouldEnabledProductionLineAndDisableOccupationTypeNameFieldsWhenWorkOnLineIsSelected() { String dictionaryName = "Praca na linii"; String technicalCode = "01workOnLine"; given(occupationType.getFieldValue()).willReturn(dictionaryName); SearchCriterion criterion = SearchRestrictions.eq(NAME, dictionaryName); given(builder.add(criterion)).willReturn(builder); given(builder.uniqueResult()).willReturn(dictionary); given(dictionary.getStringField(TECHNICAL_CODE)).willReturn(technicalCode); detailsHooks.setFieldsEnabledWhenTypeIsSpecific(view); verify(productionLine).setVisible(true); verify(occupationTypeName).setVisible(false); } | public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } |
@Test public void shouldDisabledProductionLineAndEnableOccupationTypeNameFieldsWhenOtherCaseIsSelected() { String dictionaryName = "Inne zadania"; String technicalCode = "02otherCase"; given(occupationType.getFieldValue()).willReturn(dictionaryName); SearchCriterion criterion = SearchRestrictions.eq(NAME, dictionaryName); given(builder.add(criterion)).willReturn(builder); given(builder.uniqueResult()).willReturn(dictionary); given(dictionary.getStringField(TECHNICAL_CODE)).willReturn(technicalCode); detailsHooks.setFieldsEnabledWhenTypeIsSpecific(view); verify(productionLine).setVisible(false); verify(occupationTypeName).setVisible(true); } | public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } |
@Test public void shouldDisabledProductionLineAndOccupationTypeNameFieldsWhenMixDictionaryIsSelected() { String dictionaryName = "MIX"; given(occupationType.getFieldValue()).willReturn(dictionaryName); SearchCriterion criterion = SearchRestrictions.eq(NAME, dictionaryName); given(builder.add(criterion)).willReturn(builder); given(builder.uniqueResult()).willReturn(dictionary); given(dictionary.getStringField(TECHNICAL_CODE)).willReturn(Mockito.anyString()); detailsHooks.setFieldsEnabledWhenTypeIsSpecific(view); verify(productionLine).setVisible(false); verify(occupationTypeName).setVisible(false); } | public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } |
@Test public void shouldDisabledProductionLineAndOccupationTypeNameFieldsWhenEmptyIsSelected() { String dictionaryName = ""; given(occupationType.getFieldValue()).willReturn(dictionaryName); SearchCriterion criterion = SearchRestrictions.eq(NAME, dictionaryName); given(builder.add(criterion)).willReturn(builder); given(builder.uniqueResult()).willReturn(null); detailsHooks.setFieldsEnabledWhenTypeIsSpecific(view); verify(productionLine).setVisible(false); verify(occupationTypeName).setVisible(false); } | public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } | StaffAssignmentToShiftDetailsHooks { public void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view) { FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); Entity dictionaryItem = findDictionaryItemByName(occupationType.getFieldValue().toString()); if (dictionaryItem == null) { setFieldsEnabled(view, false, false); } else { String occupationTypeTechnicalCode = dictionaryItem.getStringField(TECHNICAL_CODE); if (WORK_ON_LINE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, true, false); } else if (OTHER_CASE.getStringValue().equals(occupationTypeTechnicalCode)) { setFieldsEnabled(view, false, true); } else { setFieldsEnabled(view, false, false); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } |
@Test public void shouldntSetOccupationTypeToDefaultWhenFormIsSaved() { String dictionaryName = "Praca na linii"; given(staffAssignmentToShiftForm.getEntityId()).willReturn(1L); given(occupationType.getFieldValue()).willReturn(dictionaryName); detailsHooks.setOccupationTypeToDefault(view); verify(occupationType, never()).setFieldValue(Mockito.anyString()); } | public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } |
@Test public void shouldntSetOccupationTypeToDefaultWhenDictionaryIsNull() { given(staffAssignmentToShiftForm.getEntityId()).willReturn(null); given(occupationType.getFieldValue()).willReturn(null); SearchCriterion criterion = SearchRestrictions.eq(TECHNICAL_CODE, WORK_ON_LINE.getStringValue()); given(builder.add(criterion)).willReturn(builder); given(builder.uniqueResult()).willReturn(null); detailsHooks.setOccupationTypeToDefault(view); verify(occupationType, never()).setFieldValue(Mockito.anyString()); } | public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } |
@Test public void shouldReturnTrueWhenValidateTransferAndAllFieldsArentNull() { given(transfer.getStringField(TYPE)).willReturn(TRANSPORT.getStringValue()); given(transfer.getField(TIME)).willReturn(time); given(transfer.getBelongsToField(LOCATION_FROM)).willReturn(locationFrom); given(transfer.getBelongsToField(LOCATION_TO)).willReturn(locationTo); boolean result = transferModelValidators.validateTransfer(transferDD, transfer); assertTrue(result); verify(transfer, never()).addError(Mockito.any(FieldDefinition.class), Mockito.anyString()); } | public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } boolean validateTransfer(final DataDefinition transferDD, final Entity transfer); boolean checkIfLocationFromOrLocationToHasExternalNumber(final DataDefinition transferDD, final Entity transfer); } | TransferModelValidators { public boolean validateTransfer(final DataDefinition transferDD, final Entity transfer) { boolean isValid = true; boolean result = true; String type = transfer.getStringField(TYPE); Date time = (Date) transfer.getField(TIME); if (type == null) { transfer.addError(transferDD.getField(TYPE), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_TYPE); isValid = false; } else { result = validateLocation(transferDD, transfer, type); } if (time == null) { transfer.addError(transferDD.getField(TIME), L_MATERIAL_FLOW_VALIDATE_GLOBAL_ERROR_FILL_DATE); isValid = false; } if (isValid) { isValid = result; } return isValid; } boolean validateTransfer(final DataDefinition transferDD, final Entity transfer); boolean checkIfLocationFromOrLocationToHasExternalNumber(final DataDefinition transferDD, final Entity transfer); } |
@Test public void shouldSetOccupationTypeToDefaultWhenDictionary() { given(staffAssignmentToShiftForm.getEntityId()).willReturn(null); given(occupationType.getFieldValue()).willReturn(null); SearchCriterion criterion = SearchRestrictions.eq(TECHNICAL_CODE, WORK_ON_LINE.getStringValue()); given(builder.add(criterion)).willReturn(builder); given(builder.uniqueResult()).willReturn(dictionary); given(dictionary.getStringField(NAME)).willReturn(Mockito.anyString()); detailsHooks.setOccupationTypeToDefault(view); verify(occupationType).setFieldValue(Mockito.anyString()); } | public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } | StaffAssignmentToShiftDetailsHooks { public void setOccupationTypeToDefault(final ViewDefinitionState view) { FormComponent staffAssignmentToShiftForm = (FormComponent) view.getComponentByReference("form"); FieldComponent occupationType = (FieldComponent) view.getComponentByReference(OCCUPATION_TYPE); if ((staffAssignmentToShiftForm.getEntityId() == null) && (occupationType.getFieldValue() == null)) { Entity dictionaryItem = findDictionaryItemByTechnicalCode(WORK_ON_LINE.getStringValue()); if (dictionaryItem != null) { String occupationTypeName = dictionaryItem.getStringField(NAME); occupationType.setFieldValue(occupationTypeName); occupationType.requestComponentUpdateState(); } } } void setCriteriaModifiers(final ViewDefinitionState view); void setFieldsEnabledWhenTypeIsSpecific(final ViewDefinitionState view); void setOccupationTypeToDefault(final ViewDefinitionState view); } |
@Test public void shouldReturnIfTheTechnologyIsntInDraftState() { given(view.getComponentByReference("form")).willReturn(form); given(form.getEntity()).willReturn(technology); given(technology.getStringField("state")).willReturn("02accepted"); technologyListenersTN.checkOperationOutputQuantities(view, componentState, null); verify(normService, never()).checkOperationOutputQuantities(technology); verify(form, never()).addMessage(Mockito.anyString(), Mockito.eq(MessageType.INFO), Mockito.eq(false)); } | public void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent technologyForm = (FormComponent) view.getComponentByReference(L_FORM); if (technologyForm.getEntityId() == null) { return; } Entity technology = technologyForm.getEntity(); if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) { return; } technology = technology.getDataDefinition().get(technology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } technologyForm.addMessage("technologies.technology.validate.error.invalidQuantity", MessageType.INFO, false, builder.toString()); } } | TechnologyListenersTN { public void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent technologyForm = (FormComponent) view.getComponentByReference(L_FORM); if (technologyForm.getEntityId() == null) { return; } Entity technology = technologyForm.getEntity(); if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) { return; } technology = technology.getDataDefinition().get(technology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } technologyForm.addMessage("technologies.technology.validate.error.invalidQuantity", MessageType.INFO, false, builder.toString()); } } } | TechnologyListenersTN { public void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent technologyForm = (FormComponent) view.getComponentByReference(L_FORM); if (technologyForm.getEntityId() == null) { return; } Entity technology = technologyForm.getEntity(); if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) { return; } technology = technology.getDataDefinition().get(technology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } technologyForm.addMessage("technologies.technology.validate.error.invalidQuantity", MessageType.INFO, false, builder.toString()); } } } | TechnologyListenersTN { public void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent technologyForm = (FormComponent) view.getComponentByReference(L_FORM); if (technologyForm.getEntityId() == null) { return; } Entity technology = technologyForm.getEntity(); if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) { return; } technology = technology.getDataDefinition().get(technology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } technologyForm.addMessage("technologies.technology.validate.error.invalidQuantity", MessageType.INFO, false, builder.toString()); } } void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | TechnologyListenersTN { public void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent technologyForm = (FormComponent) view.getComponentByReference(L_FORM); if (technologyForm.getEntityId() == null) { return; } Entity technology = technologyForm.getEntity(); if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) { return; } technology = technology.getDataDefinition().get(technology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } technologyForm.addMessage("technologies.technology.validate.error.invalidQuantity", MessageType.INFO, false, builder.toString()); } } void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Ignore @Test public void shouldPassValidationErrorsToTheEntityForAcceptedTechnology() { given(view.getComponentByReference("form")).willReturn(form); given(form.getEntity()).willReturn(technology); given(technology.getStringField("state")).willReturn("01draft"); given(technology.getDataDefinition()).willReturn(dataDefinition); given(technology.getId()).willReturn(0L); given(dataDefinition.get(0L)).willReturn(technology); technologyListenersTN.checkOperationOutputQuantities(view, componentState, null); verify(form).addMessage(Mockito.eq("err1"), Mockito.eq(MessageType.INFO), Mockito.eq(false)); verify(form).addMessage(Mockito.eq("err2"), Mockito.eq(MessageType.INFO), Mockito.eq(false)); } | public void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent technologyForm = (FormComponent) view.getComponentByReference(L_FORM); if (technologyForm.getEntityId() == null) { return; } Entity technology = technologyForm.getEntity(); if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) { return; } technology = technology.getDataDefinition().get(technology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } technologyForm.addMessage("technologies.technology.validate.error.invalidQuantity", MessageType.INFO, false, builder.toString()); } } | TechnologyListenersTN { public void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent technologyForm = (FormComponent) view.getComponentByReference(L_FORM); if (technologyForm.getEntityId() == null) { return; } Entity technology = technologyForm.getEntity(); if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) { return; } technology = technology.getDataDefinition().get(technology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } technologyForm.addMessage("technologies.technology.validate.error.invalidQuantity", MessageType.INFO, false, builder.toString()); } } } | TechnologyListenersTN { public void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent technologyForm = (FormComponent) view.getComponentByReference(L_FORM); if (technologyForm.getEntityId() == null) { return; } Entity technology = technologyForm.getEntity(); if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) { return; } technology = technology.getDataDefinition().get(technology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } technologyForm.addMessage("technologies.technology.validate.error.invalidQuantity", MessageType.INFO, false, builder.toString()); } } } | TechnologyListenersTN { public void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent technologyForm = (FormComponent) view.getComponentByReference(L_FORM); if (technologyForm.getEntityId() == null) { return; } Entity technology = technologyForm.getEntity(); if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) { return; } technology = technology.getDataDefinition().get(technology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } technologyForm.addMessage("technologies.technology.validate.error.invalidQuantity", MessageType.INFO, false, builder.toString()); } } void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } | TechnologyListenersTN { public void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent technologyForm = (FormComponent) view.getComponentByReference(L_FORM); if (technologyForm.getEntityId() == null) { return; } Entity technology = technologyForm.getEntity(); if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) { return; } technology = technology.getDataDefinition().get(technology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } technologyForm.addMessage("technologies.technology.validate.error.invalidQuantity", MessageType.INFO, false, builder.toString()); } } void checkOperationOutputQuantities(final ViewDefinitionState view, final ComponentState componentState,
final String[] args); } |
@Test public void shouldNotFreakOutWhenTheOutputProductComponentCannotBeFound() { given(technologyService.getMainOutputProductComponent(opComp1)).willThrow(new IllegalStateException()); technologyOperationComponentDetailsHooks.checkOperationOutputQuantities(view); } | public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } void checkOperationOutputQuantities(final ViewDefinitionState view); void updateNextOperationAfterProducedQuantityFieldStateonWindowLoad(final ViewDefinitionState viewDefinitionState); void updateFieldsStateOnWindowLoad(final ViewDefinitionState viewDefinitionState); void fillUnitFields(final ViewDefinitionState view); } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } void checkOperationOutputQuantities(final ViewDefinitionState view); void updateNextOperationAfterProducedQuantityFieldStateonWindowLoad(final ViewDefinitionState viewDefinitionState); void updateFieldsStateOnWindowLoad(final ViewDefinitionState viewDefinitionState); void fillUnitFields(final ViewDefinitionState view); } |
@Ignore @Test public void shouldAttachCorrectErrorToTheRightComponentIfQuantitiesAreDifferent() { String number = decimalFormat.format(prodComp1.getDecimalField("quantity")); technologyOperationComponentDetailsHooks.checkOperationOutputQuantities(view); verify(productionInOneCycle).addMessage(Mockito.anyString(), MessageType.FAILURE); } | public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } void checkOperationOutputQuantities(final ViewDefinitionState view); void updateNextOperationAfterProducedQuantityFieldStateonWindowLoad(final ViewDefinitionState viewDefinitionState); void updateFieldsStateOnWindowLoad(final ViewDefinitionState viewDefinitionState); void fillUnitFields(final ViewDefinitionState view); } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } void checkOperationOutputQuantities(final ViewDefinitionState view); void updateNextOperationAfterProducedQuantityFieldStateonWindowLoad(final ViewDefinitionState viewDefinitionState); void updateFieldsStateOnWindowLoad(final ViewDefinitionState viewDefinitionState); void fillUnitFields(final ViewDefinitionState view); } |
@Test public void shouldNotGiveAnyErrorIfQuantitiesAreTheSame() { given(prodComp1.getDecimalField("quantity")).willReturn(new BigDecimal(1.1f)); given(opComp1.getDecimalField("productionInOneCycle")).willReturn(new BigDecimal(1.1f)); technologyOperationComponentDetailsHooks.checkOperationOutputQuantities(view); verify(productionInOneCycle, Mockito.never()).addMessage(Mockito.anyString(), Mockito.eq(MessageType.FAILURE)); } | public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } void checkOperationOutputQuantities(final ViewDefinitionState view); void updateNextOperationAfterProducedQuantityFieldStateonWindowLoad(final ViewDefinitionState viewDefinitionState); void updateFieldsStateOnWindowLoad(final ViewDefinitionState viewDefinitionState); void fillUnitFields(final ViewDefinitionState view); } | TechnologyOperationComponentDetailsHooks { public void checkOperationOutputQuantities(final ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference("form"); if (form.getEntityId() == null) { return; } Entity operationComponent = form.getEntity(); operationComponent = operationComponent.getDataDefinition().get(operationComponent.getId()); BigDecimal timeNormsQuantity = operationComponent.getDecimalField("productionInOneCycle"); Entity productOutComponent = null; try { productOutComponent = technologyService.getMainOutputProductComponent(operationComponent); } catch (IllegalStateException e) { return; } BigDecimal currentQuantity = productOutComponent.getDecimalField("quantity"); if (timeNormsQuantity != null && timeNormsQuantity.compareTo(currentQuantity) != 0) { form.addMessage("technologies.technologyOperationComponent.validate.error.invalidQuantity", MessageType.INFO, false, numberService.format(currentQuantity), productOutComponent.getBelongsToField("product").getStringField("unit")); } } void checkOperationOutputQuantities(final ViewDefinitionState view); void updateNextOperationAfterProducedQuantityFieldStateonWindowLoad(final ViewDefinitionState viewDefinitionState); void updateFieldsStateOnWindowLoad(final ViewDefinitionState viewDefinitionState); void fillUnitFields(final ViewDefinitionState view); } |
@Test public void shouldAlwaysPassIfTheTechnologyIsInDraftState() { given(stateChangeContext.getOwner()).willReturn(technology); given(technology.getDataDefinition()).willReturn(dataDefinition); given(technology.getStringField("state")).willReturn("01draft"); boolean isValid = technologyStateChangeListenerServiceTNFO.checkOperationOutputQuantities(stateChangeContext); assertTrue(isValid); } | public boolean checkOperationOutputQuantities(final StateChangeContext stateChangeContext) { Entity techology = stateChangeContext.getOwner(); Entity technology = techology.getDataDefinition().get(techology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { stateChangeContext.addValidationError("technologies.technology.validate.global.error.treeIsNotValid"); StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } stateChangeContext.addMessage("technologies.technology.validate.error.invalidQuantity", StateMessageType.FAILURE, false, builder.toString()); } return messages.isEmpty(); } | TechnologyStateChangeListenerServiceTNFO { public boolean checkOperationOutputQuantities(final StateChangeContext stateChangeContext) { Entity techology = stateChangeContext.getOwner(); Entity technology = techology.getDataDefinition().get(techology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { stateChangeContext.addValidationError("technologies.technology.validate.global.error.treeIsNotValid"); StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } stateChangeContext.addMessage("technologies.technology.validate.error.invalidQuantity", StateMessageType.FAILURE, false, builder.toString()); } return messages.isEmpty(); } } | TechnologyStateChangeListenerServiceTNFO { public boolean checkOperationOutputQuantities(final StateChangeContext stateChangeContext) { Entity techology = stateChangeContext.getOwner(); Entity technology = techology.getDataDefinition().get(techology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { stateChangeContext.addValidationError("technologies.technology.validate.global.error.treeIsNotValid"); StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } stateChangeContext.addMessage("technologies.technology.validate.error.invalidQuantity", StateMessageType.FAILURE, false, builder.toString()); } return messages.isEmpty(); } } | TechnologyStateChangeListenerServiceTNFO { public boolean checkOperationOutputQuantities(final StateChangeContext stateChangeContext) { Entity techology = stateChangeContext.getOwner(); Entity technology = techology.getDataDefinition().get(techology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { stateChangeContext.addValidationError("technologies.technology.validate.global.error.treeIsNotValid"); StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } stateChangeContext.addMessage("technologies.technology.validate.error.invalidQuantity", StateMessageType.FAILURE, false, builder.toString()); } return messages.isEmpty(); } boolean checkOperationOutputQuantities(final StateChangeContext stateChangeContext); boolean checkIfAllOperationComponenthHaveTJSet(final StateChangeContext stateChangeContext); } | TechnologyStateChangeListenerServiceTNFO { public boolean checkOperationOutputQuantities(final StateChangeContext stateChangeContext) { Entity techology = stateChangeContext.getOwner(); Entity technology = techology.getDataDefinition().get(techology.getId()); List<String> messages = normService.checkOperationOutputQuantities(technology); if (!messages.isEmpty()) { stateChangeContext.addValidationError("technologies.technology.validate.global.error.treeIsNotValid"); StringBuilder builder = new StringBuilder(); for (String message : messages) { builder.append(message); builder.append(", "); } stateChangeContext.addMessage("technologies.technology.validate.error.invalidQuantity", StateMessageType.FAILURE, false, builder.toString()); } return messages.isEmpty(); } boolean checkOperationOutputQuantities(final StateChangeContext stateChangeContext); boolean checkIfAllOperationComponenthHaveTJSet(final StateChangeContext stateChangeContext); } |
@Test public void shouldOmmitCheckingIfTheTreeIsntCompleteYet() { EntityTree tree = mockEntityTreeIterator(new LinkedList<Entity>()); given(technology.getTreeField("operationComponents")).willReturn(tree); List<String> messages = normService.checkOperationOutputQuantities(technology); assertTrue(messages.isEmpty()); } | public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } List<String> checkOperationOutputQuantities(final Entity technology); } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } List<String> checkOperationOutputQuantities(final Entity technology); } |
@Test public void shouldNotFreakOutIfItCantFindOutputProductForAnOperationComponent() { EntityTree tree = mockEntityTreeIterator(asList(operComp1)); given(technology.getTreeField("operationComponents")).willReturn(tree); given(technologyService.getProductCountForOperationComponent(operComp1)).willThrow(new IllegalStateException()); List<String> messages = normService.checkOperationOutputQuantities(technology); assertTrue(messages.isEmpty()); } | public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } List<String> checkOperationOutputQuantities(final Entity technology); } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } List<String> checkOperationOutputQuantities(final Entity technology); } |
@Ignore @Test public void shouldReturnAnErrorMessageIfTheQuantitiesDontMatch() { EntityTree tree = mockEntityTreeIterator(asList(operComp1)); given(technology.getTreeField("operationComponents")).willReturn(tree); given(technologyService.getProductCountForOperationComponent(operComp1)).willReturn(new BigDecimal(13.5)); given(operComp1.getDecimalField("productionInOneCycle")).willReturn(new BigDecimal(13.51)); Locale locale = LocaleContextHolder.getLocale(); given(translationService.translate("technologies.technology.validate.error.invalidQuantity1", locale)).willReturn( "message1"); given(operComp1.getStringField("nodeNumber")).willReturn("1"); given(translationService.translate("technologies.technology.validate.error.invalidQuantity2", locale)).willReturn( "message2"); List<String> messages = normService.checkOperationOutputQuantities(technology); assertEquals(1, messages.size()); assertEquals("message1 1 message2", messages.get(0)); } | public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } List<String> checkOperationOutputQuantities(final Entity technology); } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } List<String> checkOperationOutputQuantities(final Entity technology); } |
@Test public final void shouldSetInputProductsRequiredForTypeFromParameters() { given(inputProductsRequiredForTypeField.getFieldValue()).willReturn(null); orderDetailsHooksMR.setInputProductsRequiredForTypeFromParameters(view); verify(inputProductsRequiredForTypeField).setFieldValue(InputProductsRequiredForType.START_ORDER.getStringValue()); } | public void setInputProductsRequiredForTypeFromParameters(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); if (orderForm.getEntityId() != null) { return; } FieldComponent inputProductsRequiredForTypeField = (FieldComponent) view .getComponentByReference(OrderFieldsMR.INPUT_PRODUCTS_REQUIRED_FOR_TYPE); String inputProductsRequiredForType = (String) inputProductsRequiredForTypeField.getFieldValue(); if (StringUtils.isEmpty(inputProductsRequiredForType)) { inputProductsRequiredForTypeField.setFieldValue(getInputProductsRequiredForType()); } inputProductsRequiredForTypeField.requestComponentUpdateState(); } | OrderDetailsHooksMR { public void setInputProductsRequiredForTypeFromParameters(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); if (orderForm.getEntityId() != null) { return; } FieldComponent inputProductsRequiredForTypeField = (FieldComponent) view .getComponentByReference(OrderFieldsMR.INPUT_PRODUCTS_REQUIRED_FOR_TYPE); String inputProductsRequiredForType = (String) inputProductsRequiredForTypeField.getFieldValue(); if (StringUtils.isEmpty(inputProductsRequiredForType)) { inputProductsRequiredForTypeField.setFieldValue(getInputProductsRequiredForType()); } inputProductsRequiredForTypeField.requestComponentUpdateState(); } } | OrderDetailsHooksMR { public void setInputProductsRequiredForTypeFromParameters(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); if (orderForm.getEntityId() != null) { return; } FieldComponent inputProductsRequiredForTypeField = (FieldComponent) view .getComponentByReference(OrderFieldsMR.INPUT_PRODUCTS_REQUIRED_FOR_TYPE); String inputProductsRequiredForType = (String) inputProductsRequiredForTypeField.getFieldValue(); if (StringUtils.isEmpty(inputProductsRequiredForType)) { inputProductsRequiredForTypeField.setFieldValue(getInputProductsRequiredForType()); } inputProductsRequiredForTypeField.requestComponentUpdateState(); } } | OrderDetailsHooksMR { public void setInputProductsRequiredForTypeFromParameters(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); if (orderForm.getEntityId() != null) { return; } FieldComponent inputProductsRequiredForTypeField = (FieldComponent) view .getComponentByReference(OrderFieldsMR.INPUT_PRODUCTS_REQUIRED_FOR_TYPE); String inputProductsRequiredForType = (String) inputProductsRequiredForTypeField.getFieldValue(); if (StringUtils.isEmpty(inputProductsRequiredForType)) { inputProductsRequiredForTypeField.setFieldValue(getInputProductsRequiredForType()); } inputProductsRequiredForTypeField.requestComponentUpdateState(); } void setInputProductsRequiredForTypeFromParameters(final ViewDefinitionState view); } | OrderDetailsHooksMR { public void setInputProductsRequiredForTypeFromParameters(final ViewDefinitionState view) { FormComponent orderForm = (FormComponent) view.getComponentByReference(L_FORM); if (orderForm.getEntityId() != null) { return; } FieldComponent inputProductsRequiredForTypeField = (FieldComponent) view .getComponentByReference(OrderFieldsMR.INPUT_PRODUCTS_REQUIRED_FOR_TYPE); String inputProductsRequiredForType = (String) inputProductsRequiredForTypeField.getFieldValue(); if (StringUtils.isEmpty(inputProductsRequiredForType)) { inputProductsRequiredForTypeField.setFieldValue(getInputProductsRequiredForType()); } inputProductsRequiredForTypeField.requestComponentUpdateState(); } void setInputProductsRequiredForTypeFromParameters(final ViewDefinitionState view); } |
@Ignore @Test public void shouldReturnNoErrorsIfTheQuantitiesDoMatch() { EntityTree tree = mockEntityTreeIterator(asList(operComp1)); given(technology.getTreeField("operationComponents")).willReturn(tree); given(technologyService.getProductCountForOperationComponent(operComp1)).willReturn(new BigDecimal(13.5)); given(operComp1.getDecimalField("productionInOneCycle")).willReturn(new BigDecimal(13.500)); List<String> messages = normService.checkOperationOutputQuantities(technology); assertEquals(0, messages.size()); } | public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } List<String> checkOperationOutputQuantities(final Entity technology); } | NormService { public List<String> checkOperationOutputQuantities(final Entity technology) { List<String> messages = Lists.newArrayList(); List<Entity> operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS); for (Entity operationComponent : operationComponents) { BigDecimal timeNormsQuantity = getProductionInOneCycle(operationComponent); BigDecimal currentQuantity; try { currentQuantity = technologyService.getProductCountForOperationComponent(operationComponent); } catch (IllegalStateException e) { continue; } if (timeNormsQuantity == null || timeNormsQuantity.compareTo(currentQuantity) != 0) { String nodeNumber = operationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER); if (nodeNumber == null) { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); if (operation != null) { String name = operation.getStringField(OperationFields.NAME); if (name != null) { messages.add(name); } } } else { messages.add(nodeNumber); } } } return messages; } List<String> checkOperationOutputQuantities(final Entity technology); } |
@Test public final void shouldReturnMinimalSamplesLoader() throws Exception { given(multiTenantService.getTenantSamplesDataset()).willReturn(SamplesDataset.MINIMAL); SamplesLoader samplesLoader = samplesLoaderResolver.resolve(); assertEquals(minimalSamplesLoader, samplesLoader); } | public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } SamplesLoader resolve(); } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } SamplesLoader resolve(); } |
@Test public final void shouldReturnTestSamplesLoader() throws Exception { given(multiTenantService.getTenantSamplesDataset()).willReturn(SamplesDataset.TEST); SamplesLoader samplesLoader = samplesLoaderResolver.resolve(); assertEquals(testSamplesLoader, samplesLoader); } | public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } SamplesLoader resolve(); } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } SamplesLoader resolve(); } |
@Test public final void shouldReturnGeneratedSamplesLoader() throws Exception { given(multiTenantService.getTenantSamplesDataset()).willReturn(SamplesDataset.GENERATED); SamplesLoader samplesLoader = samplesLoaderResolver.resolve(); assertEquals(generatedSamplesLoader, samplesLoader); } | public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } SamplesLoader resolve(); } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } SamplesLoader resolve(); } |
@Test public final void shouldReturnDummySamplesLoader() throws Exception { given(multiTenantService.getTenantSamplesDataset()).willReturn(SamplesDataset.NONE); SamplesLoader samplesLoader = samplesLoaderResolver.resolve(); assertEquals(dummySamplesLoader, samplesLoader); } | public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } SamplesLoader resolve(); } | SamplesLoaderResolver { public SamplesLoader resolve() { final SamplesDataset samplesDataset = multiTenantService.getTenantSamplesDataset(); switch (samplesDataset) { case MINIMAL: return minimalSamplesLoader; case TEST: return testSamplesLoader; case GENERATED: return generatedSamplesLoader; case NONE: return dummySamplesLoader; default: throw new IllegalArgumentException("Unsupported dataset: " + samplesDataset); } } SamplesLoader resolve(); } |
@Test public void shouldRedirectToDeliveryReportOnPrintDelivery() throws Exception { String stateValue = "111"; when(formComponent.getFieldValue()).thenReturn(stateValue); deliveryDetailsListeners.printDeliveryReport(view, formComponent, args); verify(view).redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + stateValue, true, false); } | public final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args) { if (state instanceof FormComponent) { state.performEvent(view, "save", args); if (!state.isHasError()) { view.redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + state.getFieldValue(), true, false); } } else { state.addMessage("deliveries.delivery.report.componentFormError", MessageType.FAILURE); } } | DeliveryDetailsListeners { public final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args) { if (state instanceof FormComponent) { state.performEvent(view, "save", args); if (!state.isHasError()) { view.redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + state.getFieldValue(), true, false); } } else { state.addMessage("deliveries.delivery.report.componentFormError", MessageType.FAILURE); } } } | DeliveryDetailsListeners { public final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args) { if (state instanceof FormComponent) { state.performEvent(view, "save", args); if (!state.isHasError()) { view.redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + state.getFieldValue(), true, false); } } else { state.addMessage("deliveries.delivery.report.componentFormError", MessageType.FAILURE); } } } | DeliveryDetailsListeners { public final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args) { if (state instanceof FormComponent) { state.performEvent(view, "save", args); if (!state.isHasError()) { view.redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + state.getFieldValue(), true, false); } } else { state.addMessage("deliveries.delivery.report.componentFormError", MessageType.FAILURE); } } void fillCompanyFieldsForSupplier(final ViewDefinitionState view, final ComponentState state, final String[] args); final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args); final void printOrderReport(final ViewDefinitionState view, final ComponentState state, final String[] args); final void copyProductsWithoutQuantityAndPrice(final ViewDefinitionState view, final ComponentState state,
final String[] args); final void copyProductsWithQuantityAndPrice(final ViewDefinitionState view, final ComponentState state,
final String[] args); final void recalculateReservations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void changeStorageLocations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void assignStorageLocations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void createRelatedDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args); BigDecimal getConversion(Entity product); final void showRelatedDeliveries(final ViewDefinitionState view, final ComponentState state, final String[] args); final void showProduct(final ViewDefinitionState view, final ComponentState state, final String[] args); void disableShowProductButton(final ViewDefinitionState view, final ComponentState state, final String[] args); void updateChangeStorageLocationButton(final ViewDefinitionState view, final ComponentState state, final String[] args); void validateColumnsWidthForOrder(final ViewDefinitionState view, final ComponentState state, final String[] args); void validateColumnsWidthForDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args); void downloadAtachment(final ViewDefinitionState view, final ComponentState state, final String[] args); } | DeliveryDetailsListeners { public final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args) { if (state instanceof FormComponent) { state.performEvent(view, "save", args); if (!state.isHasError()) { view.redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + state.getFieldValue(), true, false); } } else { state.addMessage("deliveries.delivery.report.componentFormError", MessageType.FAILURE); } } void fillCompanyFieldsForSupplier(final ViewDefinitionState view, final ComponentState state, final String[] args); final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args); final void printOrderReport(final ViewDefinitionState view, final ComponentState state, final String[] args); final void copyProductsWithoutQuantityAndPrice(final ViewDefinitionState view, final ComponentState state,
final String[] args); final void copyProductsWithQuantityAndPrice(final ViewDefinitionState view, final ComponentState state,
final String[] args); final void recalculateReservations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void changeStorageLocations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void assignStorageLocations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void createRelatedDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args); BigDecimal getConversion(Entity product); final void showRelatedDeliveries(final ViewDefinitionState view, final ComponentState state, final String[] args); final void showProduct(final ViewDefinitionState view, final ComponentState state, final String[] args); void disableShowProductButton(final ViewDefinitionState view, final ComponentState state, final String[] args); void updateChangeStorageLocationButton(final ViewDefinitionState view, final ComponentState state, final String[] args); void validateColumnsWidthForOrder(final ViewDefinitionState view, final ComponentState state, final String[] args); void validateColumnsWidthForDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args); void downloadAtachment(final ViewDefinitionState view, final ComponentState state, final String[] args); static final String OFFER; } |
@Test public void shouldAddMessageWhenStateIsNotFormComponentOnPrintDelivery() throws Exception { String stateValue = "111"; when(grid.getFieldValue()).thenReturn(stateValue); deliveryDetailsListeners.printDeliveryReport(view, grid, args); verify(grid).addMessage("deliveries.delivery.report.componentFormError", MessageType.FAILURE); verify(view, never()).redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + stateValue, true, false); } | public final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args) { if (state instanceof FormComponent) { state.performEvent(view, "save", args); if (!state.isHasError()) { view.redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + state.getFieldValue(), true, false); } } else { state.addMessage("deliveries.delivery.report.componentFormError", MessageType.FAILURE); } } | DeliveryDetailsListeners { public final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args) { if (state instanceof FormComponent) { state.performEvent(view, "save", args); if (!state.isHasError()) { view.redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + state.getFieldValue(), true, false); } } else { state.addMessage("deliveries.delivery.report.componentFormError", MessageType.FAILURE); } } } | DeliveryDetailsListeners { public final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args) { if (state instanceof FormComponent) { state.performEvent(view, "save", args); if (!state.isHasError()) { view.redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + state.getFieldValue(), true, false); } } else { state.addMessage("deliveries.delivery.report.componentFormError", MessageType.FAILURE); } } } | DeliveryDetailsListeners { public final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args) { if (state instanceof FormComponent) { state.performEvent(view, "save", args); if (!state.isHasError()) { view.redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + state.getFieldValue(), true, false); } } else { state.addMessage("deliveries.delivery.report.componentFormError", MessageType.FAILURE); } } void fillCompanyFieldsForSupplier(final ViewDefinitionState view, final ComponentState state, final String[] args); final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args); final void printOrderReport(final ViewDefinitionState view, final ComponentState state, final String[] args); final void copyProductsWithoutQuantityAndPrice(final ViewDefinitionState view, final ComponentState state,
final String[] args); final void copyProductsWithQuantityAndPrice(final ViewDefinitionState view, final ComponentState state,
final String[] args); final void recalculateReservations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void changeStorageLocations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void assignStorageLocations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void createRelatedDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args); BigDecimal getConversion(Entity product); final void showRelatedDeliveries(final ViewDefinitionState view, final ComponentState state, final String[] args); final void showProduct(final ViewDefinitionState view, final ComponentState state, final String[] args); void disableShowProductButton(final ViewDefinitionState view, final ComponentState state, final String[] args); void updateChangeStorageLocationButton(final ViewDefinitionState view, final ComponentState state, final String[] args); void validateColumnsWidthForOrder(final ViewDefinitionState view, final ComponentState state, final String[] args); void validateColumnsWidthForDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args); void downloadAtachment(final ViewDefinitionState view, final ComponentState state, final String[] args); } | DeliveryDetailsListeners { public final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args) { if (state instanceof FormComponent) { state.performEvent(view, "save", args); if (!state.isHasError()) { view.redirectTo("/deliveries/deliveryReport." + args[0] + "?id=" + state.getFieldValue(), true, false); } } else { state.addMessage("deliveries.delivery.report.componentFormError", MessageType.FAILURE); } } void fillCompanyFieldsForSupplier(final ViewDefinitionState view, final ComponentState state, final String[] args); final void printDeliveryReport(final ViewDefinitionState view, final ComponentState state, final String[] args); final void printOrderReport(final ViewDefinitionState view, final ComponentState state, final String[] args); final void copyProductsWithoutQuantityAndPrice(final ViewDefinitionState view, final ComponentState state,
final String[] args); final void copyProductsWithQuantityAndPrice(final ViewDefinitionState view, final ComponentState state,
final String[] args); final void recalculateReservations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void changeStorageLocations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void assignStorageLocations(final ViewDefinitionState view, final ComponentState state, final String[] args); final void createRelatedDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args); BigDecimal getConversion(Entity product); final void showRelatedDeliveries(final ViewDefinitionState view, final ComponentState state, final String[] args); final void showProduct(final ViewDefinitionState view, final ComponentState state, final String[] args); void disableShowProductButton(final ViewDefinitionState view, final ComponentState state, final String[] args); void updateChangeStorageLocationButton(final ViewDefinitionState view, final ComponentState state, final String[] args); void validateColumnsWidthForOrder(final ViewDefinitionState view, final ComponentState state, final String[] args); void validateColumnsWidthForDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args); void downloadAtachment(final ViewDefinitionState view, final ComponentState state, final String[] args); static final String OFFER; } |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.