This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new 4b49642e8 [ISSUE #3978]Remove unnecessary annotations in 
TopicCreateRequest and add unit test. (#3981)
4b49642e8 is described below

commit 4b49642e859895171e9fe8f3ef7dc6432514ada2
Author: pandaapo <[email protected]>
AuthorDate: Wed Jun 7 10:46:03 2023 +0800

    [ISSUE #3978]Remove unnecessary annotations in TopicCreateRequest and add 
unit test. (#3981)
    
    * Mainly add unit test for TopicCreateRequest.
    
    * Change field name.
---
 .../admin/rocketmq/handler/TopicsHandler.java      |  2 +-
 .../admin/rocketmq/request/TopicCreateRequest.java | 17 +++---
 .../rocketmq/request/TopicCreateRequestTest.java   | 63 ++++++++++++++++++++++
 3 files changed, 71 insertions(+), 11 deletions(-)

diff --git 
a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/handler/TopicsHandler.java
 
b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/handler/TopicsHandler.java
index c0aa2c7c1..836f293ef 100644
--- 
a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/handler/TopicsHandler.java
+++ 
b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/handler/TopicsHandler.java
@@ -64,7 +64,7 @@ public class TopicsHandler implements HttpHandler {
             String params = NetUtils.parsePostBody(httpExchange);
             TopicCreateRequest topicCreateRequest =
                 JsonUtils.parseObject(params, TopicCreateRequest.class);
-            String topic = topicCreateRequest.getName();
+            String topic = topicCreateRequest.getTopic();
 
             if (StringUtils.isBlank(topic)) {
                 result = "Create topic failed. Parameter topic not found.";
diff --git 
a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/request/TopicCreateRequest.java
 
b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/request/TopicCreateRequest.java
index 7adaa77cd..81a99b1cb 100644
--- 
a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/request/TopicCreateRequest.java
+++ 
b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/request/TopicCreateRequest.java
@@ -26,22 +26,19 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 @JsonIgnoreProperties(ignoreUnknown = true)
 public class TopicCreateRequest {
 
-    private String name;
+    private String topic;
 
     @JsonCreator
-    public TopicCreateRequest(@JsonProperty("name") String topic) {
-        super();
-        this.name = topic;
+    public TopicCreateRequest(@JsonProperty("topic") String topic) {
+        this.topic = topic;
     }
 
-    @JsonProperty("name")
-    public String getName() {
-        return this.name;
+    public String getTopic() {
+        return this.topic;
     }
 
-    @JsonProperty("name")
-    public void setName(String name) {
-        this.name = name;
+    public void setTopic(String topic) {
+        this.topic = topic;
     }
 
 }
diff --git 
a/eventmesh-admin/eventmesh-admin-rocketmq/src/test/java/org/apache/eventmesh/admin/rocketmq/request/TopicCreateRequestTest.java
 
b/eventmesh-admin/eventmesh-admin-rocketmq/src/test/java/org/apache/eventmesh/admin/rocketmq/request/TopicCreateRequestTest.java
new file mode 100644
index 000000000..e72d727d9
--- /dev/null
+++ 
b/eventmesh-admin/eventmesh-admin-rocketmq/src/test/java/org/apache/eventmesh/admin/rocketmq/request/TopicCreateRequestTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.admin.rocketmq.request;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class TopicCreateRequestTest {
+
+    @Test
+    public void testTopicCreateRequest() {
+        String name = "testTopic";
+        TopicCreateRequest topicCreateRequest = new TopicCreateRequest(name);
+
+        assertEquals(name, topicCreateRequest.getTopic());
+    }
+
+    @Test
+    public void testTopicCreateRequestSetName() {
+        TopicCreateRequest topicCreateRequest = new TopicCreateRequest(null);
+        assertNull(topicCreateRequest.getTopic());
+
+        String name = "testTopic";
+        topicCreateRequest.setTopic(name);
+        assertEquals(name, topicCreateRequest.getTopic());
+    }
+
+    @Test
+    public void testTopicCreateRequestSerialization() throws Exception {
+        String topic = "testTopic";
+        TopicCreateRequest topicCreateRequest = new TopicCreateRequest(topic);
+
+        ObjectMapper objectMapper = new ObjectMapper();
+        String json = objectMapper.writeValueAsString(topicCreateRequest);
+
+        assertTrue(json.contains("topic"));
+
+        TopicCreateRequest deserializedRequest = objectMapper.readValue(json, 
TopicCreateRequest.class);
+
+        assertEquals(topic, deserializedRequest.getTopic());
+    }
+
+}


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

Reply via email to