@Test public void should_create_operation_for_given_business_data_and_generated_contract_input() throws Exception { final SimpleFieldToContractInputMapping mapping = new SimpleFieldToContractInputMapping(SimpleFieldBuilder.aStringField("firstName").build()); final FieldToContractInputMappingOperationBuilder operationBuilder = mock(FieldToContractInputMappingOperationBuilder.class); final RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class); final BusinessObjectModelRepositoryStore businessStore = mock(BusinessObjectModelRepositoryStore.class); when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)) .thenReturn(businessStore); final RootContractInputGenerator rootContractInputGenerator = new RootContractInputGenerator( "rootInputName", newArrayList(mapping), repositoryAccessor, operationBuilder, mock(FieldToContractInputMappingExpressionBuilder.class)); final BusinessObjectData businessObjectData = aBusinessData().withName("employee").build(); rootContractInputGenerator.build(businessObjectData); verify(operationBuilder).toOperation(businessObjectData, mapping); }
@Test public void should_create_initilal_value_expression_for_given_multiple_business_data_and_generated_contract_input() throws Exception { final SimpleFieldToContractInputMapping mapping = new SimpleFieldToContractInputMapping(SimpleFieldBuilder.aStringField("firstName").build()); final FieldToContractInputMappingOperationBuilder operationBuilder = mock(FieldToContractInputMappingOperationBuilder.class); final RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class); final BusinessObjectModelRepositoryStore businessStore = mock(BusinessObjectModelRepositoryStore.class); when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)) .thenReturn(businessStore); final FieldToContractInputMappingExpressionBuilder expressionBuilder = mock(FieldToContractInputMappingExpressionBuilder.class); final RootContractInputGenerator rootContractInputGenerator = new RootContractInputGenerator( "rootInputName", newArrayList(mapping), repositoryAccessor, operationBuilder, expressionBuilder); final BusinessObjectData businessObjectData = aBusinessData().withName("employee").multiple().build(); rootContractInputGenerator.build(businessObjectData); final ArgumentCaptor<FieldToContractInputMapping> argumentCaptor = ArgumentCaptor.forClass(FieldToContractInputMapping.class); verify(expressionBuilder).toExpression(eq(businessObjectData), argumentCaptor.capture()); final FieldToContractInputMapping fieldToContractInputMapping = argumentCaptor.getValue(); assertThat(fieldToContractInputMapping.getField().getName()).isEqualTo("rootInputName"); assertThat(fieldToContractInputMapping.getField().isCollection()).isTrue(); assertThat(fieldToContractInputMapping.getChildren()).hasSize(1); }
@Test public void should_create_a_complex_contract_input_with_generated_child_input_from_mapping() throws Exception { final SimpleFieldToContractInputMapping notGeneratedMapping = new SimpleFieldToContractInputMapping(SimpleFieldBuilder.aStringField("input2").build()); notGeneratedMapping.setGenerated(false); final RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class); final BusinessObjectModelRepositoryStore businessStore = mock(BusinessObjectModelRepositoryStore.class); when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)) .thenReturn(businessStore); final RootContractInputGenerator rootContractInputGenerator = new RootContractInputGenerator( "rootInputName", newArrayList( notGeneratedMapping, new SimpleFieldToContractInputMapping( SimpleFieldBuilder.aStringField("input1").build())), repositoryAccessor, mock(FieldToContractInputMappingOperationBuilder.class), mock(FieldToContractInputMappingExpressionBuilder.class)); rootContractInputGenerator.build(aBusinessData().build()); assertThat(rootContractInputGenerator.getRootContractInput().getInputs()).hasSize(1); }
@Test public void should_create_a_complex_contract_input_with_root_input_name() throws Exception { final RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class); final BusinessObjectModelRepositoryStore businessStore = mock(BusinessObjectModelRepositoryStore.class); when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)) .thenReturn(businessStore); final RootContractInputGenerator rootContractInputGenerator = new RootContractInputGenerator( "rootInputName", Collections.<FieldToContractInputMapping>emptyList(), repositoryAccessor, mock(FieldToContractInputMappingOperationBuilder.class), mock(FieldToContractInputMappingExpressionBuilder.class)); rootContractInputGenerator.build(aBusinessData().build()); ContractInputAssert.assertThat(rootContractInputGenerator.getRootContractInput()) .hasName("rootInputName") .hasType(ContractInputType.COMPLEX); }
/* * (non-Javadoc) * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) */ @Override public IStatus validate(final Object value) { final String content = inputExpression.getContent(); final WebPageRepositoryStore repositoryStore = repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class); return repositoryStore.getChild(content) == null ? ValidationStatus.error( Messages.bind( Messages.pageDoesntExists, String.format("%s (%s)", inputExpression.getName(), content))) : ValidationStatus.ok(); }
@Test public void should_create_operation_for_given_multiple_business_data_and_generated_contract_input() throws Exception { final SimpleField firstNameField = SimpleFieldBuilder.aStringField("firstName").build(); final SimpleFieldToContractInputMapping mapping = new SimpleFieldToContractInputMapping(firstNameField); final BusinessObjectModelRepositoryStore businessObjectStore = mock(BusinessObjectModelRepositoryStore.class); final BusinessObject bo = aBO("org.test.Employee").withField(firstNameField).build(); when(businessObjectStore.getBusinessObjectByQualifiedName("org.test.Employee")).thenReturn(bo); final RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class); when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)) .thenReturn(businessObjectStore); final FieldToContractInputMappingOperationBuilder operationBuilder = mock(FieldToContractInputMappingOperationBuilder.class); final RootContractInputGenerator rootContractInputGenerator = new RootContractInputGenerator( "employeesInput", newArrayList(mapping), repositoryAccessor, operationBuilder, mock(FieldToContractInputMappingExpressionBuilder.class)); final BusinessObjectData businessObjectData = aBusinessData().withName("employees").withClassname("org.test.Employee").multiple().build(); rootContractInputGenerator.build(businessObjectData); final ArgumentCaptor<FieldToContractInputMapping> argumentCaptor = ArgumentCaptor.forClass(FieldToContractInputMapping.class); verify(operationBuilder).toOperation(eq(businessObjectData), argumentCaptor.capture()); final Field field = argumentCaptor.getValue().getField(); assertThat(field).isInstanceOf(RelationField.class); assertThat(field.getName()).isEqualTo("employeesInput"); assertThat(field.isCollection()).isTrue(); assertThat(((RelationField) field).getReference().getQualifiedName()) .isEqualTo("org.test.Employee"); assertThat(((RelationField) field).getType()).isEqualTo(RelationField.Type.COMPOSITION); }
/* * (non-Javadoc) * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) */ @Override public IStatus validate(final Object value) { final String content = inputExpression.getContent(); final WebPageRepositoryStore repositoryStore = repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class); String errorMessage = null; if (ProcessPackage.Literals.RECAP_FLOW__OVERVIEW_FORM_MAPPING.equals(feature)) { errorMessage = Messages.bind(Messages.pageDoesntExist, content); } else { errorMessage = Messages.bind(Messages.formDoesntExist, content); } return repositoryStore.getChild(content) == null ? ValidationStatus.error(errorMessage) : ValidationStatus.ok(); }
private RepositoryAccessor repositoryAccessor() { final RepositoryAccessor repositoryAccessor = new RepositoryAccessor(); repositoryAccessor.init(); return repositoryAccessor; }
private WebPageFileStore fileStoreFromFormUUID(final String formUUID) { checkArgument(!isNullOrEmpty(formUUID)); return repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class).getChild(formUUID); }