-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added two integration tests to have some coverage
- Loading branch information
1 parent
5bcc080
commit d53d6c5
Showing
4 changed files
with
225 additions
and
2 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
117 changes: 117 additions & 0 deletions
117
src/test/java/jenkins/plugins/office365connector/workflow/AdaptiveCardIT.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,117 @@ | ||
package jenkins.plugins.office365connector.workflow; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.*; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.Job; | ||
import hudson.model.Result; | ||
import hudson.scm.ChangeLogSet; | ||
import jenkins.model.Jenkins; | ||
import jenkins.plugins.office365connector.FileUtils; | ||
import jenkins.plugins.office365connector.Office365ConnectorWebhookNotifier; | ||
import jenkins.plugins.office365connector.Webhook; | ||
import jenkins.plugins.office365connector.helpers.AffectedFileBuilder; | ||
import jenkins.plugins.office365connector.helpers.ClassicDisplayURLProviderBuilder; | ||
import jenkins.plugins.office365connector.helpers.WebhookBuilder; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.MockedStatic; | ||
|
||
/** | ||
* @author Markus Helbig (markush81@github) | ||
*/ | ||
public class AdaptiveCardIT extends AbstractTest { | ||
|
||
private static final String JOB_NAME = "myFirst_Job_"; | ||
private static final String CAUSE_DESCRIPTION = "Started by John"; | ||
private static final int BUILD_NUMBER = 167; | ||
private static final String DEVELOPER = "Mike"; | ||
|
||
private MockedStatic<Jenkins> staticJenkins; | ||
|
||
@Before | ||
public void setUp() { | ||
staticJenkins = mockStatic(Jenkins.class); | ||
Jenkins jenkins = mock(Jenkins.class); | ||
mockListener(); | ||
|
||
run = mockRun(); | ||
mockCause(CAUSE_DESCRIPTION); | ||
|
||
mockDisplayURLProvider(JOB_NAME, BUILD_NUMBER); | ||
mockEnvironment(); | ||
mockHttpWorker(); | ||
mockGetChangeSets(); | ||
|
||
staticJenkins.when(Jenkins::get).thenReturn(jenkins); | ||
|
||
Webhook.DescriptorImpl mockDescriptor = mock(Webhook.DescriptorImpl.class); | ||
when(mockDescriptor.getName()).thenReturn("testName"); | ||
|
||
when(jenkins.getDescriptorOrDie(Webhook.class)).thenReturn(mockDescriptor); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
staticJenkins.close(); | ||
} | ||
|
||
private AbstractBuild mockRun() { | ||
AbstractBuild run = mock(AbstractBuild.class); | ||
|
||
when(run.getNumber()).thenReturn(BUILD_NUMBER); | ||
|
||
Job job = mockJob(JOB_NAME); | ||
when(run.getParent()).thenReturn(job); | ||
|
||
mockProperty(job, WebhookBuilder.sampleWebhookWithAllStatusesAdaptiveCard()); | ||
|
||
return run; | ||
} | ||
|
||
private void mockGetChangeSets() { | ||
List<ChangeLogSet> files = new AffectedFileBuilder().singleChangeLog(run, DEVELOPER); | ||
when(run.getChangeSets()).thenReturn(files); | ||
} | ||
|
||
|
||
@Test | ||
public void testAdaptiveCardStarted() { | ||
|
||
// given | ||
when(run.getResult()).thenReturn(Result.SUCCESS); | ||
Office365ConnectorWebhookNotifier notifier = new Office365ConnectorWebhookNotifier(run, mockListener()); | ||
|
||
// when | ||
notifier.sendBuildCompletedNotification(); | ||
|
||
// then | ||
assertHasSameContent(workerData.get(0), FileUtils.getContentFile("adaptivecard_success.json")); | ||
assertEquals(1, workerConstruction.constructed().size()); | ||
} | ||
|
||
@Test | ||
public void testAdaptiveCardStep() { | ||
|
||
// given | ||
StepParameters stepParameters = new StepParameters( | ||
"helloMessage", ClassicDisplayURLProviderBuilder.LOCALHOST_URL_TEMPLATE, | ||
"funnyStatus", Collections.emptyList(), "#FF00FF", false); | ||
|
||
when(run.getResult()).thenReturn(Result.FAILURE); | ||
Office365ConnectorWebhookNotifier notifier = new Office365ConnectorWebhookNotifier(run, mockListener()); | ||
|
||
// when | ||
notifier.sendBuildStepNotification(stepParameters); | ||
|
||
// then | ||
assertHasSameContent(workerData.get(0), FileUtils.getContentFile("adaptivecard_step.json")); | ||
assertEquals(1, workerConstruction.constructed().size()); | ||
} | ||
} |
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,27 @@ | ||
{ | ||
"summary": "myFirst_Job_: Build #167", | ||
"themeColor": "#FF00FF", | ||
"sections": [ | ||
{ | ||
"markdown": true, | ||
"facts": [ | ||
{ | ||
"name": "Status", | ||
"value": "funnyStatus" | ||
} | ||
], | ||
"activityTitle": "Notification from myFirst\\_Job\\_", | ||
"activitySubtitle": "helloMessage" | ||
} | ||
], | ||
"potentialAction": [ | ||
{ | ||
"@context": "http://schema.org", | ||
"@type": "ViewAction", | ||
"name": "View Build", | ||
"target": [ | ||
"http://localhost/job/myFirst_Job_/167/display/redirect" | ||
] | ||
} | ||
] | ||
} |
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,70 @@ | ||
{ | ||
"type": "message", | ||
"attachments": [ | ||
{ | ||
"contentType": "application/vnd.microsoft.card.adaptive", | ||
"content": { | ||
"type": "AdaptiveCard", | ||
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json", | ||
"version": "1.4", | ||
"msTeams": { | ||
"width": "Full" | ||
}, | ||
"body": [ | ||
{ | ||
"text": "myFirst_Job_: Build #167 Success", | ||
"weight": "bolder", | ||
"size": "large", | ||
"color": "good", | ||
"type": "TextBlock", | ||
"wrap": true | ||
}, | ||
{ | ||
"type": "ColumnSet", | ||
"columns": [ | ||
{ | ||
"type": "Column", | ||
"items": [ | ||
{ | ||
"text": "Notification from myFirst\\_Job\\_: Build Success", | ||
"weight": "bolder", | ||
"size": "default", | ||
"color": "default", | ||
"type": "TextBlock", | ||
"wrap": true | ||
}, | ||
{ | ||
"text": "Latest status of build #167", | ||
"weight": "default", | ||
"size": "default", | ||
"color": "default", | ||
"type": "TextBlock", | ||
"wrap": true | ||
} | ||
] | ||
} | ||
], | ||
"witdth": "stretch" | ||
}, | ||
{ | ||
"facts": [ | ||
{ | ||
"title": "Status", | ||
"value": "Build Success" | ||
}, | ||
{ | ||
"title": "Remarks", | ||
"value": "Started by John." | ||
}, | ||
{ | ||
"title": "Developers", | ||
"value": "Mike" | ||
} | ||
], | ||
"type": "FactSet" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |