Skip to content

Commit dd574eb

Browse files
authored
More processors (#79)
* Add AttendeesProcessor * Add UidProcessor * Add RemindersProcessor * Fix typo * Also provide main Entity to processors * Indenting * Fix processor calls + tests * Add CategoriesProcessor * Add UrlProcessor * Add UnknownPropertiesProcessor * Add AccessLevelProcessor * Add processors for title, location, description * Add StatusProcessor * Add AvailabilityProcessor * Add ColorProcessor * Add OrganizerProcessor * Add MutatorsProcessor * Add SequenceProcessor * Make logger private
1 parent 3b1b133 commit dd574eb

29 files changed

+1208
-383
lines changed

lib/src/androidTest/kotlin/at/bitfire/synctools/mapping/calendar/LegacyAndroidEventProcessorTest.kt

Lines changed: 0 additions & 266 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import android.content.ContentUris
1212
import android.content.ContentValues
1313
import android.provider.CalendarContract.ACCOUNT_TYPE_LOCAL
1414
import android.provider.CalendarContract.AUTHORITY
15-
import android.provider.CalendarContract.Attendees
1615
import android.provider.CalendarContract.Events
1716
import android.provider.CalendarContract.ExtendedProperties
1817
import androidx.core.content.contentValuesOf
@@ -24,9 +23,7 @@ import at.bitfire.ical4android.impl.TestCalendar
2423
import at.bitfire.ical4android.util.AndroidTimeUtils
2524
import at.bitfire.ical4android.util.MiscUtils.asSyncAdapter
2625
import at.bitfire.ical4android.util.MiscUtils.closeCompat
27-
import at.bitfire.synctools.icalendar.Css3Color
2826
import at.bitfire.synctools.storage.calendar.AndroidCalendar
29-
import at.bitfire.synctools.storage.calendar.AndroidCalendarProvider
3027
import at.bitfire.synctools.storage.calendar.AndroidEvent2
3128
import at.bitfire.synctools.test.InitCalendarProviderRule
3229
import net.fortuna.ical4j.model.Date
@@ -35,22 +32,18 @@ import net.fortuna.ical4j.model.Parameter
3532
import net.fortuna.ical4j.model.ParameterList
3633
import net.fortuna.ical4j.model.TimeZoneRegistryFactory
3734
import net.fortuna.ical4j.model.parameter.Language
38-
import net.fortuna.ical4j.model.property.Clazz
3935
import net.fortuna.ical4j.model.property.DtEnd
4036
import net.fortuna.ical4j.model.property.DtStart
4137
import net.fortuna.ical4j.model.property.RecurrenceId
42-
import net.fortuna.ical4j.model.property.Status
4338
import net.fortuna.ical4j.model.property.XProperty
4439
import org.junit.After
4540
import org.junit.Assert.assertEquals
46-
import org.junit.Assert.assertFalse
4741
import org.junit.Assert.assertNull
4842
import org.junit.Assert.assertTrue
4943
import org.junit.Before
5044
import org.junit.Rule
5145
import org.junit.Test
5246
import org.junit.rules.TestRule
53-
import java.net.URI
5447

5548
/**
5649
* Tests mapping from [at.bitfire.synctools.storage.calendar.EventAndExceptions] to [Event].
@@ -148,51 +141,6 @@ class LegacyAndroidEventProcessorTest {
148141
}
149142

150143

151-
@Test
152-
fun testPopulateEvent_Sequence_Int() {
153-
populateEvent(true, asSyncAdapter = true) {
154-
put(AndroidEvent2.COLUMN_SEQUENCE, 5)
155-
}.let { result ->
156-
assertEquals(5, result.sequence)
157-
}
158-
}
159-
160-
@Test
161-
fun testPopulateEvent_Sequence_Null() {
162-
populateEvent(true, asSyncAdapter = true) {
163-
putNull(AndroidEvent2.COLUMN_SEQUENCE)
164-
}.let { result ->
165-
assertNull(result.sequence)
166-
}
167-
}
168-
169-
@Test
170-
fun testPopulateEvent_IsOrganizer_False() {
171-
populateEvent(true, asSyncAdapter = true) {
172-
put(Events.IS_ORGANIZER, "0")
173-
}.let { result ->
174-
assertFalse(result.isOrganizer!!)
175-
}
176-
}
177-
178-
@Test
179-
fun testPopulateEvent_IsOrganizer_Null() {
180-
populateEvent(true, asSyncAdapter = true) {
181-
putNull(Events.IS_ORGANIZER)
182-
}.let { result ->
183-
assertNull(result.isOrganizer)
184-
}
185-
}
186-
187-
@Test
188-
fun testPopulateEvent_IsOrganizer_True() {
189-
populateEvent(true, asSyncAdapter = true) {
190-
put(Events.IS_ORGANIZER, "1")
191-
}.let { result ->
192-
assertTrue(result.isOrganizer!!)
193-
}
194-
}
195-
196144
@Test
197145
fun testPopulateEvent_NonAllDay_NonRecurring() {
198146
populateEvent(false) {
@@ -344,220 +292,6 @@ class LegacyAndroidEventProcessorTest {
344292
}
345293
}
346294

347-
@Test
348-
fun testPopulateEvent_Summary() {
349-
populateEvent(true) {
350-
put(Events.TITLE, "Sample Title")
351-
}.let { result ->
352-
assertEquals("Sample Title", result.summary)
353-
}
354-
}
355-
356-
@Test
357-
fun testPopulateEvent_Location() {
358-
populateEvent(true) {
359-
put(Events.EVENT_LOCATION, "Sample Location")
360-
}.let { result ->
361-
assertEquals("Sample Location", result.location)
362-
}
363-
}
364-
365-
@Test
366-
fun testPopulateEvent_Url() {
367-
populateEvent(true,
368-
extendedProperties = mapOf(AndroidEvent2.EXTNAME_URL to "https://example.com")
369-
).let { result ->
370-
assertEquals(URI("https://example.com"), result.url)
371-
}
372-
}
373-
374-
@Test
375-
fun testPopulateEvent_Description() {
376-
populateEvent(true) {
377-
put(Events.DESCRIPTION, "Sample Description")
378-
}.let { result ->
379-
assertEquals("Sample Description", result.description)
380-
}
381-
}
382-
383-
@Test
384-
fun testPopulateEvent_Color_FromIndex() {
385-
val provider = AndroidCalendarProvider(testAccount, client)
386-
provider.provideCss3ColorIndices()
387-
populateEvent(true) {
388-
put(Events.EVENT_COLOR_KEY, Css3Color.silver.name)
389-
}.let { result ->
390-
assertEquals(Css3Color.silver, result.color)
391-
}
392-
}
393-
394-
@Test
395-
fun testPopulateEvent_Color_FromValue() {
396-
populateEvent(true) {
397-
put(Events.EVENT_COLOR, Css3Color.silver.argb)
398-
}.let { result ->
399-
assertEquals(Css3Color.silver, result.color)
400-
}
401-
}
402-
403-
@Test
404-
fun testPopulateEvent_Status_Confirmed() {
405-
populateEvent(true) {
406-
put(Events.STATUS, Events.STATUS_CONFIRMED)
407-
}.let { result ->
408-
assertEquals(Status.VEVENT_CONFIRMED, result.status)
409-
}
410-
}
411-
412-
@Test
413-
fun testPopulateEvent_Status_Tentative() {
414-
populateEvent(true) {
415-
put(Events.STATUS, Events.STATUS_TENTATIVE)
416-
}.let { result ->
417-
assertEquals(Status.VEVENT_TENTATIVE, result.status)
418-
}
419-
}
420-
421-
@Test
422-
fun testPopulateEvent_Status_Cancelled() {
423-
populateEvent(true) {
424-
put(Events.STATUS, Events.STATUS_CANCELED)
425-
}.let { result ->
426-
assertEquals(Status.VEVENT_CANCELLED, result.status)
427-
}
428-
}
429-
430-
@Test
431-
fun testPopulateEvent_Status_None() {
432-
assertNull(populateEvent(true).status)
433-
}
434-
435-
@Test
436-
fun testPopulateEvent_Availability_Busy() {
437-
populateEvent(true) {
438-
put(Events.AVAILABILITY, Events.AVAILABILITY_BUSY)
439-
}.let { result ->
440-
assertTrue(result.opaque)
441-
}
442-
}
443-
444-
@Test
445-
fun testPopulateEvent_Availability_Tentative() {
446-
populateEvent(true) {
447-
put(Events.AVAILABILITY, Events.AVAILABILITY_TENTATIVE)
448-
}.let { result ->
449-
assertTrue(result.opaque)
450-
}
451-
}
452-
453-
@Test
454-
fun testPopulateEvent_Availability_Free() {
455-
populateEvent(true) {
456-
put(Events.AVAILABILITY, Events.AVAILABILITY_FREE)
457-
}.let { result ->
458-
assertFalse(result.opaque)
459-
}
460-
}
461-
462-
@Test
463-
fun testPopulateEvent_Organizer_NotGroupScheduled() {
464-
assertNull(populateEvent(true).organizer)
465-
}
466-
467-
@Test
468-
fun testPopulateEvent_Organizer_NotGroupScheduled_ExplicitOrganizer() {
469-
populateEvent(true) {
470-
put(Events.ORGANIZER, "[email protected]")
471-
}.let { result ->
472-
assertNull(result.organizer)
473-
}
474-
}
475-
476-
@Test
477-
fun testPopulateEvent_Organizer_GroupScheduled() {
478-
populateEvent(true, insertCallback = { id ->
479-
client.insert(Attendees.CONTENT_URI.asSyncAdapter(testAccount), ContentValues().apply {
480-
put(Attendees.EVENT_ID, id)
481-
put(Attendees.ATTENDEE_EMAIL, "[email protected]")
482-
put(Attendees.ATTENDEE_TYPE, Attendees.RELATIONSHIP_ORGANIZER)
483-
})
484-
}) {
485-
put(Events.ORGANIZER, "[email protected]")
486-
}.let { result ->
487-
assertEquals("mailto:[email protected]", result.organizer?.value)
488-
}
489-
}
490-
491-
@Test
492-
fun testPopulateEvent_Classification_Public() {
493-
populateEvent(true) {
494-
put(Events.ACCESS_LEVEL, Events.ACCESS_PUBLIC)
495-
}.let { result ->
496-
assertEquals(Clazz.PUBLIC, result.classification)
497-
}
498-
}
499-
500-
@Test
501-
fun testPopulateEvent_Classification_Private() {
502-
populateEvent(true) {
503-
put(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE)
504-
}.let { result ->
505-
assertEquals(Clazz.PRIVATE, result.classification)
506-
}
507-
}
508-
509-
@Test
510-
fun testPopulateEvent_Classification_Confidential() {
511-
populateEvent(true) {
512-
put(Events.ACCESS_LEVEL, Events.ACCESS_CONFIDENTIAL)
513-
}.let { result ->
514-
assertEquals(Clazz.CONFIDENTIAL, result.classification)
515-
}
516-
}
517-
518-
@Test
519-
fun testPopulateEvent_Classification_Confidential_Retained() {
520-
populateEvent(true,
521-
extendedProperties = mapOf(UnknownProperty.CONTENT_ITEM_TYPE to UnknownProperty.toJsonString(Clazz.CONFIDENTIAL))
522-
) {
523-
put(Events.ACCESS_LEVEL, Events.ACCESS_DEFAULT)
524-
}.let { result ->
525-
assertEquals(Clazz.CONFIDENTIAL, result.classification)
526-
}
527-
}
528-
529-
@Test
530-
fun testPopulateEvent_Classification_Default() {
531-
populateEvent(true) {
532-
put(Events.ACCESS_LEVEL, Events.ACCESS_DEFAULT)
533-
}.let { result ->
534-
assertNull(result.classification)
535-
}
536-
}
537-
538-
@Test
539-
fun testPopulateEvent_Classification_Custom() {
540-
populateEvent(
541-
true,
542-
valuesBuilder = {
543-
put(Events.ACCESS_LEVEL, Events.ACCESS_DEFAULT)
544-
},
545-
extendedProperties = mapOf(
546-
UnknownProperty.CONTENT_ITEM_TYPE to UnknownProperty.toJsonString(Clazz("TOP-SECRET"))
547-
)
548-
).let { result ->
549-
assertEquals(Clazz("TOP-SECRET"), result.classification)
550-
}
551-
}
552-
553-
@Test
554-
fun testPopulateEvent_Classification_None() {
555-
populateEvent(true) {
556-
}.let { result ->
557-
assertNull(result.classification)
558-
}
559-
}
560-
561295

562296
@Test
563297
fun testPopulateUnknownProperty() {

0 commit comments

Comments
 (0)