Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fortuna
committed
Jan 17, 2010
1 parent
a0553ce
commit c6dbadd
Showing
5 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/test/java/net/fortuna/ical4j/extensions/CalendarBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ical4j.validation.relaxed=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|