-
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.
Merge pull request #8 from estigma88/email-notifications
Sending emails to notify post results
- Loading branch information
Showing
18 changed files
with
176 additions
and
24 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
import com.coderstower.socialmediapubisher.extesion.ITestHandler; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.mail.SimpleMailMessage; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
|
@@ -12,7 +15,7 @@ public class PostNextToLinkedInTest extends MockedEdgesConfig { | |
|
||
@Test | ||
public void publishNextPostSuccessful(WireMockRuntimeInfo wireMockRuntimeInfo, ITestHandler iTestHandler) { | ||
iTestHandler.loadWiremockMocks(wireMockRuntimeInfo, "testcases/post/next/linkedin/wiremock/"); | ||
iTestHandler.loadWiremockMocks(wireMockRuntimeInfo, "testcases/post/next/linkedin/success/wiremock/"); | ||
|
||
var response = given(). | ||
port(port). | ||
|
@@ -23,6 +26,36 @@ public void publishNextPostSuccessful(WireMockRuntimeInfo wireMockRuntimeInfo, I | |
.body() | ||
.asString(); | ||
|
||
iTestHandler.validateJSONResponse("testcases/post/next/linkedin/response.json", response); | ||
iTestHandler.validateJSONResponse("testcases/post/next/linkedin/success/response.json", response); | ||
|
||
SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); | ||
simpleMailMessage.setTo("[email protected]"); | ||
simpleMailMessage.setFrom("[email protected]"); | ||
simpleMailMessage.setSubject("SocialMediaPublisher: Success publishing group group1"); | ||
simpleMailMessage.setText("Post(id=post1, name=Post 1, description=This is a new post 1, tags=[java, code], url=http://coders.com/post1, publishedDate=2020-03-03T05:06:08.000000001, publications=[Publication(id=linkedIn123, status=SUCCESS, publisher=linkedin, credentialId=id132, publishedDate=2020-03-03T05:06:08.000000001)], group=group1)"); | ||
|
||
verify(mailSender).send(simpleMailMessage); | ||
} | ||
|
||
@Test | ||
public void publishNextPostFail(WireMockRuntimeInfo wireMockRuntimeInfo, ITestHandler iTestHandler) { | ||
iTestHandler.loadWiremockMocks(wireMockRuntimeInfo, "testcases/post/next/linkedin/failureExpiredCredentials/wiremock/"); | ||
|
||
var response = given(). | ||
port(port). | ||
post("/posts/group1/next"). | ||
then(). | ||
statusCode(401). | ||
extract() | ||
.body() | ||
.asString(); | ||
|
||
SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); | ||
simpleMailMessage.setTo("[email protected]"); | ||
simpleMailMessage.setFrom("[email protected]"); | ||
simpleMailMessage.setSubject("SocialMediaPublisher: Error publishing group group1"); | ||
simpleMailMessage.setText("Unauthorized for linkedin id132. Please login again here: http://localhost:8080/oauth2/linkedin/credentials"); | ||
|
||
verify(mailSender).send(simpleMailMessage); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
.../post/next/linkedin/failureExpiredCredentials/wiremock/mappings/getOauth2Credentials.json
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,44 @@ | ||
{ | ||
"request": { | ||
"method": "POST", | ||
"url": "/", | ||
"headers": { | ||
"X-Amz-Target": { | ||
"equalTo": "DynamoDB_20120810.Scan" | ||
} | ||
}, | ||
"bodyPatterns": [ | ||
{ | ||
"equalToJson": { | ||
"TableName": "Oauth2Credentials" | ||
} | ||
} | ||
] | ||
}, | ||
"response": { | ||
"status": 200, | ||
"jsonBody": { | ||
"Count": 1, | ||
"Items": [ | ||
{ | ||
"id": { | ||
"S": "id132" | ||
}, | ||
"accessToken": { | ||
"S": "accessToken132" | ||
}, | ||
"expirationDate": { | ||
"S": "2019-04-28T16:24:12" | ||
}, | ||
"allowedGroups": { | ||
"L": [ | ||
{ | ||
"S": "group1" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
src/main/java/com/coderstower/socialmediapubisher/application/factory/MailProperties.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,11 @@ | ||
package com.coderstower.socialmediapubisher.application.factory; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class MailProperties { | ||
private final String senderEmail; | ||
private final String receiverEmail; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/coderstower/socialmediapubisher/application/factory/PostProperties.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,11 @@ | ||
package com.coderstower.socialmediapubisher.application.factory; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import org.springframework.web.util.UriTemplate; | ||
|
||
@Data | ||
@Builder | ||
public class PostProperties { | ||
private final MailProperties mail; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,23 @@ spring: | |
profiles: | ||
group: | ||
itest: linkedin | ||
mail: | ||
properties: | ||
"[mail.smtp.auth]": true | ||
"[mail.smtp.starttls.enable]": true | ||
"[mail.smtp.connectiontimeout]": 5000 | ||
"[mail.smtp.timeout]": 3000 | ||
"[mail.smtp.writetimeout]": 5000 | ||
host: smtp.gmail.com | ||
password: xxxxx | ||
username: yyyyy | ||
port: 587 | ||
|
||
social-media-publisher: | ||
post: | ||
mail: | ||
sender-email: [email protected] | ||
receiver-email: [email protected] | ||
linked-in: | ||
base-url: https://api.linkedin.com | ||
credentials: | ||
|