use of com.thoughtworks.go.domain.notificationdata.StageNotificationData in project gocd by gocd.
the class StageStatusPluginNotifierTest method shouldNotifyInterestedPluginsIfStageStateIsScheduled.
@Test
public void shouldNotifyInterestedPluginsIfStageStateIsScheduled() throws Exception {
when(notificationPluginRegistry.isAnyPluginInterestedIn(NotificationExtension.STAGE_STATUS_CHANGE_NOTIFICATION)).thenReturn(true);
when(stage.isScheduled()).thenReturn(true);
when(stage.isReRun()).thenReturn(false);
when(stage.getState()).thenReturn(StageState.Unknown);
String pipelineName = "pipeline-name";
when(stage.getIdentifier()).thenReturn(new StageIdentifier(pipelineName, 1, "stage", "1"));
when(goConfigService.findGroupNameByPipeline(new CaseInsensitiveString(pipelineName))).thenReturn("group1");
when(pipelineSqlMapDao.findBuildCauseOfPipelineByNameAndCounter(pipelineName, stage.getIdentifier().getPipelineCounter())).thenReturn(BuildCause.createManualForced());
stageStatusPluginNotifier.stageStatusChanged(stage);
verify(pluginNotificationQueue).post(captor.capture());
assertThat(captor.getValue().getData() instanceof StageNotificationData, is(true));
StageNotificationData data = (StageNotificationData) captor.getValue().getData();
assertThat(data.getStage(), is(stage));
assertThat(data.getBuildCause(), is(BuildCause.createManualForced()));
assertThat(data.getPipelineGroup(), is("group1"));
}
use of com.thoughtworks.go.domain.notificationdata.StageNotificationData in project gocd by gocd.
the class NotificationExtensionTestBase method shouldTalkToPluginToNotify.
@Test
public void shouldTalkToPluginToNotify() throws Exception {
Result response = new Result();
String notificationName = "notification-name";
String jsonResponse = "json-response";
StageNotificationData stageNotificationData = new StageNotificationData(new Stage(), BuildCause.createWithEmptyModifications(), "group");
when(jsonMessageHandler().requestMessageForNotify(stageNotificationData)).thenReturn(jsonResponse);
when(jsonMessageHandler().responseMessageForNotify(RESPONSE_BODY)).thenReturn(response);
Result deserializedResponse = notificationExtension.notify(PLUGIN_ID, notificationName, stageNotificationData);
assertRequest(requestArgumentCaptor.getValue(), NotificationExtension.EXTENSION_NAME, apiVersion(), notificationName, jsonResponse);
verify(jsonMessageHandler()).responseMessageForNotify(RESPONSE_BODY);
assertSame(response, deserializedResponse);
}
use of com.thoughtworks.go.domain.notificationdata.StageNotificationData in project gocd by gocd.
the class JsonMessageHandler2_0_Test method shouldConstructTheStageNotificationRequest.
@Test
public void shouldConstructTheStageNotificationRequest() throws Exception {
Pipeline pipeline = createPipeline();
String gitModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(0).getLatestModification().getModifiedTime());
String hgModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(1).getLatestModification().getModifiedTime());
String svnModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(2).getLatestModification().getModifiedTime());
String tfsModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(3).getLatestModification().getModifiedTime());
String p4ModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(4).getLatestModification().getModifiedTime());
String dependencyModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(5).getLatestModification().getModifiedTime());
String packageMaterialModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(6).getLatestModification().getModifiedTime());
String pluggableScmModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(7).getLatestModification().getModifiedTime());
String expected = "{\n" + "\t\"pipeline\": {\n" + "\t\t\"name\": \"pipeline-name\",\n" + "\t\t\"label\": \"LABEL-1\",\n" + "\t\t\"counter\": \"1\",\n" + "\t\t\"group\": \"pipeline-group\",\n" + "\t\t\"build-cause\": [{\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"git-configuration\": {\n" + "\t\t\t\t\t\"shallow-clone\": false,\n" + "\t\t\t\t\t\"branch\": \"branch\",\n" + "\t\t\t\t\t\"url\": \"http://user:******@gitrepo.com\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"git\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + gitModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"type\": \"mercurial\",\n" + "\t\t\t\t\"mercurial-configuration\": {\n" + "\t\t\t\t\t\"url\": \"http://user:******@hgrepo.com\"\n" + "\t\t\t\t}\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + hgModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"svn-configuration\": {\n" + "\t\t\t\t\t\"check-externals\": false,\n" + "\t\t\t\t\t\"url\": \"http://user:******@svnrepo.com\",\n" + "\t\t\t\t\t\"username\": \"username\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"svn\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + svnModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"type\": \"tfs\",\n" + "\t\t\t\t\"tfs-configuration\": {\n" + "\t\t\t\t\t\"domain\": \"domain\",\n" + "\t\t\t\t\t\"project-path\": \"project-path\",\n" + "\t\t\t\t\t\"url\": \"http://user:******@tfsrepo.com\",\n" + "\t\t\t\t\t\"username\": \"username\"\n" + "\t\t\t\t}\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + tfsModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"perforce-configuration\": {\n" + "\t\t\t\t\t\"view\": \"view\",\n" + "\t\t\t\t\t\"use-tickets\": false,\n" + "\t\t\t\t\t\"url\": \"127.0.0.1:1666\",\n" + "\t\t\t\t\t\"username\": \"username\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"perforce\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + p4ModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"pipeline-configuration\": {\n" + "\t\t\t\t\t\"pipeline-name\": \"pipeline-name\",\n" + "\t\t\t\t\t\"stage-name\": \"stage-name\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"pipeline\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"pipeline-name/1/stage-name/1\",\n" + "\t\t\t\t\"modified-time\": \"" + dependencyModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"plugin-id\": \"pluginid\",\n" + "\t\t\t\t\"package-configuration\": {\n" + "\t\t\t\t\t\"k3\": \"package-v1\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"repository-configuration\": {\n" + "\t\t\t\t\t\"k1\": \"repo-v1\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"package\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + packageMaterialModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"plugin-id\": \"pluginid\",\n" + "\t\t\t\t\"scm-configuration\": {\n" + "\t\t\t\t\t\"k1\": \"v1\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"scm\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + pluggableScmModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}],\n" + "\t\t\"stage\": {\n" + "\t\t\t\"name\": \"stage-name\",\n" + "\t\t\t\"counter\": \"1\",\n" + "\t\t\t\"approval-type\": \"success\",\n" + "\t\t\t\"approved-by\": \"changes\",\n" + "\t\t\t\"state\": \"Passed\",\n" + "\t\t\t\"result\": \"Passed\",\n" + "\t\t\t\"create-time\": \"2011-07-13T19:43:37.100Z\",\n" + "\t\t\t\"last-transition-time\": \"2011-07-13T19:43:37.100Z\",\n" + "\t\t\t\"jobs\": [{\n" + "\t\t\t\t\"name\": \"job-name\",\n" + "\t\t\t\t\"schedule-time\": \"2011-07-13T19:43:37.100Z\",\n" + "\t\t\t\t\"assign-time\": \"2011-07-13T19:43:37.100Z\",\n" + "\t\t\t\t\"complete-time\": \"2011-07-13T19:43:37.100Z\",\n" + "\t\t\t\t\"state\": \"Completed\",\n" + "\t\t\t\t\"result\": \"Passed\",\n" + "\t\t\t\t\"agent-uuid\": \"uuid\"\n" + "\t\t\t}]\n" + "\t\t}\n" + "\t}\n" + "}";
String request = messageHandler.requestMessageForNotify(new StageNotificationData(pipeline.getFirstStage(), pipeline.getBuildCause(), "pipeline-group"));
JSONAssert.assertEquals(expected, request, JSONCompareMode.NON_EXTENSIBLE);
}
use of com.thoughtworks.go.domain.notificationdata.StageNotificationData in project gocd by gocd.
the class StageStatusPluginNotifier method stageStatusChanged.
@Override
public void stageStatusChanged(final Stage stage) {
if (isAnyPluginInterestedInStageStatus() && isStageStateScheduledOrCompleted(stage)) {
String pipelineName = stage.getIdentifier().getPipelineName();
String pipelineGroup = goConfigService.findGroupNameByPipeline(new CaseInsensitiveString(pipelineName));
BuildCause buildCause = pipelineSqlMapDao.findBuildCauseOfPipelineByNameAndCounter(pipelineName, stage.getIdentifier().getPipelineCounter());
StageNotificationData data = new StageNotificationData(stage, buildCause, pipelineGroup);
pluginNotificationQueue.post(new PluginNotificationMessage<>(NotificationExtension.STAGE_STATUS_CHANGE_NOTIFICATION, data));
}
}
use of com.thoughtworks.go.domain.notificationdata.StageNotificationData in project gocd by gocd.
the class JsonMessageHandler1_0_Test method shouldConstructTheStageNotificationRequest.
@Test
public void shouldConstructTheStageNotificationRequest() throws Exception {
Pipeline pipeline = createPipeline();
String gitModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(0).getLatestModification().getModifiedTime());
String hgModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(1).getLatestModification().getModifiedTime());
String svnModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(2).getLatestModification().getModifiedTime());
String tfsModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(3).getLatestModification().getModifiedTime());
String p4ModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(4).getLatestModification().getModifiedTime());
String dependencyModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(5).getLatestModification().getModifiedTime());
String packageMaterialModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(6).getLatestModification().getModifiedTime());
String pluggableScmModifiedTime = new SimpleDateFormat(DATE_PATTERN).format(pipeline.getBuildCause().getMaterialRevisions().getMaterialRevision(7).getLatestModification().getModifiedTime());
String expected = "{\n" + "\t\"pipeline\": {\n" + "\t\t\"name\": \"pipeline-name\",\n" + "\t\t\"counter\": \"1\",\n" + "\t\t\"group\": \"pipeline-group\",\n" + "\t\t\"build-cause\": [{\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"git-configuration\": {\n" + "\t\t\t\t\t\"shallow-clone\": false,\n" + "\t\t\t\t\t\"branch\": \"branch\",\n" + "\t\t\t\t\t\"url\": \"http://user:******@gitrepo.com\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"git\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + gitModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"type\": \"mercurial\",\n" + "\t\t\t\t\"mercurial-configuration\": {\n" + "\t\t\t\t\t\"url\": \"http://user:******@hgrepo.com\"\n" + "\t\t\t\t}\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + hgModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"svn-configuration\": {\n" + "\t\t\t\t\t\"check-externals\": false,\n" + "\t\t\t\t\t\"url\": \"http://user:******@svnrepo.com\",\n" + "\t\t\t\t\t\"username\": \"username\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"svn\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + svnModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"type\": \"tfs\",\n" + "\t\t\t\t\"tfs-configuration\": {\n" + "\t\t\t\t\t\"domain\": \"domain\",\n" + "\t\t\t\t\t\"project-path\": \"project-path\",\n" + "\t\t\t\t\t\"url\": \"http://user:******@tfsrepo.com\",\n" + "\t\t\t\t\t\"username\": \"username\"\n" + "\t\t\t\t}\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + tfsModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"perforce-configuration\": {\n" + "\t\t\t\t\t\"view\": \"view\",\n" + "\t\t\t\t\t\"use-tickets\": false,\n" + "\t\t\t\t\t\"url\": \"127.0.0.1:1666\",\n" + "\t\t\t\t\t\"username\": \"username\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"perforce\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + p4ModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"pipeline-configuration\": {\n" + "\t\t\t\t\t\"pipeline-name\": \"pipeline-name\",\n" + "\t\t\t\t\t\"stage-name\": \"stage-name\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"pipeline\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"pipeline-name/1/stage-name/1\",\n" + "\t\t\t\t\"modified-time\": \"" + dependencyModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"plugin-id\": \"pluginid\",\n" + "\t\t\t\t\"package-configuration\": {\n" + "\t\t\t\t\t\"k3\": \"package-v1\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"repository-configuration\": {\n" + "\t\t\t\t\t\"k1\": \"repo-v1\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"package\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + packageMaterialModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}, {\n" + "\t\t\t\"material\": {\n" + "\t\t\t\t\"plugin-id\": \"pluginid\",\n" + "\t\t\t\t\"scm-configuration\": {\n" + "\t\t\t\t\t\"k1\": \"v1\"\n" + "\t\t\t\t},\n" + "\t\t\t\t\"type\": \"scm\"\n" + "\t\t\t},\n" + "\t\t\t\"changed\": true,\n" + "\t\t\t\"modifications\": [{\n" + "\t\t\t\t\"revision\": \"1\",\n" + "\t\t\t\t\"modified-time\": \"" + pluggableScmModifiedTime + "\",\n" + "\t\t\t\t\"data\": {}\n" + "\t\t\t}]\n" + "\t\t}],\n" + "\t\t\"stage\": {\n" + "\t\t\t\"name\": \"stage-name\",\n" + "\t\t\t\"counter\": \"1\",\n" + "\t\t\t\"approval-type\": \"success\",\n" + "\t\t\t\"approved-by\": \"changes\",\n" + "\t\t\t\"state\": \"Passed\",\n" + "\t\t\t\"result\": \"Passed\",\n" + "\t\t\t\"create-time\": \"2011-07-13T19:43:37.100Z\",\n" + "\t\t\t\"last-transition-time\": \"2011-07-13T19:43:37.100Z\",\n" + "\t\t\t\"jobs\": [{\n" + "\t\t\t\t\"name\": \"job-name\",\n" + "\t\t\t\t\"schedule-time\": \"2011-07-13T19:43:37.100Z\",\n" + "\t\t\t\t\"complete-time\": \"2011-07-13T19:43:37.100Z\",\n" + "\t\t\t\t\"state\": \"Completed\",\n" + "\t\t\t\t\"result\": \"Passed\",\n" + "\t\t\t\t\"agent-uuid\": \"uuid\"\n" + "\t\t\t}]\n" + "\t\t}\n" + "\t}\n" + "}";
String request = messageHandler.requestMessageForNotify(new StageNotificationData(pipeline.getFirstStage(), pipeline.getBuildCause(), "pipeline-group"));
JSONAssert.assertEquals(expected, request, JSONCompareMode.NON_EXTENSIBLE);
}
Aggregations