Search in sources :

Example 6 with AmazonCloudFormation

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

the class CloudformationStackTests method changeSetDoesNotExists.

@Test
public void changeSetDoesNotExists() {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    AmazonCloudFormationException ex = new AmazonCloudFormationException("foo");
    ex.setErrorCode("ValidationError");
    ex.setErrorMessage("change set bar does not exist");
    Mockito.when(client.describeChangeSet(new DescribeChangeSetRequest().withStackName("foo").withChangeSetName("bar"))).thenThrow(ex);
    Assertions.assertThat(stack.changeSetExists("bar")).isFalse();
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with AmazonCloudFormation

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

the class CloudformationStackTests method createNewStackChangeSet.

@Test
public void createNewStackChangeSet() throws ExecutionException {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    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);
    stack.createChangeSet("c1", "templateBody", null, Collections.<Parameter>emptyList(), Collections.<Tag>emptyList(), 25, ChangeSetType.CREATE, "myarn");
    ArgumentCaptor<CreateChangeSetRequest> captor = ArgumentCaptor.forClass(CreateChangeSetRequest.class);
    Mockito.verify(client).createChangeSet(captor.capture());
    Assertions.assertThat(captor.getValue()).isEqualTo(new CreateChangeSetRequest().withChangeSetType(ChangeSetType.CREATE).withStackName("foo").withTemplateBody("templateBody").withCapabilities(Capability.values()).withParameters(Collections.<Parameter>emptyList()).withChangeSetName("c1").withRoleARN("myarn"));
    Mockito.verify(this.eventPrinter).waitAndPrintChangeSetEvents(Mockito.eq("foo"), Mockito.eq("c1"), Mockito.any(Waiter.class), Mockito.eq(25L));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Waiter(com.amazonaws.waiters.Waiter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with AmazonCloudFormation

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

the class CloudformationStackTests method updateStackWithPreviousTemplate.

@Test
public void updateStackWithPreviousTemplate() throws ExecutionException {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    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);
    stack.update(null, null, Collections.<Parameter>emptyList(), Collections.<Tag>emptyList(), 12, "myarn");
    ArgumentCaptor<UpdateStackRequest> captor = ArgumentCaptor.forClass(UpdateStackRequest.class);
    Mockito.verify(client).updateStack(captor.capture());
    Assertions.assertThat(captor.getValue()).isEqualTo(new UpdateStackRequest().withStackName("foo").withUsePreviousTemplate(true).withCapabilities(Capability.values()).withParameters(Collections.<Parameter>emptyList()).withRoleARN("myarn"));
    Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(12L));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Waiter(com.amazonaws.waiters.Waiter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with AmazonCloudFormation

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

the class CloudformationStackTests method createStack.

@Test
public void createStack() throws ExecutionException {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    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);
    stack.create("templateBody", null, Collections.<Parameter>emptyList(), Collections.<Tag>emptyList(), 7, 25, "myarn", OnFailure.DO_NOTHING.toString());
    ArgumentCaptor<CreateStackRequest> captor = ArgumentCaptor.forClass(CreateStackRequest.class);
    Mockito.verify(client).createStack(captor.capture());
    Assertions.assertThat(captor.getValue()).isEqualTo(new CreateStackRequest().withStackName("foo").withTemplateBody("templateBody").withCapabilities(Capability.values()).withParameters(Collections.<Parameter>emptyList()).withTimeoutInMinutes(7).withOnFailure(OnFailure.DO_NOTHING).withRoleARN("myarn"));
    Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(25L));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Waiter(com.amazonaws.waiters.Waiter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with AmazonCloudFormation

use of com.amazonaws.services.cloudformation.AmazonCloudFormation 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);
    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()));
    stack.executeChangeSet("bar", 25);
    Mockito.verify(client).executeChangeSet(Mockito.any(ExecuteChangeSetRequest.class));
    Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(25L));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Waiter(com.amazonaws.waiters.Waiter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)21 TaskListener (hudson.model.TaskListener)17 Test (org.junit.Test)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 AmazonCloudFormationWaiters (com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters)10 Waiter (com.amazonaws.waiters.Waiter)9 AwsSyncClientBuilder (com.amazonaws.client.builder.AwsSyncClientBuilder)4 Before (org.junit.Before)4 EnvVars (hudson.EnvVars)3 StepContext (org.jenkinsci.plugins.workflow.steps.StepContext)1