Esempio n. 1
0
  @Test
  public void shouldAutoPopulateOwnerAndCreator() {
    when(entityService.getEntityFieldsForUI(ENTITY_ID))
        .thenReturn(
            asList(
                FieldTestHelper.fieldDto(1L, "owner", String.class.getName(), "String field", null),
                FieldTestHelper.fieldDto(
                    1L, "creator", String.class.getName(), "String field", null)));
    mockEntity();
    setUpSecurityContext();

    EntityRecord record = instanceService.newInstance(ENTITY_ID);

    List<FieldRecord> fieldRecords = record.getFields();
    assertEquals(
        asList("motech", "motech"), extract(fieldRecords, on(FieldRecord.class).getValue()));
  }
Esempio n. 2
0
  @Test
  public void shouldReturnNewInstances() {
    mockSampleFields();
    mockEntity();

    EntityRecord record = instanceService.newInstance(ENTITY_ID);

    assertNotNull(record);
    assertEquals(Long.valueOf(ENTITY_ID), record.getEntitySchemaId());
    assertNull(record.getId());

    List<FieldRecord> fieldRecords = record.getFields();
    assertCommonFieldRecordFields(fieldRecords);
    assertEquals(
        asList("Default", 7, null, null, null),
        extract(fieldRecords, on(FieldRecord.class).getValue()));
  }
Esempio n. 3
0
  @Test
  public void shouldNotAutoPopulateOwnerAndCreatorForNonEditableFields() {
    FieldDto ownerField =
        FieldTestHelper.fieldDto(1L, "owner", String.class.getName(), "String field", null);
    ownerField.setNonEditable(true);
    FieldDto creatorField =
        FieldTestHelper.fieldDto(1L, "creator", String.class.getName(), "String field", null);
    creatorField.setNonEditable(true);

    when(entityService.getEntityFieldsForUI(ENTITY_ID))
        .thenReturn(asList(ownerField, creatorField));
    mockEntity();
    setUpSecurityContext();

    EntityRecord record = instanceService.newInstance(ENTITY_ID);

    List<FieldRecord> fieldRecords = record.getFields();
    assertEquals(asList(null, null), extract(fieldRecords, on(FieldRecord.class).getValue()));
  }