/*
 * 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.rocketmq.common.filter;

import java.util.HashSet;
import java.util.Set;
import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData;
import org.apache.rocketmq.remoting.protocol.RemotingSerializable;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class FilterAPITest {
    private String topic = "FooBar";
    private String group = "FooBarGroup";
    private String subString = "TAG1 || Tag2 || tag3";

    @Test
    public void testBuildSubscriptionData() throws Exception {
        SubscriptionData subscriptionData =
            FilterAPI.buildSubscriptionData(group, topic, subString);
        assertThat(subscriptionData.getTopic()).isEqualTo(topic);
        assertThat(subscriptionData.getSubString()).isEqualTo(subString);
        String [] tags = subString.split("\\|\\|");
        Set<String> tagSet = new HashSet<>();
        for (String tag : tags) {
            tagSet.add(tag.trim());
        }
        assertThat(subscriptionData.getTagsSet()).isEqualTo(tagSet);
    }

    @Test
    public void testSubscriptionData() throws Exception {
        SubscriptionData subscriptionData =
            FilterAPI.buildSubscriptionData("ConsumerGroup1", "TestTopic", "TAG1 || Tag2 || tag3");
        subscriptionData.setFilterClassSource("java hello");
        String prettyJson = RemotingSerializable.toJson(subscriptionData, true);
        long subVersion = subscriptionData.getSubVersion();
        assertThat(prettyJson).isEqualTo("{\n" +
            "\t\"classFilterMode\":false,\n" +
            "\t\"codeSet\":[2567159,2598904,3552217],\n" +
            "\t\"subString\":\"TAG1 || Tag2 || tag3\",\n" +
            "\t\"subVersion\":" + subVersion + ",\n" +
            "\t\"tagsSet\":[\"TAG1\",\"Tag2\",\"tag3\"],\n" +
            "\t\"topic\":\"TestTopic\"\n" +
            "}");
    }
}

@@ -963,75 +963,8 @@
 ta;%0A
-import org.apache.rocketmq.remoting.protocol.RemotingSerializable;%0A
 impo
@@ -1789,822 +1789,7 @@
    %7D
-%0A%0A    @Test%0A    public void testSubscriptionData() throws Exception %7B%0A        SubscriptionData subscriptionData =%0A            FilterAPI.buildSubscriptionData(%22ConsumerGroup1%22, %22TestTopic%22, %22TAG1 %7C%7C Tag2 %7C%7C tag3%22);%0A        subscriptionData.setFilterClassSource(%22java hello%22);%0A        String prettyJson = RemotingSerializable.toJson(subscriptionData, true);%0A        long subVersion = subscriptionData.getSubVersion();%0A        assertThat(prettyJson).isEqualTo(%22%7B%5Cn%22 +%0A            %22%5Ct%5C%22classFilterMode%5C%22:false,%5Cn%22 +%0A            %22%5Ct%5C%22codeSet%5C%22:%5B2567159,2598904,3552217%5D,%5Cn%22 +%0A            %22%5Ct%5C%22subString%5C%22:%5C%22TAG1 %7C%7C Tag2 %7C%7C tag3%5C%22,%5Cn%22 +%0A            %22%5Ct%5C%22subVersion%5C%22:%22 + subVersion + %22,%5Cn%22 +%0A            %22%5Ct%5C%22tagsSet%5C%22:%5B%5C%22TAG1%5C%22,%5C%22Tag2%5C%22,%5C%22tag3%5C%22%5D,%5Cn%22 +%0A            %22%5Ct%5C%22topic%5C%22:%5C%22TestTopic%5C%22%5Cn%22 +%0A            %22%7D%22);%0A    %7D
 %0A%7D%0A

Remove testSubscriptionData for rocketmq-common