Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
fix(#0): Removed OfType Constraint Type
Browse files Browse the repository at this point in the history
  • Loading branch information
cdowding-sl committed Oct 10, 2019
1 parent d166055 commit fd38c56
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 278 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
Given there is a field foo
And the data requested is violating
And the generator can generate at most 5 rows
And we do not violate any of type constraints

Scenario: Running the generator in violate mode for not equal to is successful (decimal)
Given foo is anything but equal to 8
And foo has type "decimal"
And foo is granular to 1
And we do not violate any of type constraints
And we do not violate any granular to constraints
And the generation strategy is full
Then the following data should be generated:
Expand All @@ -22,7 +20,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And foo has type "decimal"
And the generation strategy is full
And we do not violate any equal to constraints
And we do not violate any of type constraints
Then the following data should be generated:
| foo |
| 8 |
Expand All @@ -43,7 +40,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And foo has type "decimal"
And the generation strategy is random
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains anything but null

Expand All @@ -53,7 +49,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And foo is anything but null
And foo is before 2019-01-01T00:00:00.000Z
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains only datetime data
And foo contains datetimes after or at 2019-01-01T00:00:00.000Z
Expand All @@ -64,7 +59,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And the generation strategy is random
And foo is less than 10
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains only numeric data
And foo contains numeric values greater than or equal to 10
Expand All @@ -75,7 +69,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And foo is anything but null
And foo is shorter than 10
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains only string data
And foo contains strings longer than or equal to 10
Expand All @@ -86,7 +79,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And foo is anything but null
And foo is matching regex /[a-z]{0,9}/
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains only string data
And foo contains anything but strings matching /[a-z]{0,9}/
Expand All @@ -97,7 +89,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And the generation strategy is random
And foo is anything but matching regex /[a-z]{0,9}/
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains only string data
And foo contains strings matching /[a-z]{0,9}/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1512,122 +1512,6 @@ Feature: Values can be specified by using if, then and else constraints
| foo | bar |
| "dddd" | "4444" |

Scenario: An if constraint that contains an ISIN constraint in the then clause generates valid ISINs when the if clause applies
Given foo is in set:
| "GB0002634946" |
| "bb" |
| "ccc" |
| "dddd" |
And foo is anything but null
And bar is in set:
| "GB0002634946" |
| "22" |
| "333" |
| "4444" |
And bar is anything but null
And foo has type "string"
And bar has type "string"
And there is a constraint:
"""
{
"if": { "field": "foo", "is": "equalTo", "value": "bb" },
"then": { "field": "bar", "is": "ofType", "value": "ISIN" },
"else": { "field": "bar", "is": "equalTo", "value": "333" }
}
"""
Then the following data should be generated:
| foo | bar |
| "GB0002634946" | "333" |
| "bb" | "GB0002634946" |
| "ccc" | "333" |
| "dddd" | "333" |

Scenario: An if constraint that contains an ISIN constraint in the else clause generates valid ISINs when the if clause does not apply
Given foo is in set:
| "GB0002634946" |
| "bb" |
| "ccc" |
| "dddd" |
And foo is anything but null
And bar is in set:
| "GB0002634946" |
| "22" |
| "333" |
| "4444" |
And bar is anything but null
And foo has type "string"
And bar has type "string"
And there is a constraint:
"""
{
"if": { "field": "foo", "is": "equalTo", "value": "bb" },
"then": { "field": "bar", "is": "equalTo", "value": "22" },
"else": { "field": "bar", "is": "ofType", "value": "ISIN" }
}
"""
Then the following data should be generated:
| foo | bar |
| "GB0002634946" | "GB0002634946" |
| "bb" | "22" |
| "ccc" | "GB0002634946" |
| "dddd" | "GB0002634946" |

Scenario: An if constraint that contains an ISIN constraint in the then clause combined with an in set constraint that does not contain any valid ISINs only generates data that matches the else clause
Given foo is in set:
| "aa" |
| "bb" |
| "ccc" |
| "dddd" |
And foo is anything but null
And bar is in set:
| "11" |
| "22" |
| "333" |
| "4444" |
And bar is anything but null
And foo has type "string"
And bar has type "string"
And there is a constraint:
"""
{
"if": { "field": "foo", "is": "equalTo", "value": "ccc" },
"then": { "field": "bar", "is": "ofType", "value": "ISIN" },
"else": { "field": "bar", "is": "equalTo", "value": "333" }
}
"""
Then the following data should be generated:
| foo | bar |
| "aa" | "333" |
| "bb" | "333" |
| "dddd" | "333" |

Scenario: An if constraint with an else clause containing an ISIN constraint which contradicts an in set constraint generates data that only matches the then clause
Given foo is in set:
| "aa" |
| "bb" |
| "ccc" |
| "dddd" |
And foo is anything but null
And bar is in set:
| "11" |
| "22" |
| "333" |
| "4444" |
And bar is anything but null
And foo has type "string"
And bar has type "string"
And there is a constraint:
"""
{
"if": { "field": "foo", "is": "equalTo", "value": "ccc" },
"then": { "field": "bar", "is": "equalTo", "value": "333" },
"else": { "field": "bar", "is": "ofType", "value": "ISIN" }
}
"""
Then the following data should be generated:
| foo | bar |
| "ccc" | "333" |

Scenario: Running an if request that contains a non contradictory greaterThan constraint within its if statement should be successful
Given foo is in set:
| 10 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,3 @@ Feature: Type mandation validation
And there is a field purchase_time
Then the profile is invalid because "Fields price, purchase_time are not typed; add their type to the field definition"

Scenario: An anyOf constraint whose branches don't all satisfy type mandation should not satisfy type mandation
Given there is a field user_id
And there is a constraint:
"""
{ "anyOf": [
{ "field": "user_id", "is": "ofType", "value": "string" },
{ "not": { "field": "user_id", "is": "null" } }
]}
"""
Then the profile is invalid because "Field \[user_id\]: is not typed; add its type to the field definition"

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.scottlogic.deg.generator.profile.RuleInformation;
import com.scottlogic.deg.profile.dto.ConstraintDTO;
import com.scottlogic.deg.profile.reader.atomic.ConstraintReaderHelpers;
import com.scottlogic.deg.profile.reader.atomic.OfTypeConstraintFactory;
import com.scottlogic.deg.profile.serialisation.ProfileDeserialiser;
import com.scottlogic.deg.profile.dto.ProfileDTO;

Expand Down Expand Up @@ -108,6 +109,17 @@ public Profile read(String profileJson) throws IOException {
rules.add(new Rule(new RuleInformation("nullable-rules"), nullableRules));
}

// add types
Collection<Constraint> typeRules = profileDto.fields.stream()
.filter(fieldDTO -> fieldDTO.type != null )
.map(fieldDTO -> OfTypeConstraintFactory.create(profileFields.getByName(fieldDTO.name), fieldDTO.type))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());

if (typeRules.size() > 0) {
rules.add(new Rule(new RuleInformation("type-rules"), typeRules));
}
return new Profile(profileFields, rules, profileDto.description);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ private InMapRelation createInMapRelation(Field field, Field other, DistributedL
Set<Constraint> getSubConstraints(ProfileFields fields, Collection<ConstraintDTO> allOf) {
return allOf.stream()
.map(subConstraintDto -> apply(subConstraintDto, fields))
.filter(constraint -> !(constraint instanceof RemoveFromTree))
.collect(Collectors.toSet());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ public static Optional<Constraint> create(Field field, String value){
case "string":
case "datetime":
return Optional.empty();

case "integer":
return Optional.of(new IsGranularToNumericConstraint(field,
NumericGranularityFactory.create(BigDecimal.ONE))
);

case "ISIN":
case "SEDOL":
case "CUSIP":
Expand All @@ -32,7 +30,6 @@ public static Optional<Constraint> create(Field field, String value){
field,
StandardConstraintTypes.valueOf(value.toUpperCase()))
);

case "firstname":
case "lastname":
case "fullname":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ private static Stream<Arguments> stringLengthInvalidOperandProvider() {
Arguments.of(IS_STRING_SHORTER_THAN, nullValueDto));
}

private static Stream<Arguments> ofTypeInvalidValueProvider() {
ConstraintDTO numericTypeValueDto = new ConstraintDTO();
numericTypeValueDto.field = "test";
numericTypeValueDto.value = "numeric";

return Stream.of(Arguments.of(AtomicConstraintType.IS_OF_TYPE, numericTypeValueDto));
}

private static Stream<Arguments> numericOutOfBoundsOperandProvider() {
ConstraintDTO maxValueDtoPlusOne = new ConstraintDTO();
maxValueDtoPlusOne.field = "test";
Expand Down Expand Up @@ -218,18 +210,11 @@ public void testAtomicConstraintReader(AtomicConstraintType type, ConstraintDTO

@DisplayName("Should fail when operators have an invalid operand")
@ParameterizedTest(name = "{0} should be invalid")
@MethodSource({"stringLengthInvalidOperandProvider", "ofTypeInvalidValueProvider"})
@MethodSource({"stringLengthInvalidOperandProvider"})
public void testAtomicConstraintReaderWithInvalidOperands(AtomicConstraintType type, ConstraintDTO dto) {
Assertions.assertThrows(InvalidProfileException.class, () -> ConstraintValueValidator.validate(createField(dto.field), type, dto.value));
}

@Test
public void testBaseConstraintReaderMapWithUnmappedOperands() {
Assertions.assertThrows(
InvalidProfileException.class,
() -> ConstraintValueValidator.validate(createField("test"), IS_OF_TYPE, "garbage"));
}

@DisplayName("Should fail when value property is numeric and out of bounds")
@ParameterizedTest(name = "{0} should be invalid")
@MethodSource("numericOutOfBoundsOperandProvider")
Expand Down
Loading

0 comments on commit fd38c56

Please sign in to comment.