@SuppressWarnings("deprecation")
    @VisibleForTesting
    public String getWebSocketReadUri(String topic) {
        String serviceURLWithoutTrailingSlash = serviceURL.substring(0,
                serviceURL.endsWith("/") ? serviceURL.length() - 1 : serviceURL.length());

        TopicName topicName = TopicName.get(topic);
        String wsTopic;
        if (topicName.isV2()) {
            wsTopic = String.format("%s/%s/%s/%s", topicName.getDomain(), topicName.getTenant(),
                    topicName.getNamespacePortion(), topicName.getLocalName());
        } else {
            wsTopic = String.format("%s/%s/%s/%s/%s", topicName.getDomain(), topicName.getTenant(),
                    topicName.getCluster(), topicName.getNamespacePortion(), topicName.getLocalName());
        }

        String msgIdQueryParam;
        if ("latest".equals(startMessageId) || "earliest".equals(startMessageId)) {
            msgIdQueryParam = startMessageId;
        } else {
            MessageId msgId = parseMessageId(startMessageId);
            msgIdQueryParam = Base64.getEncoder().encodeToString(msgId.toByteArray());
        }

        String uriFormat = "%s/ws" + (topicName.isV2() ? "/v2/" : "/") + "reader/%s?messageId=%s";
        return String.format(uriFormat, serviceURLWithoutTrailingSlash, wsTopic, msgIdQueryParam);
    }
@Test(dataProvider = "startMessageIds")
    public void testGetWebSocketReadUri(String msgId, String msgIdQueryParam) throws Exception {
        CmdRead cmdRead = new CmdRead();
        cmdRead.updateConfig(null, null, "ws://localhost:8080/");
        Field startMessageIdField = CmdRead.class.getDeclaredField("startMessageId");
        startMessageIdField.setAccessible(true);
        startMessageIdField.set(cmdRead, msgId);

        String topicNameV1 = "persistent://public/cluster/default/t1";
        assertEquals(cmdRead.getWebSocketReadUri(topicNameV1),
                "ws://localhost:8080/ws/reader/persistent/public/cluster/default/t1?messageId=" + msgIdQueryParam);

        String topicNameV2 = "persistent://public/default/t2";
        assertEquals(cmdRead.getWebSocketReadUri(topicNameV2),
                "ws://localhost:8080/ws/v2/reader/persistent/public/default/t2?messageId=" + msgIdQueryParam);
    }