verifyNoMoreInteractions(state);
}
<<<<<<< HEAD
@Test
public void shouldNoFillProductInComponentsIfFormIsNotValid() throws Exception {
// given
FormComponent form = mock(FormComponent.class, Mockito.RETURNS_DEEP_STUBS);
given(form.isValid()).willReturn(false);
ViewDefinitionState state = mock(ViewDefinitionState.class);
given(state.getComponentByReference("form")).willReturn(form);
// when
genealogyService.fillProductInComponents(state);
// then
verify(state, atLeastOnce()).getComponentByReference(anyString());
verifyNoMoreInteractions(state);
}
@Test
public void shouldHideProductInComponentsIfThereIsNoTechnology() throws Exception {
// given
ComponentState products = mock(ComponentState.class);
FormComponent form = mock(FormComponent.class, Mockito.RETURNS_DEEP_STUBS);
given(form.isValid()).willReturn(true);
given(form.getEntity().getField("order").toString()).willReturn("13");
Entity order = mock(Entity.class);
given(order.getBelongsToField("technology")).willReturn(null);
given(dataDefinitionService.get("orders", "order").get(13L)).willReturn(order);
ViewDefinitionState state = mock(ViewDefinitionState.class);
given(state.getComponentByReference("form")).willReturn(form);
given(state.getComponentByReference("productGridLayout")).willReturn(products);
// when
genealogyService.fillProductInComponents(state);
// then
verify(products).setVisible(false);
verify(state, atLeastOnce()).getComponentByReference(anyString());
verifyNoMoreInteractions(state);
}
@Test
public void shouldHideProductInComponentsIfThereIsNoProductsForGenealogy() throws Exception {
// given
ComponentState products = mock(ComponentState.class);
FormComponent form = mock(FormComponent.class, Mockito.RETURNS_DEEP_STUBS);
given(form.isValid()).willReturn(true);
given(form.getEntity().getField("order").toString()).willReturn("13");
DataDefinition dataDefinition = mock(DataDefinition.class);
EntityTree operationComponents = new EntityTreeImpl(dataDefinition, "joinField", null);
Entity technology = mock(Entity.class);
given(technology.getTreeField("operationComponents")).willReturn(operationComponents);
Entity order = mock(Entity.class);
given(order.getBelongsToField("technology")).willReturn(technology);
given(dataDefinitionService.get("orders", "order").get(13L)).willReturn(order);
ViewDefinitionState state = mock(ViewDefinitionState.class);
given(state.getComponentByReference("form")).willReturn(form);
given(state.getComponentByReference("productGridLayout")).willReturn(products);
// when
genealogyService.fillProductInComponents(state);
// then
verify(products).setVisible(false);
verify(state, atLeastOnce()).getComponentByReference(anyString());
verifyNoMoreInteractions(state);
}
@Test
public void shouldShowProductInComponents() throws Exception {
// given
ComponentState products = mock(ComponentState.class);
FieldComponent productsList = mock(FieldComponent.class);
List expectedGenealogyProductInComponents = prepareExpectedGenealogyProductInComponents();
EntityList existingGenealogyProductInComponents = prepareExistingGenealogyProductInComponents();
EntityTree operationProductInComponents = prepareOperationProductInComponents();
FormComponent form = mock(FormComponent.class, Mockito.RETURNS_DEEP_STUBS);
given(form.isValid()).willReturn(true);
given(form.getEntityId()).willReturn(11L);
given(form.getEntity().getField("order").toString()).willReturn("13");
Entity genealogyProductInComponent = new DefaultEntity(null);
given(dataDefinitionService.get("genealogiesForComponents", "genealogyProductInComponent").create()).willReturn(
genealogyProductInComponent);
Entity technology = mock(Entity.class);
given(technology.getTreeField("operationComponents")).willReturn(operationProductInComponents);
Entity order = mock(Entity.class);
given(dataDefinitionService.get("orders", "order").get(13L)).willReturn(order);
given(order.getBelongsToField("technology")).willReturn(technology);
Entity genealogy = mock(Entity.class);
given(dataDefinitionService.get("genealogies", "genealogy").get(11L)).willReturn(genealogy);
given(genealogy.getHasManyField("productInComponents")).willReturn(existingGenealogyProductInComponents);
ViewDefinitionState state = mock(ViewDefinitionState.class);
given(state.getComponentByReference("form")).willReturn(form);
given(state.getComponentByReference("productGridLayout")).willReturn(products);
given(state.getComponentByReference("productInComponentsList")).willReturn(productsList);
// when
genealogyService.fillProductInComponents(state);
// then
verify(products, never()).setVisible(false);
verify(productsList).setFieldValue(expectedGenealogyProductInComponents);
verify(state, atLeastOnce()).getComponentByReference(anyString());
verifyNoMoreInteractions(state);
}
@SuppressWarnings("unchecked")
private EntityTree prepareOperationProductInComponents() {
List entities = new ArrayList();
List subEntities = new ArrayList();
List productsEntities1 = new ArrayList();
List productsEntities3 = new ArrayList();
}
productsEntities1.add(craeteOperationProductInComponent(101L, true));
productsEntities3.add(craeteOperationProductInComponent(103L, true));
productsEntities3.add(craeteOperationProductInComponent(104L, false));
DataDefinition treeDataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
given(treeDataDefinition.find().belongsTo(anyString(), any()).orderAscBy(eq("priority")).list().getEntities())
.willReturn(entities, subEntities);
DataDefinition listDataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
given(listDataDefinition.find().belongsTo(anyString(), any()).list().getEntities()).willReturn(productsEntities1,
productsEntities3);
EntityTree subOperationComponents = new EntityTreeImpl(treeDataDefinition, "joinField", 13L);
EntityList operationProductInComponents1 = new EntityListImpl(listDataDefinition, "joinField", 1L);
EntityList operationProductInComponents3 = new EntityListImpl(listDataDefinition, "joinField", 3L);
Entity operationComponent1 = mock(Entity.class);
given(operationComponent1.getId()).willReturn(1L);
given(operationComponent1.getField("entityType")).willReturn("operation");
given(operationComponent1.getHasManyField("operationProductInComponents")).willReturn(operationProductInComponents1);
given(operationComponent1.getBelongsToField("parent")).willReturn(null);
Entity referenceTechnology = mock(Entity.class);
given(referenceTechnology.getTreeField("operationComponents")).willReturn(subOperationComponents);
Entity operationComponent2 = mock(Entity.class);
given(operationComponent2.getId()).willReturn(2L);
given(operationComponent2.getField("entityType")).willReturn("referenceTechnology");
given(operationComponent2.getBelongsToField("referenceTechnology")).willReturn(referenceTechnology);
given(operationComponent2.getBelongsToField("parent")).willReturn(operationComponent1);
Entity operationComponent3 = mock(Entity.class);
given(operationComponent3.getId()).willReturn(3L);
given(operationComponent3.getField("entityType")).willReturn("operation");
given(operationComponent3.getHasManyField("operationProductInComponents")).willReturn(operationProductInComponents3);
given(operationComponent3.getBelongsToField("parent")).willReturn(null);
entities.add(operationComponent1);
entities.add(operationComponent2);
subEntities.add(operationComponent3);
EntityTree operationComponents = new EntityTreeImpl(treeDataDefinition, "joinField", 13L);
return operationComponents;
}
private EntityList prepareExistingGenealogyProductInComponents() {
List existingEntities = new ArrayList();
existingEntities.add(craeteGenealogyProductInComponent(101L, craeteOperationProductInComponent(101L, true)));
existingEntities.add(craeteGenealogyProductInComponent(102L, craeteOperationProductInComponent(102L, true)));
DataDefinition existingListDataDefinition = mock(DataDefinition.class, RETURNS_DEEP_STUBS);
given(existingListDataDefinition.find().belongsTo(anyString(), any()).list().getEntities()).willReturn(existingEntities);
EntityList existingOperationComponents = new EntityListImpl(existingListDataDefinition, "joinField", 11L);
return existingOperationComponents;
}
private List prepareExpectedGenealogyProductInComponents() {
List expectedEntities = new ArrayList();
expectedEntities.add(craeteGenealogyProductInComponent(101L, craeteOperationProductInComponent(101L, true)));
expectedEntities.add(craeteGenealogyProductInComponent(null, craeteOperationProductInComponent(103L, true)));
return expectedEntities;
}
private Entity craeteGenealogyProductInComponent(final Long id, final Entity operationProductInComponent) {
Entity genealogyProductInComponent = new DefaultEntity(null, id);
genealogyProductInComponent.setField("productInComponent", operationProductInComponent);
return genealogyProductInComponent;
}
private Entity craeteOperationProductInComponent(final Long id, final boolean batchRequired) {
Entity operationProductInComponent = new DefaultEntity(null, id);
operationProductInComponent.setField("batchRequired", batchRequired);
return operationProductInComponent;
=======
>>>>>>> 06bfef8cb5fce10d086dcc972502ce9d01560636
} |