test: tested delegatee resolvation
This commit is contained in:
@@ -30,6 +30,14 @@ public final class CalendarUserAddress {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CalendarUserAddress(String value) {
|
||||||
|
var uri = URI.create(value);
|
||||||
|
if (!"mailto".equalsIgnoreCase(uri.getScheme())) {
|
||||||
|
throw new IllegalArgumentException("Calendar User Address (CAL-ADDRESS) only accept mailto URI.");
|
||||||
|
}
|
||||||
|
this.value = uri;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.onixbyte.icalendar.datatype.CalendarUserAddress;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegate
|
* Delegate
|
||||||
@@ -38,6 +39,10 @@ public final class Delegatee implements PropertyParameter {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private List<CalendarUserAddress> value;
|
private List<CalendarUserAddress> value;
|
||||||
|
|
||||||
@@ -45,8 +50,28 @@ public final class Delegatee implements PropertyParameter {
|
|||||||
this.value = new ArrayList<>();
|
this.value = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addDelegatee(URI delegateeUri) {
|
public Builder addDelegatee(CalendarUserAddress delegatee) {
|
||||||
value.add(new CalendarUserAddress(delegateeUri));
|
value.add(delegatee);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addDelegatee(URI delegatee) {
|
||||||
|
value.add(new CalendarUserAddress(delegatee));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addDelegatee(String delegatee) {
|
||||||
|
value.add(new CalendarUserAddress(delegatee));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addDelegatees(List<CalendarUserAddress> delegatees) {
|
||||||
|
value.addAll(delegatees);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addDelegatees(Supplier<List<CalendarUserAddress>> delegatees) {
|
||||||
|
value.addAll(delegatees.get());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (C) 2023 CodeCraftersCN.
|
~ Copyright (C) 2024-2024 OnixByte.
|
||||||
~
|
~
|
||||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
~ you may not use this file except in compliance with the License.
|
~ you may not use this file except in compliance with the License.
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
~ limitations under the License.
|
~ limitations under the License.
|
||||||
-->
|
-->
|
||||||
<configuration>
|
<configuration>
|
||||||
<property name="COLOURFUL_OUTPUT" value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
|
<property name="COLOURFUL_OUTPUT" value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%15.15t]) %cyan(%-39.39logger{39}) %black(:) %msg%n"/>
|
||||||
<property name="STANDARD_OUTPUT" value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
|
<property name="STANDARD_OUTPUT" value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
|
||||||
|
|
||||||
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
|
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024-2024 OnixByte.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.onixbyte.icalendar.test;
|
||||||
|
|
||||||
|
import com.onixbyte.icalendar.datatype.CalendarUserAddress;
|
||||||
|
import com.onixbyte.icalendar.property.parameter.Delegatee;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class DelegateeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddStringDelegatee() {
|
||||||
|
var delegatee = Delegatee.builder()
|
||||||
|
.addDelegatee("mailto:user01@example.onixbyte.com")
|
||||||
|
.build()
|
||||||
|
.resolve();
|
||||||
|
log.info("#testAddStringDelegatee {}", delegatee);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddUriDelegatee() {
|
||||||
|
var delegatee = Delegatee.builder()
|
||||||
|
.addDelegatee(URI.create("mailto:user01@example.onixbyte.com"))
|
||||||
|
.build()
|
||||||
|
.resolve();
|
||||||
|
log.info("#testAddUriDelegatee {}", delegatee);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddCauDelegateeWithStringConstructor() {
|
||||||
|
var delegatee = Delegatee.builder()
|
||||||
|
.addDelegatee(new CalendarUserAddress("mailto:user01@example.onixbyte.com"))
|
||||||
|
.build()
|
||||||
|
.resolve();
|
||||||
|
log.info("#testAddCauDelegateeWithStringConstructor {}", delegatee);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddCauDelegateeWithUriConstructor() {
|
||||||
|
var delegatee = Delegatee.builder()
|
||||||
|
.addDelegatee(new CalendarUserAddress(URI.create("mailto:user01@example.onixbyte.com")))
|
||||||
|
.build()
|
||||||
|
.resolve();
|
||||||
|
log.info("#testAddCauDelegateeWithUriConstructor {}", delegatee);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddDelegateeSeparately() {
|
||||||
|
var delegatee = Delegatee.builder()
|
||||||
|
.addDelegatee(new CalendarUserAddress(URI.create("mailto:user01@example.onixbyte.com")))
|
||||||
|
.addDelegatee(URI.create("mailto:user02@example.onixbyte.com"))
|
||||||
|
.addDelegatee("mailto:user03@example.onixbyte.com")
|
||||||
|
.build()
|
||||||
|
.resolve();
|
||||||
|
log.info("#testAddDelegateeSeparately {}", delegatee);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddDelegateeSeparatelyWithIncorrectUri() {
|
||||||
|
try {
|
||||||
|
var delegatee = Delegatee.builder()
|
||||||
|
.addDelegatee(new CalendarUserAddress(URI.create("mailto:user01@example.onixbyte.com")))
|
||||||
|
.addDelegatee(URI.create("mailto:user02@example.onixbyte.com"))
|
||||||
|
.addDelegatee("https://example.onixbyte.com")
|
||||||
|
.build()
|
||||||
|
.resolve();
|
||||||
|
log.info("#testAddDelegateeSeparatelyWithIncorrectUri {}", delegatee);
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
log.error("#testAddDelegateeSeparatelyWithIncorrectUri {}", iae.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddDelegateesWithCau() {
|
||||||
|
try {
|
||||||
|
var delegatee = Delegatee.builder()
|
||||||
|
.addDelegatees(List.of(
|
||||||
|
new CalendarUserAddress("mailto:user01@example.onixbyte.com"),
|
||||||
|
new CalendarUserAddress("mailto:user02@example.onixbyte.com")
|
||||||
|
))
|
||||||
|
.build()
|
||||||
|
.resolve();
|
||||||
|
log.info("#testAddDelegateesWithCau {}", delegatee);
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
log.error("#testAddDelegateesWithCau {}", iae.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddDelegateesWithSupplier() {
|
||||||
|
try {
|
||||||
|
var delegatee = Delegatee.builder()
|
||||||
|
.addDelegatees(() -> Stream.of("mailto:user01@example.onixbyte.com", "mailto:user02@example.onixbyte.com")
|
||||||
|
.map(CalendarUserAddress::new)
|
||||||
|
.toList())
|
||||||
|
.build()
|
||||||
|
.resolve();
|
||||||
|
log.info("#testAddDelegateesWithSupplier {}", delegatee);
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
log.error("#testAddDelegateesWithSupplier {}", iae.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2024-2024 OnixByte.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.onixbyte.icalendar.test;
|
|
||||||
|
|
||||||
import com.onixbyte.icalendar.component.Calendar;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TestWebCalendar
|
|
||||||
*
|
|
||||||
* @author Zihlu Wang
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class TestCalendar {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testWebCalendar() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user