Search in sources :

Example 6 with FieldConfigDate

use of com.sldeditor.ui.detail.config.FieldConfigDate in project sldeditor by robward-scisys.

the class FieldConfigDateTest method testRevertToDefaultValue.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigDate#revertToDefaultValue()}.
 */
@Test
public void testRevertToDefaultValue() {
    boolean valueOnly = true;
    FieldConfigDate field = new FieldConfigDate(new FieldConfigCommonData(Date.class, FieldIdEnum.NAME, "label", valueOnly));
    field.revertToDefaultValue();
    assertNull(field.getStringValue());
    field.createUI();
    field.revertToDefaultValue();
    String expectedDefaultValue = "default value";
    assertTrue(expectedDefaultValue.compareTo(field.getStringValue()) != 0);
}
Also used : FieldConfigDate(com.sldeditor.ui.detail.config.FieldConfigDate) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Date(java.util.Date) FieldConfigDate(com.sldeditor.ui.detail.config.FieldConfigDate) Test(org.junit.Test)

Example 7 with FieldConfigDate

use of com.sldeditor.ui.detail.config.FieldConfigDate in project sldeditor by robward-scisys.

the class FieldConfigDateTest method testGenerateExpression.

/**
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigDate#generateExpression()}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigDate#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigDate#populateField(java.util.Date)}. Test
 * method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigDate#setTestValue(com.sldeditor.ui.detail.config.FieldId, java.lang.String)}.
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigDate#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    class TestFieldConfigDate extends FieldConfigDate {

        public TestFieldConfigDate(FieldConfigCommonData commonData) {
            super(commonData);
        }

        public Expression callGenerateExpression() {
            return generateExpression();
        }
    }
    TestFieldConfigDate field = new TestFieldConfigDate(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly));
    Expression actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);
    // Try string values - erroneous
    field.createUI();
    field.populateExpression("");
    SimpleDateFormat f = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
    String dateString = "10-01-2012 23:13:26";
    Date dateTime1 = null;
    try {
        dateTime1 = f.parse(dateString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    field.populateExpression(dateTime1);
    actualExpression = field.callGenerateExpression();
    DateFormat df = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH);
    DateFormat tf = new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH);
    String dateFormat1String = String.format("%sT%sZ", df.format(dateTime1), tf.format(dateTime1));
    assertTrue(dateFormat1String.compareTo(actualExpression.toString()) == 0);
    field.populateExpression(dateString);
    actualExpression = field.callGenerateExpression();
    String dateFormat1aString = String.format("%sT%sZ", df.format(dateTime1), tf.format(dateTime1));
    assertTrue(dateFormat1aString.compareTo(actualExpression.toString()) == 0);
    String dateTime2 = "23-05-2015 11:56:47";
    field.setTestValue(FieldIdEnum.UNKNOWN, dateTime2);
    Date dateTime21 = null;
    try {
        dateTime21 = f.parse(dateTime2);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    String dateFormat2String = String.format("%sT%sZ", df.format(dateTime21), tf.format(dateTime21));
    actualExpression = field.callGenerateExpression();
    assertTrue(dateFormat2String.compareTo(actualExpression.toString()) == 0);
}
Also used : FieldConfigDate(com.sldeditor.ui.detail.config.FieldConfigDate) Geometry(com.vividsolutions.jts.geom.Geometry) Expression(org.opengis.filter.expression.Expression) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) FieldConfigDate(com.sldeditor.ui.detail.config.FieldConfigDate) Test(org.junit.Test)

Example 8 with FieldConfigDate

use of com.sldeditor.ui.detail.config.FieldConfigDate in project sldeditor by robward-scisys.

the class FieldConfigDateTest method testCreateCopy.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigDate#createCopy(com.sldeditor.ui.detail.config.FieldConfigBase)}.
 */
@Test
public void testCreateCopy() {
    boolean valueOnly = true;
    class TestFieldConfigDate extends FieldConfigDate {

        public TestFieldConfigDate(FieldConfigCommonData commonData) {
            super(commonData);
        }

        public FieldConfigPopulate callCreateCopy(FieldConfigBase fieldConfigBase) {
            return createCopy(fieldConfigBase);
        }
    }
    TestFieldConfigDate field = new TestFieldConfigDate(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly));
    FieldConfigDate copy = (FieldConfigDate) field.callCreateCopy(null);
    assertNull(copy);
    copy = (FieldConfigDate) field.callCreateCopy(field);
    assertEquals(field.getFieldId(), copy.getFieldId());
    assertTrue(field.getLabel().compareTo(copy.getLabel()) == 0);
    assertEquals(field.isValueOnly(), copy.isValueOnly());
}
Also used : FieldConfigDate(com.sldeditor.ui.detail.config.FieldConfigDate) Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Test(org.junit.Test)

Aggregations

FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)8 FieldConfigDate (com.sldeditor.ui.detail.config.FieldConfigDate)8 Date (java.util.Date)7 Test (org.junit.Test)7 Geometry (com.vividsolutions.jts.geom.Geometry)3 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)2 DateFormat (java.text.DateFormat)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 UndoEvent (com.sldeditor.common.undo.UndoEvent)1 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)1 Disjoint (com.sldeditor.filter.v2.function.geometry.Disjoint)1 FieldConfigBoolean (com.sldeditor.ui.detail.config.FieldConfigBoolean)1 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)1 FieldConfigDouble (com.sldeditor.ui.detail.config.FieldConfigDouble)1 FieldConfigGeometry (com.sldeditor.ui.detail.config.FieldConfigGeometry)1 FieldConfigInteger (com.sldeditor.ui.detail.config.FieldConfigInteger)1 FieldConfigMapUnits (com.sldeditor.ui.detail.config.FieldConfigMapUnits)1 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)1 GroupConfig (com.sldeditor.ui.detail.config.base.GroupConfig)1