https://github.com/mailslurp/examples
rootProject.name = 'java-gradle-junit5'
plugins {
id 'java'
}
group 'com.mailslurp.examples'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'com.mailslurp:mailslurp-client-java:15.17.4'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}
test {
useJUnitPlatform()
}
# Email testing
See [examples repository](https://github.com/mailslurp/examples) for source.
-include ../.env
test:
API_KEY=$(API_KEY) ./gradlew clean test
package com.mailslurp.examples;
//<gen>java_demo_imports
import com.mailslurp.apis.*;
import com.mailslurp.clients.*;
import com.mailslurp.models.*;
//</gen>
import java.util.Base64;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.*;
public class ExampleUsageTest {
private final static String YOUR_API_KEY = System.getenv("API_KEY");
private static final Boolean UNREAD_ONLY = true;
// private static final Long TIMEOUT_MILLIS = 30000L;
private static final Integer TIMEOUT_MILLIS = 30000;
@BeforeAll
public static void Setup() {
assertNotNull(YOUR_API_KEY);
}
@Test
public void CanCreateInboxes() throws Exception {
//<gen>java_demo_create_client
// create a MailSlurp client with your API_KEY
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setApiKey(YOUR_API_KEY);
//</gen>
//<gen>java_demo_client_timeout
defaultClient.setConnectTimeout(TIMEOUT_MILLIS);
defaultClient.setWriteTimeout(TIMEOUT_MILLIS);
defaultClient.setReadTimeout(TIMEOUT_MILLIS);
//</gen>
//<gen>java_demo_create_controller
InboxControllerApi inboxControllerApi = new InboxControllerApi(defaultClient);
//</gen>
//<gen>java_demo_create_inbox
InboxDto inbox = inboxControllerApi.createInboxWithDefaults();
// verify inbox
assertEquals(inbox.getEmailAddress().contains("@mailslurp"), true);
assertNotNull(inbox.getId());
//</gen>
//<gen>java_demo_create_inbox_options
CreateInboxDto options = new CreateInboxDto()
.description("My inbox")
.inboxType(CreateInboxDto.InboxTypeEnum.SMTP_INBOX);
InboxDto inboxWithOptions = inboxControllerApi.createInboxWithOptions(options);
//</gen>
assertNotNull(inboxWithOptions.getId());
//<gen>java_demo_get_inbox
// get inbox by id
InboxDto inboxById = inboxControllerApi.getInbox(inbox.getId());
// lookup inbox by address
InboxByEmailAddressResult inboxByAddress = inboxControllerApi.getInboxByEmailAddress(inbox.getEmailAddress());
assertEquals(inboxByAddress.getInboxId(), inbox.getId());
// lookup inbox by name
InboxByNameResult inboxByName = inboxControllerApi.getInboxByName("Non-existing inbox");
assertFalse(inboxByName.getExists());
//</gen>
//<gen>java_demo_list_inboxes
PageInboxProjection allInboxes = inboxControllerApi.getAllInboxes(0, 10, null, null, null, null, null, null, null, null, null);
// can access pagination
assertTrue(allInboxes.getTotalElements() > 0);
assertEquals(allInboxes.getPageable().getPageNumber().intValue(), 0);
assertEquals(allInboxes.getPageable().getPageSize().intValue(), 10);
// can access inboxes
InboxPreview inboxPreview = allInboxes.getContent().get(0);
//</gen>
assertNotNull(inboxPreview.getCreatedAt());
}
@Test
public void CanSendEmails() throws Exception {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setApiKey(YOUR_API_KEY);
InboxControllerApi inboxControllerApi = new InboxControllerApi(defaultClient);
InboxDto inbox = inboxControllerApi.createInboxWithDefaults();
InboxDto inbox2 = inboxControllerApi.createInboxWithDefaults();
//<gen>java_demo_send_email
SendEmailOptions sendEmailOptions = new SendEmailOptions()
.to(singletonList(inbox.getEmailAddress()))
.subject("Test")
.body("Hello");
inboxControllerApi.sendEmail(inbox.getId(), sendEmailOptions);
//</gen>
//<gen>java_demo_upload_attachment
byte[] bytes = {0}; // test file, in reality read a file or input stream as bytes;
UploadAttachmentOptions uploadAttachmentOptions = new UploadAttachmentOptions()
.contentType("text/plain")
.filename("hello.txt")
.base64Contents(Base64.getEncoder().encodeToString(bytes));
AttachmentControllerApi attachmentControllerApi = new AttachmentControllerApi(defaultClient);
List<String> attachmentIds = attachmentControllerApi.uploadAttachment(uploadAttachmentOptions);
//</gen>
//<gen>java_demo_send_attachment
SendEmailOptions sendOptions = new SendEmailOptions()
.to(singletonList(inbox2.getEmailAddress()))
.subject("Test email")
.body("Hello with attachment")
.attachments(attachmentIds);
inboxControllerApi.sendEmail(inbox2.getId(), sendOptions);
//</gen>
WaitForControllerApi waitForControllerApi = new WaitForControllerApi(defaultClient);
Email email = waitForControllerApi.waitForLatestEmail(inbox2.getId(), TIMEOUT_MILLIS.longValue(), UNREAD_ONLY, null, null, null, null);
//<gen>java_demo_download_attachments
String attachmentId = email.getAttachments().get(0);
// get attachment file name etc
AttachmentMetaData attachmentInfo = attachmentControllerApi.getAttachmentInfo(attachmentId);
assertNotNull(attachmentInfo.getName());
// download as bytes
byte[] attachmentBytes = attachmentControllerApi.downloadAttachmentAsBytes(attachmentId);
//</gen>
assertNotNull(attachmentBytes);
}
@Test
public void CanReceiveEmail() throws Exception {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setApiKey(YOUR_API_KEY);
InboxControllerApi inboxControllerApi = new InboxControllerApi(defaultClient);
InboxDto inbox1 = inboxControllerApi.createInboxWithDefaults();
InboxDto inbox2 = inboxControllerApi.createInboxWithDefaults();
SendEmailOptions sendEmailOptions = new SendEmailOptions()
.to(singletonList(inbox2.getEmailAddress()))
.subject("Hello inbox2")
.body("Your code is: 123");
inboxControllerApi.sendEmail(inbox1.getId(), sendEmailOptions);
//<gen>java_demo_wait_for_email
WaitForControllerApi waitForControllerApi = new WaitForControllerApi(defaultClient);
Email email = waitForControllerApi.waitForLatestEmail(inbox2.getId(), TIMEOUT_MILLIS.longValue(), UNREAD_ONLY, null, null, null, null);
assertEquals(email.getSubject(), "Hello inbox2");
assertEquals(email.getBody().contains("Your code is:"), true);
//</gen>
//<gen>java_demo_wait_for_matching_email
Pattern p = Pattern.compile("Your code is: ([0-9]{3})");
Matcher m = p.matcher(email.getBody());
m.find();
String code = m.group(1);
assertEquals(code, "123");
//</gen>
//<gen>java_demo_matching
inboxControllerApi.sendEmail(inbox1.getId(), new SendEmailOptions()
.to(singletonList(inbox1.getEmailAddress()))
.subject("Verification code")
.body("Your code is: 456"));
// complex match option
List<EmailPreview> verificationEmail = waitForControllerApi.waitFor(new WaitForConditions()
.inboxId(inbox1.getId())
.unreadOnly(true)
.countType(WaitForConditions.CountTypeEnum.EXACTLY)
.count(1)
.addMatchesItem(new MatchOption()
.field(MatchOption.FieldEnum.FROM)
.should(MatchOption.ShouldEnum.EQUAL)
.value(inbox1.getEmailAddress()))
.addMatchesItem(new MatchOption()
.field(MatchOption.FieldEnum.SUBJECT)
.should(MatchOption.ShouldEnum.CONTAIN)
.value("Verification code")));
assertEquals(verificationEmail.size(), 1);
//</gen>
InboxDto inbox3 = inboxControllerApi.createInboxWithDefaults();
//<gen>java_demo_extract
inboxControllerApi.sendEmail(inbox1.getId(), new SendEmailOptions()
.to(singletonList(inbox3.getEmailAddress()))
.subject("HTML notification")
.body("<div><p>Use xpath selectors to <em class='needle'>find</em> content.</p></div>"));
Email emailWithHtml = waitForControllerApi.waitForLatestEmail(inbox3.getId(), TIMEOUT_MILLIS.longValue(), UNREAD_ONLY, null, null, null, null);
// extract content from email body
EmailTextLinesResult emailHTMLQuery = new EmailControllerApi(defaultClient).getEmailHTMLQuery(emailWithHtml.getId(), ".needle");
assertEquals(emailHTMLQuery.getLines().get(0), "find");
//</gen>
}
}
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
PK
A META-INF/ PK
A m�>=@ ? META-INF/MANIFEST.MF�M��LK-.�
K-*��ϳR0�3����-�I�M�+I,
�d��Z)�%��*�%��r�r PK
A org/ PK
A org/gradle/ PK
A org/gradle/wrapper/ PK
A Pr��� - * org/gradle/wrapper/GradleWrapperMain.class�Xx�����բr��"�E;�"L1X�! $| @D� ����n��%N�t��F��'q
N����Nwz��齓�8�g�t�� }�>4����+�{���>��e k�"�T��R���rx����y*J$��Wp����B?^$ /V��ԏs~�L��UTI�*�B.�Rūp^��U�qɯQ�Z�N��[����*���я7��foQ�Vux��Z�]�;T,���;��ǻT��n�����rx����������U|��0R*F1��"R0��#*6ᒊ;pُ+r�G�xX�#��cr��*>�O��S����H�G�H�?�����*��/�����+*v�sw�ki���n�w��kW���==�]����)�1�LJ�m+j��j�����Ѥ!,������no�ȩN����l��P�P6�l��#���P�~_�9@m�H�؝�3��XԐF��zt�nE�<M��Ñ����i
5Y�@�h<m�##�ոÙpg��H�N�b��:T貣]��(��cY@MKީ[�.G�l��\-�L.�#!)�e�v[��%#��0�Q�mg4��j�bz|@:��ᡠ�~3~���
���&l#�'�*K@��6�P�;��y�t�d�#{e"O,!r�Kڑh�$]���ꥱf�~�D͡!i��(��E�HS���I�$�/��\��3��뎂�18��@>D*�mpn�rg2ⵡ<Z~\�Җe+����LOid&5��ػ��k�(-�!v������c� fe�n�5�'m��v3h�,��ݶ�b�>�$����
M�S�Nk��b�v�I��p�|N�A[-2<D����QSа��[C���`F�:��o����d�N`(�Z鲭JR�a氆o��
����yN
�LF[`��q�4|?��C�H��5��1�&��CO3�~��)���_��"x����pOW�+
��o�{��)�r4�S�.���k$���Ep��n�$F�YcI������=���h%lN$^L8ס?��Zv�%w��ɺ'��I��5���7ܿ㪆�*����k�@YΖ�_r߿<��?xB�5:$1CE§�bM�p��9ADj2'�%�v$fd)_�5Q*��
�xM��L`K���vp���1�0�/���
�V0�I�?8h��`?{�1=a�/M,_���]ǎ��&41S�+WD�&*E�"��S���\�pU�51G�eF�y����|I\ �"j�y(�΅���:��Ѳ��45O��O�y�&ŒP�t�S���ѳ�^GDW��M���-�P2f���L�ȕ�s02����Kj\�3��;�y��x�άmNq`�2��v1o�]vS%���M�*gIai�ϛ��R#/ I�EV�@(_1���
�����-�Z��z��y=�0��BS5���U�U^'z��jN1u(���8�D�*�
��U�=�=]���Cd~��`>E卭��Zx��Ǵ0͜�-N7J3s��D��^�����}Q����.oV���Bӊ������JT*&�N�u]��6�6�G��>�&�O0�V�>ۘ��<Qȯ���#�1�-�/�����7�Zk����\,3�N����sK{���6���)/���������#���?l8�y�dR�����nwk�?H�������!�=^����WZ���83O�i�є�!���.Mx��LсB*�������TI��BՖ��Mt$O� �f/���<ӳ�M����~�{]�v�<�¦y"9��N�`�~���'�5cvs6e�we�5��d�+8ߛ5����s�!������
�����˱�!����2� ���R�� ��Y��Qe�=2����1�vq(�=���Q(M�_
�5��K(�+
�u��Zw
3S(�$WHr�$Gw��k����_C
��J�0�I�QH-���Ma^
55\�������¦ҕcXԤ֨
���)���!ō��#�(�b�8�Rֲ�Oz��� t��֣+0+����с5�&b���
0p3�`�D��f�c��c+F��ވ��v'|��^:LDKqG�5����(��������$�1@ԏrn`�1�s�P���w���9�t'(�<m�"ƈ�=&��I:BYE�]LTB}+��h�
��Vd&�(w��@ݮC��P���+�8$��:��!�V�!�_e�J�߅�,geY��("�ђ�+���U�[h�I�Q���'K�܌8>R��#�3��PSX���6�p�m�afx��V��+T�hNa�=�'��[}������{[G�+���"� \��jE�GrSh#n�v"�J��m�"в
� �R5h!R��q+m��d� n�������8�Y5w�f� �k�:˯�L8w�����o�����T��N�JU�M;��dP�(Ka�ݘ�X,';R�f��S�X�t�j1�A�����DWi��Q�C7�fSZM�8vRzU����D�ĕ�� <���PK
A ��.q/ 3 # gradle-wrapper-classpath.properties+(��JM.)�M/JL�I�M��ԁ2ˋ
R�t�3�RS��J�J2sSm� PK
A ) gradle-wrapper-parameter-names.properties PK
A org/gradle/cli/ PK
A ��?�< S 1 org/gradle/cli/AbstractCommandLineConverter.class�T]oA=���"��~C?��R*O��h4!����aY�m`�C��ߢ/4����2��P���a��9{�s���?�PF�@;:v
D�c@���{xY9y�x��\Yc�fs�ڑ߱V�g{m[�x�KH��[�{ʅ�'�&?��b�N��ӵKV�-��)�%��^�{������m!mQaظ������|�j�U��n���l㌟�R�{N�����}f[��C�����-��k��ږ�=,ȍ��ak^���߫�^t��֔���-J��_,�/]���c��t�ˡ�+;X���r��C�uVQCW� u�h�Ca�oܠ������1a�6C���2Qľ�L��K��
&�!9��a{ Q�23Qu�{�'�M���~rՐ���3|i153�mn�Devf���߆J����~-C�H�;"d�9�����edc���Dq�ָSX��`I�w/!)��:�Fy�7���_�|�@�8_A�#��F��VX!�K`���R~�;�x��)�>=�N�Rnp����c�h��⟐��ϔ�4=c/�-e��PK
A ׃��X �
; org/gradle/cli/AbstractPropertiesCommandLineConverter.class�V[WU�N2��0� H��Ԅ��KK�IQJ�������;L�0f���O��Z��Z_�t������A��}N.i�2Y9��}���;�v���O�6�Q0��e|�`�|��`w,�'?��
��H����` �=��
V���>�B��x�����&c��.cC���i���?]c���З1-c���i8��"qB[k�cr�Ɣ�m�e����B��h���Ћfb~��M�V�d8�i��ޞf����'��$
F]�p�䙶�0�fv�}-QԬB"�9�U ёѻ���E#�0�f���f�[��-�Pv�T�4��V5�%\���X3L�X����QgIW����W]�p��0�?���:���ĒVJFO���MA`i
Үq�����A�1\W@
��\�A܊�A)5"ɓ�4����8,��F�h�J+g�^�z��K��a�@7��e<��f͂�y"�߾�;D='���+�;��%��,��W��J�/G�d����L�Xg<�m�x#����x
�*&0.�Ko '�+�A�|g��<ߡ o�(`[��b�*��Sa�����������C���%M�U�4�ܹz��%�LEu|t��g�1qBu�)���k$1����
5����xE;i1g��Yu[s밨��D:2�KZM�u6�?Al��T'�[�'\�L�z ��o�B��E�1]^����.���&�z6�K�Z6<��S+Y�h~�u.�V�8X�b��u���2��i�t�e��d��N�۾��H;�4A��?2/y/���j���~���43�1���ˀ$� ��<�g�yWjFK$���j,��
�t��D��� �� �'R��k���$G �}/a�N�ƫ֪�j�~�����DH���AR����� ?���
�#�0,_;���iq��9|��)�[A�l �q"��0���%�T���q�Զ��9��N����R�7��3�w��o��="\�� �b��j��kD�����Q0����-��#Ku�s�u��Q��Ā�ٿ���c�c�ں) Q��=��[��tx�V �p�2�?�`�'g[��:��YMᶘ��PK
A }��yG K 1 org/gradle/cli/CommandLineArgumentException.class���J1�O�3���Zm+���U�V
"
����i�Ff�̨������$-U�fq�{r�wO�����34K(`˄mu
�����=}�^DE��S�E�=.�T}.�m���Q���/
��&���t��_��G�"�]�8�bl *�b&ҫ�=�\�.��$����rA�^��2�(�d�[�ŀf�&V��2S���o�/c�PF� ��?^E��5�.)���-��/��1ttu��yN�N�3y��+:���ԕ;XէƬJ�k�⠌u�0�ʜu�g���;�S�~��tӾ���0w3�*6��M�]�PK
A ���� g ) org/gradle/cli/CommandLineConverter.class�QMK�@}���ԯ�'�"4
F<6� EQ($xߦ�%��vS��<��Q�6�L
]Xv�;����߯o �8w�upJp�L-�6�~/���S���b�f�%�u<� �*D�<.�id���n$�b&לpW'<(a��R�`�q��Kx��l�r?I�����OF�l��$�j�ήw����vRm_U�%J��������vJQ��?���_��F�%p}�b.�;o���-7ۉZ�3��fSm���i�M�l�g����pl��~Qqk*[9�a��#��PK
A Sf
� g &