jkevan commented on code in PR #426:
URL: https://github.com/apache/unomi/pull/426#discussion_r879463136
##########
itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java:
##########
@@ -56,87 +54,185 @@ public class JSONSchemaIT extends BaseIT {
@Filter(timeout = 600000)
protected SchemaService schemaService;
- @Inject
- @Filter(timeout = 600000)
- protected PersistenceService persistenceService;
-
@Before
public void setUp() throws InterruptedException {
keepTrying("Couldn't find json schema endpoint", () ->
get(JSONSCHEMA_URL, List.class), Objects::nonNull, DEFAULT_TRYING_TIMEOUT,
DEFAULT_TRYING_TRIES);
}
@After
- public void tearDown() {
-
schemaService.deleteSchema("https://unomi.apache.org/schemas/json/events/testEventType/1-0-0");
+ public void tearDown() throws InterruptedException {
+ removeItems(JsonSchemaWrapper.class, Event.class);
+ // ensure all schemas have been cleaned from schemaService.
+ keepTrying("Couldn't find json schemas",
Review Comment:
Thx it have been updated !
##########
itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java:
##########
@@ -56,87 +54,185 @@ public class JSONSchemaIT extends BaseIT {
@Filter(timeout = 600000)
protected SchemaService schemaService;
- @Inject
- @Filter(timeout = 600000)
- protected PersistenceService persistenceService;
-
@Before
public void setUp() throws InterruptedException {
keepTrying("Couldn't find json schema endpoint", () ->
get(JSONSCHEMA_URL, List.class), Objects::nonNull, DEFAULT_TRYING_TIMEOUT,
DEFAULT_TRYING_TRIES);
}
@After
- public void tearDown() {
-
schemaService.deleteSchema("https://unomi.apache.org/schemas/json/events/testEventType/1-0-0");
+ public void tearDown() throws InterruptedException {
+ removeItems(JsonSchemaWrapper.class, Event.class);
+ // ensure all schemas have been cleaned from schemaService.
+ keepTrying("Couldn't find json schemas",
+ () -> schemaService.getInstalledJsonSchemaIds(),
+ (list) ->
(!list.contains("https://unomi.apache.org/schemas/json/events/dummy/1-0-0") &&
+
!list.contains("https://unomi.apache.org/schemas/json/events/dummy/properties/1-0-0")),
+ DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
}
@Test
- public void testGetJsonSchemasMetadatas() throws InterruptedException {
- List jsonSchemas = get(JSONSCHEMA_URL, List.class);
- assertTrue("JSON schema list should be empty", jsonSchemas.isEmpty());
+ public void testValidation_SaveDeleteSchemas() throws
InterruptedException, IOException {
+ // check that event is not valid at first
+
assertFalse(schemaService.isValid(resourceAsString("schemas/event-dummy-valid.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"));
+
+ // Push schemas
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy.json"));
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties.json"));
+ keepTrying("Event should be valid",
+ () ->
schemaService.isValid(resourceAsString("schemas/event-dummy-valid.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"),
+ isValid -> isValid,
+ DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
- post(JSONSCHEMA_URL, "schemas/events/test-event-type.json",
ContentType.TEXT_PLAIN);
+ // Test multiple invalid event:
+ // unevaluated property at root:
+
assertFalse(schemaService.isValid(resourceAsString("schemas/event-dummy-invalid-1.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"));
+ // unevaluated property in properties:
+
assertFalse(schemaService.isValid(resourceAsString("schemas/event-dummy-invalid-2.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"));
+ // bad type number but should be string:
+
assertFalse(schemaService.isValid(resourceAsString("schemas/event-dummy-invalid-3.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"));
+
+ // remove one of the schema:
+
assertTrue(schemaService.deleteSchema("https://unomi.apache.org/schemas/json/events/dummy/properties/1-0-0"));
+ keepTrying("Event should be invalid since of the schema have been
deleted",
+ () ->
schemaService.isValid(resourceAsString("schemas/event-dummy-valid.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"),
+ isValid -> !isValid,
+ DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
+ }
- jsonSchemas = keepTrying("Couldn't find json schemas", () ->
get(JSONSCHEMA_URL, List.class), (list) -> !list.isEmpty(),
+ @Test
+ public void testValidation_UpdateSchema() throws InterruptedException,
IOException {
+ // check that event is not valid at first
+
assertFalse(schemaService.isValid(resourceAsString("schemas/event-dummy-valid.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"));
+
+ // Push schemas
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy.json"));
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties.json"));
+ keepTrying("Event should be valid",
+ () ->
schemaService.isValid(resourceAsString("schemas/event-dummy-valid.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"),
+ isValid -> isValid,
+ DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
+
+ // Test the invalid event, that use the new prop "invalidPropName" in
properties:
+
assertFalse(schemaService.isValid(resourceAsString("schemas/event-dummy-invalid-2.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"));
+
+ // update the schema to allow "invalidPropName":
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties-updated.json"));
+ keepTrying("Event should be valid since of the schema have been
updated",
+ () ->
schemaService.isValid(resourceAsString("schemas/event-dummy-invalid-2.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"),
+ isValid -> isValid,
DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
- assertFalse("JSON schema list should not be empty",
jsonSchemas.isEmpty());
- assertEquals("JSON schema list should not be empty", 1,
jsonSchemas.size());
}
@Test
- public void testSaveNewValidJSONSchema() throws InterruptedException {
+ public void testExtension_SaveDelete() throws InterruptedException,
IOException {
+ // Push base schemas
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy.json"));
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties.json"));
+ keepTrying("Event should be valid",
+ () ->
schemaService.isValid(resourceAsString("schemas/event-dummy-valid.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"),
+ isValid -> isValid,
+ DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
- assertTrue("JSON schema list should be empty",
persistenceService.getAllItems(JsonSchemaWrapper.class).isEmpty());
+ // check that extended event is not valid at first
+
assertFalse(schemaService.isValid(resourceAsString("schemas/event-dummy-extended.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"));
- CloseableHttpResponse response = post(JSONSCHEMA_URL,
"schemas/events/test-event-type.json", ContentType.TEXT_PLAIN);
+ // register both extensions (for root event and the properties level)
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy-extension.json"));
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties-extension.json"));
+ keepTrying("Extended event should be valid since of the extensions
have been deployed",
+ () ->
schemaService.isValid(resourceAsString("schemas/event-dummy-extended.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"),
+ isValid -> isValid,
+ DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
- assertEquals("Invalid response code", 200,
response.getStatusLine().getStatusCode());
- List jsonSchemas = keepTrying("Couldn't find json schemas", () ->
get(JSONSCHEMA_URL, List.class), (list) -> !list.isEmpty(),
+ // delete one of the extension
+
schemaService.deleteSchema("https://unomi.apache.org/schemas/json/events/dummy/properties/extension/1-0-0");
+ keepTrying("Extended event should be invalid again, one necessary
extension have been removed",
+ () ->
schemaService.isValid(resourceAsString("schemas/event-dummy-extended.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"),
+ isValid -> !isValid,
DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
- assertFalse("JSON schema list should not be empty",
jsonSchemas.isEmpty());
}
@Test
- public void testSavePredefinedJSONSchema() throws IOException {
- assertTrue("JSON schema list should be empty",
persistenceService.getAllItems(JsonSchemaWrapper.class).isEmpty());
- try (CloseableHttpResponse response = post(JSONSCHEMA_URL,
"schemas/events/predefined-event-type.json", ContentType.TEXT_PLAIN)) {
- assertEquals("Unable to save schema", 400,
response.getStatusLine().getStatusCode());
- }
+ public void testExtension_Update() throws InterruptedException,
IOException {
+ // Push base schemas
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy.json"));
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties.json"));
+ keepTrying("Event should be valid",
+ () ->
schemaService.isValid(resourceAsString("schemas/event-dummy-valid.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"),
+ isValid -> isValid,
+ DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
+
+ // check that extended event is not valid at first
+
assertFalse(schemaService.isValid(resourceAsString("schemas/event-dummy-extended.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"));
+
+ // register both extensions (for root event and the properties level)
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy-extension.json"));
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties-extension.json"));
+ keepTrying("Extended event should be valid since of the extensions
have been deployed",
+ () ->
schemaService.isValid(resourceAsString("schemas/event-dummy-extended.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"),
+ isValid -> isValid,
+ DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
+
+ // check that extended event 2 is not valid due to usage of
unevaluatedProperty not bring by schemas or extensions
+
assertFalse(schemaService.isValid(resourceAsString("schemas/event-dummy-extended-2.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"));
+
+ // Update extensions to allow the extended event 2
+
schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties-extension-2.json"));
+ keepTrying("Extended event 2 should be valid since of the extensions
have been updated",
+ () ->
schemaService.isValid(resourceAsString("schemas/event-dummy-extended-2.json"),
"https://unomi.apache.org/schemas/json/events/dummy/1-0-0"),
+ isValid -> isValid,
+ DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
}
@Test
- public void testDeleteJSONSchema() throws InterruptedException {
- assertTrue("JSON schema list should be empty",
persistenceService.getAllItems(JsonSchemaWrapper.class).isEmpty());
+ public void testEndPoint_GetInstalledJsonSchemas() throws
InterruptedException {
+ List<String> jsonSchemas = get(JSONSCHEMA_URL, List.class);
+ assertFalse("JSON schema list should not be empty, it should contains
predefined Unomi schemas", jsonSchemas.isEmpty());
Review Comment:
Thx it have been updated !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]