Search in sources :

Example 1 with AmazonCloudFormation

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

the class CFNCreateChangeSetTests method setupSdk.

@Before
public void setupSdk() throws Exception {
    this.stack = Mockito.mock(CloudFormationStack.class);
    PowerMockito.mockStatic(AWSClientFactory.class);
    PowerMockito.whenNew(CloudFormationStack.class).withAnyArguments().thenReturn(this.stack);
    AmazonCloudFormation cloudFormation = Mockito.mock(AmazonCloudFormation.class);
    PowerMockito.when(AWSClientFactory.create(Mockito.any(AwsSyncClientBuilder.class), Mockito.any(EnvVars.class))).thenReturn(cloudFormation);
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) EnvVars(hudson.EnvVars) AwsSyncClientBuilder(com.amazonaws.client.builder.AwsSyncClientBuilder) Before(org.junit.Before)

Example 2 with AmazonCloudFormation

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

the class CFNExecuteChangeSetTests method setupSdk.

@Before
public void setupSdk() throws Exception {
    this.stack = Mockito.mock(CloudFormationStack.class);
    PowerMockito.mockStatic(AWSClientFactory.class);
    PowerMockito.whenNew(CloudFormationStack.class).withAnyArguments().thenReturn(this.stack);
    AmazonCloudFormation cloudFormation = Mockito.mock(AmazonCloudFormation.class);
    PowerMockito.when(AWSClientFactory.create(Mockito.any(AwsSyncClientBuilder.class), Mockito.any(EnvVars.class))).thenReturn(cloudFormation);
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) EnvVars(hudson.EnvVars) AwsSyncClientBuilder(com.amazonaws.client.builder.AwsSyncClientBuilder) Before(org.junit.Before)

Example 3 with AmazonCloudFormation

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

the class CloudformationStackTests method describeStack.

@Test
public void describeStack() {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz"))));
    Assertions.assertThat(stack.describeOutputs()).isEqualTo(Collections.singletonMap("bar", "baz"));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with AmazonCloudFormation

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

the class CloudformationStackTests method updateStack.

@Test
public void updateStack() 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("templateBody", null, Collections.<Parameter>emptyList(), Collections.<Tag>emptyList(), 25, "myarn");
    ArgumentCaptor<UpdateStackRequest> captor = ArgumentCaptor.forClass(UpdateStackRequest.class);
    Mockito.verify(client).updateStack(captor.capture());
    Assertions.assertThat(captor.getValue()).isEqualTo(new UpdateStackRequest().withStackName("foo").withTemplateBody("templateBody").withCapabilities(Capability.values()).withParameters(Collections.<Parameter>emptyList()).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 5 with AmazonCloudFormation

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

the class CloudformationStackTests method stackDoesNotExists.

@Test
public void stackDoesNotExists() {
    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("stack foo does not exist");
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenThrow(ex);
    Assertions.assertThat(stack.exists()).isFalse();
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) 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