aloyszhang commented on code in PR #8941:
URL: https://github.com/apache/inlong/pull/8941#discussion_r1379683561


##########
inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/queue/PulsarUtilsTest.java:
##########
@@ -17,39 +17,671 @@
 
 package org.apache.inlong.manager.service.queue;
 
+import org.apache.inlong.manager.common.consts.InlongConstants;
+import org.apache.inlong.manager.pojo.cluster.pulsar.PulsarClusterInfo;
+import org.apache.inlong.manager.pojo.queue.pulsar.PulsarLookupTopicInfo;
+import org.apache.inlong.manager.pojo.queue.pulsar.PulsarMessageInfo;
+import org.apache.inlong.manager.pojo.queue.pulsar.PulsarNamespacePolicies;
+import org.apache.inlong.manager.pojo.queue.pulsar.PulsarPersistencePolicies;
+import org.apache.inlong.manager.pojo.queue.pulsar.PulsarRetentionPolicies;
+import org.apache.inlong.manager.pojo.queue.pulsar.PulsarTenantInfo;
+import org.apache.inlong.manager.pojo.queue.pulsar.PulsarTopicMetadata;
 import org.apache.inlong.manager.service.resource.queue.pulsar.PulsarUtils;
 
-import org.apache.pulsar.client.admin.PulsarAdmin;
-import org.apache.pulsar.client.admin.internal.PulsarAdminImpl;
-import org.apache.pulsar.client.api.Authentication;
-import org.apache.pulsar.client.api.PulsarClientException;
-import org.apache.pulsar.client.impl.auth.AuthenticationDisabled;
-import org.junit.jupiter.api.Assertions;
+import com.google.common.collect.Sets;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+import org.apache.commons.lang3.StringUtils;
+import org.junit.Ignore;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.springframework.util.ReflectionUtils;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
 
-import java.lang.reflect.Field;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.powermock.api.mockito.PowerMockito.when;
 
 /**
  * Test class for Pulsar utils.
  */
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
 public class PulsarUtilsTest {
 
+    private static final Gson GSON = new GsonBuilder().create(); // thread safe
+
+    private static final String DEFAULT_SERVICE_URL = "http://127.0.0.1:8080";;
+
+    private static final String DEFAULT_TENANT = "public";
+
+    private static final String DEFAULT_NAMESPACE = "default";
+
+    private static final String DEFAULT_TOPIC = "testtopic";
+
+    private static final String DEFAULT_NON_PRTITIONED_TOPIC = "testtopic_np";
+
+    private static final int DEFAULT_PARTITIONS_NUM = 3;
+
+    private static final String DEFAULT_TOPIC_PATH = DEFAULT_TENANT + "/" + 
DEFAULT_NAMESPACE + "/" + DEFAULT_TOPIC;
+
+    private static final String DEFAULT_NON_PRTITIONED_TOPIC_PATH =
+            DEFAULT_TENANT + "/" + DEFAULT_NAMESPACE + "/" + 
DEFAULT_NON_PRTITIONED_TOPIC;
+
+    @Mock
+    private RestTemplate restTemplate;
+
+    @Mock
+    private ResponseEntity<String> exchange;
+
+    @Mock
+    private ResponseEntity<byte[]> byteExchange;
+
+    @Mock
+    private PulsarClusterInfo pulsarClusterInfo;
+
+    private static PulsarNamespacePolicies policies;
+
+    @BeforeAll
+    public static void beforeAll() {
+        policies = new PulsarNamespacePolicies();
+        policies.setMessageTtlInSeconds(10);
+        PulsarPersistencePolicies persistencePolicies = new 
PulsarPersistencePolicies();
+        persistencePolicies.setBookkeeperEnsemble(1);
+        persistencePolicies.setBookkeeperAckQuorum(2);
+        persistencePolicies.setBookkeeperWriteQuorum(3);
+        persistencePolicies.setManagedLedgerMaxMarkDeleteRate(4.0);
+        policies.setPersistence(persistencePolicies);
+        PulsarRetentionPolicies retentionPolicies = new 
PulsarRetentionPolicies();
+        retentionPolicies.setRetentionSizeInMB(2048l);
+        retentionPolicies.setRetentionTimeInMinutes(500);
+        policies.setRetentionPolicies(retentionPolicies);
+    }
+
+    @BeforeEach
+    public void before() {
+        when(pulsarClusterInfo.getAdminUrl()).thenReturn(DEFAULT_SERVICE_URL);
+        when(pulsarClusterInfo.getToken()).thenReturn("testtoken");
+
+    }
+    /**
+     * Test cases for {@link PulsarUtils#getPulsarClusters}.
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testGetPulsarClusters() throws Exception {
+        final String url = DEFAULT_SERVICE_URL + 
PulsarUtils.QUERY_CLUSTERS_PATH;
+        final String result = "[\"standalone\"]";
+        List<String> expected = GSON.fromJson(result, ArrayList.class);
+        when(restTemplate.exchange(eq(url), eq(HttpMethod.GET), 
any(HttpEntity.class), eq(String.class))).thenReturn(

Review Comment:
   It's better to run a pulsar broker service in the test, and then use the 
pulsar service to verify all these HTTP requests work well.



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

Reply via email to