/*
 * 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.inlong.sort.util;

import org.apache.inlong.sort.protocol.enums.SchemaChangePolicy;
import org.apache.inlong.sort.protocol.enums.SchemaChangeType;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Test for {@link SchemaChangeUtils}
 */
public class SchemaChangeUtilsTest {

    private String policies;
    private Map<SchemaChangeType, SchemaChangePolicy> policyMap;

    @Before
    public void init() {
        policyMap = new LinkedHashMap<>();
        policyMap.put(SchemaChangeType.CREATE_TABLE, SchemaChangePolicy.ENABLE);
        policyMap.put(SchemaChangeType.DROP_TABLE, SchemaChangePolicy.LOG);
        policyMap.put(SchemaChangeType.RENAME_TABLE, SchemaChangePolicy.LOG);
        policyMap.put(SchemaChangeType.TRUNCATE_TABLE, SchemaChangePolicy.LOG);
        policyMap.put(SchemaChangeType.ADD_COLUMN, SchemaChangePolicy.ENABLE);
        policyMap.put(SchemaChangeType.DROP_COLUMN, SchemaChangePolicy.ENABLE);
        policyMap.put(SchemaChangeType.RENAME_COLUMN, SchemaChangePolicy.IGNORE);
        policyMap.put(SchemaChangeType.CHANGE_COLUMN_TYPE, SchemaChangePolicy.ERROR);
        policies = "1=1&2=3&3=3&4=3&5=1&6=1&7=2&8=4";
    }

    @Test
    public void testSerialize() {
        Assert.assertEquals(policies, SchemaChangeUtils.serialize(policyMap));
    }

    @Test
    public void testDeserialize() {
        Assert.assertEquals(policyMap, SchemaChangeUtils.deserialize(policies));
    }

}
