net.fortuna.ical4j.data.CalendarBuilder Java Examples
The following examples show how to use
net.fortuna.ical4j.data.CalendarBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IcsConverter.java From ganttproject with GNU General Public License v3.0 | 7 votes |
public static void main(String[] args) throws Exception { Args mainArgs = new Args(); try { new JCommander(new Object[] { mainArgs }, args); } catch (Throwable e) { e.printStackTrace(); return; } if (mainArgs.file.size() != 1) { System.err.println("Only 1 input file should be specified"); return; } CalendarBuilder builder = new CalendarBuilder(); Calendar c = builder.build(new UnfoldingReader(new FileReader(mainArgs.file.get(0)))); for (Component comp : (List<Component>)c.getComponents()) { System.err.println(comp); } }
Example #2
Source File: ICALToJsonAttributeTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void serviceShouldFilterMailsWithoutSender() throws Exception { testee.init(FakeMailetConfig.builder().build()); byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting.ics"); Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics)); ImmutableMap<String, Calendar> icals = ImmutableMap.of("key", calendar); Mail mail = FakeMail.builder() .name("mail") .recipient(MailAddressFixture.OTHER_AT_JAMES) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_SOURCE, AttributeValue.ofAny(icals))) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_RAW_SOURCE, AttributeValue.ofAny(icals))) .build(); testee.service(mail); assertThat(mail.getAttribute(ICALToJsonAttribute.DEFAULT_DESTINATION)) .isEmpty(); }
Example #3
Source File: ICALToJsonAttributeTest.java From james-project with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test void serviceShouldAttachEmptyListWhenNoRecipient() throws Exception { testee.init(FakeMailetConfig.builder().build()); byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting.ics"); Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics)); ImmutableMap<String, Calendar> icals = ImmutableMap.of("key", calendar); ImmutableMap<String, byte[]> rawIcals = ImmutableMap.of("key", ics); Mail mail = FakeMail.builder() .name("mail") .sender(SENDER) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_SOURCE, AttributeValue.ofAny(icals))) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_RAW_SOURCE, AttributeValue.ofAny(rawIcals))) .build(); testee.service(mail); assertThat(AttributeUtils.getValueAndCastFromMail(mail, ICALToJsonAttribute.DEFAULT_DESTINATION, Map.class)) .isPresent() .hasValueSatisfying(map -> assertThat(map).isEmpty()); }
Example #4
Source File: TeamCalImportPage.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
protected void importEvents() { checkAccess(); final FileUpload fileUpload = form.fileUploadField.getFileUpload(); if (fileUpload != null) { try { final InputStream is = fileUpload.getInputStream(); actionLog.reset(); final String clientFilename = fileUpload.getClientFileName(); final CalendarBuilder builder = new CalendarBuilder(); final Calendar calendar = builder.build(is); final ImportStorage<TeamEventDO> storage = teamCalImportDao.importEvents(calendar, clientFilename, actionLog); setStorage(storage); } catch (final Exception ex) { log.error(ex.getMessage(), ex); error("An error occurred (see log files for details): " + ex.getMessage()); clear(); } finally { fileUpload.closeStreams(); } } }
Example #5
Source File: EventCollectionResource.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
private String extractUid(String icalendar) throws IOException, ParserException { String uid = null; StringReader reader = new StringReader(icalendar); CalendarBuilder builder = new CalendarBuilder(); Calendar calendar = builder.build(new UnfoldingReader(reader, true)); if ( calendar != null && calendar.getComponents() != null ) { Iterator<Component> iterator = calendar.getComponents().iterator(); while (iterator.hasNext()) { Component component = iterator.next(); if ( component instanceof VEvent ) { uid = ((VEvent)component).getUid().getValue(); break; } } } return uid; }
Example #6
Source File: ICalendarService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
/** * Load the calendar events from the given reader. * * @param calendar the target {@link ICalendar} * @param reader the input source reader * @throws IOException * @throws ParserException */ @Transactional(rollbackOn = {Exception.class}) public void load(ICalendar calendar, Reader reader) throws IOException, ParserException { Preconditions.checkNotNull(calendar, "calendar can't be null"); Preconditions.checkNotNull(reader, "reader can't be null"); final CalendarBuilder builder = new CalendarBuilder(); final Calendar cal = builder.build(reader); if (calendar.getName() == null && cal.getProperty(X_WR_CALNAME) != null) { calendar.setName(cal.getProperty(X_WR_CALNAME).getValue()); } for (Object item : cal.getComponents(Component.VEVENT)) { findOrCreateEvent((VEvent) item, calendar); } }
Example #7
Source File: ICALAttributeDTOTest.java From james-project with Apache License 2.0 | 6 votes |
@Test public void buildShouldWork() throws Exception { byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting.ics"); Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics)); MailAddress recipient = MailAddressFixture.ANY_AT_JAMES; MailAddress sender = MailAddressFixture.OTHER_AT_JAMES; ICALAttributeDTO ical = ICALAttributeDTO.builder() .from(calendar, ics) .sender(sender) .recipient(recipient) .replyTo(sender); assertThat(ical.getRecipient()).isEqualTo(recipient.asString()); assertThat(ical.getSender()).isEqualTo(sender.asString()); assertThat(ical.getUid()) .contains("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7" + "c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc"); assertThat(ical.getMethod()).contains("REQUEST"); assertThat(ical.getRecurrenceId()).isEmpty(); assertThat(ical.getDtstamp()).contains("20170106T115036Z"); assertThat(ical.getSequence()).isEqualTo("0"); assertThat(ical.getIcal()).isEqualTo(new String(ics, "UTF-8")); }
Example #8
Source File: ICALToHeadersTest.java From james-project with Apache License 2.0 | 6 votes |
@Test public void serviceShouldWriteSingleICalendarToHeaders() throws Exception { Calendar calendar = new CalendarBuilder().build(ClassLoader.getSystemResourceAsStream("ics/meeting.ics")); ImmutableMap<String, Calendar> icals = ImmutableMap.<String, Calendar>builder() .put("key", calendar) .build(); testee.init(FakeMailetConfig.builder().build()); Mail mail = FakeMail.builder() .name("mail") .mimeMessage(MimeMessageUtil.defaultMimeMessage()) .attribute(makeAttribute(icals)) .build(); testee.service(mail); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_METHOD_HEADER)).containsOnly("REQUEST"); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_UID_HEADER)) .containsOnly("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc"); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_DTSTAMP_HEADER)).containsOnly("20170106T115036Z"); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_RECURRENCE_ID_HEADER)).isNull(); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_SEQUENCE_HEADER)).containsOnly("0"); }
Example #9
Source File: ICALToHeadersTest.java From james-project with Apache License 2.0 | 6 votes |
@Test public void serviceShouldWriteOnlyOneICalendarToHeaders() throws Exception { Calendar calendar = new CalendarBuilder().build(ClassLoader.getSystemResourceAsStream("ics/meeting.ics")); Calendar calendar2 = new CalendarBuilder().build(ClassLoader.getSystemResourceAsStream("ics/meeting_2.ics")); ImmutableMap<String, Calendar> icals = ImmutableMap.<String, Calendar>builder() .put("key", calendar) .put("key2", calendar2) .build(); testee.init(FakeMailetConfig.builder().build()); Mail mail = FakeMail.builder() .name("mail") .mimeMessage(MimeMessageUtil.defaultMimeMessage()) .attribute(makeAttribute(icals)) .build(); testee.service(mail); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_UID_HEADER)).hasSize(1); }
Example #10
Source File: ICALToHeadersTest.java From james-project with Apache License 2.0 | 6 votes |
@Test public void serviceShouldNotWriteHeaderWhenPropertyIsAbsent() throws Exception { Calendar calendar = new CalendarBuilder().build(ClassLoader.getSystemResourceAsStream("ics/meeting_without_dtstamp.ics")); ImmutableMap<String, Calendar> icals = ImmutableMap.<String, Calendar>builder() .put("key", calendar) .build(); testee.init(FakeMailetConfig.builder().build()); Mail mail = FakeMail.builder() .name("mail") .mimeMessage(MimeMessageUtil.defaultMimeMessage()) .attribute(makeAttribute(icals)) .build(); testee.service(mail); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_METHOD_HEADER)).containsOnly("REQUEST"); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_UID_HEADER)) .containsOnly("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc"); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_DTSTAMP_HEADER)).isNull(); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_RECURRENCE_ID_HEADER)).isNull(); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_SEQUENCE_HEADER)).containsOnly("0"); }
Example #11
Source File: RecurrenceExpanderTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets calendar. * @param name The name. * @return The calendar. * @throws Exception - if something is wrong this exception is thrown. */ protected Calendar getCalendar(String name) throws Exception { CalendarBuilder cb = new CalendarBuilder(); InputStream in = getClass().getClassLoader().getResourceAsStream("expander/" + name); if (in == null) { throw new IllegalStateException("resource " + name + " not found"); } Calendar calendar = cb.build(in); return calendar; }
Example #12
Source File: CalendarUtils.java From cosmo with Apache License 2.0 | 5 votes |
private static void clearTZRegistry(CalendarBuilder cb) { // Clear timezone registry if present TimeZoneRegistry tzr = cb.getRegistry(); if (tzr != null) { tzr.clear(); } }
Example #13
Source File: LimitRecurrenceSetTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Tests the set of limit recurrence. * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testLimitRecurrenceSetThisAndFuture() throws Exception { CalendarBuilder cb = new CalendarBuilder(); FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_taf_test.ics"); Calendar calendar = cb.build(fis); Assert.assertEquals(4, calendar.getComponents().getComponents("VEVENT").size()); VTimeZone vtz = (VTimeZone) calendar.getComponents().getComponent("VTIMEZONE"); TimeZone tz = new TimeZone(vtz); OutputFilter filter = new OutputFilter("test"); DateTime start = new DateTime("20060108T170000", tz); DateTime end = new DateTime("20060109T170000", tz); start.setUtc(true); end.setUtc(true); Period period = new Period(start, end); filter.setLimit(period); filter.setAllSubComponents(); filter.setAllProperties(); StringBuilder buffer = new StringBuilder(); filter.filter(calendar, buffer); StringReader sr = new StringReader(buffer.toString()); Calendar filterCal = cb.build(sr); Assert.assertEquals(2, filterCal.getComponents().getComponents("VEVENT").size()); // Make sure 2nd and 3rd override are dropped ComponentList<VEvent> vevents = filterCal.getComponents().getComponents(VEvent.VEVENT); for(VEvent c : vevents) { Assert.assertNotSame("event 6 changed",c.getProperties().getProperty("SUMMARY").getValue()); Assert.assertNotSame("event 6 changed 2",c.getProperties().getProperty("SUMMARY").getValue()); } }
Example #14
Source File: LimitRecurrenceSetTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Tests limit floating recurrence set. * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testLimitFloatingRecurrenceSet() throws Exception { CalendarBuilder cb = new CalendarBuilder(); FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_float_test.ics"); Calendar calendar = cb.build(fis); Assert.assertEquals(3, calendar.getComponents().getComponents("VEVENT").size()); OutputFilter filter = new OutputFilter("test"); DateTime start = new DateTime("20060102T170000"); DateTime end = new DateTime("20060104T170000"); start.setUtc(true); end.setUtc(true); Period period = new Period(start, end); filter.setLimit(period); filter.setAllSubComponents(); filter.setAllProperties(); StringBuilder buffer = new StringBuilder(); filter.filter(calendar, buffer); StringReader sr = new StringReader(buffer.toString()); Calendar filterCal = cb.build(sr); Assert.assertEquals(2, filterCal.getComponents().getComponents("VEVENT").size()); // Make sure 2nd override is dropped ComponentList<VEvent> vevents = filterCal.getComponents().getComponents(VEvent.VEVENT); for(VEvent c : vevents) { Assert.assertNotSame("event 6 changed 2",c.getProperties().getProperty("SUMMARY").getValue()); } }
Example #15
Source File: LimitRecurrenceSetTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Tests limit recurrence set. * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testLimitRecurrenceSet() throws Exception { CalendarBuilder cb = new CalendarBuilder(); FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_test.ics"); Calendar calendar = cb.build(fis); Assert.assertEquals(5, calendar.getComponents().getComponents("VEVENT").size()); VTimeZone vtz = (VTimeZone) calendar.getComponents().getComponent("VTIMEZONE"); TimeZone tz = new TimeZone(vtz); OutputFilter filter = new OutputFilter("test"); DateTime start = new DateTime("20060104T010000", tz); DateTime end = new DateTime("20060106T010000", tz); start.setUtc(true); end.setUtc(true); Period period = new Period(start, end); filter.setLimit(period); filter.setAllSubComponents(); filter.setAllProperties(); StringBuilder buffer = new StringBuilder(); filter.filter(calendar, buffer); StringReader sr = new StringReader(buffer.toString()); Calendar filterCal = cb.build(sr); ComponentList<CalendarComponent> comps = filterCal.getComponents(); Assert.assertEquals(3, comps.getComponents("VEVENT").size()); Assert.assertEquals(1, comps.getComponents("VTIMEZONE").size()); // Make sure 3rd and 4th override are dropped ComponentList<CalendarComponent> events = comps.getComponents("VEVENT"); for(CalendarComponent c : events) { Assert.assertNotSame("event 6 changed 3",c.getProperties().getProperty("SUMMARY").getValue()); Assert.assertNotSame("event 6 changed 4",c.getProperties().getProperty("SUMMARY").getValue()); } }
Example #16
Source File: CalendarFilterEvaluaterTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets calendar. * @param name The name. * @return The calendar. * @throws Exception - if something is wrong this exception is thrown. */ protected Calendar getCalendar(String name) throws Exception { CalendarBuilder cb = new CalendarBuilder(); InputStream in = getClass().getClassLoader().getResourceAsStream(name); if (in == null) { throw new IllegalStateException("resource " + name + " not found"); } Calendar calendar = cb.build(in); return calendar; }
Example #17
Source File: CalendarUtils.java From cosmo with Apache License 2.0 | 5 votes |
/** * Parse icalendar string into calendar component * * @param calendar * icalendar string * @return Component object * @throws ParserException * - if something is wrong this exception is thrown. * @throws IOException * - if something is wrong this exception is thrown. */ public static Component parseComponent(String component) throws ParserException, IOException { if (component == null) { return null; } /* * Don't use dispenser as this method may be called from within a build() as in the case of the custom timezone * registry parsing a timezone */ CalendarBuilder builder = new CalendarBuilder(); StringReader sr = new StringReader("BEGIN:VCALENDAR\n" + component + "END:VCALENDAR"); return (Component) conformToRfc5545(builder.build(sr)).getComponents().get(0); }
Example #18
Source File: InstanceListTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets calendar. * * @param name The name. * @return The calendar. * @throws Exception - if something is wrong this exception is thrown. */ protected Calendar getCalendar(String name) throws Exception { CalendarBuilder cb = new CalendarBuilder(); InputStream in = getClass().getClassLoader().getResourceAsStream("instancelist/" + name); if (in == null) { throw new IllegalStateException("resource " + name + " not found"); } Calendar calendar = cb.build(in); return calendar; }
Example #19
Source File: HibernateContentDaoTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Tests content dao create freeBusy. * * @throws Exception * - if something is wrong this exception is thrown. */ @Test public void testContentDaoCreateFreeBusy() throws Exception { User user = getUser(userDao, "testuser"); CollectionItem root = (CollectionItem) contentDao.getRootItem(user); FreeBusyItem newItem = new HibFreeBusyItem(); newItem.setOwner(user); newItem.setName("test"); newItem.setIcalUid("icaluid"); CalendarBuilder cb = new CalendarBuilder(); net.fortuna.ical4j.model.Calendar calendar = cb.build(helper.getInputStream("vfreebusy.ics")); newItem.setFreeBusyCalendar(calendar); newItem = (FreeBusyItem) contentDao.createContent(root, newItem); Assert.assertTrue(getHibItem(newItem).getId() > -1); Assert.assertNotNull(newItem.getUid()); clearSession(); ContentItem queryItem = (ContentItem) contentDao.findItemByUid(newItem.getUid()); helper.verifyItem(newItem, queryItem); }
Example #20
Source File: HibernateContentDaoTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Tests content dao create availability. * * @throws Exception * - if something is wrong this exception is thrown. */ @Test public void testContentDaoCreateAvailability() throws Exception { User user = getUser(userDao, "testuser"); CollectionItem root = (CollectionItem) contentDao.getRootItem(user); AvailabilityItem newItem = new HibAvailabilityItem(); newItem.setOwner(user); newItem.setName("test"); newItem.setIcalUid("icaluid"); CalendarBuilder cb = new CalendarBuilder(); net.fortuna.ical4j.model.Calendar calendar = cb.build(helper.getInputStream("vavailability.ics")); newItem.setAvailabilityCalendar(calendar); newItem = (AvailabilityItem) contentDao.createContent(root, newItem); Assert.assertTrue(getHibItem(newItem).getId() > -1); Assert.assertNotNull(newItem.getUid()); clearSession(); ContentItem queryItem = (ContentItem) contentDao.findItemByUid(newItem.getUid()); helper.verifyItem(newItem, queryItem); }
Example #21
Source File: EventStampTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets calendar. * @param name The name. * @return The calendar. * @throws Exception - if something is wrong this exception is thrown. */ protected Calendar getCalendar(String name) throws Exception { CalendarBuilder cb = new CalendarBuilder(); FileInputStream fis = new FileInputStream(baseDir + name); Calendar calendar = cb.build(fis); return calendar; }
Example #22
Source File: EntityConverterTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets calendar. * @param name The name. * @return The calendar. * @throws Exception - if something is wrong this exception is thrown. */ protected Calendar getCalendar(String name) throws Exception { CalendarBuilder cb = new CalendarBuilder(); FileInputStream fis = new FileInputStream(baseDir + name); Calendar calendar = cb.build(fis); return calendar; }
Example #23
Source File: ThisAndFutureHelperTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets calendar. * @param name The name. * @return The calendar. * @throws Exception - if something is wrong this exception is thrown. */ protected Calendar getCalendar(String name) throws Exception { CalendarBuilder cb = new CalendarBuilder(); FileInputStream fis = new FileInputStream(baseDir + name); Calendar calendar = cb.build(fis); return calendar; }
Example #24
Source File: StandardContentServiceTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets calendar. * @param filename The file name. * @return The calendar. * @throws Exception - if something is wrong this exception is thrown. */ private Calendar getCalendar(String filename) throws Exception { CalendarBuilder cb = new CalendarBuilder(); FileInputStream fis = new FileInputStream(baseDir + filename); Calendar calendar = cb.build(fis); return calendar; }
Example #25
Source File: CalendarClientsAdapterTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * MKCALENDAR in icalIOS7 provides a timezone without prodid * @throws IOException * @throws ParserException * @throws ValidationException */ @Test public void icalIOS7_missingTimezoneProductIdIsAdded() throws IOException, ParserException, ValidationException{ Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(geticalIOS7Calendar())); CalendarClientsAdapter.adaptTimezoneCalendarComponent(calendar); calendar.validate(true);//must not throw exceptions }
Example #26
Source File: DropIcsPanel.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * @see org.projectforge.web.wicket.components.DropFileContainer#onStringImport(org.apache.wicket.ajax.AjaxRequestTarget, * java.lang.String, java.lang.String) */ @Override protected void onStringImport(final AjaxRequestTarget target, final String fileName, final String content) { try { final CalendarBuilder builder = new CalendarBuilder(); final Calendar calendar = builder.build(new StringReader(content)); onIcsImport(target, calendar); } catch (final Exception ex) { // TODO ju: handle exception log.fatal("unable to import dropped calendar", ex); } }
Example #27
Source File: ICALToJsonAttributeTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void serviceShouldAttachJson() throws Exception { testee.init(FakeMailetConfig.builder().build()); byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting.ics"); Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics)); ImmutableMap<String, Calendar> icals = ImmutableMap.of("key", calendar); ImmutableMap<String, byte[]> rawIcals = ImmutableMap.of("key", ics); MailAddress recipient = MailAddressFixture.ANY_AT_JAMES2; Mail mail = FakeMail.builder() .name("mail") .sender(SENDER) .recipient(recipient) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_SOURCE, AttributeValue.ofAny(icals))) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_RAW_SOURCE, AttributeValue.ofAny(rawIcals))) .build(); testee.service(mail); assertThat(AttributeUtils.getValueAndCastFromMail(mail, ICALToJsonAttribute.DEFAULT_DESTINATION, MAP_STRING_BYTES_CLASS)) .isPresent() .hasValueSatisfying(jsons -> { assertThat(jsons).hasSize(1); assertThatJson(new String(jsons.values().iterator().next(), StandardCharsets.UTF_8)) .isEqualTo("{" + "\"ical\": \"" + toJsonValue(ics) + "\"," + "\"sender\": \"" + SENDER.asString() + "\"," + "\"replyTo\": \"" + SENDER.asString() + "\"," + "\"recipient\": \"" + recipient.asString() + "\"," + "\"uid\": \"f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc\"," + "\"sequence\": \"0\"," + "\"dtstamp\": \"20170106T115036Z\"," + "\"method\": \"REQUEST\"," + "\"recurrence-id\": null" + "}"); }); }
Example #28
Source File: ICALToJsonAttributeTest.java From james-project with Apache License 2.0 | 5 votes |
@ParameterizedTest @MethodSource("validReplyToHeaders") void serviceShouldAttachJsonWithTheReplyToAttributeValueWhenPresent(String replyToHeader) throws Exception { testee.init(FakeMailetConfig.builder().build()); byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting.ics"); Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics)); ImmutableMap<String, Calendar> icals = ImmutableMap.of("key", calendar); ImmutableMap<String, byte[]> rawIcals = ImmutableMap.of("key", ics); MailAddress recipient = MailAddressFixture.ANY_AT_JAMES2; MailAddress replyTo = MailAddressFixture.OTHER_AT_JAMES; Mail mail = FakeMail.builder() .name("mail") .sender(SENDER) .recipient(recipient) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_SOURCE, AttributeValue.ofAny(icals))) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_RAW_SOURCE, AttributeValue.ofAny(rawIcals))) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .addHeader(ICALToJsonAttribute.REPLY_TO_HEADER_NAME, replyToHeader)) .build(); testee.service(mail); assertThat(AttributeUtils.getValueAndCastFromMail(mail, ICALToJsonAttribute.DEFAULT_DESTINATION, MAP_STRING_BYTES_CLASS)) .isPresent() .hasValueSatisfying(jsons -> { assertThat(jsons).hasSize(1); assertThatJson(new String(jsons.values().iterator().next(), StandardCharsets.UTF_8)) .isEqualTo("{" + "\"ical\": \"" + toJsonValue(ics) + "\"," + "\"sender\": \"" + SENDER.asString() + "\"," + "\"replyTo\": \"" + replyTo.asString() + "\"," + "\"recipient\": \"" + recipient.asString() + "\"," + "\"uid\": \"f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc\"," + "\"sequence\": \"0\"," + "\"dtstamp\": \"20170106T115036Z\"," + "\"method\": \"REQUEST\"," + "\"recurrence-id\": null" + "}"); }); }
Example #29
Source File: ICALToJsonAttributeTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void serviceShouldAttachJsonWithTheSenderAsReplyToAttributeValueWhenReplyToIsInvalid() throws Exception { testee.init(FakeMailetConfig.builder().build()); byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting.ics"); Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics)); ImmutableMap<String, Calendar> icals = ImmutableMap.of("key", calendar); ImmutableMap<String, byte[]> rawIcals = ImmutableMap.of("key", ics); MailAddress recipient = MailAddressFixture.ANY_AT_JAMES2; Mail mail = FakeMail.builder() .name("mail") .sender(SENDER) .recipient(recipient) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_SOURCE, AttributeValue.ofAny(icals))) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_RAW_SOURCE, AttributeValue.ofAny(rawIcals))) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .addHeader(ICALToJsonAttribute.REPLY_TO_HEADER_NAME, "[email protected]@il.adr")) .build(); testee.service(mail); assertThat(AttributeUtils.getValueAndCastFromMail(mail, ICALToJsonAttribute.DEFAULT_DESTINATION, MAP_STRING_BYTES_CLASS)) .isPresent() .hasValueSatisfying(jsons -> { assertThat(jsons).hasSize(1); assertThatJson(new String(jsons.values().iterator().next(), StandardCharsets.UTF_8)) .isEqualTo("{" + "\"ical\": \"" + toJsonValue(ics) + "\"," + "\"sender\": \"" + SENDER.asString() + "\"," + "\"replyTo\": \"" + SENDER.asString() + "\"," + "\"recipient\": \"" + recipient.asString() + "\"," + "\"uid\": \"f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc\"," + "\"sequence\": \"0\"," + "\"dtstamp\": \"20170106T115036Z\"," + "\"method\": \"REQUEST\"," + "\"recurrence-id\": null" + "}"); }); }
Example #30
Source File: ICALToJsonAttributeTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void serviceShouldFilterInvalidICS() throws Exception { testee.init(FakeMailetConfig.builder().build()); byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting.ics"); byte[] ics2 = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting_without_uid.ics"); Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics)); Calendar calendar2 = new CalendarBuilder().build(new ByteArrayInputStream(ics2)); ImmutableMap<String, Calendar> icals = ImmutableMap.of("key", calendar, "key2", calendar2); ImmutableMap<String, byte[]> rawIcals = ImmutableMap.of("key", ics, "key2", ics2); MailAddress recipient = MailAddressFixture.OTHER_AT_JAMES; Mail mail = FakeMail.builder() .name("mail") .sender(SENDER) .recipient(recipient) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_SOURCE, AttributeValue.ofAny(icals))) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_RAW_SOURCE, AttributeValue.ofAny(rawIcals))) .build(); testee.service(mail); assertThat(AttributeUtils.getValueAndCastFromMail(mail, ICALToJsonAttribute.DEFAULT_DESTINATION, MAP_STRING_BYTES_CLASS)) .isPresent() .hasValueSatisfying(jsons -> { assertThat(jsons).hasSize(1); List<String> actual = toSortedValueList(jsons); assertThatJson(actual.get(0)).isEqualTo("{" + "\"ical\": \"" + toJsonValue(ics) + "\"," + "\"sender\": \"" + SENDER.asString() + "\"," + "\"recipient\": \"" + recipient.asString() + "\"," + "\"replyTo\": \"" + SENDER.asString() + "\"," + "\"uid\": \"f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc\"," + "\"sequence\": \"0\"," + "\"dtstamp\": \"20170106T115036Z\"," + "\"method\": \"REQUEST\"," + "\"recurrence-id\": null" + "}"); }); }