Skip to content

Commit 09c6e2e

Browse files
committed
Added a new test to avoid regression
#2204 breaks this test
1 parent b91f62b commit 09c6e2e

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/test/java/org/apache/ibatis/submitted/cache/CacheTest.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2020 the original author or authors.
2+
* Copyright 2009-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ void setUp() throws Exception {
5050

5151
// populate in-memory database
5252
BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
53-
"org/apache/ibatis/submitted/cache/CreateDB.sql");
53+
"org/apache/ibatis/submitted/cache/CreateDB.sql");
5454
}
5555

5656
/*
@@ -250,6 +250,25 @@ void shouldApplyCacheNamespaceRef() {
250250
}
251251
}
252252

253+
@Test
254+
void shouldResultBeCachedAfterInsert() {
255+
try (SqlSession sqlSession = sqlSessionFactory.openSession(true)) {
256+
PersonMapper pm = sqlSession.getMapper(PersonMapper.class);
257+
// create
258+
Person p = new Person(3, "hello", "world");
259+
pm.create(p);
260+
// select (result should be cached)
261+
Assertions.assertEquals(3, pm.findAll().size());
262+
// create without flush (cache unchanged)
263+
Person p2 = new Person(4, "bonjour", "world");
264+
pm.createWithoutFlushCache(p2);
265+
}
266+
try (SqlSession sqlSession = sqlSessionFactory.openSession(true)) {
267+
PersonMapper pm = sqlSession.getMapper(PersonMapper.class);
268+
Assertions.assertEquals(3, pm.findAll().size());
269+
}
270+
}
271+
253272
@Test
254273
void shouldApplyCustomCacheProperties() {
255274
CustomCache customCache = unwrap(sqlSessionFactory.getConfiguration().getCache(CustomCacheMapper.class.getName()));
@@ -274,23 +293,23 @@ void shouldApplyCustomCacheProperties() {
274293
void shouldErrorUnsupportedProperties() {
275294
when(() -> sqlSessionFactory.getConfiguration().addMapper(CustomCacheUnsupportedPropertyMapper.class));
276295
then(caughtException()).isInstanceOf(CacheException.class)
277-
.hasMessage("Unsupported property type for cache: 'date' of type class java.util.Date");
296+
.hasMessage("Unsupported property type for cache: 'date' of type class java.util.Date");
278297
}
279298

280299
@Test
281300
void shouldErrorInvalidCacheNamespaceRefAttributesSpecifyBoth() {
282301
when(() -> sqlSessionFactory.getConfiguration().getMapperRegistry()
283-
.addMapper(InvalidCacheNamespaceRefBothMapper.class));
302+
.addMapper(InvalidCacheNamespaceRefBothMapper.class));
284303
then(caughtException()).isInstanceOf(BuilderException.class)
285-
.hasMessage("Cannot use both value() and name() attribute in the @CacheNamespaceRef");
304+
.hasMessage("Cannot use both value() and name() attribute in the @CacheNamespaceRef");
286305
}
287306

288307
@Test
289308
void shouldErrorInvalidCacheNamespaceRefAttributesIsEmpty() {
290309
when(() -> sqlSessionFactory.getConfiguration().getMapperRegistry()
291-
.addMapper(InvalidCacheNamespaceRefEmptyMapper.class));
310+
.addMapper(InvalidCacheNamespaceRefEmptyMapper.class));
292311
then(caughtException()).isInstanceOf(BuilderException.class)
293-
.hasMessage("Should be specified either value() or name() attribute in the @CacheNamespaceRef");
312+
.hasMessage("Should be specified either value() or name() attribute in the @CacheNamespaceRef");
294313
}
295314

296315
private CustomCache unwrap(Cache cache){
@@ -311,7 +330,7 @@ private CustomCache unwrap(Cache cache){
311330
}
312331

313332
@CacheNamespace(implementation = CustomCache.class, properties = {
314-
@Property(name = "date", value = "2016/11/21")
333+
@Property(name = "date", value = "2016/11/21")
315334
})
316335
private interface CustomCacheUnsupportedPropertyMapper {
317336
}

0 commit comments

Comments
 (0)