/*
 * 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.swapper.impl;

import org.apache.shardingsphere.core.rule.Authentication;
import org.apache.shardingsphere.core.rule.ProxyUser;
import org.apache.shardingsphere.core.yaml.config.common.YamlAuthenticationConfiguration;
import org.junit.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class AuthenticationYamlSwapperTest {
        
    @Test
    public void assertSwapToYaml() {
        ProxyUser user1 = new ProxyUser("pwd1", Collections.singleton("db1"));
        ProxyUser user2 = new ProxyUser("pwd2", Collections.singleton("db2"));
        Map<String, ProxyUser> users = new HashMap<>();
        users.put("user1", user1);
        users.put("user2", user2);
        Authentication authentication = new Authentication();
        authentication.getUsers().putAll(users);
        YamlAuthenticationConfiguration actual = new AuthenticationYamlSwapper().swap(authentication);
        assertThat(actual.getUsers().size(), is(2));
        assertThat(actual.getUsers().get("user2").getPassword(), is("pwd2"));
    }
    
    @Test
    public void assertSwapToObject() {
    }
}

@@ -1073,49 +1073,80 @@
 org.
-junit.Test;%0A%0Aimport java.util.Collec
+apache.shardingsphere.core.yaml.config.common.YamlProxyUserConfigura
 tion
-s
 ;%0Aim
@@ -1154,26 +1154,24 @@
 ort 
-java.util.HashMap;
+org.junit.Test;%0A
 %0Aimp
@@ -1184,19 +1184,27 @@
 va.util.
-Map
+Collections
 ;%0A%0Aimpor
@@ -1552,104 +1552,95 @@
     
-Map%3CString, ProxyUser%3E users = new HashMap%3C%3E();%0A        users.put(%22user1%22, user1);%0A        users
+Authentication authentication = new Authentication();%0A        authentication.getUsers()
 .put
@@ -1649,79 +1649,17 @@
 user
-2
+1
 %22, user
-2);%0A        Authentication authentication = new Authentication(
+1
 );%0A 
@@ -1698,17 +1698,23 @@
 .put
-All(users
+(%22user2%22, user2
 );%0A 
@@ -2002,20 +2002,764 @@
 oObject() %7B%0A
+        YamlProxyUserConfiguration user1 = new YamlProxyUserConfiguration();%0A        user1.setPassword(%22pwd1%22);%0A        user1.setAuthorizedSchemas(%22db1%22);%0A        YamlProxyUserConfiguration user2 = new YamlProxyUserConfiguration();%0A        user2.setPassword(%22pwd2%22);%0A        user2.setAuthorizedSchemas(%22db2,db1%22);%0A        YamlAuthenticationConfiguration configuration = new YamlAuthenticationConfiguration();%0A        configuration.getUsers().put(%22user1%22, user1);%0A        configuration.getUsers().put(%22user2%22, user2);%0A        Authentication actual = new AuthenticationYamlSwapper().swap(configuration);%0A        assertThat(actual.getUsers().size(), is(2));%0A        assertThat(actual.getUsers().get(%22user2%22).getAuthorizedSchemas().size(), is(2));%0A
     %7D%0A%7D%0A

add assertSwapToObject()