@@ -0,0 +1,3536 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.apache.shardingsphere.proxy.backend.schema;%0A%0Aimport org.apache.shardingsphere.infra.auth.Authentication;%0Aimport org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;%0Aimport org.apache.shardingsphere.kernel.context.SchemaContext;%0Aimport org.apache.shardingsphere.kernel.context.StandardSchemaContexts;%0Aimport org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;%0Aimport org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;%0Aimport org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.MockDataSource;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport javax.sql.DataSource;%0Aimport java.lang.reflect.Field;%0Aimport java.util.Collections;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.Optional;%0Aimport java.util.Properties;%0A%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when;%0A%0Apublic final class ProxySchemaContextsTest %7B%0A    %0A    private Map%3CString, DataSource%3E mockDataSourceMap;%0A    %0A    @Before%0A    public void setUp() %7B%0A        mockDataSourceMap = new HashMap%3C%3E(2, 1);%0A        mockDataSourceMap.put(%22ds_1%22, new MockDataSource());%0A        mockDataSourceMap.put(%22ds_2%22, new MockDataSource());%0A    %7D%0A    %0A    @Test%0A    public void assertGetDataSourceSample() throws NoSuchFieldException, IllegalAccessException %7B%0A        assertThat(ProxySchemaContexts.getInstance().getDataSourceSample(), is(Optional.empty()));%0A        Field schemaContexts = ProxySchemaContexts.getInstance().getClass().getDeclaredField(%22schemaContexts%22);%0A        schemaContexts.setAccessible(true);%0A        schemaContexts.set(ProxySchemaContexts.getInstance(), new StandardSchemaContexts(getSchemaContextMap(), new Authentication(), new ConfigurationProperties(new Properties())));%0A        Optional%3CDataSource%3E actual = ProxySchemaContexts.getInstance().getDataSourceSample();%0A        assertThat(actual, is(Optional.of(mockDataSourceMap.entrySet().iterator().next().getValue())));%0A        %0A    %7D%0A    %0A    private Map%3CString, SchemaContext%3E getSchemaContextMap() %7B%0A        SchemaContext schemaContext = mock(SchemaContext.class);%0A        ShardingSphereSchema shardingSphereSchema = mock(ShardingSphereSchema.class);%0A        RuntimeContext runtimeContext = mock(RuntimeContext.class);%0A        when(shardingSphereSchema.getDataSources()).thenReturn(mockDataSourceMap);%0A        when(schemaContext.getName()).thenReturn(%22schema%22);%0A        when(schemaContext.getSchema()).thenReturn(shardingSphereSchema);%0A        when(schemaContext.getRuntimeContext()).thenReturn(runtimeContext);%0A        return Collections.singletonMap(%22schema%22, schemaContext);%0A    %7D%0A%7D%0A

Add test case for ProxySchemaContexts.getDataSourceSample (#6610)