@Override public TestProperty replaceValue( TestProperty value, Function<String, String> replacementFunction) { return new TestProperty( value .getConfiguration() .clone( replacementFunction.apply(value.getConfiguration().getName()), replacementFunction), replacementFunction.apply(value.getValue())); }
@Override public Object getPropertyObject(String keyString, Bindings bindings) throws ScriptException { if (bindings != null) { bindings.put("station", this); } for (TestProperty tsp : getProperties()) { if (tsp.getName().equals(keyString)) { return tsp.getPropertyObject(bindings); } } if (getTestProject() != null) { return getTestProject().getPropertyObject(keyString, bindings); } return null; }
@Test public void prepareParameters() { VCardPropertyScribeImpl m = new VCardPropertyScribeImpl() { @Override protected void _prepareParameters( TestProperty property, VCardParameters copy, VCardVersion version, VCard vcard) { copy.put("PARAM", "value"); } }; TestProperty property = new TestProperty("value"); VCardParameters copy = m.prepareParameters(property, V4_0, new VCard()); assertNotSame(property.getParameters(), copy); assertEquals("value", copy.first("PARAM")); }
@Override public String getSearchKey(TestProperty value) { return value.getValue(); }
@Override public Form getEditionForm(ProjectEntity entity, TestProperty value) { return Form.create() .with(Text.of("value").label("Value").value(value != null ? value.getValue() : "")); }
@Test public void timezones() throws Exception { StreamReader reader = new StreamReaderImpl() { @Override protected ICalendar _readNext() { ICalendar ical = new ICalendar(); VTimezone timezone = new VTimezone("tz"); { StandardTime standard = new StandardTime(); standard.setDateStart(new DateTimeComponents(2014, 9, 1, 2, 0, 0, false)); standard.setTimezoneOffsetFrom(new UtcOffset(true, 10, 0)); standard.setTimezoneOffsetTo(new UtcOffset(true, 9, 0)); timezone.addStandardTime(standard); DaylightSavingsTime daylight = new DaylightSavingsTime(); daylight.setDateStart(new DateTimeComponents(2014, 1, 1, 2, 0, 0, false)); daylight.setTimezoneOffsetFrom(new UtcOffset(true, 9, 0)); daylight.setTimezoneOffsetTo(new UtcOffset(true, 10, 0)); timezone.addDaylightSavingsTime(daylight); } ical.addComponent(timezone); TestProperty floating = new TestProperty(icalDate("2014-09-21T10:22:00")); context.addFloatingDate(floating, floating.date); ical.addProperty(floating); String tzid = timezone.getTimezoneId().getValue(); TestProperty timezoned = new TestProperty(icalDate("2014-10-01T13:07:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); tzid = timezone.getTimezoneId().getValue(); timezoned = new TestProperty(icalDate("2014-08-01T13:07:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); tzid = timezone.getTimezoneId().getValue(); timezoned = new TestProperty(icalDate("2013-12-01T13:07:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); tzid = "/America/New_York"; timezoned = new TestProperty(icalDate("2014-07-04T09:00:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); tzid = "America/New_York"; timezoned = new TestProperty(icalDate("2014-07-04T09:00:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); tzid = "foobar"; timezoned = new TestProperty(icalDate("2014-06-11T14:00:00")); timezoned.getParameters().setTimezoneId(tzid); context.addTimezonedDate(tzid, timezoned, timezoned.date); ical.addProperty(timezoned); return ical; } }; ICalendar ical = reader.readNext(); TimezoneInfo tzinfo = reader.getTimezoneInfo(); Collection<VTimezone> components = tzinfo.getComponents(); assertEquals(1, components.size()); assertEquals(0, ical.getComponents(VTimezone.class).size()); VTimezone component = components.iterator().next(); Iterator<TestProperty> it = ical.getProperties(TestProperty.class).iterator(); // floating-time property TestProperty property = it.next(); assertTrue(tzinfo.isFloating(property)); assertNull(tzinfo.getComponent(property)); assertNull(tzinfo.getTimeZone(property)); assertNull(property.getParameters().getTimezoneId()); assertEquals(date("2014-09-21 10:22:00"), property.date); // timezoned property property = it.next(); assertFalse(tzinfo.isFloating(property)); assertEquals(component, tzinfo.getComponent(property)); assertTrue(tzinfo.getTimeZone(property) instanceof ICalTimeZone); assertNull(property.getParameters().getTimezoneId()); assertEquals(utc("2014-10-01 04:07:00"), property.date); // timezoned property property = it.next(); assertFalse(tzinfo.isFloating(property)); assertEquals(component, tzinfo.getComponent(property)); assertTrue(tzinfo.getTimeZone(property) instanceof ICalTimeZone); assertNull(property.getParameters().getTimezoneId()); assertEquals(utc("2014-08-01 03:07:00"), property.date); // timezoned property property = it.next(); assertFalse(tzinfo.isFloating(property)); assertEquals(component, tzinfo.getComponent(property)); assertTrue(tzinfo.getTimeZone(property) instanceof ICalTimeZone); assertNull(property.getParameters().getTimezoneId()); assertEquals(utc("2013-12-01 04:07:00"), property.date); // property with Olsen TZID property = it.next(); assertFalse(tzinfo.isFloating(property)); assertNull(tzinfo.getComponent(property)); assertEquals(TimeZone.getTimeZone("America/New_York"), tzinfo.getTimeZone(property)); assertNull(property.getParameters().getTimezoneId()); assertEquals(utc("2014-07-04 13:00:00"), property.date); // property with Olsen TZID that doesn't point to a VTIMEZONE component property = it.next(); assertFalse(tzinfo.isFloating(property)); assertNull(tzinfo.getComponent(property)); assertEquals(TimeZone.getTimeZone("America/New_York"), tzinfo.getTimeZone(property)); assertNull(property.getParameters().getTimezoneId()); assertEquals(utc("2014-07-04 13:00:00"), property.date); // property with TZID that doesn't point to a VTIMEZONE component property = it.next(); assertFalse(tzinfo.isFloating(property)); assertNull(tzinfo.getComponent(property)); assertNull(tzinfo.getTimeZone(property)); assertEquals("foobar", property.getParameters().getTimezoneId()); assertEquals(date("2014-06-11 14:00:00"), property.date); assertFalse(it.hasNext()); assertWarnings(2, reader); }