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 46fa6bde7 [ISSUE #3946]Add unit test method or class for classes:
NetUtils, TopicResponse (#3947)
46fa6bde7 is described below
commit 46fa6bde7d028aa970454fd2e952b53ab42d8d7c
Author: pandaapo <[email protected]>
AuthorDate: Mon May 22 10:56:18 2023 +0800
[ISSUE #3946]Add unit test method or class for classes: NetUtils,
TopicResponse (#3947)
* Add unit test methods for NetUtils, JsonUtils
* Revoke redundant test method. Add test class.
---
.../admin/rocketmq/response/TopicResponseTest.java | 56 ++++++++++++++++++++++
.../eventmesh/common/utils/NetUtilsTest.java | 9 ++++
2 files changed, 65 insertions(+)
diff --git
a/eventmesh-admin/eventmesh-admin-rocketmq/src/test/java/org/apache/eventmesh/admin/rocketmq/response/TopicResponseTest.java
b/eventmesh-admin/eventmesh-admin-rocketmq/src/test/java/org/apache/eventmesh/admin/rocketmq/response/TopicResponseTest.java
new file mode 100644
index 000000000..311dc6efc
--- /dev/null
+++
b/eventmesh-admin/eventmesh-admin-rocketmq/src/test/java/org/apache/eventmesh/admin/rocketmq/response/TopicResponseTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.response;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class TopicResponseTest {
+
+ @Test
+ public void testTopicResponse() {
+ String topic = "testtopic";
+ String createdTime = "2023-05-17 10:30:00";
+ TopicResponse topicResponse = new TopicResponse(topic, createdTime);
+
+ assertEquals(topic, topicResponse.getTopic());
+ assertEquals(createdTime, topicResponse.getCreatedTime());
+ }
+
+ @Test
+ public void testTopicResponseSerialization() throws Exception {
+ String topic = "testtopic";
+ String createdTime = "2023-05-17 10:30:00";
+ TopicResponse topicResponse = new TopicResponse(topic, createdTime);
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ String json = objectMapper.writeValueAsString(topicResponse);
+
+ assertTrue(json.contains("topic"));
+ assertTrue(json.contains("created_time"));
+
+ TopicResponse deserializedResponse = objectMapper.readValue(json,
TopicResponse.class);
+
+ assertEquals(topic, deserializedResponse.getTopic());
+ assertEquals(createdTime, deserializedResponse.getCreatedTime());
+ }
+}
diff --git
a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/NetUtilsTest.java
b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/NetUtilsTest.java
index ca62207a5..34d07a840 100644
---
a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/NetUtilsTest.java
+++
b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/NetUtilsTest.java
@@ -20,6 +20,7 @@ package org.apache.eventmesh.common.utils;
import org.apache.eventmesh.common.enums.HttpMethod;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -70,4 +71,12 @@ public class NetUtilsTest {
Assert.assertEquals(expected, actual);
}
+
+ @Test
+ public void testSendSuccessResponseHeaders() throws IOException {
+ HttpExchange exchange = Mockito.mock(HttpExchange.class);
+ NetUtils.sendSuccessResponseHeaders(exchange);
+ Mockito.verify(exchange, Mockito.times(1))
+ .sendResponseHeaders(Mockito.anyInt(), Mockito.anyLong());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]