Search in sources :

Example 6 with Change

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

the class CFNCreateChangeSetTests method createChangeSetStackDoesNotExist.

@Test
public void createChangeSetStackDoesNotExist() throws Exception {
    WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(this.stack.exists()).thenReturn(false);
    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.CREATE), 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 7 with Change

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

the class CloudformationStackTests method changeSetExists.

@Test
public void changeSetExists() {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    Mockito.when(taskListener.getLogger()).thenReturn(System.out);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    Mockito.when(client.describeChangeSet(new DescribeChangeSetRequest().withStackName("foo").withChangeSetName("bar"))).thenReturn(new DescribeChangeSetResult().withChanges(new Change()));
    Assertions.assertThat(stack.changeSetExists("bar")).isTrue();
}
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 8 with Change

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

the class CFNCreateChangeSetTests method updateChangeSetWithRawTemplate.

@Test
public void updateChangeSetWithRawTemplate() throws Exception {
    WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(this.stack.exists()).thenReturn(false);
    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.CREATE), 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