Skip to content

Commit

Permalink
Generate a new dataset name for each test
Browse files Browse the repository at this point in the history
Signed-off-by: stevenhorsman <steven@uk.ibm.com>
  • Loading branch information
stevenhorsman committed Jul 23, 2019
1 parent a12eb01 commit 2134807
Showing 1 changed file with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.restassured.http.ContentType;
import io.restassured.response.Response;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.http.HttpStatus;
import org.junit.After;
import org.junit.Test;
Expand All @@ -31,8 +32,6 @@

public class DataSetsCreateIntegrationTests extends AbstractDataSetsIntegrationTest {

private static final String TEST_DATA_SET = HLQ + ".TEST.DELETE";

// TODO - use junit 5 and nest the cleanup?
private String cleanUp = null;

Expand All @@ -43,23 +42,29 @@ public void cleanUp() throws Exception {
}
}

private String createDatasetName() {
return HLQ + ".A" + RandomStringUtils.randomAlphanumeric(7);
}

@Test
public void testCreatePds() throws Exception {
DataSetCreateRequest pdsRequest = createPdsRequest(TEST_DATA_SET);
cleanUp = TEST_DATA_SET;
String testDataSet = createDatasetName();
DataSetCreateRequest pdsRequest = createPdsRequest(testDataSet);
cleanUp = testDataSet;
createDataSet(pdsRequest).then().statusCode(HttpStatus.SC_CREATED)
.header("Location", endsWith(DATASETS_ROOT_ENDPOINT + "/" + TEST_DATA_SET)).body(equalTo(""));
.header("Location", endsWith(DATASETS_ROOT_ENDPOINT + "/" + testDataSet)).body(equalTo(""));

List<DataSetAttributes> actual = getDataSetsDetails(TEST_DATA_SET).then().statusCode(HttpStatus.SC_OK).extract()
List<DataSetAttributes> actual = getDataSetsDetails(testDataSet).then().statusCode(HttpStatus.SC_OK).extract()
.body().jsonPath().getList("items", DataSetAttributes.class);
assertEquals("Should have created the correct type", DataSetOrganisationType.PO,
actual.get(0).getDataSetOrganization());
}

@Test
public void testTryingToCreateExistingPdsThrowsError() throws Exception {
DataSetCreateRequest pdsRequest = createPdsRequest(TEST_DATA_SET);
cleanUp = TEST_DATA_SET;
String testDataSet = createDatasetName();
DataSetCreateRequest pdsRequest = createPdsRequest(testDataSet);
cleanUp = testDataSet;
createDataSet(pdsRequest);

// TODO - work out how to decipher the dynamic allocation error codes
Expand All @@ -73,15 +78,16 @@ public void testTryingToCreateExistingPdsThrowsError() throws Exception {

@Test
public void testCreateSds() throws Exception {
DataSetCreateRequest sdsRequest = createSdsRequest(TEST_DATA_SET);
cleanUp = TEST_DATA_SET;
String testDataSet = createDatasetName();
DataSetCreateRequest sdsRequest = createSdsRequest(testDataSet);
cleanUp = testDataSet;
// Add debug
Response response = createDataSet(sdsRequest);
System.out.println(response.asString());
response.then().statusCode(HttpStatus.SC_CREATED)
.header("Location", endsWith(DATASETS_ROOT_ENDPOINT + "/" + TEST_DATA_SET)).body(equalTo(""));
.header("Location", endsWith(DATASETS_ROOT_ENDPOINT + "/" + testDataSet)).body(equalTo(""));

List<DataSetAttributes> actual = getDataSetsDetails(TEST_DATA_SET).then().statusCode(HttpStatus.SC_OK).extract()
List<DataSetAttributes> actual = getDataSetsDetails(testDataSet).then().statusCode(HttpStatus.SC_OK).extract()
.body().jsonPath().getList("items", DataSetAttributes.class);
assertEquals("Should have created the correct type", DataSetOrganisationType.PS,
actual.get(0).getDataSetOrganization());
Expand All @@ -90,25 +96,27 @@ public void testCreateSds() throws Exception {

@Test
public void testCreatePdse() throws Exception {
DataSetCreateRequest pdseRequest = createPdseRequest(TEST_DATA_SET);
cleanUp = TEST_DATA_SET;
String testDataSet = createDatasetName();
DataSetCreateRequest pdseRequest = createPdseRequest(testDataSet);
cleanUp = testDataSet;
Response createDataSet = createDataSet(pdseRequest);
createDataSet.then().statusCode(HttpStatus.SC_CREATED)
.header("Location", endsWith(DATASETS_ROOT_ENDPOINT + "/" + TEST_DATA_SET)).body(equalTo(""));
.header("Location", endsWith(DATASETS_ROOT_ENDPOINT + "/" + testDataSet)).body(equalTo(""));

List<DataSetAttributes> actual = getDataSetsDetails(TEST_DATA_SET).then().statusCode(HttpStatus.SC_OK).extract()
List<DataSetAttributes> actual = getDataSetsDetails(testDataSet).then().statusCode(HttpStatus.SC_OK).extract()
.body().jsonPath().getList("items", DataSetAttributes.class);
assertEquals("Should have created the correct type", DataSetOrganisationType.PO_E,
actual.get(0).getDataSetOrganization());
}

@Test
public void testPostDatasetWithInvalidRequestFails() throws Exception {
ZoweApiRestException expected = new InvalidDirectoryBlockException(TEST_DATA_SET);
String testDataSet = createDatasetName();
ZoweApiRestException expected = new InvalidDirectoryBlockException(testDataSet);
ApiError expectedError = expected.getApiError();

DataSetCreateRequest sdsRequestWithDirBlk = createSdsRequest(TEST_DATA_SET);
cleanUp = TEST_DATA_SET;
DataSetCreateRequest sdsRequestWithDirBlk = createSdsRequest(testDataSet);
cleanUp = testDataSet;
sdsRequestWithDirBlk.setDirectoryBlocks(10);
createDataSet(sdsRequestWithDirBlk).then().statusCode(expectedError.getStatus().value())
.contentType(ContentType.JSON).body("status", equalTo(expectedError.getStatus().name()))
Expand Down

0 comments on commit 2134807

Please sign in to comment.