seung-00 commented on code in PR #4790:
URL: https://github.com/apache/zeppelin/pull/4790#discussion_r1722054918


##########
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 {

Review Comment:
   How about unifying the method names? 
   toJson/fromJson in RemoteZeppelinServerResourceTest vs. 
deserialization/serialization in HeliumRegistrySerializerTest.



##########
zeppelin-interpreter/src/test/java/org/apache/zeppelin/cluster/event/ClusterMessageSerDeserTest.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.cluster.event;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ClusterMessageSerDeserTest {
+
+    private ClusterMessage clusterMessage;
+
+    @BeforeEach
+    void setUp() {
+        clusterMessage = new 
ClusterMessage(ClusterEvent.BROADCAST_NEW_PARAGRAPH);
+    }
+
+    @Test
+    void toJson() {
+        // Given
+        clusterMessage.put("key1", "value1");
+        clusterMessage.put("key2", "value2");
+        clusterMessage.setMsgId(UUID.randomUUID().toString());
+
+        // First, let's check the serialized JSON serialization
+        String serializedJSON = 
ClusterMessage.serializeMessage(clusterMessage);
+        assertEquals(
+                a2q("{\n" +
+                        "  'clusterEvent': 'BROADCAST_NEW_PARAGRAPH',\n" +
+                        "  'data': {\n" +
+                        "    'key1': 'value1',\n" +
+                        "    'key2': 'value2'\n" +
+                        "  },\n" +
+                        "  'msgId': '" + clusterMessage.getMsgId() + "'\n" +
+                        "}"),
+                serializedJSON);
+
+        // Now, let's check the serialized JSON deserialization
+        ClusterMessage deserialized = 
ClusterMessage.deserializeMessage(serializedJSON);
+        assertEquals(clusterMessage.clusterEvent, deserialized.clusterEvent);
+        assertEquals(clusterMessage.getData(), deserialized.getData());
+        assertEquals(clusterMessage.getMsgId(), deserialized.getMsgId());
+    }
+
+    @Test
+    void fromJson_withInvalidField() {
+        String invalidJson = a2q("{" +
+                "'clusterEvent':'SET_RUNNERS_PERMISSIONS'," +
+                "'data':{'key1':'value1','key2':'value2'}," +
+                "'invalidField':'invalidValue'" +
+                "}");
+
+        ClusterMessage deserialized = 
ClusterMessage.deserializeMessage(invalidJson);
+        assertEquals(ClusterEvent.SET_RUNNERS_PERMISSIONS, 
deserialized.clusterEvent);
+        assertEquals(mapOf("key1", "value1", "key2", "value2"), 
deserialized.getData());
+        assertNull(deserialized.getMsgId());
+    }
+
+    @Test
+    void fromJson_withNothing() {
+        // When only the empty JSON object is provided,
+        ClusterMessage deserialized = ClusterMessage.deserializeMessage("{}");
+
+        // Then, all fields should be null or empty
+        assertNull(deserialized.clusterEvent);
+        assertNull(deserialized.getData());
+        assertNull(deserialized.getMsgId());
+    }
+
+    @Test
+    void fromJson_withNullFields() {
+        String jsonWithNullFields = a2q("{" +
+                "'clusterEvent':null," +
+                "'data':null," +
+                "'msgId':null" +
+                "}");
+
+        ClusterMessage deserialized = 
ClusterMessage.deserializeMessage(jsonWithNullFields);
+        assertNull(deserialized.clusterEvent);
+        assertNull(deserialized.getData());
+        assertNull(deserialized.getMsgId());
+    }
+
+    @Test
+    void toJson_withEmptyData() {
+        ClusterMessage original = new 
ClusterMessage(ClusterEvent.CLEAR_PERMISSION);
+        original.setMsgId("");
+        original.getData().clear();
+
+        String serializedJSON = ClusterMessage.serializeMessage(original);
+        assertEquals(
+                a2q("{\n" +
+                        "  'clusterEvent': 'CLEAR_PERMISSION',\n" +
+                        "  'data': {},\n" +
+                        "  'msgId': ''\n" +
+                        "}"),
+                serializedJSON);
+
+        ClusterMessage deserialized = 
ClusterMessage.deserializeMessage(serializedJSON);
+        assertEquals(original.clusterEvent, deserialized.clusterEvent);
+        assertEquals(original.getData(), deserialized.getData());
+        assertEquals(original.getMsgId(), deserialized.getMsgId());
+    }
+
+    @Test
+    void fromJson_withLargeDataSet() {
+        Map<String, String> largeData = new HashMap<>();
+        for (int i = 0; i < 1000; i++) {
+            largeData.put("key" + i, "value" + i);
+        }
+
+        ClusterMessage original = new 
ClusterMessage(ClusterEvent.SET_READERS_PERMISSIONS);
+        original.setMsgId(UUID.randomUUID().toString());
+        original.put(largeData);
+
+        String serializedJSON = ClusterMessage.serializeMessage(original);
+        ClusterMessage deserialized = 
ClusterMessage.deserializeMessage(serializedJSON);
+
+        assertEquals(original.clusterEvent, deserialized.clusterEvent);
+        assertEquals(original.getData(), deserialized.getData());
+        assertEquals(original.getMsgId(), deserialized.getMsgId());
+    }
+
+    private Map<String, String> mapOf(
+            String key, String value,
+            String key2, String value2
+    ) {
+        Map<String, String> map = new HashMap<>();
+        map.put(key, value);
+        map.put(key2, value2);
+        return map;
+    }
+
+    private static String a2q(String json) {
+        return json.replace("'", "\"");
+    }

Review Comment:
   Is a2q really necessary? If not, I think using a pure JSON format without 
a2q could make the test clearer. Keeping the test focused on the target, which 
in this case is JSON serialization/deserialization, could help keep the test 
simple. 
   Also, in this PR HeliumRegistrySerializerTest does not use a2q.



##########
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:
   It seems like a performance test. In my opinion, it's better to avoid 
performance testing in unit tests. I think unit tests and performance tests 
have different purposes. 



-- 
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