/*
 * 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.shardingsphere.core.yaml.engine;

import org.apache.shardingsphere.core.yaml.config.common.YamlUser;
import org.junit.Test;

import java.util.Map;
import java.util.Properties;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public final class YamlEngineTest {
    
    @Test
    public void assertUnmarshal() {
        YamlUser actual = YamlEngine.unmarshal("password: pwd\nauthorizedSchemas: db1", YamlUser.class);
        assertThat(actual.getPassword(), is("pwd"));
        assertThat(actual.getAuthorizedSchemas(), is("db1"));
    }
    
    @SuppressWarnings("unchecked")
    @Test
    public void assertUnmarshalMap() {
        Map<String, Object> actual = (Map<String, Object>) YamlEngine.unmarshal("password: pwd\nauthorizedSchemas: db1");
        assertThat(actual.get("password").toString(), is("pwd"));
        assertThat(actual.get("authorizedSchemas").toString(), is("db1"));
    }
    
    @SuppressWarnings("unchecked")
    @Test
    public void assertUnmarshalProperties() {
        Properties actual = YamlEngine.unmarshalProperties("password: pwd\nauthorizedSchemas: db1");
        assertThat(actual.getProperty("authorizedSchemas"), is("db1"));
        assertThat(actual.getProperty("password"), is("pwd"));
    }
    
    @Test
    public void assertMarshal() {
        YamlUser actual = new YamlUser();
        actual.setPassword("pwd");
        actual.setAuthorizedSchemas("db1");
        assertThat(YamlEngine.marshal(actual), is("password: pwd\nauthorizedSchemas: db1\n"));
    }
}

@@ -2310,31 +2310,16 @@
 l), is(%22
-password: pwd%5Cn
 authoriz
@@ -2333,16 +2333,31 @@
 as: db1%5C
+npassword: pwd%5C
 n%22));%0A  

modify assertMarshal()