Search in sources :

Example 11 with TaskListener

use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.

the class CloudFormationStackSetTest method setup.

@Before
public void setup() {
    TaskListener listener = Mockito.mock(TaskListener.class);
    Mockito.when(listener.getLogger()).thenReturn(System.out);
    client = Mockito.mock(AmazonCloudFormation.class);
    sleepStrategy = Mockito.mock(SleepStrategy.class);
    stackSet = new CloudFormationStackSet(client, "foo", listener, sleepStrategy);
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) Before(org.junit.Before)

Example 12 with TaskListener

use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method createStackWithStackChangeSetReviewInProgress.

@Test
public void createStackWithStackChangeSetReviewInProgress() 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));
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatus("REVIEW_IN_PROGRESS")));
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    stack.createChangeSet("c1", "templateBody", null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, ChangeSetType.UPDATE, "myarn", null);
    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.emptyList()).withChangeSetName("c1").withRoleARN("myarn"));
    Mockito.verify(this.eventPrinter).waitAndPrintChangeSetEvents(Mockito.eq("foo"), Mockito.eq("c1"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) CreateChangeSetRequest(com.amazonaws.services.cloudformation.model.CreateChangeSetRequest) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Waiter(com.amazonaws.waiters.Waiter) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Stack(com.amazonaws.services.cloudformation.model.Stack) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with TaskListener

use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method executeChangeSetIfNoChangesButSuccessfulStatus.

@Test
public void executeChangeSetIfNoChangesButSuccessfulStatus() throws ExecutionException {
    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().withStatus(ChangeSetStatus.CREATE_COMPLETE));
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatus(StackStatus.CREATE_COMPLETE).withOutputs(new Output().withOutputKey("bar").withOutputValue("baz"))));
    Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client));
    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");
}
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) 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 14 with TaskListener

use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method createNewStackChangeSet_NoSubmittedChanges.

@Test
public void createNewStackChangeSet_NoSubmittedChanges() 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));
    Mockito.when(client.describeStacks(Mockito.any())).thenReturn(new DescribeStacksResult());
    Mockito.when(client.describeChangeSet(Mockito.any())).thenReturn(new DescribeChangeSetResult().withStatus(ChangeSetStatus.FAILED).withStatusReason("The submitted information didn't contain changes"));
    Mockito.doThrow(new ExecutionException(new WaiterUnrecoverableException("foo"))).when(this.eventPrinter).waitAndPrintChangeSetEvents(Mockito.eq("foo"), Mockito.eq("c1"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT));
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    stack.createChangeSet("c1", "templateBody", null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, ChangeSetType.CREATE, "myarn", null);
    Mockito.verify(this.eventPrinter, Mockito.atLeastOnce()).waitAndPrintChangeSetEvents(Mockito.any(), Mockito.any(), Mockito.any(Waiter.class), Mockito.any());
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) WaiterUnrecoverableException(com.amazonaws.waiters.WaiterUnrecoverableException) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) ExecutionException(java.util.concurrent.ExecutionException) Waiter(com.amazonaws.waiters.Waiter) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with TaskListener

use of hudson.model.TaskListener 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));
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenReturn(new DescribeStacksResult());
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    stack.createChangeSet("c1", "templateBody", null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, ChangeSetType.CREATE, "myarn", null);
    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.emptyList()).withChangeSetName("c1").withRoleARN("myarn"));
    Mockito.verify(this.eventPrinter).waitAndPrintChangeSetEvents(Mockito.eq("foo"), Mockito.eq("c1"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) CreateChangeSetRequest(com.amazonaws.services.cloudformation.model.CreateChangeSetRequest) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Waiter(com.amazonaws.waiters.Waiter) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TaskListener (hudson.model.TaskListener)42 Test (org.junit.Test)28 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 DescribeStacksResult (com.amazonaws.services.cloudformation.model.DescribeStacksResult)16 AmazonCloudFormationWaiters (com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters)16 Waiter (com.amazonaws.waiters.Waiter)15 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)14 Stack (com.amazonaws.services.cloudformation.model.Stack)12 EnvVars (hudson.EnvVars)10 Output (com.amazonaws.services.cloudformation.model.Output)9 DescribeChangeSetResult (com.amazonaws.services.cloudformation.model.DescribeChangeSetResult)8 IOException (java.io.IOException)8 DescribeChangeSetRequest (com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest)6 LogTaskListener (hudson.util.LogTaskListener)4 PrintStream (java.io.PrintStream)4 ArrayList (java.util.ArrayList)4 Change (com.amazonaws.services.cloudformation.model.Change)3 CreateChangeSetRequest (com.amazonaws.services.cloudformation.model.CreateChangeSetRequest)3 ExecuteChangeSetRequest (com.amazonaws.services.cloudformation.model.ExecuteChangeSetRequest)3