コード例 #1
0
 public ContractInput toContractInput(final ContractInput parentInput) {
   contractInput = ProcessFactory.eINSTANCE.createContractInput();
   contractInput.setName(field.getName());
   contractInput.setType(toContractInputType());
   contractInput.setMultiple(field != null && field.isCollection());
   if (parentInput != null) {
     parentInput.getInputs().add(contractInput);
   }
   return contractInput;
 }
コード例 #2
0
  @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);
  }