-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from sinch/DEVEXP-648-support-additional-prop…
…erties-serialization feat (Java): Support 'AdditionalProperty' interface for form parameters serialization
- Loading branch information
Showing
22 changed files
with
705 additions
and
227 deletions.
There are no files selected for viewing
5 changes: 3 additions & 2 deletions
5
...nt/src/main/com/sinch/sdk/domains/mailgun/api/v1/adapters/DeliveryTimeFormSerializer.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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package com.sinch.sdk.domains.mailgun.api.v1.adapters; | ||
|
||
import com.sinch.sdk.core.databind.FormSerializer; | ||
import java.util.Map; | ||
|
||
public class DeliveryTimeFormSerializer extends FormSerializer<Integer> { | ||
|
||
@Override | ||
public String serialize(Integer in) { | ||
return String.format("%dh", in); | ||
public void serialize(Integer in, String fieldName, Map<String, Object> out) { | ||
out.put(fieldName, String.format("%dh", in)); | ||
} | ||
} |
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
103 changes: 103 additions & 0 deletions
103
client/src/test/java/com/sinch/sdk/domains/mailgun/api/v1/adapters/EmailsServiceTest.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,103 @@ | ||
package com.sinch.sdk.domains.mailgun.api.v1.adapters; | ||
|
||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.adelean.inject.resources.junit.jupiter.TestWithResources; | ||
import com.sinch.sdk.BaseTest; | ||
import com.sinch.sdk.core.TestHelpers; | ||
import com.sinch.sdk.core.http.AuthManager; | ||
import com.sinch.sdk.core.http.HttpClient; | ||
import com.sinch.sdk.domains.mailgun.api.v1.internal.EmailsApi; | ||
import com.sinch.sdk.domains.mailgun.models.v1.emails.request.SendEmailRequestTest; | ||
import com.sinch.sdk.domains.mailgun.models.v1.emails.request.SendMimeEmailRequestTest; | ||
import com.sinch.sdk.domains.mailgun.models.v1.emails.response.GetStoredEmailResponse; | ||
import com.sinch.sdk.domains.mailgun.models.v1.emails.response.GetStoredEmailResponseTest; | ||
import com.sinch.sdk.domains.mailgun.models.v1.emails.response.SendEmailResponse; | ||
import com.sinch.sdk.domains.mailgun.models.v1.emails.response.SendEmailResponseTest; | ||
import com.sinch.sdk.domains.mailgun.models.v1.emails.response.SendingQueuesStatusResponse; | ||
import com.sinch.sdk.domains.mailgun.models.v1.emails.response.SendingQueuesStatusResponseTest; | ||
import com.sinch.sdk.models.MailgunContext; | ||
import java.util.Map; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Captor; | ||
import org.mockito.Mock; | ||
|
||
@TestWithResources | ||
class EmailsServiceTest extends BaseTest { | ||
|
||
@Mock MailgunContext context; | ||
@Mock EmailsApi api; | ||
@Mock HttpClient httpClient; | ||
@Mock Map<String, AuthManager> authManagers; | ||
@Captor ArgumentCaptor<String> domainNameCaptor; | ||
|
||
EmailsService service; | ||
|
||
String domainName = "fooDomain"; | ||
String storageKey = "fooStorageKey"; | ||
|
||
@BeforeEach | ||
public void initMocks() { | ||
service = spy(new EmailsService(context, httpClient, authManagers)); | ||
doReturn(api).when(service).getApi(); | ||
} | ||
|
||
@Test | ||
void send() { | ||
when(api.sendEmail(eq(domainName), eq(SendEmailRequestTest.sendEmailRequest))) | ||
.thenReturn(SendEmailResponseTest.expectedSendEmailResponse); | ||
|
||
SendEmailResponse response = service.send(domainName, SendEmailRequestTest.sendEmailRequest); | ||
|
||
TestHelpers.recursiveEquals(response, SendEmailResponseTest.expectedSendEmailResponse); | ||
} | ||
|
||
@Test | ||
void sendMime() { | ||
when(api.sendMimeEmail(eq(domainName), eq(SendMimeEmailRequestTest.sendMimEmailRequest))) | ||
.thenReturn(SendEmailResponseTest.expectedSendEmailResponse); | ||
|
||
SendEmailResponse response = | ||
service.sendMime(domainName, SendMimeEmailRequestTest.sendMimEmailRequest); | ||
|
||
TestHelpers.recursiveEquals(response, SendEmailResponseTest.expectedSendEmailResponse); | ||
} | ||
|
||
@Test | ||
void get() { | ||
when(api.getStoredEmail(eq(domainName), eq(storageKey))) | ||
.thenReturn(GetStoredEmailResponseTest.expectedGetEmailResponse); | ||
|
||
GetStoredEmailResponse response = service.get(domainName, storageKey); | ||
|
||
TestHelpers.recursiveEquals(response, GetStoredEmailResponseTest.expectedGetEmailResponse); | ||
} | ||
|
||
@Test | ||
void getSendingQueuesStatus() { | ||
when(api.getSendingQueuesStatus(eq(domainName))) | ||
.thenReturn(SendingQueuesStatusResponseTest.expectedSendingQueuesStatusResponse); | ||
|
||
SendingQueuesStatusResponse response = service.getSendingQueuesStatus(domainName); | ||
|
||
TestHelpers.recursiveEquals( | ||
response, SendingQueuesStatusResponseTest.expectedSendingQueuesStatusResponse); | ||
} | ||
|
||
@Test | ||
void purgeDomainQueues() { | ||
|
||
service.purgeDomainQueues(domainName); | ||
|
||
verify(api).purgeDomainQueues(domainNameCaptor.capture()); | ||
|
||
Assertions.assertThat(domainNameCaptor.getValue()).isEqualTo(domainName); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
client/src/test/java/com/sinch/sdk/domains/mailgun/api/v1/adapters/MailgunServiceTest.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,62 @@ | ||
package com.sinch.sdk.domains.mailgun.api.v1.adapters; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.sinch.sdk.core.http.HttpClient; | ||
import com.sinch.sdk.models.MailgunContext; | ||
import com.sinch.sdk.models.MailgunCredentials; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
|
||
class MailgunServiceTest { | ||
@Mock HttpClient httpClient; | ||
|
||
@Test | ||
void doNotAcceptNullKey() { | ||
MailgunCredentials credentials = MailgunCredentials.builder().setApiKey(null).build(); | ||
MailgunContext context = MailgunContext.builder().build(); | ||
Exception exception = | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> new MailgunService(credentials, context, httpClient)); | ||
assertTrue(exception.getMessage().contains("apiKey")); | ||
} | ||
|
||
@Test | ||
void doNotAcceptNullContext() { | ||
MailgunCredentials credentials = MailgunCredentials.builder().setApiKey("foo").build(); | ||
Exception exception = | ||
assertThrows( | ||
NullPointerException.class, () -> new MailgunService(credentials, null, httpClient)); | ||
assertTrue(exception.getMessage().contains("Mailgun service requires context to be defined")); | ||
} | ||
|
||
@Test | ||
void doNotAcceptEmptyURL() { | ||
MailgunCredentials credentials = MailgunCredentials.builder().setApiKey("foo").build(); | ||
MailgunContext context = MailgunContext.builder().setUrl("").build(); | ||
Exception exception = | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> new MailgunService(credentials, context, httpClient)); | ||
assertTrue(exception.getMessage().contains("Mailgun service requires 'url' to be defined")); | ||
} | ||
|
||
@Test | ||
void doNotAcceptNullURL() { | ||
MailgunCredentials credentials = MailgunCredentials.builder().setApiKey("foo").build(); | ||
MailgunContext context = MailgunContext.builder().build(); | ||
Exception exception = | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> new MailgunService(credentials, context, httpClient)); | ||
assertTrue(exception.getMessage().contains("Mailgun service requires 'url' to be defined")); | ||
} | ||
|
||
@Test | ||
void passInit() { | ||
MailgunCredentials credentials = MailgunCredentials.builder().setApiKey("foo").build(); | ||
MailgunContext context = MailgunContext.builder().setUrl("foo").build(); | ||
assertDoesNotThrow(() -> new MailgunService(credentials, context, httpClient), "Init passed"); | ||
} | ||
} |
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.