You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by GitBox <gi...@apache.org> on 2022/05/30 13:44:36 UTC

[GitHub] [unomi] jsinovassin opened a new pull request, #429: UNOMI-580 : add endpoint to get schema + clean

jsinovassin opened a new pull request, #429:
URL: https://github.com/apache/unomi/pull/429

   https://issues.apache.org/jira/browse/UNOMI-580


-- 
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: dev-unsubscribe@unomi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [unomi] jkevan merged pull request #429: UNOMI-580 : add endpoint to get schema + clean

Posted by GitBox <gi...@apache.org>.
jkevan merged PR #429:
URL: https://github.com/apache/unomi/pull/429


-- 
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: dev-unsubscribe@unomi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [unomi] jkevan commented on a diff in pull request #429: UNOMI-580 : add endpoint to get schema + clean

Posted by GitBox <gi...@apache.org>.
jkevan commented on code in PR #429:
URL: https://github.com/apache/unomi/pull/429#discussion_r885507188


##########
extensions/json-schema/rest/src/main/java/org/apache/unomi/schema/rest/JsonSchemaEndPoint.java:
##########
@@ -65,6 +69,22 @@ public Set<String> getInstalledJsonSchemaIds() {
         return schemaService.getInstalledJsonSchemaIds();
     }
 
+    /**
+     * Get a schema by it's id
+     *
+     * @param id of the schema
+     * @return Json schema matching the id
+     */
+    @POST
+    @Path("/query")
+    public String getSchema(String id) {
+        JsonSchemaWrapper schema = schemaService.getSchema(id);
+        if (schema != null) {
+            return schema.getSchema().replace("\n", "");
+        }
+        return "";

Review Comment:
   Probably better to return null ?



-- 
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: dev-unsubscribe@unomi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [unomi] jkevan commented on a diff in pull request #429: UNOMI-580 : add endpoint to get schema + clean

Posted by GitBox <gi...@apache.org>.
jkevan commented on code in PR #429:
URL: https://github.com/apache/unomi/pull/429#discussion_r884970022


##########
extensions/json-schema/rest/src/main/java/org/apache/unomi/schema/rest/JsonSchemaEndPoint.java:
##########
@@ -65,6 +68,18 @@ public Set<String> getInstalledJsonSchemaIds() {
         return schemaService.getInstalledJsonSchemaIds();
     }
 
+    /**
+     * Get a schema by it's id
+     *
+     * @param id of the schema
+     * @return Json schema matching the id
+     */
+    @POST
+    @Path("/queryId")

Review Comment:
   may be we could name it "query" directly ? like what we have for the "delete"



##########
extensions/json-schema/rest/src/main/java/org/apache/unomi/schema/rest/JsonSchemaEndPoint.java:
##########
@@ -65,6 +68,18 @@ public Set<String> getInstalledJsonSchemaIds() {
         return schemaService.getInstalledJsonSchemaIds();
     }
 
+    /**
+     * Get a schema by it's id
+     *
+     * @param id of the schema
+     * @return Json schema matching the id
+     */
+    @POST
+    @Path("/queryId")
+    public String getSchema(String id) {
+        return schemaService.getSchema(id).getSchema().replace("\n", "");

Review Comment:
   be careful of NPE here what happen if: schemaService.getSchema(id) is returning null ? :)



##########
extensions/json-schema/rest/src/main/java/org/apache/unomi/schema/rest/JsonSchemaEndPoint.java:
##########
@@ -85,14 +100,13 @@ public Response save(String jsonSchema) {
     }
 
     /**
-     * Deletes a JSON schema.
-     * The id is a Base64 id as the id have is basically an URL
+     * Deletes a JSON schema by it's id.
      *
-     * @param base64JsonSchemaId the identifier of the JSON schema that we want to delete
+     * @param id the identifier of the JSON schema that we want to delete
      */
-    @DELETE
-    @Path("/{base64JsonSchemaId}")
-    public void remove(@PathParam("base64JsonSchemaId") String base64JsonSchemaId) {
-        schemaService.deleteSchema(new String(Base64.getDecoder().decode(base64JsonSchemaId)));
+    @POST
+    @Path("/delete")
+    public void remove(String id) {
+        schemaService.deleteSchema(id);
     }

Review Comment:
   Could be great to have a response here, in case the id doest exist for exemple, or even if the id is matching a predefined schema, in this case the schemaService.deleteSchema is returning false. 
   So it could be great to reflect the status of the service return in the endPoint.



##########
itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java:
##########
@@ -64,155 +72,176 @@ public void setUp() throws InterruptedException {
     public void tearDown() throws InterruptedException {
         removeItems(JsonSchemaWrapper.class, Event.class);
         // ensure all schemas have been cleaned from schemaService.
-        keepTrying("Should not find json schemas anymore",
-                () -> 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);
+        keepTrying("Should not find json schemas anymore", () -> 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 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"));
+        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);
+        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 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"));
+        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"));
+        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"));
+        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);
+        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);
     }
 
     @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"));
+        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);
+        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"));
+        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);
+        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);
     }
 
     @Test
     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);
+        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"));
+        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);
+        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);
 
         // 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);
+        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);
     }
 
     @Test
     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);
+        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"));
+        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);
+        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"));
+        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);
+        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 testEndPoint_GetInstalledJsonSchemas() throws InterruptedException {
+    public void testEndPoint_GetInstalledJsonSchemas() {
         List<String> jsonSchemas = get(JSONSCHEMA_URL, List.class);
         assertFalse("JSON schema list should not be empty, it should contain predefined Unomi schemas", jsonSchemas.isEmpty());
     }
 
     @Test
-    public void testEndPoint_SaveDelete() throws InterruptedException, IOException {
+    public void testEndPoint_GetJsonSchemasById() throws Exception {
+        // Push base schemas
+        schemaService.saveSchema(resourceAsString("schemas/schema-dummy.json"));
+        schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties.json"));
+
+        final String schemaId = "https://unomi.apache.org/schemas/json/events/dummy/1-0-0";
+        final HttpPost request = new HttpPost(getFullUrl(JSONSCHEMA_URL + "/queryId"));
+
+        request.setEntity(new StringEntity(schemaId, ContentType.APPLICATION_JSON));

Review Comment:
   This is not JSON Actually, we should may not use this content type here.



##########
itests/src/test/java/org/apache/unomi/itests/JSONSchemaIT.java:
##########
@@ -64,155 +72,176 @@ public void setUp() throws InterruptedException {
     public void tearDown() throws InterruptedException {
         removeItems(JsonSchemaWrapper.class, Event.class);
         // ensure all schemas have been cleaned from schemaService.
-        keepTrying("Should not find json schemas anymore",
-                () -> 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);
+        keepTrying("Should not find json schemas anymore", () -> 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 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"));
+        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);
+        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 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"));
+        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"));
+        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"));
+        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);
+        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);
     }
 
     @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"));
+        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);
+        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"));
+        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);
+        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);
     }
 
     @Test
     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);
+        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"));
+        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);
+        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);
 
         // 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);
+        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);
     }
 
     @Test
     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);
+        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"));
+        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);
+        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"));
+        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);
+        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 testEndPoint_GetInstalledJsonSchemas() throws InterruptedException {
+    public void testEndPoint_GetInstalledJsonSchemas() {
         List<String> jsonSchemas = get(JSONSCHEMA_URL, List.class);
         assertFalse("JSON schema list should not be empty, it should contain predefined Unomi schemas", jsonSchemas.isEmpty());
     }
 
     @Test
-    public void testEndPoint_SaveDelete() throws InterruptedException, IOException {
+    public void testEndPoint_GetJsonSchemasById() throws Exception {
+        // Push base schemas
+        schemaService.saveSchema(resourceAsString("schemas/schema-dummy.json"));
+        schemaService.saveSchema(resourceAsString("schemas/schema-dummy-properties.json"));
+
+        final String schemaId = "https://unomi.apache.org/schemas/json/events/dummy/1-0-0";
+        final HttpPost request = new HttpPost(getFullUrl(JSONSCHEMA_URL + "/queryId"));
+
+        request.setEntity(new StringEntity(schemaId, ContentType.APPLICATION_JSON));
+
+        keepTrying("Should return a schema with when calling the endpoint", () -> {
+            try (CloseableHttpResponse response = executeHttpRequest(request)) {
+                return EntityUtils.toString(response.getEntity());
+            } catch (IOException e) {
+                LOGGER.error("Failed to get the json schema with the id: {}", schemaId);
+            }
+            return "";
+        }, entity -> entity.contains("DummyEvent"), DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
+    }
+
+    @Test
+    public void testEndPoint_SaveDelete() throws Exception {
         assertNull(schemaService.getSchema("https://unomi.apache.org/schemas/json/events/dummy/1-0-0"));
 
         // Post schema using REST call
-        try(CloseableHttpResponse response = post(JSONSCHEMA_URL, "schemas/schema-dummy.json", ContentType.TEXT_PLAIN)) {
+        try (CloseableHttpResponse response = post(JSONSCHEMA_URL, "schemas/schema-dummy.json", ContentType.TEXT_PLAIN)) {
             assertEquals("Invalid response code", 200, response.getStatusLine().getStatusCode());
         }
 
         // See schema is available
-        keepTrying("Schema should have been created", () -> schemaService.getSchema("https://unomi.apache.org/schemas/json/events/dummy/1-0-0"),
-                Objects::nonNull, DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
+        keepTrying("Schema should have been created",
+                () -> schemaService.getSchema("https://unomi.apache.org/schemas/json/events/dummy/1-0-0"), Objects::nonNull,
+                DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
 
         // Delete Schema using REST call
-        String encodedString = Base64.getEncoder()
-                .encodeToString("https://unomi.apache.org/schemas/json/events/dummy/1-0-0".getBytes());
-        CloseableHttpResponse response = delete(JSONSCHEMA_URL + "/" + encodedString);
+        final HttpPost request = new HttpPost(getFullUrl(JSONSCHEMA_URL + "/delete"));
+        request.setEntity(new StringEntity("https://unomi.apache.org/schemas/json/events/dummy/1-0-0", ContentType.APPLICATION_JSON));

Review Comment:
   This is not JSON Actually, we should may not use this content type here.



-- 
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: dev-unsubscribe@unomi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org