Skip to content

Commit

Permalink
Added calendar builder test
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Jan 17, 2010
1 parent a0553ce commit c6dbadd
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 6 deletions.
Expand Up @@ -45,15 +45,15 @@
*/
public class MSOlkOriginalEnd extends DateProperty {

private static final String NAME = "X-MS-OLK-ORIGINALEND";
public static final String PROPERTY_NAME = "X-MS-OLK-ORIGINALEND";

public static final PropertyFactory FACTORY = new Factory();

/**
* @param factory
*/
public MSOlkOriginalEnd(PropertyFactory factory) {
super(NAME, factory);
super(PROPERTY_NAME, factory);
}

/**
Expand All @@ -62,7 +62,7 @@ public MSOlkOriginalEnd(PropertyFactory factory) {
* @throws ParseException
*/
public MSOlkOriginalEnd(ParameterList aList, PropertyFactory factory, String value) throws ParseException {
super(NAME, aList, factory);
super(PROPERTY_NAME, aList, factory);
setValue(value);
}

Expand Down
Expand Up @@ -45,15 +45,15 @@
*/
public class MSOlkOriginalStart extends DateProperty {

private static final String NAME = "X-MS-OLK-ORIGINALSTART";
public static final String PROPERTY_NAME = "X-MS-OLK-ORIGINALSTART";

public static final PropertyFactory FACTORY = new Factory();

/**
* @param factory
*/
public MSOlkOriginalStart(PropertyFactory factory) {
super(NAME, factory);
super(PROPERTY_NAME, factory);
}

/**
Expand All @@ -62,7 +62,7 @@ public MSOlkOriginalStart(PropertyFactory factory) {
* @throws ParseException
*/
public MSOlkOriginalStart(ParameterList aList, PropertyFactory factory, String value) throws ParseException {
super(NAME, aList, factory);
super(PROPERTY_NAME, aList, factory);
setValue(value);
}

Expand Down
104 changes: 104 additions & 0 deletions src/test/java/net/fortuna/ical4j/extensions/CalendarBuilderTest.java
@@ -0,0 +1,104 @@
/**
* This file is part of Base Modules.
*
* Copyright (c) 2010, Ben Fortuna [fortuna@micronode.com]
*
* Base Modules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Base Modules is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Base Modules. If not, see <http://www.gnu.org/licenses/>.
*/

package net.fortuna.ical4j.extensions;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.data.CalendarParser;
import net.fortuna.ical4j.data.CalendarParserFactory;
import net.fortuna.ical4j.data.ParserException;
import net.fortuna.ical4j.extensions.property.MSOlkOriginalEnd;
import net.fortuna.ical4j.extensions.property.MSOlkOriginalStart;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.ParameterFactoryRegistry;
import net.fortuna.ical4j.model.PropertyFactoryRegistry;
import net.fortuna.ical4j.model.TimeZoneRegistry;
import net.fortuna.ical4j.model.TimeZoneRegistryFactory;
import net.fortuna.ical4j.model.ValidationException;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;


/**
* @author Ben
*
*/
@RunWith(Parameterized.class)
public class CalendarBuilderTest {

private CalendarBuilder builder;

private String filename;

private boolean expectedValid;

public CalendarBuilderTest(String filename, boolean expectedValid) {
this.filename = filename;
this.expectedValid = expectedValid;
}

@Before
public void setUp() {
CalendarParser parser = CalendarParserFactory.getInstance().createParser();

PropertyFactoryRegistry propertyFactoryRegistry = new PropertyFactoryRegistry();
propertyFactoryRegistry.register(MSOlkOriginalStart.PROPERTY_NAME, MSOlkOriginalStart.FACTORY);
propertyFactoryRegistry.register(MSOlkOriginalEnd.PROPERTY_NAME, MSOlkOriginalEnd.FACTORY);

ParameterFactoryRegistry parameterFactoryRegistry = new ParameterFactoryRegistry();

TimeZoneRegistry tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry();

builder = new CalendarBuilder(parser, propertyFactoryRegistry, parameterFactoryRegistry, tzRegistry);
}

@Test
public void testBuild() throws FileNotFoundException, IOException, ParserException, ValidationException {
Calendar calendar = builder.build(getClass().getResourceAsStream(filename));
try {
calendar.validate();
if (!expectedValid) {
Assert.fail("Expected invalid calendar");
}
}
catch (ValidationException e) {
if (expectedValid) {
Assert.fail(String.format("Expected valid calendar: %s", e.getMessage()));
}
}
}

@Parameters
public static Collection<Object[]> parameters() {
List<Object[]> params = new ArrayList<Object[]>();
params.add(new Object[] { "/samples/Bodypart2.ics", true });
return params;
}
}
1 change: 1 addition & 0 deletions src/test/resources/ical4j.properties
@@ -0,0 +1 @@
ical4j.validation.relaxed=true
36 changes: 36 additions & 0 deletions src/test/resources/samples/Bodypart2.ics
@@ -0,0 +1,36 @@
BEGIN:VCALENDAR
METHOD:COUNTER
PRODID:Microsoft Exchange Server 2007
VERSION:2.0
BEGIN:VTIMEZONE
TZID:US Mountain Standard Time
BEGIN:STANDARD
DTSTART:16010101T000000
TZOFFSETFROM:-0700
TZOFFSETTO:-0700
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T000000
TZOFFSETFROM:-0700
TZOFFSETTO:-0700
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
ATTENDEE;PARTSTAT=TENTATIVE;CN=some@email.com:MAILTO:some@email.com
DTSTART;TZID=US Mountain Standard Time:20091231T153000
DTEND;TZID=US Mountain Standard Time:20091231T163000
X-MS-OLK-ORIGINALSTART;TZID=US Mountain Standard Time:20091230T153000
X-MS-OLK-ORIGINALEND;TZID=US Mountain Standard Time:20091230T163000
SUMMARY;LANGUAGE=en-US:New Time Proposed: Invitation: Test invitation from
Gmail @ Wed Dec 30 5:30pm - 6:30pm (some@email.com)
LOCATION;LANGUAGE=en-US:
UID:923c4k6s5r4rc80lvmjh47qlm0@google.com
SEQUENCE:0
DTSTAMP:20091229T223200Z
COMMENT;LANGUAGE=en-US:\n\n------------------\nNew Meeting Time Proposed:\n
Thursday\, December 31\, 2009 5:30 PM-6:30 PM (GMT-05:00) Eastern Time (US
& Canada).\n\n
END:VEVENT
END:VCALENDAR


0 comments on commit c6dbadd

Please sign in to comment.