Skip to content

Commit

Permalink
[ISSUE #3946]Add unit test method or class for classes: NetUtils, Top…
Browse files Browse the repository at this point in the history
…icResponse (#3947)

* Add unit test methods for NetUtils, JsonUtils

* Revoke redundant test method. Add test class.
  • Loading branch information
pandaapo committed May 22, 2023
1 parent cdfec82 commit 46fa6bd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -70,4 +71,12 @@ public void testParsePostBody() throws Exception {
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());
}
}

0 comments on commit 46fa6bd

Please sign in to comment.