FieldFactoryImpl implements FieldFactory { @Override public Component constructField(AttributeModel am) { return constructField(FieldFactoryContext.createDefault(am)); } FieldFactoryImpl();  FieldFactoryImpl(FieldFactory delegate); @SuppressWarnings("unchecked") void addConvertersAndValidators(BindingBuilder<U, V> builder, AttributeModel am,
			Converter<V, U> customConverter, Validator<V> customValidator, Validator<V> customRequiredValidator); @Override Component constructField(AttributeModel am); Component constructField(FieldFactoryContext context); @SuppressWarnings("unchecked") Component constructInternalLinkField(
			AttributeModel am, EntityModel<?> entityModel);  }
@Test public void testTextField() { Component ac = constructField("name", false); assertTrue(ac instanceof TextField); TextField tf = (TextField) ac; assertEquals("Name", tf.getLabel()); }
@Test public void testURLField() { Component ac = constructField("url", false); assertTrue(ac instanceof URLField); }
@Test public void testTextArea() { Component ac = constructField("someTextArea", false); assertTrue(ac instanceof TextArea); }
@Test public void testLongField() { Component ac = constructField("age", false); assertTrue(ac instanceof TextField); }
@Test public void testIntegerField() { Component ac = constructField("age", false); assertTrue(ac instanceof TextField); }
@Test public void testCollectionField() { Component ac = constructField("tags", false); assertTrue(ac instanceof ElementCollectionGrid); ElementCollectionGrid<?, ?, ?> ct = (ElementCollectionGrid<?, ?, ?>) ac; assertEquals(25, ct.getMaxLength().intValue()); }
@Test public void testBigDecimalField() { Component ac = constructField("discount", false); assertTrue(ac instanceof TextField); }
@Test public void testBigDecimalPercentageField() { Component ac = constructField("rate", false); assertTrue(ac instanceof TextField); }
@Test public void testDateField() { Component ac = constructField("birthDate", false); assertTrue(ac instanceof DatePicker); }
@Test public void testZonedDateTimeField() { Component ac = constructField("zoned", false); assertTrue(ac instanceof ZonedDateTimePicker); }
@Test public void testLocalTimeField() { Component ac = constructField("registrationTime", false); assertTrue(ac instanceof TimePicker); }
@Test public void testWeekField() { Component ac = constructField("birthWeek", false); assertTrue(ac instanceof TextField); }
@Test @SuppressWarnings("unchecked") public void testEnumField() { Component ac = constructField("someEnum", false); assertTrue(ac instanceof ComboBox); ComboBox<TestEnum> cb = (ComboBox<TestEnum>) ac; ListDataProvider<TestEnum> ldp = (ListDataProvider<TestEnum>) cb.getDataProvider(); assertTrue(ldp.getItems().contains(TestEnum.A)); assertTrue(ldp.getItems().contains(TestEnum.B)); assertTrue(ldp.getItems().contains(TestEnum.C)); }
@Test @SuppressWarnings("unchecked") public void testSearchBooleanField() { Component ac = constructField("someBoolean", true); assertTrue(ac instanceof ComboBox); ComboBox<Boolean> cb = (ComboBox<Boolean>) ac; ListDataProvider<Boolean> ldp = (ListDataProvider<Boolean>) cb.getDataProvider(); assertTrue(ldp.getItems().contains(Boolean.TRUE)); assertTrue(ldp.getItems().contains(Boolean.FALSE)); }
@Test public void testNormalBooleanField() { Component ac = constructField("someBoolean", false); assertTrue(ac instanceof Checkbox); }
@Test public void testConstructEntityComboBoxMultipleSearch() { EntityModel<TestEntity2> em = factory.getModel("TestEntity2Multi", TestEntity2.class); FieldFactoryContext context = FieldFactoryContext.create() .setAttributeModel(em.getAttributeModel("testEntityAlt")).setSearch(true); assertThrows(OCSRuntimeException.class, () -> fieldFactory.constructField(context)); }
@Test public void testDetailTokenFieldSelect() { Component ac = constructField("testEntities", false); assertTrue(ac instanceof QuickAddTokenSelect<?, ?>); QuickAddTokenSelect<?, ?> tf = (QuickAddTokenSelect<?, ?>) ac; assertNull(tf.getFilter()); }
@Test public void testDetailLookup() { Component ac = constructField("testEntities", "TestEntityLookup"); assertTrue(ac instanceof EntityLookupField); EntityLookupField<?, ?> fl = (EntityLookupField<?, ?>) ac; assertNull(fl.getFilter()); assertEquals("Test Entities", fl.getLabel()); assertNull(fl.getAddButton()); }