-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from grookage/v1
ValidationUtils Bug Fix + Tests
- Loading branch information
Showing
43 changed files
with
1,279 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
leia-client/src/test/java/com/grookage/leia/client/SchemaClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2024. Koushik R <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.grookage.leia.client; | ||
|
||
import com.grookage.leia.client.refresher.LeiaClientRefresher; | ||
import com.grookage.leia.models.ResourceHelper; | ||
import com.grookage.leia.models.schema.SchemaDetails; | ||
import com.grookage.leia.models.schema.SchemaKey; | ||
import com.grookage.leia.validator.LeiaSchemaValidator; | ||
import lombok.Builder; | ||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
class SchemaClientTest { | ||
|
||
static class TestableSchemaClient extends AbstractSchemaClient { | ||
|
||
@Builder | ||
public TestableSchemaClient(LeiaClientRefresher refresher, LeiaSchemaValidator schemaValidator) { | ||
super(refresher, schemaValidator); | ||
} | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
void testSchemaClient() { | ||
final var clientRefresher = Mockito.mock(LeiaClientRefresher.class); | ||
final var schemaValidator = Mockito.mock(LeiaSchemaValidator.class); | ||
final var schemaClient = TestableSchemaClient.builder() | ||
.refresher(clientRefresher) | ||
.schemaValidator(schemaValidator) | ||
.build(); | ||
Assertions.assertNull(schemaClient.getSchemaDetails()); | ||
Assertions.assertThrows(IllegalStateException.class, () -> schemaClient.getSchemaDetails(Set.of("testNamespace"))); | ||
Assertions.assertFalse(schemaClient.valid(SchemaKey.builder().build())); | ||
final var schemaDetails = ResourceHelper | ||
.getResource("schema/schemaDetails.json", SchemaDetails.class); | ||
Assertions.assertNotNull(schemaDetails); | ||
final var schemaKey = schemaDetails.getSchemaKey(); | ||
Mockito.when(clientRefresher.getConfiguration()).thenReturn(List.of(schemaDetails)); | ||
final var details = schemaClient.getSchemaDetails(); | ||
Assertions.assertNotNull(details); | ||
Assertions.assertTrue(schemaClient.getSchemaDetails(Set.of()).isEmpty()); | ||
Assertions.assertTrue(schemaClient.getSchemaDetails(Set.of("random")).isEmpty()); | ||
Assertions.assertFalse(schemaClient.getSchemaDetails(Set.of("testNamespace")).isEmpty()); | ||
Assertions.assertFalse(schemaClient.valid(schemaKey)); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
leia-client/src/test/java/com/grookage/leia/client/datasource/NamespaceDataSourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2024. Koushik R <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.grookage.leia.client.datasource; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.Supplier; | ||
|
||
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<Set<String>>() { | ||
|
||
private static final AtomicReference<Boolean> supplierMarker = new AtomicReference<>(false); | ||
|
||
@Override | ||
public Set<String> get() { | ||
return supplierMarker.get() ? | ||
Set.of("testNamespace") : Set.of(); | ||
} | ||
|
||
public void mark() { | ||
supplierMarker.set(true); | ||
} | ||
}; | ||
final var suppliedSource = new DynamicNamespaceDataSource(supplier); | ||
Assertions.assertNotNull(suppliedSource.getNamespaces()); | ||
Assertions.assertTrue(suppliedSource.getNamespaces().isEmpty()); | ||
|
||
supplier.mark(); | ||
Assertions.assertNotNull(suppliedSource.getNamespaces()); | ||
Assertions.assertFalse(suppliedSource.getNamespaces().isEmpty()); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
leia-core/src/test/java/com/grookage/leia/core/ingestion/hub/SchemaProcessorHubTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2024. Koushik R <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.grookage.leia.core.ingestion.hub; | ||
|
||
import com.grookage.leia.core.ingestion.VersionIDGenerator; | ||
import com.grookage.leia.models.schema.engine.SchemaEvent; | ||
import com.grookage.leia.repository.SchemaRepository; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
class SchemaProcessorHubTest { | ||
|
||
@Test | ||
void testSchemaProcessorHub() { | ||
final var schemaRepository = Mockito.mock(SchemaRepository.class); | ||
final var generator = new VersionIDGenerator() { | ||
@Override | ||
public String generateVersionId(String prefix) { | ||
return "V1234"; | ||
} | ||
}; | ||
final var hub = SchemaProcessorHub.of() | ||
.withSchemaRepository(schemaRepository) | ||
.withVersionIDGenerator(generator) | ||
.build(); | ||
Assertions.assertNotNull(hub.getProcessor(SchemaEvent.CREATE_SCHEMA).orElse(null)); | ||
Assertions.assertThrows(NullPointerException.class, () -> SchemaProcessorHub.of() | ||
.withVersionIDGenerator(generator) | ||
.build()); | ||
Assertions.assertThrows(NullPointerException.class, () -> SchemaProcessorHub.of() | ||
.withSchemaRepository(schemaRepository) | ||
.build()); | ||
} | ||
} |
Oops, something went wrong.