-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
37cba46
commit a5a8e22
Showing
10 changed files
with
402 additions
and
43 deletions.
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
...ntegrationTest/src/main/java/io/toolisticon/fluapigen/integrationtest/EmailFluentApi.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,150 @@ | ||
package io.toolisticon.fluapigen.integrationtest; | ||
|
||
import io.toolisticon.fluapigen.api.FluentApi; | ||
import io.toolisticon.fluapigen.api.FluentApiBackingBean; | ||
import io.toolisticon.fluapigen.api.FluentApiBackingBeanField; | ||
import io.toolisticon.fluapigen.api.FluentApiBackingBeanMapping; | ||
import io.toolisticon.fluapigen.api.FluentApiCommand; | ||
import io.toolisticon.fluapigen.api.FluentApiImplicitValue; | ||
import io.toolisticon.fluapigen.api.FluentApiInlineBackingBeanMapping; | ||
import io.toolisticon.fluapigen.api.FluentApiInterface; | ||
import io.toolisticon.fluapigen.api.FluentApiParentBackingBeanMapping; | ||
import io.toolisticon.fluapigen.api.FluentApiRoot; | ||
import io.toolisticon.fluapigen.api.MappingAction; | ||
import io.toolisticon.fluapigen.api.TargetBackingBean; | ||
import io.toolisticon.fluapigen.validation.api.Matches; | ||
import io.toolisticon.fluapigen.validation.api.NotNull; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
@FluentApi("EmailFluentApiStarter") | ||
public class EmailFluentApi { | ||
|
||
// --------------------------------------------------- | ||
// -- Backing Beans | ||
// --------------------------------------------------- | ||
|
||
/** | ||
* The root backing bean. | ||
*/ | ||
@FluentApiBackingBean | ||
public interface EmailBB { | ||
|
||
List<RecipientBB> recipients(); | ||
|
||
String subject(); | ||
|
||
String body(); | ||
|
||
List<AttachmentBB> attachments(); | ||
} | ||
|
||
/** | ||
* Backing bean for storing recipients | ||
*/ | ||
@FluentApiBackingBean | ||
public interface RecipientBB{ | ||
RecipientKind recipientKind(); | ||
|
||
String emailAddress(); | ||
} | ||
|
||
public enum RecipientKind { | ||
TO, | ||
CC, | ||
BCC; | ||
} | ||
|
||
/** | ||
* Backing Bean for attachments | ||
*/ | ||
@FluentApiBackingBean | ||
public interface AttachmentBB { | ||
@FluentApiBackingBeanField() | ||
File attachment(); | ||
|
||
String attachmentName(); | ||
} | ||
|
||
// --------------------------------------------------- | ||
// -- Commands | ||
// --------------------------------------------------- | ||
|
||
@FluentApiCommand | ||
public static class SendEmailCommand { | ||
public static EmailBB sendEmail(EmailBB emailBB) { | ||
// Implementation for sending the email | ||
return emailBB; | ||
} | ||
} | ||
|
||
// --------------------------------------------------- | ||
// -- Fluent Api | ||
// --------------------------------------------------- | ||
|
||
|
||
@FluentApiRoot | ||
@FluentApiInterface(EmailBB.class) | ||
public interface EmailStartInterface { | ||
|
||
@FluentApiInlineBackingBeanMapping("recipients") | ||
@FluentApiImplicitValue(value="TO", id="recipientKind", target = TargetBackingBean.INLINE) | ||
AddRecipientsOrSetSubject to ( | ||
@FluentApiBackingBeanMapping(value = "emailAddress", target = TargetBackingBean.INLINE) | ||
@NotNull @Matches(".*[@].*") String emailAddress); | ||
|
||
@FluentApiInlineBackingBeanMapping("recipients") | ||
@FluentApiImplicitValue(value="CC", id="recipientKind", target = TargetBackingBean.INLINE) | ||
AddRecipientsOrSetSubject cc (@FluentApiBackingBeanMapping(value = "emailAddress", target = TargetBackingBean.INLINE) | ||
@NotNull @Matches(".*[@].*") String emailAddress); | ||
@FluentApiInlineBackingBeanMapping("recipients") | ||
@FluentApiImplicitValue(value="BCC", id="recipientKind", target = TargetBackingBean.INLINE) | ||
AddRecipientsOrSetSubject bcc (@FluentApiBackingBeanMapping(value = "emailAddress", target = TargetBackingBean.INLINE) | ||
@NotNull @Matches(".*[@].*") String emailAddress); | ||
} | ||
|
||
@FluentApiInterface(EmailBB.class) | ||
public interface AddRecipientsOrSetSubject { | ||
EmailStartInterface and(); | ||
|
||
AddBodyInterface withSubject (@FluentApiBackingBeanMapping(value="subject") @NotNull String subject); | ||
|
||
} | ||
|
||
@FluentApiInterface(EmailBB.class) | ||
public interface AddBodyInterface { | ||
|
||
AddAttachmentOrCloseCommandInterface withBody(@FluentApiBackingBeanMapping(value="subject") @NotNull String body) ; | ||
|
||
} | ||
|
||
@FluentApiInterface(EmailBB.class) | ||
public interface AddAttachmentOrCloseCommandInterface { | ||
|
||
AddAttachmentInterface addAttachment(); | ||
|
||
|
||
@FluentApiCommand(SendEmailCommand.class) | ||
EmailBB sendEmail(); | ||
|
||
} | ||
|
||
|
||
@FluentApiInterface(AttachmentBB.class) | ||
public interface AddAttachmentFileInterface { | ||
|
||
@FluentApiParentBackingBeanMapping(value = "attachments", action = MappingAction.ADD) | ||
AddAttachmentOrCloseCommandInterface fromFile(@FluentApiBackingBeanMapping(value="attachment") File file); | ||
} | ||
|
||
@FluentApiInterface(AttachmentBB.class) | ||
public interface AddAttachmentInterface extends AddAttachmentFileInterface{ | ||
|
||
AddAttachmentFileInterface withCustomName (@FluentApiBackingBeanMapping(value="attachmentName") String attachmentName); | ||
|
||
} | ||
|
||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...rationTest/src/test/java/io/toolisticon/fluapigen/integrationtest/EmailFluentApiTest.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,24 @@ | ||
package io.toolisticon.fluapigen.integrationtest; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
|
||
public class EmailFluentApiTest { | ||
|
||
@Test | ||
public void test() { | ||
EmailFluentApi.EmailBB emailBB = EmailFluentApiStarter.cc("[email protected]") | ||
.and().to("[email protected]") | ||
.and().cc("[email protected]") | ||
.withSubject("Test") | ||
.withBody("LOREM IPSUM") | ||
.addAttachment().withCustomName("itWorks.png").fromFile(new File("abc.png")) | ||
.sendEmail(); | ||
|
||
MatcherAssert.assertThat(emailBB, Matchers.notNullValue()); | ||
} | ||
|
||
} |
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
Oops, something went wrong.