Exemplo n.º 1
0
  private void initForm(List<FieldConfigImpl> fieldList) throws Exception {
    group.setFieldConfigImplList(fieldList);
    group.afterPropertiesSet();

    formConfig.setGroupConfigImplList(createGroupList(group));
    formConfig.afterPropertiesSet();
  }
Exemplo n.º 2
0
  @Test
  public void getFormConfig() throws Exception {
    // no form
    assertNull(group.getFormConfig());

    // with form
    initForm(createFieldList(field1));
    assertSame(formConfig, group.getFormConfig());
  }
Exemplo n.º 3
0
  @Test
  public void isTrimmingByDefault() {
    // default
    assertTrue(group.isTrimmingByDefault());

    // set value
    group.setTrimmingByDefault(false);
    assertFalse(group.isTrimmingByDefault());
  }
Exemplo n.º 4
0
  @Test
  public void toString_() throws Exception {
    // empty
    assertEquals("GroupConfig[name: group1, fields: 0]", group.toString());

    // with fields
    initForm(createFieldList(field1, field2, field3));
    assertEquals("GroupConfig[name: group1, fields: 3]", group.toString());
  }
Exemplo n.º 5
0
  @Before
  public void init() throws Exception {
    formConfig = new FormConfigImpl();

    field1 = new FieldConfigImpl();
    field1.setName("fiELd1");

    field2 = new FieldConfigImpl();
    field2.setName("field2");

    field3 = new FieldConfigImpl();
    field3.setName("FIELD3");

    field4 = new FieldConfigImpl();
    field4.setName("field4");

    group = new GroupConfigImpl();
    group.setName("group1");

    group1 = new GroupConfigImpl();
    group1.setName("group1");
    group1.setFieldConfigImplList(createFieldList(field1));

    group2 = new GroupConfigImpl();
    group2.setName("group2");
    group2.setFieldConfigImplList(createFieldList(field2));

    group3 = new GroupConfigImpl();
    group3.setName("group3");
    group3.setFieldConfigImplList(createFieldList(field3));

    group4 = new GroupConfigImpl();
    group4.setName("group4");
    group4.setFieldConfigImplList(createFieldList(field4));
  }
Exemplo n.º 6
0
  @Test
  public void getFieldConfig() throws Exception {
    // not init
    assertNull(group.getFieldConfig("test"));

    // init
    initForm(createFieldList(field1, field2, field3));

    // case insensitive
    assertSame(field1, group.getFieldConfig("FIELD1"));
    assertSame(field2, group.getFieldConfig("field2"));
    assertSame(field3, group.getFieldConfig("fiELD3"));
  }
Exemplo n.º 7
0
  private void import_dupFields(boolean importAll) throws Exception {
    init();

    List<Import> imports;
    field3.setName("field1"); // group2.field1 duped with group1.field1

    group1 = new GroupConfigImpl();
    group1.setName("group1");
    group1.setFieldConfigImplList(createFieldList(field1));
    group1.afterPropertiesSet();

    group2 = new GroupConfigImpl();
    group2.setName("group2");
    group2.setFieldConfigImplList(createFieldList(field2, field3));

    if (importAll) {
      imports = createImportList(new ImportImpl("group1", null));
    } else {
      imports = createImportList(new ImportImpl("group1", "field1"));
    }

    group2.setImports(imports);
    group2.afterPropertiesSet();

    formConfig.setGroupConfigImplList(createGroupList(group1, group2));

    try {
      formConfig.afterPropertiesSet();
      fail();
    } catch (IllegalArgumentException e) {
      assertThat(e, exception("Duplicated field name: \"group2.field1\""));
    }
  }
Exemplo n.º 8
0
  @Test
  public void getFieldConfigByKey() throws Exception {
    // not init
    try {
      group.getFieldConfigByKey("test");
      fail();
    } catch (IllegalStateException e) {
      assertThat(e, exception("fieldsByKey not inited"));
    }

    // init
    initForm(createFieldList(field1, field2, field3));

    // case insensitive
    assertSame(field1, group.getFieldConfigByKey("f"));
    assertSame(field2, group.getFieldConfigByKey("fi"));
    assertSame(field3, group.getFieldConfigByKey("fie"));
  }
Exemplo n.º 9
0
  @Test
  public void isPostOnly() throws Exception {
    // default, no form config
    assertTrue(group.isPostOnly());

    // default, with form config
    initForm(createFieldList(field1));

    formConfig.setPostOnlyByDefault(false);
    assertFalse(group.isPostOnly());

    formConfig.setPostOnlyByDefault(true);
    assertTrue(group.isPostOnly());

    // set value
    group.setPostOnly(false);
    assertFalse(group.isPostOnly());
  }
Exemplo n.º 10
0
  @Test
  public void getImports() throws Exception {
    // default is empty
    assertTrue(group.getImports().isEmpty());

    // setImports
    List<Import> imports = createImportList(new ImportImpl("groupName", "fieldName"));
    group.setImports(imports);

    assertEquals(1, group.getImports().size());
    assertSame(imports.get(0), group.getImports().get(0));

    // unmodifiable
    try {
      group.getImports().clear();
      fail();
    } catch (UnsupportedOperationException e) {
    }
  }
Exemplo n.º 11
0
  @Test
  public void import_fieldNotFound() throws Exception {
    group2.setImports(createImportList(new ImportImpl("group1", "notExistField")));

    formConfig.setGroupConfigImplList(createGroupList(group1, group2));

    try {
      formConfig.afterPropertiesSet();
      fail();
    } catch (IllegalArgumentException e) {
      assertThat(e, exception("Field \"group1.notExistField\" not found"));
    }
  }
Exemplo n.º 12
0
  @Test
  public void getName() {
    GroupConfigImpl groupConfig = new GroupConfigImpl();

    // no name
    assertNull(groupConfig.getName());

    // empty name
    groupConfig.setName("");
    assertNull(groupConfig.getName());

    groupConfig.setName("  ");
    assertNull(groupConfig.getName());

    // normal name
    groupConfig.setName("  hello ");
    assertEquals("hello", groupConfig.getName());
  }
Exemplo n.º 13
0
  @Test
  public void getParentGroup() {
    // no key
    assertNull(group.getParentGroup());

    // empty key
    group.setParentGroup("");
    assertNull(group.getParentGroup());

    group.setParentGroup("  ");
    assertNull(group.getParentGroup());

    // normal key
    group.setParentGroup("  hello ");
    assertEquals("hello", group.getParentGroup());
  }
Exemplo n.º 14
0
  @Test
  public void getKey() throws Exception {
    // no key
    assertNull(group.getKey());

    // empty key
    group.setKey("");
    assertNull(group.getKey());

    group.setKey("  ");
    assertNull(group.getKey());

    // normal key
    group.setKey("  hello ");
    assertEquals("hello", group.getKey());

    // via form.init
    initForm(createFieldList(field1));
    assertEquals("g", group.getKey());
  }
Exemplo n.º 15
0
  @Test
  public void getFieldConfigList() throws Exception {
    // default, empty
    assertTrue(group.getFieldConfigList().isEmpty());

    // field name is null
    try {
      initForm(createFieldList(new FieldConfigImpl()));
      fail();
    } catch (IllegalArgumentException e) {
      assertThat(e, exception("name"));
    }

    // set fields
    initForm(createFieldList(field1, field2, field3));

    assertEquals(3, group.getFieldConfigList().size());
    assertArrayEquals(new Object[] {field1, field2, field3}, group.getFieldConfigList().toArray());

    // set null
    initForm((List<FieldConfigImpl>) null);
    assertEquals(3, group.getFieldConfigList().size());

    // set empty
    initForm(new ArrayList<FieldConfigImpl>());
    assertEquals(0, group.getFieldConfigList().size());

    // unmodifiable
    try {
      group.getFieldConfigList().clear();
      fail();
    } catch (UnsupportedOperationException e) {
    }

    // set duplicated fields
    try {
      initForm(createFieldList(field1, field2, field1));
      fail();
    } catch (IllegalArgumentException e) {
      assertThat(e, exception("Duplicated field name: \"group1.fiELd1\""));
    }
  }
Exemplo n.º 16
0
  private void assertPostOnly(Boolean parentValue, Boolean overrideValue, boolean expectedValue)
      throws Exception {
    init();

    if (parentValue != null) {
      group1.setPostOnly(parentValue);
    }

    group1.afterPropertiesSet();

    if (overrideValue != null) {
      group2.setPostOnly(overrideValue);
    }

    group2.setParentGroup("group1");
    group2.afterPropertiesSet();

    formConfig.setGroupConfigImplList(createGroupList(group1, group2));
    formConfig.afterPropertiesSet();

    assertEquals(expectedValue, group2.isPostOnly());
  }
Exemplo n.º 17
0
  @Test
  public void extend_overrideField() throws Exception {
    field3.setName("field1"); // group2.field1 overrides group1.field1

    group1 = new GroupConfigImpl();
    group1.setName("group1");
    group1.setFieldConfigImplList(createFieldList(field1));
    group1.afterPropertiesSet();

    group2 = new GroupConfigImpl();
    group2.setName("group2");
    group2.setFieldConfigImplList(createFieldList(field2, field3));
    group2.setParentGroup("group1");
    group2.afterPropertiesSet();

    formConfig.setGroupConfigImplList(createGroupList(group1, group2));
    formConfig.afterPropertiesSet();

    assertEquals(1, group1.getFieldConfigList().size());
    assertSame(field1, group1.getFieldConfig("field1"));

    assertEquals(2, group2.getFieldConfigList().size());
    assertSame(field3, group2.getFieldConfig("field1"));
    assertSame(field2, group2.getFieldConfig("field2"));
  }