Search in sources :

Example 1 with Change

use of com.amazonaws.services.cloudformation.model.Change in project pipeline-aws-plugin by jenkinsci.

the class CFNCreateChangeSetTests method createChangeSetStackParametersFromMap.

@Test
public void createChangeSetStackParametersFromMap() throws Exception {
    WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(this.stack.exists()).thenReturn(true);
    Mockito.when(this.stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult().withChanges(new Change()).withStatus(ChangeSetStatus.CREATE_COMPLETE));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  def changes = cfnCreateChangeSet(stack: 'foo', changeSet: 'bar', params: ['foo': 'bar', 'baz': 'true'])\n" + "  echo \"changesCount=${changes.size()}\"\n" + "}\n", true));
    Run run = this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    this.jenkinsRule.assertLogContains("changesCount=1", run);
    PowerMockito.verifyNew(CloudFormationStack.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
    Mockito.verify(this.stack).createChangeSet(Mockito.eq("bar"), Mockito.anyString(), Mockito.anyString(), Mockito.eq(Arrays.asList(new Parameter().withParameterKey("foo").withParameterValue("bar"), new Parameter().withParameterKey("baz").withParameterValue("true"))), Mockito.anyCollectionOf(Tag.class), Mockito.anyCollectionOf(String.class), Mockito.any(PollConfiguration.class), Mockito.eq(ChangeSetType.UPDATE), Mockito.anyString(), Mockito.any());
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TaskListener(hudson.model.TaskListener) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Run(hudson.model.Run) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) Change(com.amazonaws.services.cloudformation.model.Change) Tag(com.amazonaws.services.cloudformation.model.Tag) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with Change

use of com.amazonaws.services.cloudformation.model.Change in project pipeline-aws-plugin by jenkinsci.

the class CFNCreateChangeSetTests method createChangeSetWithRawTemplate.

@Test
public void createChangeSetWithRawTemplate() throws Exception {
    WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(this.stack.exists()).thenReturn(true);
    Mockito.when(this.stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult().withChanges(new Change()).withStatus(ChangeSetStatus.CREATE_COMPLETE));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  def changes = cfnCreateChangeSet(stack: 'foo', changeSet: 'bar', template: 'foobaz')\n" + "  echo \"changesCount=${changes.size()}\"\n" + "}\n", true));
    Run run = this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    this.jenkinsRule.assertLogContains("changesCount=1", run);
    PowerMockito.verifyNew(CloudFormationStack.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
    Mockito.verify(this.stack).createChangeSet(Mockito.eq("bar"), Mockito.eq("foobaz"), Mockito.anyString(), Mockito.anyCollectionOf(Parameter.class), Mockito.anyCollectionOf(Tag.class), Mockito.anyCollectionOf(String.class), Mockito.any(PollConfiguration.class), Mockito.eq(ChangeSetType.UPDATE), Mockito.anyString(), Mockito.any());
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TaskListener(hudson.model.TaskListener) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Run(hudson.model.Run) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) Change(com.amazonaws.services.cloudformation.model.Change) Tag(com.amazonaws.services.cloudformation.model.Tag) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with Change

use of com.amazonaws.services.cloudformation.model.Change in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method describeChangeSet.

@Test
public void describeChangeSet() {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    Mockito.when(taskListener.getLogger()).thenReturn(System.out);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    DescribeChangeSetResult expected = new DescribeChangeSetResult().withChanges(new Change());
    Mockito.when(client.describeChangeSet(Mockito.any(DescribeChangeSetRequest.class))).thenReturn(expected);
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    DescribeChangeSetResult result = stack.describeChangeSet("bar");
    Assertions.assertThat(result).isSameAs(expected);
    ArgumentCaptor<DescribeChangeSetRequest> captor = ArgumentCaptor.forClass(DescribeChangeSetRequest.class);
    Mockito.verify(client).describeChangeSet(captor.capture());
    Assertions.assertThat(captor.getValue()).isEqualTo(new DescribeChangeSetRequest().withStackName("foo").withChangeSetName("bar"));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeChangeSetRequest(com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest) TaskListener(hudson.model.TaskListener) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) Change(com.amazonaws.services.cloudformation.model.Change) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with Change

use of com.amazonaws.services.cloudformation.model.Change in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method executeChangeSetWithChanges.

@Test
public void executeChangeSetWithChanges() throws ExecutionException {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    Mockito.when(taskListener.getLogger()).thenReturn(System.out);
    Mockito.when(taskListener.getLogger()).thenReturn(System.out);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client));
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    Mockito.when(client.describeChangeSet(new DescribeChangeSetRequest().withStackName("foo").withChangeSetName("bar"))).thenReturn(new DescribeChangeSetResult().withChanges(new Change()));
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatus("CREATE_COMPLETE").withOutputs(new Output().withOutputKey("bar").withOutputValue("baz"))));
    Map<String, String> outputs = stack.executeChangeSet("bar", PollConfiguration.DEFAULT);
    Mockito.verify(client).executeChangeSet(Mockito.any(ExecuteChangeSetRequest.class));
    Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT));
    Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true");
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) ExecuteChangeSetRequest(com.amazonaws.services.cloudformation.model.ExecuteChangeSetRequest) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) Change(com.amazonaws.services.cloudformation.model.Change) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Stack(com.amazonaws.services.cloudformation.model.Stack) DescribeChangeSetRequest(com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest) Output(com.amazonaws.services.cloudformation.model.Output) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Waiter(com.amazonaws.waiters.Waiter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with Change

use of com.amazonaws.services.cloudformation.model.Change in project pipeline-aws-plugin by jenkinsci.

the class CFNCreateChangeSetTests method createChangeSetStackExists.

@Test
public void createChangeSetStackExists() throws Exception {
    WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(this.stack.exists()).thenReturn(true);
    Mockito.when(this.stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult().withChanges(new Change()).withStatus(ChangeSetStatus.CREATE_COMPLETE));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  def changes = cfnCreateChangeSet(stack: 'foo', changeSet: 'bar')\n" + "  echo \"changesCount=${changes.size()}\"\n" + "}\n", true));
    Run run = this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    this.jenkinsRule.assertLogContains("changesCount=1", run);
    PowerMockito.verifyNew(CloudFormationStack.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
    Mockito.verify(this.stack).createChangeSet(Mockito.eq("bar"), Mockito.anyString(), Mockito.anyString(), Mockito.anyCollectionOf(Parameter.class), Mockito.anyCollectionOf(Tag.class), Mockito.anyCollectionOf(String.class), Mockito.any(PollConfiguration.class), Mockito.eq(ChangeSetType.UPDATE), Mockito.anyString(), Mockito.any());
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TaskListener(hudson.model.TaskListener) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Run(hudson.model.Run) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) Change(com.amazonaws.services.cloudformation.model.Change) Tag(com.amazonaws.services.cloudformation.model.Tag) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)8 Change (com.amazonaws.services.cloudformation.model.Change)8 DescribeChangeSetResult (com.amazonaws.services.cloudformation.model.DescribeChangeSetResult)8 TaskListener (hudson.model.TaskListener)8 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Parameter (com.amazonaws.services.cloudformation.model.Parameter)5 Tag (com.amazonaws.services.cloudformation.model.Tag)5 Run (hudson.model.Run)5 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)5 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)5 DescribeChangeSetRequest (com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest)3 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)1 DescribeStacksResult (com.amazonaws.services.cloudformation.model.DescribeStacksResult)1 ExecuteChangeSetRequest (com.amazonaws.services.cloudformation.model.ExecuteChangeSetRequest)1 Output (com.amazonaws.services.cloudformation.model.Output)1 Stack (com.amazonaws.services.cloudformation.model.Stack)1 AmazonCloudFormationWaiters (com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters)1 Waiter (com.amazonaws.waiters.Waiter)1