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

Commit

Permalink
feat(#1508): Removed AtomicConstraintType
Browse files Browse the repository at this point in the history
  • Loading branch information
cdowding-sl committed Oct 30, 2019
1 parent 27603d5 commit 119e79c
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 114 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,45 @@

package com.scottlogic.deg.orchestrator.violate;

import com.scottlogic.deg.common.profile.AtomicConstraintType;
import com.scottlogic.deg.generator.profile.constraints.atomic.*;
import com.scottlogic.deg.profile.common.ConstraintType;

public class AtomicConstraintTypeMapper {
public Class toConstraintClass(AtomicConstraintType type) {
public Class toConstraintClass(ConstraintType type) {
switch (type) {
case IS_NULL:
return IsNullConstraint.class;
case MATCHES_REGEX:
return MatchesRegexConstraint.class;
case CONTAINS_REGEX:
return ContainsRegexConstraint.class;
case HAS_LENGTH:
case OF_LENGTH:
return StringHasLengthConstraint.class;
case IS_STRING_LONGER_THAN:
case LONGER_THAN:
return IsStringLongerThanConstraint.class;
case IS_STRING_SHORTER_THAN:
case SHORTER_THAN:
return IsStringShorterThanConstraint.class;
case IS_GREATER_THAN_CONSTANT:
case GREATER_THAN:
return IsGreaterThanConstantConstraint.class;
case IS_GREATER_THAN_OR_EQUAL_TO_CONSTANT:
case GREATER_THAN_OR_EQUAL_TO:
return IsGreaterThanOrEqualToConstantConstraint.class;
case IS_LESS_THAN_CONSTANT:
case LESS_THAN:
return IsLessThanConstantConstraint.class;
case IS_LESS_THAN_OR_EQUAL_TO_CONSTANT:
case LESS_THAN_OR_EQUAL_TO:
return IsLessThanOrEqualToConstantConstraint.class;
case IS_AFTER_CONSTANT_DATE_TIME:
case AFTER:
return IsAfterConstantDateTimeConstraint.class;
case IS_AFTER_OR_EQUAL_TO_CONSTANT_DATE_TIME:
case AFTER_OR_AT:
return IsAfterOrEqualToConstantDateTimeConstraint.class;
case IS_BEFORE_CONSTANT_DATE_TIME:
case BEFORE:
return IsBeforeConstantDateTimeConstraint.class;
case IS_BEFORE_OR_EQUAL_TO_CONSTANT_DATE_TIME:
case BEFORE_OR_AT:
return IsBeforeOrEqualToConstantDateTimeConstraint.class;
case IS_GRANULAR_TO:
case GRANULAR_TO:
return IsGranularToNumericConstraint.class;
case IS_EQUAL_TO_CONSTANT:
case EQUAL_TO:
return EqualToConstraint.class;
case IS_IN_SET:
case IN_SET:
return IsInSetConstraint.class;
default:
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.inject.Injector;
import com.google.inject.Module;
import com.scottlogic.deg.orchestrator.generate.GenerateCommandLine;
import com.scottlogic.deg.common.profile.AtomicConstraintType;
import com.scottlogic.deg.profile.common.ConstraintType;
import picocli.CommandLine;

import java.io.IOException;
Expand Down Expand Up @@ -50,9 +50,9 @@ public Integer call() throws IOException {
names = {"--dont-violate"},
arity = "0..",
description = "Choose types of constraint should not be violated")
private List<AtomicConstraintType> constraintsToNotViolate;
private List<ConstraintType> constraintsToNotViolate;

public List<AtomicConstraintType> getConstraintsToNotViolate() {
public List<ConstraintType> getConstraintsToNotViolate() {
return constraintsToNotViolate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package com.scottlogic.deg.orchestrator.violate;

import com.scottlogic.deg.orchestrator.guice.AllConfigSource;
import com.scottlogic.deg.common.profile.AtomicConstraintType;
import com.scottlogic.deg.profile.common.ConstraintType;

import java.util.List;

public interface ViolateConfigSource extends AllConfigSource {
List<AtomicConstraintType> getConstraintsToNotViolate();
List<ConstraintType> getConstraintsToNotViolate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.scottlogic.deg.orchestrator.cucumber.testframework.steps;

import com.fasterxml.jackson.core.JsonParseException;
import com.scottlogic.deg.common.profile.AtomicConstraintType;
import com.scottlogic.deg.generator.config.detail.CombinationStrategyType;
import com.scottlogic.deg.generator.config.detail.DataGenerationType;
import com.scottlogic.deg.orchestrator.cucumber.testframework.utils.*;
Expand Down Expand Up @@ -81,7 +80,7 @@ public void setTheCombinationStrategy(CombinationStrategyType strategy) {

@When("we do not violate any {operator} constraints")
public void constraintTypeIsNotViolated(String operator) {
this.state.addConstraintToNotViolate(AtomicConstraintType.fromText(operator));
this.state.addConstraintToNotViolate(ConstraintType.fromPropertyName(operator));
}

@Given("the data requested is {generationMode}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import com.scottlogic.deg.generator.config.detail.DataGenerationType;
import com.scottlogic.deg.orchestrator.cucumber.testframework.utils.CucumberGenerationMode;
import com.scottlogic.deg.orchestrator.cucumber.testframework.utils.GeneratorTestUtilities;
import com.scottlogic.deg.profile.common.ConstraintType;
import com.scottlogic.deg.profile.reader.InvalidProfileException;
import com.scottlogic.deg.common.profile.AtomicConstraintType;
import cucumber.api.TypeRegistry;
import cucumber.api.TypeRegistryConfigurer;
import io.cucumber.cucumberexpressions.ParameterType;
Expand All @@ -34,7 +34,7 @@

public class TypeRegistryConfiguration implements TypeRegistryConfigurer {

private final Set<AtomicConstraintType> allOperators = new HashSet<>(Arrays.asList(AtomicConstraintType.values()));
private final Set<ConstraintType> allOperators = new HashSet<>(Arrays.asList(ConstraintType.values()));

@Override
public Locale locale() {
Expand Down Expand Up @@ -135,10 +135,10 @@ private String extractConstraint(String gherkinConstraint) {
.collect(Collectors.joining());
}

private String getHumanReadableOperationRegex(Set<AtomicConstraintType> types) {
private String getHumanReadableOperationRegex(Set<ConstraintType> types) {
return
types.stream()
.map(act -> act.toString().replaceAll("([a-z])([A-Z]+)", "$1 $2").toLowerCase())
.map(act -> act.propertyName.replaceAll("([a-z])([A-Z]+)", "$1 $2").toLowerCase())
.collect(Collectors.joining("|", "(", ")"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.scottlogic.deg.orchestrator.guice.AllConfigSource;
import com.scottlogic.deg.orchestrator.violate.ViolateConfigSource;
import com.scottlogic.deg.output.guice.OutputFormat;
import com.scottlogic.deg.common.profile.AtomicConstraintType;
import com.scottlogic.deg.profile.common.ConstraintType;

import java.io.File;
import java.nio.file.Path;
Expand All @@ -49,7 +49,7 @@ public CombinationStrategyType getCombinationStrategyType() {
}

@Override
public List<AtomicConstraintType> getConstraintsToNotViolate() {
public List<ConstraintType> getConstraintsToNotViolate() {
return state.getConstraintsToNotViolate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.scottlogic.deg.common.profile.SpecificFieldType;
import com.scottlogic.deg.common.profile.AtomicConstraintType;
import com.scottlogic.deg.generator.config.detail.CombinationStrategyType;
import com.scottlogic.deg.generator.config.detail.DataGenerationType;
import com.scottlogic.deg.profile.common.ConstraintType;
Expand Down Expand Up @@ -51,7 +50,7 @@ public class CucumberTestState {

Deque<NestedConstraint> nestedConstraints = new ArrayDeque<>();

private final List<AtomicConstraintType> contstraintsToNotViolate = new ArrayList<>();
private final List<ConstraintType> contstraintsToNotViolate = new ArrayList<>();

public void startCreatingIfConstraint(int total) {
nestedConstraints.push(new NestedConstraint("if", total));
Expand Down Expand Up @@ -119,11 +118,11 @@ public void addException(Exception e) {
this.testExceptions.add(e);
}

public void addConstraintToNotViolate(AtomicConstraintType atomicConstraintType) {
contstraintsToNotViolate.add(atomicConstraintType);
public void addConstraintToNotViolate(ConstraintType constraintType) {
contstraintsToNotViolate.add(constraintType);
}

public List<AtomicConstraintType> getConstraintsToNotViolate() {
public List<ConstraintType> getConstraintsToNotViolate() {
return contstraintsToNotViolate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.scottlogic.deg.orchestrator.violation;

import com.scottlogic.deg.common.profile.AtomicConstraintType;
import com.scottlogic.deg.common.profile.HelixStringLength;
import com.scottlogic.deg.generator.profile.constraints.atomic.IsStringShorterThanConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.StringHasLengthConstraint;
Expand All @@ -25,6 +24,7 @@
import com.scottlogic.deg.orchestrator.violate.AtomicConstraintTypeMapper;
import com.scottlogic.deg.orchestrator.violate.ViolateConfigSource;
import com.scottlogic.deg.orchestrator.violate.ViolationFiltersProvider;
import com.scottlogic.deg.profile.common.ConstraintType;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
Expand Down Expand Up @@ -61,7 +61,7 @@ void whenEmptyConstraintsToViolate_ReturnEmptyListOfViolationFilters() {
void hasLengthConstraintsToViolate_ReturnsOneFilter_ThatDoesNotAcceptHasLengthConstraints() {
ViolateConfigSource configSource = mock(ViolateConfigSource.class);
when(configSource.getConstraintsToNotViolate())
.thenReturn(Arrays.asList(AtomicConstraintType.HAS_LENGTH));
.thenReturn(Arrays.asList(ConstraintType.OF_LENGTH));
ViolationFiltersProvider provider =
new ViolationFiltersProvider(configSource, new AtomicConstraintTypeMapper());

Expand All @@ -84,7 +84,7 @@ void hasLengthConstraintsToViolate_ReturnsOneFilter_ThatDoesNotAcceptHasLengthCo
void twoConstraintsToViolate_ReturnListWithTwoFilter() {
ViolateConfigSource configSource = mock(ViolateConfigSource.class);
when(configSource.getConstraintsToNotViolate())
.thenReturn(Arrays.asList(AtomicConstraintType.HAS_LENGTH, AtomicConstraintType.IS_IN_SET));
.thenReturn(Arrays.asList(ConstraintType.OF_LENGTH, ConstraintType.IN_SET));
ViolationFiltersProvider provider =
new ViolationFiltersProvider(configSource, new AtomicConstraintTypeMapper());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Collectors;

public enum ConstraintType {
EQUAL_TO(ConstraintTypeJsonProperty.EQUAL_TO),
Expand Down Expand Up @@ -47,7 +45,9 @@ public enum ConstraintType {
}

public static ConstraintType fromPropertyName(String propertyName) {
return Arrays.stream(values()).collect(Collectors.toMap(o -> o.propertyName, Function.identity())).get(propertyName);
return Arrays.stream(values())
.filter(x->x.propertyName.equalsIgnoreCase(propertyName))
.findFirst().orElse(null);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@

package com.scottlogic.deg.profile.dtos;

import com.scottlogic.deg.common.profile.AtomicConstraintType;
import com.scottlogic.deg.profile.common.ConstraintType;
import org.junit.Assert;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;

class AtomicConstraintTypeTest {
class ConstraintTypeTest{

@Test
void fromText() {
String greaterThanString = AtomicConstraintType.IS_GREATER_THAN_OR_EQUAL_TO_CONSTANT.getText();
AtomicConstraintType greaterThanOrEqualTo = AtomicConstraintType.fromText(greaterThanString);
String greaterThanString = ConstraintType.GREATER_THAN_OR_EQUAL_TO.propertyName;
ConstraintType greaterThanOrEqualTo = ConstraintType.fromPropertyName(greaterThanString);

Assert.assertThat(greaterThanOrEqualTo, is(AtomicConstraintType.IS_GREATER_THAN_OR_EQUAL_TO_CONSTANT));
Assert.assertThat(greaterThanOrEqualTo, is(ConstraintType.GREATER_THAN_OR_EQUAL_TO));
}

@Test
void fromTextLowerCase() {
AtomicConstraintType greaterThanOrEqualTo = AtomicConstraintType.fromText("shorterthan");
ConstraintType greaterThanOrEqualTo = ConstraintType.fromPropertyName("shorterthan");

Assert.assertThat(greaterThanOrEqualTo, is(AtomicConstraintType.IS_STRING_SHORTER_THAN));
Assert.assertThat(greaterThanOrEqualTo, is(ConstraintType.SHORTER_THAN));
}
}

0 comments on commit 119e79c

Please sign in to comment.