Skip to content

Commit

Permalink
First implementation of validation spec parsing -- WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stijn-dejongh committed Nov 20, 2024
1 parent 8ce0daf commit 1f1e1fb
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 94 deletions.
18 changes: 17 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>be.sddevelopment</groupId>
<groupId>be.sddevelopment.validation</groupId>
<artifactId>modular-validators</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
Expand All @@ -15,6 +15,22 @@


<dependencies>
<dependency>
<groupId>be.sddevelopment.commons</groupId>
<artifactId>commons-kernel</artifactId>
</dependency>
<dependency>
<groupId>be.sddevelopment.commons</groupId>
<artifactId>commons</artifactId>
</dependency>

<!-- BEGIN TEST SCOPE -->
<dependency>
<groupId>be.sddevelopment.commons</groupId>
<artifactId>commons-testing</artifactId>
<scope>test</scope>
</dependency>

<!-- BEGIN TEST SCOPE -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package be.sddevelopment.validation.core;

import be.sddevelopment.commons.testing.naming.ReplaceUnderscoredCamelCasing;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.commons.util.StringUtils;
Expand All @@ -21,6 +23,7 @@

@DisplayName("Constrainables")
@ExtendWith({MockitoExtension.class})
@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class)
class ConstrainedTest implements WithAssertions {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package be.sddevelopment.validation.core;

import be.sddevelopment.commons.testing.naming.ReplaceUnderscoredCamelCasing;
import be.sddevelopment.validation.CheckedTestUtils;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.StringUtils;

Expand All @@ -14,6 +16,7 @@
import static be.sddevelopment.validation.core.Reason.passed;

@DisplayName("Constraints / Rules")
@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class)
class ConstraintTest implements WithAssertions {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package be.sddevelopment.validation.core;

import be.sddevelopment.commons.testing.naming.ReplaceUnderscoredCamelCasing;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Test;

import static be.sddevelopment.validation.core.Checks.haveNonNullField;

@DisplayName("Constraints utility class")
@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class)
class ContrainsTest implements WithAssertions {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package be.sddevelopment.validation.core;

import be.sddevelopment.commons.testing.naming.ReplaceUnderscoredCamelCasing;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Test;

import static be.sddevelopment.validation.core.Reason.failed;
import static be.sddevelopment.validation.core.Reason.passed;

@DisplayName("InvalidObject Exceptions")
@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class)
class InvalidObjectExceptionTest implements WithAssertions {

@Test
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package be.sddevelopment.validation.specs.code_quality;

import be.sddevelopment.commons.testing.conventions.CodeConventions;
import be.sddevelopment.commons.testing.naming.ReplaceUnderscoredCamelCasing;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.domain.JavaConstructor;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchCondition;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.ConditionEvents;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import static com.tngtech.archunit.core.domain.JavaModifier.FINAL;
import static com.tngtech.archunit.lang.SimpleConditionEvent.satisfied;
import static com.tngtech.archunit.lang.SimpleConditionEvent.violated;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static com.tngtech.archunit.library.GeneralCodingRules.*;
import static org.junit.platform.commons.util.ReflectionUtils.makeAccessible;

@DisplayName("Complies with code conventions")
@AnalyzeClasses(packages = "be.sddevelopment.validation.core")
public class ConventionsAdherenceTests implements CodeConventions {

/* This class can be empty, it is used to run the test of its parent interface
* CodeConventions. This interface contains the tests for the code conventions,
* and will execute them based on the {@code @AnalyzeClasses} annotation.
*/

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package be.sddevelopment.validation.specs.usage;

import be.sddevelopment.commons.testing.naming.ReplaceUnderscoredCamelCasing;
import be.sddevelopment.validation.core.*;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

Expand All @@ -23,6 +25,7 @@
import static org.apache.commons.lang3.StringUtils.containsIgnoreCase;

@DisplayName("Basic Usage")
@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class)
class BasicUsageTest implements WithAssertions {

@Nested
Expand Down
32 changes: 30 additions & 2 deletions dsl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>be.sddevelopment</groupId>
<groupId>be.sddevelopment.validation</groupId>
<artifactId>modular-validators</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
Expand All @@ -26,11 +26,24 @@

<dependencies>
<dependency>
<groupId>be.sddevelopment</groupId>
<groupId>be.sddevelopment.validation</groupId>
<artifactId>core</artifactId>
</dependency>
<dependency>
<groupId>be.sddevelopment.commons</groupId>
<artifactId>commons-kernel</artifactId>
</dependency>
<dependency>
<groupId>be.sddevelopment.commons</groupId>
<artifactId>commons</artifactId>
</dependency>

<!-- BEGIN TEST SCOPE -->
<dependency>
<groupId>be.sddevelopment.commons</groupId>
<artifactId>commons-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -51,6 +64,21 @@
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package be.sddevelopment.validation.dsl;

import be.sddevelopment.commons.access.AccessProtectionUtils;
import be.sddevelopment.commons.annotations.Utility;
import be.sddevelopment.validation.core.ModularRuleset;

import java.nio.file.Path;

import static be.sddevelopment.commons.access.AccessProtectionUtils.utilityClassConstructor;

@Utility
public final class ValidatorParser {

private ValidatorParser() {
utilityClassConstructor();
}

public static ModularRuleset fromSpecification(Path validationSpec) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package be.sddevelopment.validation.dsl;

import be.sddevelopment.commons.testing.conventions.CodeConventions;
import be.sddevelopment.commons.testing.naming.ReplaceUnderscoredCamelCasing;
import com.tngtech.archunit.junit.AnalyzeClasses;
import org.junit.jupiter.api.DisplayNameGeneration;

@AnalyzeClasses(packages = "be.sddevelopment.commons")
@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class)
public class ConventionsAdherenceTests implements CodeConventions {

/* This class can be empty, it is used to run the test of its parent interface
* CodeConventions. This interface contains the tests for the code conventions,
* and will execute them based on the {@code @AnalyzeClasses} annotation.
*/

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package be.sddevelopment.validation.dsl;

import be.sddevelopment.commons.testing.naming.ReplaceUnderscoredCamelCasing;
import be.sddevelopment.validation.core.ModularRuleset;
import be.sddevelopment.validation.core.Rationale;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Paths;

@DisplayName("Parsing of validation rules")
@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class)
class ValidatorParserTest implements WithAssertions {

@Test
void createsAValidatorBasedOnSpecifications() throws IOException {
var validationSpec = Paths.get("src/test/resources/parsing/star_wars/STARWARS_VALIDATOR.puml");
var dataFile = Paths.get("src/test/resources/parsing/star_wars/STARWARS_INPUT_DATA.csv");
assertThat(validationSpec).exists();
assertThat(validationSpec).isRegularFile();

var validator = ValidatorParser.fromSpecification(validationSpec);

assertThat(validator).isNotNull();

var result = validator.check(dataFile);

assertThat(result).isNotNull()
.matches(Rationale::isPassing);
}


}
Loading

0 comments on commit 1f1e1fb

Please sign in to comment.