Pil0tXia commented on code in PR #4340:
URL: https://github.com/apache/eventmesh/pull/4340#discussion_r1286068457


##########
eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/WebhookProtocolTransportObjectTest.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.eventmesh.common.protocol.http;
+
+import org.apache.eventmesh.common.Constants;
+import org.apache.eventmesh.common.utils.JsonUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class WebhookProtocolTransportObjectTest {
+
+    private WebhookProtocolTransportObject webhookProtocolTransportObject;
+
+    @Before
+    public void setUp() {
+        webhookProtocolTransportObject = 
WebhookProtocolTransportObject.builder().build();
+    }
+
+    @Test
+    public void testSetCloudEventId() {
+        
webhookProtocolTransportObject.setCloudEventId("d0b29520-2bba-11ee-877b-2b18ac132e64");
+    }
+

Review Comment:
   I got you. You would like to use setters to build a 
`WebhookProtocolTransportObject` and test it as a whole. It is OK.
   
   However, as is marked, this is not a Unit Test, because there is no assert 
judgement in it. The marked snippet is purely a setter, which is a pre-test 
construction and preparation and should be classified under the `@Before` 
annotation. 
   
   Each unit test should have an assert judgement. You may read 
https://eventmesh.apache.org/zh/community/contribute/write-unit-test for more 
information.



##########
eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/WebhookProtocolTransportObjectTest.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.eventmesh.common.protocol.http;
+
+import org.apache.eventmesh.common.Constants;
+import org.apache.eventmesh.common.utils.JsonUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class WebhookProtocolTransportObjectTest {
+
+    private WebhookProtocolTransportObject webhookProtocolTransportObject;
+
+    @Before
+    public void setUp() {
+        webhookProtocolTransportObject = 
WebhookProtocolTransportObject.builder().build();
+    }
+
+    @Test
+    public void testSetCloudEventId() {
+        
webhookProtocolTransportObject.setCloudEventId("d0b29520-2bba-11ee-877b-2b18ac132e64");
+    }
+
+    @Test
+    public void testSetEventType() {
+        webhookProtocolTransportObject.setEventType("github.all");
+    }
+
+    @Test
+    public void testSetCloudEventName() {
+        webhookProtocolTransportObject.setCloudEventName("github-eventmesh");
+    }
+
+    @Test
+    public void testSetCloudEventSource() {
+        webhookProtocolTransportObject.setCloudEventSource("www.github.com");
+    }
+
+    @Test
+    public void testSetDataContentType() {
+        webhookProtocolTransportObject.setDataContentType("application/json");
+    }
+
+    @Test
+    public void testSetBody() {
+        Map<String, Object> bodyMap = new HashMap<>();
+        bodyMap.put("user", "tom");
+        bodyMap.put("password", "123456");
+        
webhookProtocolTransportObject.setBody(Objects.requireNonNull(JsonUtils.toJSONString(bodyMap)).getBytes(Constants.DEFAULT_CHARSET));
+    }
+
+    @Test
+    public void testBuilder() {
+        WebhookProtocolTransportObject.WebhookProtocolTransportObjectBuilder 
result = WebhookProtocolTransportObject.builder();
+        Assert.assertNotNull(result);

Review Comment:
   `assertNotNull` is not recommanded, how about `assertEqual`.



##########
eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/WebhookProtocolTransportObjectTest.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.eventmesh.common.protocol.http;
+
+import org.apache.eventmesh.common.Constants;
+import org.apache.eventmesh.common.utils.JsonUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class WebhookProtocolTransportObjectTest {
+
+    private WebhookProtocolTransportObject webhookProtocolTransportObject;
+
+    @Before
+    public void setUp() {
+        webhookProtocolTransportObject = 
WebhookProtocolTransportObject.builder().build();
+    }
+
+    @Test
+    public void testSetCloudEventId() {
+        
webhookProtocolTransportObject.setCloudEventId("d0b29520-2bba-11ee-877b-2b18ac132e64");
+    }
+
+    @Test
+    public void testSetEventType() {
+        webhookProtocolTransportObject.setEventType("github.all");
+    }
+
+    @Test
+    public void testSetCloudEventName() {
+        webhookProtocolTransportObject.setCloudEventName("github-eventmesh");
+    }
+
+    @Test
+    public void testSetCloudEventSource() {
+        webhookProtocolTransportObject.setCloudEventSource("www.github.com");
+    }
+
+    @Test
+    public void testSetDataContentType() {
+        webhookProtocolTransportObject.setDataContentType("application/json");
+    }
+
+    @Test
+    public void testSetBody() {
+        Map<String, Object> bodyMap = new HashMap<>();
+        bodyMap.put("user", "tom");
+        bodyMap.put("password", "123456");

Review Comment:
   The web request body is usually a json string instead of a Map. For example:
   
   ```json
   {
     "zen": "Design for failure.",
     "hook_id": 425906842,
     "hook": {
       "type": "Repository",
       "name": "web",
       "events": [
         "*"
       ],
       "config": {
         "insecure_ssl": "0",
         "url": 
"http://eventmesh.example.com:10106/webhook/github/eventmesh/all";
       }
     }
   }
   ```
   
   This does not affect the validation of the method, but the sample in the 
test class is an important hint to give developers examples of the data format.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to