Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make some fields in manifest file as mandatory #289

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void validateManifestFile(final URL url, final ActionRequestValidationEx
manifest = DatasourceManifest.Builder.build(url);
} catch (Exception e) {
log.info("Error occurred while reading a file from {}", url, e);
errors.addValidationError(String.format(Locale.ROOT, "Error occurred while reading a file from %s", url));
errors.addValidationError(String.format(Locale.ROOT, "Error occurred while reading a file from %s: %s", url, e.getMessage()));
return;
}

Expand All @@ -188,7 +188,7 @@ private void validateManifestFile(final URL url, final ActionRequestValidationEx
return;
}

if (updateInterval.days() >= manifest.getValidForInDays()) {
if (manifest.getValidForInDays() != null && updateInterval.days() >= manifest.getValidForInDays()) {
errors.addValidationError(
String.format(
Locale.ROOT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ public class DatasourceManifest {
}
);
static {
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), URL_FIELD);
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), DB_NAME_FIELD);
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), SHA256_HASH_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), URL_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), DB_NAME_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), SHA256_HASH_FIELD);
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), VALID_FOR_IN_DAYS_FIELD);
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), UPDATED_AT_FIELD);
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), PROVIDER_FIELD);
PARSER.declareLong(ConstructingObjectParser.constructorArg(), UPDATED_AT_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), PROVIDER_FIELD);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public class PutDatasourceRequestTests extends Ip2GeoTestCase {

public void testValidateWithInvalidUrl() {
public void testValidate_whenInvalidUrl_thenFails() {
String datasourceName = GeospatialTestHelper.randomLowerCaseString();
PutDatasourceRequest request = new PutDatasourceRequest(datasourceName);
request.setEndpoint("invalidUrl");
Expand All @@ -33,29 +33,26 @@ public void testValidateWithInvalidUrl() {
assertEquals("Invalid URL format is provided", exception.validationErrors().get(0));
}

public void testValidateWithInvalidManifestFile() {
public void testValidate_whenInvalidManifestFile_thenFails() {
String datasourceName = GeospatialTestHelper.randomLowerCaseString();
String domain = GeospatialTestHelper.randomLowerCaseString();
PutDatasourceRequest request = new PutDatasourceRequest(datasourceName);
request.setEndpoint(String.format(Locale.ROOT, "https://%s.com", domain));
request.setUpdateInterval(TimeValue.timeValueDays(1));
ActionRequestValidationException exception = request.validate();
assertEquals(1, exception.validationErrors().size());
assertEquals(
String.format(Locale.ROOT, "Error occurred while reading a file from %s", request.getEndpoint()),
exception.validationErrors().get(0)
);
assertTrue(exception.validationErrors().get(0).contains("Error occurred while reading a file"));
}

public void testValidate() throws Exception {
public void testValidate_whenValidInput_thenSucceed() throws Exception {
String datasourceName = GeospatialTestHelper.randomLowerCaseString();
PutDatasourceRequest request = new PutDatasourceRequest(datasourceName);
request.setEndpoint(sampleManifestUrl());
request.setUpdateInterval(TimeValue.timeValueDays(1));
assertNull(request.validate());
}

public void testValidateWithZeroUpdateInterval() throws Exception {
public void testValidate_whenZeroUpdateInterval_thenFails() throws Exception {
String datasourceName = GeospatialTestHelper.randomLowerCaseString();
PutDatasourceRequest request = new PutDatasourceRequest(datasourceName);
request.setEndpoint(sampleManifestUrl());
Expand All @@ -72,7 +69,7 @@ public void testValidateWithZeroUpdateInterval() throws Exception {
);
}

public void testValidateWithLargeUpdateInterval() throws Exception {
public void testValidate_whenLargeUpdateInterval_thenFail() throws Exception {
String datasourceName = GeospatialTestHelper.randomLowerCaseString();
PutDatasourceRequest request = new PutDatasourceRequest(datasourceName);
request.setEndpoint(sampleManifestUrl());
Expand All @@ -86,7 +83,7 @@ public void testValidateWithLargeUpdateInterval() throws Exception {
assertTrue(exception.validationErrors().get(0).contains("should be smaller"));
}

public void testValidateWithInvalidUrlInsideManifest() throws Exception {
public void testValidate_whenInvalidUrlInsideManifest_thenFail() throws Exception {
String datasourceName = GeospatialTestHelper.randomLowerCaseString();
PutDatasourceRequest request = new PutDatasourceRequest(datasourceName);
request.setEndpoint(sampleManifestUrlWithInvalidUrl());
Expand All @@ -100,7 +97,7 @@ public void testValidateWithInvalidUrlInsideManifest() throws Exception {
assertTrue(exception.validationErrors().get(0).contains("Invalid URL format"));
}

public void testValidateDatasourceNames() throws Exception {
public void testValidate_whenInvalidDatasourceNames_thenFails() throws Exception {
String validDatasourceName = GeospatialTestHelper.randomLowerCaseString();
String domain = GeospatialTestHelper.randomLowerCaseString();
PutDatasourceRequest request = new PutDatasourceRequest(validDatasourceName);
Expand Down Expand Up @@ -154,7 +151,7 @@ public void testValidateDatasourceNames() throws Exception {
}
}

public void testStreamInOut() throws Exception {
public void testStreamInOut_whenValidInput_thenSucceed() throws Exception {
String datasourceName = GeospatialTestHelper.randomLowerCaseString();
String domain = GeospatialTestHelper.randomLowerCaseString();
PutDatasourceRequest request = new PutDatasourceRequest(datasourceName);
Expand Down