Skip to content

Commit

Permalink
#3146 Add additional test to ensure the fully qualified statements ar…
Browse files Browse the repository at this point in the history
…e found
  • Loading branch information
epochcoder committed Jan 3, 2025
1 parent b28588e commit ad8c4d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
30 changes: 15 additions & 15 deletions src/main/java/org/apache/ibatis/session/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2024 the original author or authors.
* Copyright 2009-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,20 +15,6 @@
*/
package org.apache.ibatis.session;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.BiFunction;

import org.apache.ibatis.binding.MapperRegistry;
import org.apache.ibatis.builder.CacheRefResolver;
import org.apache.ibatis.builder.IncompleteElementException;
Expand Down Expand Up @@ -97,6 +83,20 @@
import org.apache.ibatis.type.TypeHandler;
import org.apache.ibatis.type.TypeHandlerRegistry;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.BiFunction;

/**
* @author Clinton Begin
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,16 +15,10 @@
*/
package org.apache.ibatis.submitted.global_variables_defaults;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Properties;

import org.apache.ibatis.builder.StaticSqlSource;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ResultMap;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.parsing.PropertyParser;
import org.apache.ibatis.session.Configuration;
Expand All @@ -34,6 +28,10 @@
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.Reader;
import java.util.Properties;

class ConfigurationTest {

@Test
Expand Down Expand Up @@ -87,24 +85,24 @@ void applyPropertyValueOnXmlConfiguration() throws IOException {
@Test
void testAmbiguityCache() {
Configuration configuration = new Configuration();

configuration.addMappedStatement(
new MappedStatement.Builder(configuration,
"org.apache.ibatis.submitted.DemoMapper1.selectById",
new StaticSqlSource(configuration, "select * from test where id = 1"), SqlCommandType.SELECT).build()
);
configuration.addMappedStatement(
new MappedStatement.Builder(configuration,
"org.apache.ibatis.submitted.DemoMapper1.test",
new StaticSqlSource(configuration, "select * from test"), SqlCommandType.SELECT).build()
);
configuration.addMappedStatement(
new MappedStatement.Builder(configuration,
"org.apache.ibatis.submitted.DemoMapper2.test",
new StaticSqlSource(configuration, "select * from test"), SqlCommandType.SELECT).build()
);
new MappedStatement.Builder(configuration, "org.apache.ibatis.submitted.DemoMapper1.selectById",
new StaticSqlSource(configuration, "select * from test where id = 1"), SqlCommandType.SELECT).build());
configuration
.addMappedStatement(new MappedStatement.Builder(configuration, "org.apache.ibatis.submitted.DemoMapper1.test",
new StaticSqlSource(configuration, "select * from test"), SqlCommandType.SELECT).build());
configuration
.addMappedStatement(new MappedStatement.Builder(configuration, "org.apache.ibatis.submitted.DemoMapper2.test",
new StaticSqlSource(configuration, "select * from test"), SqlCommandType.SELECT).build());

Assertions.assertThat(configuration.getMappedStatement("selectById")).isNotNull();
Assertions.assertThat(configuration.getMappedStatement("org.apache.ibatis.submitted.DemoMapper1.test")).isNotNull();
Assertions.assertThat(configuration.getMappedStatement("org.apache.ibatis.submitted.DemoMapper2.test")).isNotNull();

Assertions.assertThatThrownBy(() -> configuration.getMappedStatement("test"))
.isInstanceOf(IllegalArgumentException.class).hasMessage("test is ambiguous in Mapped Statements collection (try using the full name including the namespace, or rename one of the entries)");
.isInstanceOf(IllegalArgumentException.class).hasMessage(
"test is ambiguous in Mapped Statements collection (try using the full name including the namespace, or rename one of the entries)");
}

}

0 comments on commit ad8c4d0

Please sign in to comment.