Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
DataService integration test: happy case! (#366)
Browse files Browse the repository at this point in the history
* Add Junit integration test for data service createEnvironment

* Break data service integration test into separate files

* Use the default account id, environment and cluster for testing
  • Loading branch information
xuejing authored Feb 1, 2018
1 parent 25a41e7 commit 905306c
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 23,32 @@
import org.junit.Test;

public class CreateEnvironmentIntegrationTest extends DataServiceIntegrationTestBase {
private static final String ACCOUNT_ID = "123456789012";
private static final String ENVIRONMENT_NAME = "environmentName";
private static final String CLUSTER_ONE = "cluster1";
private static final String CLUSTER_TWO = "cluster2";
private static final String TASK_DEFINITION = "taskDefinition";
private static final DataServiceModelBuilder models = DataServiceModelBuilder.builder().build();
private static final EnvironmentId createdEnvironmentId1 =
models
.environmentId()
.accountId(ACCOUNT_ID)
.environmentName(ENVIRONMENT_NAME)
.cluster(CLUSTER_ONE)
.build();
models.environmentId().cluster(CLUSTER_ONE).build();
private static final EnvironmentId createdEnvironmentId2 =
models
.environmentId()
.accountId(ACCOUNT_ID)
.environmentName(ENVIRONMENT_NAME)
.cluster(CLUSTER_TWO)
.build();
models.environmentId().cluster(CLUSTER_TWO).build();

@Test
public void testCreateEnvironmentSuccessful() throws Exception {
final CreateEnvironmentResponse createEnvironmentResponse =
dataService.createEnvironment(
models
.createEnvironmentRequest()
.taskDefinition(TASK_DEFINITION)
.environmentId(createdEnvironmentId1)
.build());
models.createEnvironmentRequest().environmentId(createdEnvironmentId1).build());
assertThat(createEnvironmentResponse.getEnvironment().getEnvironmentId())
.isEqualTo(createdEnvironmentId1);
}

@Test
public void testCreateAnEnvironmentAlreadyExist() throws Exception {
dataService.createEnvironment(
models
.createEnvironmentRequest()
.taskDefinition(TASK_DEFINITION)
.environmentId(createdEnvironmentId1)
.build());
models.createEnvironmentRequest().environmentId(createdEnvironmentId1).build());

assertThatThrownBy(
() ->
dataService.createEnvironment(
models
.createEnvironmentRequest()
.taskDefinition(TASK_DEFINITION)
.environmentId(createdEnvironmentId1)
.build()))
models.createEnvironmentRequest().environmentId(createdEnvironmentId1).build()))
.isInstanceOf(ResourceExistsException.class)
.hasMessageContaining(
String.format("environment with id %s already exists", createdEnvironmentId1));
Expand All @@ -83,21 58,12 @@ public void testCreateAnEnvironmentAlreadyExist() throws Exception {
public void testCreateTwoEnvironmentsWithTheSameNameButDifferentClusters() throws Exception {
final CreateEnvironmentResponse createEnvironmentResponse1 =
dataService.createEnvironment(
models
.createEnvironmentRequest()
.taskDefinition(TASK_DEFINITION)
.environmentId(createdEnvironmentId1)
.build());
models.createEnvironmentRequest().environmentId(createdEnvironmentId1).build());
assertThat(createEnvironmentResponse1.getEnvironment().getEnvironmentId())
.isEqualTo(createdEnvironmentId1);

final CreateEnvironmentResponse createEnvironmentResponse2 =
dataService.createEnvironment(
models
.createEnvironmentRequest()
.taskDefinition(TASK_DEFINITION)
.environmentId(createdEnvironmentId2)
.build());
models.createEnvironmentRequest().environmentId(createdEnvironmentId2).build());
assertThat(createEnvironmentResponse2.getEnvironment().getEnvironmentId())
.isEqualTo(createdEnvironmentId2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 14,19 @@
*/
package com.amazonaws.blox.dataservice.integration;

import com.amazonaws.blox.dataservicemodel.v1.model.Cluster;
import com.amazonaws.blox.dataservicemodel.v1.model.Cluster.ClusterBuilder;
import com.amazonaws.blox.dataservicemodel.v1.model.DeploymentConfiguration;
import com.amazonaws.blox.dataservicemodel.v1.model.EnvironmentId;
import com.amazonaws.blox.dataservicemodel.v1.model.EnvironmentId.EnvironmentIdBuilder;
import com.amazonaws.blox.dataservicemodel.v1.model.EnvironmentType;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.CreateEnvironmentRequest;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.*;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.CreateEnvironmentRequest.CreateEnvironmentRequestBuilder;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.DeleteEnvironmentRequest.DeleteEnvironmentRequestBuilder;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.DescribeEnvironmentRequest.DescribeEnvironmentRequestBuilder;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.DescribeEnvironmentRevisionRequest.DescribeEnvironmentRevisionRequestBuilder;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.ListClustersRequest.ListClustersRequestBuilder;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.ListEnvironmentsRequest.ListEnvironmentsRequestBuilder;
import java.time.Instant;
import lombok.Builder;
import lombok.Value;
Expand All @@ -29,7 36,7 @@
@Value
@Builder
public class DataServiceModelBuilder {
private String accountId = "0123456789012";
private String accountId = "123456789012";
private String clusterName = "Cluster";
private String environmentName = "Environment";
private String environmentRevisionId = "EnvironmentRevisionId";
Expand All @@ -49,10 56,40 @@ public CreateEnvironmentRequestBuilder createEnvironmentRequest() {
.environmentId(environmentId().build());
}

public DescribeEnvironmentRequestBuilder describeEnvironmentRequest() {
return DescribeEnvironmentRequest.builder().environmentId(environmentId().build());
}

public DescribeEnvironmentRevisionRequestBuilder describeEnvironmentRevisionRequest() {
return DescribeEnvironmentRevisionRequest.builder()
.environmentId(environmentId().build())
.environmentRevisionId(environmentRevisionId);
}

public ListClustersRequestBuilder listClustersRequest() {
return ListClustersRequest.builder().accountId(accountId).clusterNamePrefix(clusterName);
}

public ListEnvironmentsRequestBuilder listEnvironmentsRequest() {
return ListEnvironmentsRequest.builder()
.cluster(cluster().build())
.environmentNamePrefix(environmentName);
}

public DeleteEnvironmentRequestBuilder deleteEnvironmentRequest() {
return DeleteEnvironmentRequest.builder()
.forceDelete(false)
.environmentId(environmentId().build());
}

public EnvironmentIdBuilder environmentId() {
return EnvironmentId.builder()
.accountId(accountId)
.cluster(clusterName)
.environmentName(environmentName);
}

public ClusterBuilder cluster() {
return Cluster.builder().accountId(accountId).clusterName(clusterName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 1,38 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
* License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "LICENSE" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.blox.dataservice.integration;

import static org.assertj.core.api.Assertions.assertThat;

import com.amazonaws.blox.dataservicemodel.v1.model.EnvironmentId;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.DeleteEnvironmentResponse;
import org.junit.Test;

public class DeleteEnvironmentIntegrationTest extends DataServiceIntegrationTestBase {
private static final DataServiceModelBuilder models = DataServiceModelBuilder.builder().build();
private static final EnvironmentId createdEnvironmentId = models.environmentId().build();

@Test
public void testDeleteEnvironment() throws Exception {
dataService.createEnvironment(
models.createEnvironmentRequest().environmentId(createdEnvironmentId).build());
final DeleteEnvironmentResponse deleteEnvironmentResponse =
dataService.deleteEnvironment(
models.deleteEnvironmentRequest().environmentId(createdEnvironmentId).build());

assertThat(deleteEnvironmentResponse.getEnvironment().getEnvironmentId())
.isEqualTo(createdEnvironmentId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 1,37 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
* License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "LICENSE" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.blox.dataservice.integration;

import static org.assertj.core.api.Assertions.assertThat;

import com.amazonaws.blox.dataservicemodel.v1.model.EnvironmentId;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.DescribeEnvironmentResponse;
import org.junit.Test;

public class DescribeEnvironmentIntegrationTest extends DataServiceIntegrationTestBase {
private static final DataServiceModelBuilder models = DataServiceModelBuilder.builder().build();
private static final EnvironmentId createdEnvironmentId1 = models.environmentId().build();

@Test
public void testDescribeEnvironment() throws Exception {
dataService.createEnvironment(
models.createEnvironmentRequest().environmentId(createdEnvironmentId1).build());
final DescribeEnvironmentResponse describeEnvironmentResponse =
dataService.describeEnvironment(
models.describeEnvironmentRequest().environmentId(createdEnvironmentId1).build());
assertThat(describeEnvironmentResponse.getEnvironment().getEnvironmentId())
.isEqualTo(createdEnvironmentId1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 1,47 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
* License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "LICENSE" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.blox.dataservice.integration;

import static org.assertj.core.api.Assertions.assertThat;

import com.amazonaws.blox.dataservicemodel.v1.model.EnvironmentId;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.ListClustersResponse;
import java.util.Arrays;
import org.junit.Test;

public class ListClustersIntegrationTest extends DataServiceIntegrationTestBase {
private static final String CLUSTER_ONE = "cluster1";
private static final String CLUSTER_TWO = "cluster2";
private static final DataServiceModelBuilder models = DataServiceModelBuilder.builder().build();
private static final EnvironmentId createdEnvironmentId1 =
models.environmentId().cluster(CLUSTER_ONE).build();
private static final EnvironmentId createdEnvironmentId2 =
models.environmentId().cluster(CLUSTER_TWO).build();

@Test
public void testListClusterWithTwoEnvironments() throws Exception {
dataService.createEnvironment(
models.createEnvironmentRequest().environmentId(createdEnvironmentId1).build());
dataService.createEnvironment(
models.createEnvironmentRequest().environmentId(createdEnvironmentId2).build());
final ListClustersResponse listClustersResponse =
dataService.listClusters(models.listClustersRequest().clusterNamePrefix(null).build());
assertThat(listClustersResponse.getClusters())
.isEqualTo(
Arrays.asList(
models.cluster().clusterName(CLUSTER_ONE).build(),
models.cluster().clusterName(CLUSTER_TWO).build()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 1,49 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
* License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "LICENSE" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.blox.dataservice.integration;

import static org.assertj.core.api.Assertions.assertThat;

import com.amazonaws.blox.dataservicemodel.v1.model.EnvironmentId;
import com.amazonaws.blox.dataservicemodel.v1.model.wrappers.ListEnvironmentsResponse;
import java.util.Arrays;
import org.junit.Test;

public class ListEnvironmentsIntegrationTest extends DataServiceIntegrationTestBase {
private static final String ENVIRONMENT_NAME_ONE = "environmentName1";
private static final String ENVIRONMENT_NAME_TWO = "environmentName2";
private static final DataServiceModelBuilder models = DataServiceModelBuilder.builder().build();
private static final EnvironmentId createdEnvironmentId1 =
models.environmentId().environmentName(ENVIRONMENT_NAME_ONE).build();
private static final EnvironmentId createdEnvironmentId3 =
models.environmentId().environmentName(ENVIRONMENT_NAME_TWO).build();

@Test
public void testListEnvironments() throws Exception {
dataService.createEnvironment(
models.createEnvironmentRequest().environmentId(createdEnvironmentId1).build());
dataService.createEnvironment(
models.createEnvironmentRequest().environmentId(createdEnvironmentId3).build());
final ListEnvironmentsResponse listEnvironmentsResponse =
dataService.listEnvironments(
models
.listEnvironmentsRequest()
.cluster(models.cluster().build())
.environmentNamePrefix(null)
.build());
assertThat(listEnvironmentsResponse.getEnvironmentIds())
.isEqualTo(Arrays.asList(createdEnvironmentId1, createdEnvironmentId3));
}
}

0 comments on commit 905306c

Please sign in to comment.