SchemaContextsBuilder { public SchemaContexts build() throws SQLException { Map<String, ShardingSphereSchema> schemas = new LinkedHashMap<>(ruleConfigs.size(), 1); for (String each : ruleConfigs.keySet()) { schemas.put(each, createSchema(each)); } return new StandardSchemaContexts(schemas, sqlParserEngine, executorKernel, authentication, props, databaseType); } SchemaContextsBuilder(final DatabaseType databaseType, final Map<String, Map<String, DataSource>> dataSources,
                                 final Map<String, Collection<RuleConfiguration>> ruleConfigs, final Properties props);  SchemaContextsBuilder(final DatabaseType databaseType, final Map<String, Map<String, DataSource>> dataSources,
                                 final Map<String, Collection<RuleConfiguration>> ruleConfigs, final Authentication authentication, final Properties props); SchemaContexts build();  }
@Test public void assertBuildWithoutConfiguration() throws SQLException { DatabaseType databaseType = DatabaseTypes.getActualDatabaseType("FixtureDB"); SchemaContexts actual = new SchemaContextsBuilder(databaseType, Collections.emptyMap(), Collections.emptyMap(), null).build(); assertThat(actual.getDatabaseType(), CoreMatchers.is(databaseType)); assertTrue(actual.getSchemas().isEmpty()); assertTrue(actual.getAuthentication().getUsers().isEmpty()); assertTrue(actual.getProps().getProps().isEmpty()); assertFalse(actual.isCircuitBreak()); }
@Test public void assertBuildWithConfigurationsButWithoutDataSource() throws SQLException { DatabaseType databaseType = DatabaseTypes.getActualDatabaseType("FixtureDB"); Properties props = new Properties(); props.setProperty(ConfigurationPropertyKey.EXECUTOR_SIZE.getKey(), "1"); SchemaContexts actual = new SchemaContextsBuilder(databaseType, Collections.singletonMap("logic_db", Collections.emptyMap()), Collections.singletonMap("logic_db", Collections.singleton(new FixtureRuleConfiguration())), props).build(); assertThat(actual.getDatabaseType(), CoreMatchers.is(databaseType)); assertRules(actual); assertTrue(actual.getSchemas().get("logic_db").getDataSources().isEmpty()); assertTrue(actual.getAuthentication().getUsers().isEmpty()); assertThat(actual.getProps().getProps().size(), CoreMatchers.is(1)); assertThat(actual.getProps().getValue(ConfigurationPropertyKey.EXECUTOR_SIZE), CoreMatchers.is(1)); assertFalse(actual.isCircuitBreak()); }
@Test public void assertBuildWithConfigurationsAndDataSources() throws SQLException { DatabaseType databaseType = DatabaseTypes.getActualDatabaseType("FixtureDB"); Properties props = new Properties(); props.setProperty(ConfigurationPropertyKey.EXECUTOR_SIZE.getKey(), "1"); SchemaContexts actual = new SchemaContextsBuilder(databaseType, Collections.singletonMap("logic_db", Collections.singletonMap("ds", new MockedDataSource())), Collections.singletonMap("logic_db", Collections.singleton(new FixtureRuleConfiguration())), props).build(); assertThat(actual.getDatabaseType(), CoreMatchers.is(databaseType)); assertRules(actual); assertDataSources(actual); assertTrue(actual.getAuthentication().getUsers().isEmpty()); assertThat(actual.getProps().getProps().size(), CoreMatchers.is(1)); assertThat(actual.getProps().getValue(ConfigurationPropertyKey.EXECUTOR_SIZE), CoreMatchers.is(1)); assertFalse(actual.isCircuitBreak()); }