use of com.sldeditor.filter.v2.function.temporal.Duration in project sldeditor by robward-scisys.
the class FieldConfigTimePeriodTest method testGenerateExpression.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#generateExpression()}. Test
* method for
* {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#populateField(com.sldeditor.filter.v2.function.temporal.TimePeriod)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigTimePeriod#setTestValue(com.sldeditor.ui.detail.config.FieldId, java.lang.String)}.
*/
@Test
public void testGenerateExpression() {
boolean valueOnly = true;
class TestFieldConfigTimePeriod extends FieldConfigTimePeriod {
public TestFieldConfigTimePeriod(FieldConfigCommonData commonData) {
super(commonData);
}
public Expression callGenerateExpression() {
return generateExpression();
}
}
TestFieldConfigTimePeriod field = new TestFieldConfigTimePeriod(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, null, valueOnly));
Expression actualExpression = field.callGenerateExpression();
assertNotNull(actualExpression);
// Try string values - erroneous
field.createUI();
field.createUI();
String expectedValue = "test string value";
field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
actualExpression = field.callGenerateExpression();
assertNotNull(actualExpression);
expectedValue = "test string value as expression";
field.populateExpression(expectedValue);
actualExpression = field.callGenerateExpression();
assertNotNull(actualExpression);
// Time period values
String timePeriod = "07-07-2016T17:42:27Z / 08-07-2016T17:42:27Z";
field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
field.setTestValue(FieldIdEnum.UNKNOWN, timePeriod);
actualExpression = field.callGenerateExpression();
assertTrue(timePeriod.compareTo(actualExpression.toString()) == 0);
TimePeriod period = new TimePeriod();
Duration start = new Duration();
start.setDuration(0, 0, 1, 0, 32, 9);
period.setStart(start);
field.populateField((TimePeriod) null);
field.populateField(period);
actualExpression = field.callGenerateExpression();
String expectedPeriod = period.getString();
assertTrue(expectedPeriod.compareTo(actualExpression.toString()) == 0);
TimePeriod timePeriodObj = new TimePeriod();
timePeriodObj.decode(timePeriod);
DefaultPeriod defaultPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(timePeriodObj.getStart().getDate())), new DefaultInstant(new DefaultPosition(timePeriodObj.getEnd().getDate())));
field.populateExpression(defaultPeriod);
actualExpression = field.callGenerateExpression();
assertTrue(timePeriod.compareTo(actualExpression.toString()) == 0);
}
use of com.sldeditor.filter.v2.function.temporal.Duration in project sldeditor by robward-scisys.
the class FieldConfigTimePeriod method getDuration.
/**
* Gets the duration.
*
* @param panel the panel
* @return the duration
*/
private Duration getDuration(TimePeriodPanel panel) {
Duration duration = new Duration();
if (panel.areFieldsConfigured()) {
if (panel.dateRadioButton.isSelected()) {
duration.setDate(getDate(panel));
} else {
int years = -1;
int months = -1;
int days = -1;
int hours = -1;
int minutes = -1;
int seconds = -1;
if (panel.dateCheckbox.isSelected()) {
years = (int) panel.yearSpinner.getValue();
months = (int) panel.monthSpinner.getValue();
days = (int) panel.daySpinner.getValue();
}
if (panel.timeCheckbox.isSelected()) {
hours = (int) panel.hourSpinner.getValue();
minutes = (int) panel.minuteSpinner.getValue();
seconds = (int) panel.secondSpinner.getValue();
}
duration.setDuration(years, months, days, hours, minutes, seconds);
}
}
return duration;
}
use of com.sldeditor.filter.v2.function.temporal.Duration in project sldeditor by robward-scisys.
the class DurationTest method testDurationString.
/**
* Test method for
* {@link com.sldeditor.filter.v2.function.temporal.Duration#Duration(java.lang.String)}.
*/
@Test
public void testDurationString() {
test("P10D", 0, 0, 10, 0, 0, 0, null);
test("P1Y2M3D", 1, 2, 3, 0, 0, 0, null);
test("P1Y2M", 1, 2, 0, 0, 0, 0, null);
test("P1Y2M3D4H5M6S", 1, 2, 3, 4, 5, 6, null);
test("P1Y6S", 1, 0, 0, 0, 0, 6, null);
test("P1Y0H6M", 1, 0, 0, 0, 6, 0, null);
test("P1Y6H", 1, 0, 0, 6, 0, 0, null);
test("T1H6M", 0, 0, 0, 1, 6, 0, null);
// This is not valid
test("P1M6M", 0, 1, 0, 0, 0, 0, "P1M");
test("T10H", 0, 0, 0, 10, 0, 0, null);
String dateString = "20-09-2016T17:42:27Z";
Duration duration = new Duration(dateString);
assertTrue(duration.isDate());
String actual = duration.getString();
assertTrue(dateString, dateString.compareTo(actual) == 0);
}
use of com.sldeditor.filter.v2.function.temporal.Duration in project sldeditor by robward-scisys.
the class DurationTest method testDuration.
/**
* Test method for {@link com.sldeditor.filter.v2.function.temporal.Duration#Duration()}.
*/
@Test
public void testDuration() {
Duration duration = new Duration();
assertEquals(0, duration.getDurationDays());
assertTrue(duration.isDate());
}
use of com.sldeditor.filter.v2.function.temporal.Duration in project sldeditor by robward-scisys.
the class DurationTest method test.
private void test(String durationString, int year, int month, int days, int hours, int mins, int sec, String alternative) {
Duration duration = new Duration(durationString);
assertEquals(durationString, year, duration.getDurationYears());
assertEquals(durationString, month, duration.getDurationMonths());
assertEquals(durationString, days, duration.getDurationDays());
assertEquals(durationString, hours, duration.getDurationHours());
assertEquals(durationString, mins, duration.getDurationMinutes());
assertEquals(durationString, sec, duration.getDurationSeconds());
assertFalse(durationString, duration.isDate());
String actual = duration.getString();
String expected = (alternative != null) ? alternative : durationString;
assertTrue(durationString, expected.compareTo(actual) == 0);
}
Aggregations