JooHyukKim commented on code in PR #4790:
URL: https://github.com/apache/zeppelin/pull/4790#discussion_r1729167499


##########
zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/RemoteZeppelinServerResourceTest.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.zeppelin.interpreter;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.UUID;
+
+import static 
org.apache.zeppelin.interpreter.RemoteZeppelinServerResource.Type.PARAGRAPH_RUNNERS;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class RemoteZeppelinServerResourceTest {
+
+    @Test
+    void toJson() {
+        // Given
+        RemoteZeppelinServerResource original = new 
RemoteZeppelinServerResource();
+        original.setOwnerKey(UUID.randomUUID().toString());
+        original.setData(mapOf("key1", "value", "key2", "value2"));
+        original.setResourceType(PARAGRAPH_RUNNERS);
+
+        // First, let's check the serializedJson serialization
+        String serializedJSON = original.toJson();
+        assertEquals(a2q("{" +
+                "'ownerKey':'" + original.getOwnerKey() + "'," +
+                "'resourceType':'PARAGRAPH_RUNNERS'," +
+                "'data':{'key1':'value','key2':'value2'}" +
+                "}"), serializedJSON);
+
+        // Now, let's check the serializedJson deserialization
+        RemoteZeppelinServerResource deserialized = 
RemoteZeppelinServerResource.fromJson(serializedJSON);
+        assertEquals(original.getOwnerKey(), deserialized.getOwnerKey());
+        assertEquals(original.getResourceType(), 
deserialized.getResourceType());
+        assertEquals(original.getData(), deserialized.getData());
+    }
+
+    @Test
+    void fromJson_withInvalidResourceType() {
+        String invalidJson = a2q("{" +
+                "'ownerKey':'1234'," +
+                "'resourceType':'INVALID_TYPE'," +
+                "'data':{'key1':'value','key2':'value2'}" +
+                "}");
+
+        RemoteZeppelinServerResource deserialized = 
RemoteZeppelinServerResource.fromJson(invalidJson);
+        // Deserialization is successful and type is null
+        assertNull(deserialized.getResourceType());
+        // Owner key and data are deserialized correctly
+        assertEquals("1234", deserialized.getOwnerKey());
+        assertEquals(mapOf("key1", "value", "key2", "value2"), 
deserialized.getData());
+    }
+
+    @Test
+    void fromJson_withNothing() {
+        // When only the empty JSON object is provided,
+        RemoteZeppelinServerResource deserialized = 
RemoteZeppelinServerResource.fromJson("{}");
+
+        // Then, all fields should be null
+        assertNull(deserialized.getOwnerKey());
+        assertNull(deserialized.getResourceType());
+        assertNull(deserialized.getData());
+    }
+
+    @Test
+    void fromJson_withNullFields() {
+        String jsonWithNullFields = a2q("{" +
+                "'ownerKey':null," +
+                "'resourceType':null," +
+                "'data':null" +
+                "}");
+
+        RemoteZeppelinServerResource deserialized = 
RemoteZeppelinServerResource.fromJson(jsonWithNullFields);
+        assertNull(deserialized.getOwnerKey());
+        assertNull(deserialized.getResourceType());
+        assertNull(deserialized.getData());
+    }
+
+    @Test
+    void toJson_withEmptyData() {
+        RemoteZeppelinServerResource original = new 
RemoteZeppelinServerResource();
+        original.setOwnerKey("");
+        original.setData(new TreeMap<>());
+        original.setResourceType(PARAGRAPH_RUNNERS);
+
+        String serializedJSON = original.toJson();
+        assertEquals(a2q("{" +
+                "'ownerKey':''," +
+                "'resourceType':'PARAGRAPH_RUNNERS'," +
+                "'data':{}" +
+                "}"), serializedJSON);
+
+        RemoteZeppelinServerResource deserialized = 
RemoteZeppelinServerResource.fromJson(serializedJSON);
+        assertEquals(original.getOwnerKey(), deserialized.getOwnerKey());
+        assertEquals(original.getResourceType(), 
deserialized.getResourceType());
+        assertEquals(original.getData(), deserialized.getData());
+    }
+
+    @Test
+    void fromJson_withLargeDataSet() {

Review Comment:
   Oh my bad. I think the test name made you get the wrong idea 😅.
   The test is intended to test (sort of) long data as input.
   There is a whole lot of Zeppelin integration tests that run wayyyy over a 
minute 😆
   This test won't even leave a dent on the performance of Zeppelin test suite.
   
   I changed the name from `LargeDataSet` to `LongDataset`.



##########
zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumRegistrySerializerTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.zeppelin.helium;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.UUID;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+class HeliumRegistrySerializerTest {
+
+    private String HELIUM_PACKAGE_JSON_1 = "{\n" +
+            "  \"name\" : \"[organization.A].[name.A]\",\n" +
+            "  \"description\" : \"Description-A\",\n" +
+            "  \"artifact\" : \"groupId:artifactId:version\",\n" +
+            "  \"className\" : 
\"your.package.name.YourApplicationClass-A\",\n" +
+            "  \"resources\" : [\n" +
+            "    [\"resource.name\", \":resource.class.name\"],\n" +
+            "    [\"alternative.resource.name\", 
\":alternative.class.name\"]\n" +
+            "  ],\n" +
+            "  \"icon\" : \"<i class='icon'></i>\"\n" +
+            "}";
+
+    @Test
+    void testDeserialization() throws IOException {
+        // Given
+
+        // When
+        // Define the output file
+        Path dir = Files.createDirectory(Paths.get("./" + 
UUID.randomUUID().toString()));
+        File newFile = Files.createTempFile(dir, UUID.randomUUID().toString(), 
".json").toFile();
+        FileUtils.writeStringToFile(newFile, HELIUM_PACKAGE_JSON_1, 
StandardCharsets.UTF_8);
+        FileUtils.forceDeleteOnExit(newFile);
+
+        // Write JSON string to file using Apache Commons FileUtils
+        HeliumRegistry registry = new HeliumLocalRegistry("my-registry", 
dir.toString());
+
+        // Then
+        assertEquals("my-registry", registry.name());
+        assertNotNull(registry.getAll());
+        assertEquals(1, registry.getAll().size());
+
+        HeliumPackage heliumPackage = 
registry.getAll().stream().findFirst().orElseThrow(RuntimeException::new);
+        assertEquals("[organization.A].[name.A]", heliumPackage.getName());
+        assertEquals("Description-A", heliumPackage.getDescription());
+        assertEquals("groupId:artifactId:version", 
heliumPackage.getArtifact());
+        assertEquals("your.package.name.YourApplicationClass-A", 
heliumPackage.getClassName());
+        assertEquals(2, heliumPackage.getResources().length);
+        assertEquals("resource.name", heliumPackage.getResources()[0][0]);
+        assertEquals(":resource.class.name", 
heliumPackage.getResources()[0][1]);
+        assertEquals("alternative.resource.name", 
heliumPackage.getResources()[1][0]);
+        assertEquals(":alternative.class.name", 
heliumPackage.getResources()[1][1]);
+        assertEquals("<i class='icon'></i>", heliumPackage.getIcon());
+
+    }
+
+    private File createHeliumPackage(Path testDir, String JSON) throws 
IOException {

Review Comment:
   Done!



-- 
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: reviews-unsubscr...@zeppelin.apache.org

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

Reply via email to