Skip to content

Commit

Permalink
Added strategy samples
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Jan 2, 2025
1 parent 8a93074 commit 2b4537d
Show file tree
Hide file tree
Showing 34 changed files with 532 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public enum Id {

Incident("semcal:concept:issue:incident"),


Problem("semcal:concept:issue:problem");

private final URI uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public enum Id {

DigitalDocument("semcal:concept:note:digital_document"),

WebSite("semcal:concept:note:web_site"),

Release("semcal:concept:note:release"),

Assumption("semcal:concept:note:assumption"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

/**
* A location represents a physical place.
Expand Down Expand Up @@ -64,9 +66,13 @@ public Entity get() {
Entity entity = newInstance(Entity::new);
entity.with(GeneralPropertyModifiers.KIND, ImmutableKind.LOCATION);
names.forEach(name -> entity.with(IdentificationPropertyModifiers.FN, new Fn(name)));
entity.with(GeographicalPropertyModifiers.GEO, new Geo(latitude, longitude));
entity.with(AddressPropertyModifiers.ADR, new Address("", "", "", locality,
"", postalCode, country));
if (latitude != null && longitude != null) {
entity.with(GeographicalPropertyModifiers.GEO, new Geo(latitude, longitude));
}
if (Stream.of(locality, postalCode, country).anyMatch(s -> !Objects.isNull(s) && !s.isBlank())) {
entity.with(AddressPropertyModifiers.ADR, new Address("", "", "", locality,
"", postalCode, country));
}
return entity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.fortuna.ical4j.extensions.strategy.event;

import net.fortuna.ical4j.extensions.model.concept.EventType;
import net.fortuna.ical4j.extensions.strategy.AbstractStrategy;
import net.fortuna.ical4j.model.component.VEvent;

public class Event extends AbstractStrategy<VEvent> {

@Override
public VEvent get() {
return newInstance(VEvent::new).replace(EventType.EVENT);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.fortuna.ical4j.extensions.strategy.entity


import net.fortuna.ical4j.vcard.VCardBuilder
import spock.lang.Specification

class LocationTest extends Specification {
Expand All @@ -20,4 +21,14 @@ GEO:51.5007292,-0.1272003\r
ADR:;;;London;;SW1A 0AA;United Kingdom;\r
END:VCARD\r\n'''
}

def 'test parsing equivalence'() {
expect: 'parsed model matches strategy'
new Location().withPrototype(prototype).get().propertyList == prototype.propertyList

where: 'prototype loaded from samples'
prototype << new File('src/test/resources/strategy/entity').listFiles().collect {
return new VCardBuilder(new FileInputStream(it)).build().entities
}.flatten()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.fortuna.ical4j.extensions.strategy.event


import net.fortuna.ical4j.util.Calendars
import spock.lang.Specification

class EventTest extends Specification {

def 'test parsing equivalence'() {
expect: 'parsed model matches strategy'
new Event().withPrototype(prototype).get().propertyList == prototype.propertyList

where: 'prototype loaded from samples'
prototype << new File('src/test/resources/strategy/event').listFiles().collect {
return Calendars.load(it.absolutePath).components
}.flatten()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.fortuna.ical4j.extensions.strategy.note


import net.fortuna.ical4j.util.Calendars
import spock.lang.Specification

class NoteTest extends Specification {

def 'test parsing equivalence'() {
expect: 'parsed model matches strategy'
new Note().withPrototype(prototype).get().propertyList == prototype.propertyList

where: 'prototype loaded from samples'
prototype << new File('src/test/resources/strategy/note').listFiles().collect {
return Calendars.load(it.absolutePath).components
}.flatten()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.fortuna.ical4j.extensions.strategy.observance

import net.fortuna.ical4j.extensions.model.property.Repeats
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.util.Calendars
import org.threeten.extra.Years
import spock.lang.Specification

Expand Down Expand Up @@ -43,4 +44,14 @@ DTEND;VALUE=DATE:19881112\r
RRULE:FREQ=YEARLY;INTERVAL=1\r
END:VEVENT\r\n/
}

def 'test parsing equivalence'() {
expect: 'parsed model matches strategy'
new Observance().withPrototype(prototype).get().propertyList == prototype.propertyList

where: 'prototype loaded from samples'
prototype << new File('src/test/resources/strategy/observance').listFiles().collect {
return Calendars.load(it.absolutePath).components
}.flatten()
}
}
223 changes: 223 additions & 0 deletions src/test/resources/strategy/entity/australian_gov.vcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
BEGIN:VCARD
VERSION:4.0
FN:Australian Government Directory - Commonwealth entities and companies
KIND:GROUP
URL:https://www.directory.gov.au/commonwealth-entities-and-companies
CATEGORIES:Legal and Government
MEMBER:urn:uuid:1
MEMBER:urn:uuid:2
MEMBER:urn:uuid:3
MEMBER:urn:uuid:4
MEMBER:urn:uuid:5
MEMBER:urn:uuid:6
MEMBER:urn:uuid:7
MEMBER:urn:uuid:8
MEMBER:urn:uuid:9
MEMBER:urn:uuid:10
MEMBER:urn:uuid:11
MEMBER:urn:uuid:12
MEMBER:urn:uuid:13
MEMBER:urn:uuid:14
MEMBER:urn:uuid:15
MEMBER:urn:uuid:16
MEMBER:urn:uuid:17
MEMBER:urn:uuid:18
MEMBER:urn:uuid:19
MEMBER:urn:uuid:20
MEMBER:urn:uuid:21
MEMBER:urn:uuid:22
MEMBER:urn:uuid:23
MEMBER:urn:uuid:24
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Broadcasting Corporation
KIND:ORG
URL:https://www.directory.gov.au/portfolios/infrastructure-transport-regional-development-communications-and-arts/australian-broadcasting-corporation
UID:1
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Bureau of Statistics
KIND:ORG
URL:https://www.directory.gov.au/portfolios/treasury/australian-bureau-statistics
UID:2
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Communications and Media Authority
KIND:ORG
URL:https://www.directory.gov.au/portfolios/infrastructure-transport-regional-development-communications-and-arts/australian-communications-and-media-authority
UID:3
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Competition and Consumer Commission
KIND:ORG
URL:https://www.directory.gov.au/portfolios/treasury/australian-competition-and-consumer-commission
UID:4
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Electoral Commission
KIND:ORG
URL:https://www.directory.gov.au/portfolios/finance/australian-electoral-commission
UID:5
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Federal Police
KIND:ORG
URL:https://www.directory.gov.au/portfolios/attorney-generals/australian-federal-police
UID:6
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Human Rights Commission
KIND:ORG
URL:https://www.directory.gov.au/portfolios/attorney-generals/australian-human-rights-commission
UID:7
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian National University
KIND:ORG
URL:https://www.directory.gov.au/portfolios/education/australian-national-university
UID:8
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Postal Corporation
KIND:ORG
URL:https://www.directory.gov.au/portfolios/infrastructure-transport-regional-development-communications-and-arts/australian-postal-corporation
UID:9
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Prudential Regulation Authority
KIND:ORG
URL:https://www.directory.gov.au/portfolios/treasury/australian-prudential-regulation-authority
UID:10
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Renewable Energy Agency
KIND:ORG
URL:https://www.directory.gov.au/portfolios/climate-change-energy-environment-and-water/australian-renewable-energy-agency
UID:11
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Research Council
KIND:ORG
URL:https://www.directory.gov.au/portfolios/education/australian-research-council
UID:12
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Secret Intelligence Service
KIND:ORG
URL:https://www.directory.gov.au/portfolios/foreign-affairs-and-trade/australian-secret-intelligence-service
UID:13
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Securities and Investments Commission
KIND:ORG
URL:https://www.directory.gov.au/portfolios/treasury/australian-securities-and-investments-commission
UID:14
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Security Intelligence Organisation
KIND:ORG
URL:https://www.directory.gov.au/portfolios/attorney-generals/australian-security-intelligence-organisation
UID:15
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Signals Directorate
KIND:ORG
URL:https://www.directory.gov.au/portfolios/defence/australian-signals-directorate
UID:16
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Sports Commission
KIND:ORG
URL:https://www.directory.gov.au/portfolios/health-and-aged-care/australian-sports-commission
UID:17
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian Taxation Office
KIND:ORG
URL:https://www.directory.gov.au/portfolios/treasury/australian-taxation-office
UID:18
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Australian War Memorial
KIND:ORG
URL:https://www.directory.gov.au/portfolios/veterans-affairs-part-defence-portfolio/australian-war-memorial
UID:19
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Bureau of Meteorology
KIND:ORG
URL:https://www.directory.gov.au/portfolios/climate-change-energy-environment-and-water/bureau-meteorology
UID:20
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Climate Change Authority
KIND:ORG
URL:https://www.directory.gov.au/portfolios/climate-change-energy-environment-and-water/climate-change-authority
UID:21
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Department of Agriculture, Fisheries and Forestry
KIND:ORG
URL:https://www.directory.gov.au/portfolios/agriculture-fisheries-and-forestry/department-agriculture-fisheries-and-forestry
UID:22
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Department of Defence
KIND:ORG
URL:https://www.directory.gov.au/portfolios/defence/department-defence
UID:23
END:VCARD

BEGIN:VCARD
VERSION:4.0
FN:Department of Education
KIND:ORG
URL:https://www.directory.gov.au/portfolios/education/department-education
UID:24
END:VCARD
7 changes: 7 additions & 0 deletions src/test/resources/strategy/entity/egan_reserve.vcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN:VCARD
FN:Egan Reserve
KIND:LOCATION
GEO:-37.7514239,144.9819331
URL;X-LABEL=Egan Reserve (Google Maps):https://maps.app.goo.gl/56ZEfL3g1Uy4uKa39
CATEGORIES:Lifestyle
END:VCARD
9 changes: 9 additions & 0 deletions src/test/resources/strategy/event/remembrance_day.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BEGIN:VCALENDAR
BEGIN:VEVENT
CONCEPT:semcal:concept:event
SUMMARY:Remembrance Day
DTSTART:19191111T110000
DTEND:19191111T110100
RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=11
END:VEVENT
END:VCALENDAR
7 changes: 7 additions & 0 deletions src/test/resources/strategy/note/acme_mapper.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN:VCALENDAR
BEGIN:VJOURNAL
CONCEPT:semcal:concept:note:web_site
SUMMARY:ACME Mapper
LINK;VALUE=URI;LINKREL=bookmark:https://mapper.acme.com/
END:VJOURNAL
END:VCALENDAR
Loading

0 comments on commit 2b4537d

Please sign in to comment.