diff --git a/CHANGELOG.md b/CHANGELOG.md index f87a4f5..29869eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## [0.0.1-RC3] +- Simplified NamespaceDataSource to use a supplier instead of hierarchy for static and dynamic source +- LeiaBundle: Fixed duplicate instantiation of schema repository +- TimeBasedDataProvider: Fixed the initial delay of executor to prevent multiple invocation of update on startup +- Schema Validator: Removed instance creation of schema class. It's not required for static validations. +- SchemaValidationUtils - Fixed strict type validation + ## [0.0.1-RC2] - Added tests to the core functionality to schemaValidator, refresher, client, core and models - Fixed the validation bug in SchemaValidationUtils. field.getType().isInstanceOf is a miss, Class.isAssignable is the correct way to check for class assignments. diff --git a/README.md b/README.md index 25e3a34..5bf6d96 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ And com.grookage.leia leia-bom - 0.0.1-RC2 + 0.0.1-RC3 ``` diff --git a/leia-bom/pom.xml b/leia-bom/pom.xml index 0234f26..adb6f7f 100644 --- a/leia-bom/pom.xml +++ b/leia-bom/pom.xml @@ -21,7 +21,7 @@ com.grookage.leia leia - 0.0.1-RC2 + 0.0.1-RC3 leia-bom diff --git a/leia-client-dropwizard/pom.xml b/leia-client-dropwizard/pom.xml index 30d115a..311af1c 100644 --- a/leia-client-dropwizard/pom.xml +++ b/leia-client-dropwizard/pom.xml @@ -22,7 +22,7 @@ com.grookage.leia leia-parent - 0.0.1-RC2 + 0.0.1-RC3 ../leia-parent diff --git a/leia-client/pom.xml b/leia-client/pom.xml index 7954708..3294203 100644 --- a/leia-client/pom.xml +++ b/leia-client/pom.xml @@ -22,7 +22,7 @@ com.grookage.leia leia-parent - 0.0.1-RC2 + 0.0.1-RC3 ../leia-parent diff --git a/leia-client/src/test/java/com/grookage/leia/client/datasource/NamespaceDataSourceTest.java b/leia-client/src/test/java/com/grookage/leia/client/datasource/NamespaceDataSourceTest.java index 93d5505..f89f1fe 100644 --- a/leia-client/src/test/java/com/grookage/leia/client/datasource/NamespaceDataSourceTest.java +++ b/leia-client/src/test/java/com/grookage/leia/client/datasource/NamespaceDataSourceTest.java @@ -27,10 +27,6 @@ class NamespaceDataSourceTest { @Test void testNamespaceDataSource() { - final var staticSource = new StaticNamespaceDataSource(Set.of("testNamespace")); - Assertions.assertNotNull(staticSource); - Assertions.assertNotNull(staticSource.getNamespaces()); - Assertions.assertFalse(staticSource.getNamespaces().isEmpty()); final var supplier = new Supplier>() { private static final AtomicReference supplierMarker = new AtomicReference<>(false); @@ -38,21 +34,19 @@ void testNamespaceDataSource() { @Override public Set get() { return supplierMarker.get() ? - Set.of("testNamespace") : Set.of(); + Set.of("testNamespace") : Set.of(); } public void mark() { supplierMarker.set(true); } }; - final var suppliedSource = new DynamicNamespaceDataSource(supplier); + final var suppliedSource = new NamespaceDataSource(supplier); Assertions.assertNotNull(suppliedSource.getNamespaces()); Assertions.assertTrue(suppliedSource.getNamespaces().isEmpty()); supplier.mark(); Assertions.assertNotNull(suppliedSource.getNamespaces()); Assertions.assertFalse(suppliedSource.getNamespaces().isEmpty()); - - } } diff --git a/leia-core/pom.xml b/leia-core/pom.xml index 721adb3..92ef11a 100644 --- a/leia-core/pom.xml +++ b/leia-core/pom.xml @@ -21,7 +21,7 @@ com.grookage.leia leia-parent - 0.0.1-RC2 + 0.0.1-RC3 ../leia-parent diff --git a/leia-dropwizard-es/pom.xml b/leia-dropwizard-es/pom.xml index 9676418..b6595b5 100644 --- a/leia-dropwizard-es/pom.xml +++ b/leia-dropwizard-es/pom.xml @@ -22,7 +22,7 @@ com.grookage.leia leia-parent - 0.0.1-RC2 + 0.0.1-RC3 ../leia-parent diff --git a/leia-dropwizard/pom.xml b/leia-dropwizard/pom.xml index 8bf62a6..f783848 100644 --- a/leia-dropwizard/pom.xml +++ b/leia-dropwizard/pom.xml @@ -21,7 +21,7 @@ com.grookage.leia leia-parent - 0.0.1-RC2 + 0.0.1-RC3 ../leia-parent diff --git a/leia-elastic/pom.xml b/leia-elastic/pom.xml index d13dcca..4c99a6d 100644 --- a/leia-elastic/pom.xml +++ b/leia-elastic/pom.xml @@ -22,7 +22,7 @@ com.grookage.leia leia-parent - 0.0.1-RC2 + 0.0.1-RC3 ../leia-parent diff --git a/leia-models/pom.xml b/leia-models/pom.xml index b7310a0..56ddf57 100644 --- a/leia-models/pom.xml +++ b/leia-models/pom.xml @@ -21,7 +21,7 @@ com.grookage.leia leia-parent - 0.0.1-RC2 + 0.0.1-RC3 ../leia-parent diff --git a/leia-parent/pom.xml b/leia-parent/pom.xml index f2ef349..7e0eec9 100644 --- a/leia-parent/pom.xml +++ b/leia-parent/pom.xml @@ -21,7 +21,7 @@ com.grookage.leia leia-bom - 0.0.1-RC2 + 0.0.1-RC3 ../leia-bom diff --git a/leia-refresher/pom.xml b/leia-refresher/pom.xml index d86ff9b..f20d483 100644 --- a/leia-refresher/pom.xml +++ b/leia-refresher/pom.xml @@ -21,7 +21,7 @@ com.grookage.leia leia-parent - 0.0.1-RC2 + 0.0.1-RC3 ../leia-parent diff --git a/leia-refresher/src/main/java/com/grookage/leia/provider/TimeBasedDataProvider.java b/leia-refresher/src/main/java/com/grookage/leia/provider/TimeBasedDataProvider.java index 1f34844..e81314b 100644 --- a/leia-refresher/src/main/java/com/grookage/leia/provider/TimeBasedDataProvider.java +++ b/leia-refresher/src/main/java/com/grookage/leia/provider/TimeBasedDataProvider.java @@ -63,7 +63,8 @@ public TimeBasedDataProvider(Supplier configSupplier, T initialDefaultValue, } public void start() { - this.executorService.scheduleWithFixedDelay(this.updater, 0L, this.delay, this.timeUnit); + this.executorService.scheduleWithFixedDelay(this.updater, this.delay, this.delay, this.timeUnit); + this.update(); } public void stop() { diff --git a/leia-repository/pom.xml b/leia-repository/pom.xml index 50bc187..0a4c97d 100644 --- a/leia-repository/pom.xml +++ b/leia-repository/pom.xml @@ -22,7 +22,7 @@ com.grookage.leia leia-parent - 0.0.1-RC2 + 0.0.1-RC3 ../leia-parent diff --git a/leia-schema-validator/pom.xml b/leia-schema-validator/pom.xml index fa0ccc5..5799cea 100644 --- a/leia-schema-validator/pom.xml +++ b/leia-schema-validator/pom.xml @@ -22,7 +22,7 @@ com.grookage.leia leia-parent - 0.0.1-RC2 + 0.0.1-RC3 ../leia-parent diff --git a/leia-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java b/leia-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java index 7131aab..9b32377 100644 --- a/leia-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java +++ b/leia-schema-validator/src/main/java/com/grookage/leia/validator/utils/SchemaValidationUtils.java @@ -16,6 +16,7 @@ package com.grookage.leia.validator.utils; +import com.google.common.collect.Sets; import com.grookage.leia.models.attributes.*; import com.grookage.leia.models.schema.SchemaDetails; import com.grookage.leia.models.schema.SchemaValidationType; @@ -34,19 +35,29 @@ public static boolean valid(final SchemaDetails schemaDetails, final Class klass) { final var fields = getAllFields(klass); final var validationType = schemaDetails.getValidationType(); - final var attributedNotListed = fields.stream().filter(each -> !schemaDetails.hasAttribute(each.getName())) - .collect(Collectors.toSet()); - if (!attributedNotListed.isEmpty() && - validationType == SchemaValidationType.STRICT) { - log.error("There seems to be attributes present in the class definition that are not in the schema. " + - "[Validation Failed]. The extra attributes are {}", - attributedNotListed); - return false; - } + if (validationType == SchemaValidationType.STRICT && !strictlyMatching(schemaDetails, fields)) return false; return schemaDetails.getAttributes().stream().allMatch(each -> valid(each, fields)); } + private static boolean strictlyMatching(SchemaDetails schemaDetails, List fields) { + final var fieldNames = fields.stream() + .map(Field::getName) + .map(String::toUpperCase) + .collect(Collectors.toSet()); + final var attributesListed = schemaDetails.getAttributes().stream() + .map(SchemaAttribute::getName) + .map(String::toUpperCase) + .collect(Collectors.toSet()); + final var mismatchedAttributes = Sets.symmetricDifference(fieldNames, attributesListed); + if (mismatchedAttributes.isEmpty()) { + return true; + } + log.error("There seems to be a mismatch in the attributes present in the class definition and schema. " + + "[Validation Failed]. The attributes are {}", mismatchedAttributes); + return false; + } + private static List getAllFields(Class type) { List fields = new ArrayList<>(); for (Class c = type; c != null; c = c.getSuperclass()) { diff --git a/pom.xml b/pom.xml index a433ae9..3f9eb78 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ 4.0.0 com.grookage.leia leia - 0.0.1-RC2 + 0.0.1-RC3 pom Leia