1
1
/**
2
- * Copyright 2009-2020 the original author or authors.
2
+ * Copyright 2009-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ void setUp() throws Exception {
50
50
51
51
// populate in-memory database
52
52
BaseDataTest .runScript (sqlSessionFactory .getConfiguration ().getEnvironment ().getDataSource (),
53
- "org/apache/ibatis/submitted/cache/CreateDB.sql" );
53
+ "org/apache/ibatis/submitted/cache/CreateDB.sql" );
54
54
}
55
55
56
56
/*
@@ -250,6 +250,25 @@ void shouldApplyCacheNamespaceRef() {
250
250
}
251
251
}
252
252
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
+
253
272
@ Test
254
273
void shouldApplyCustomCacheProperties () {
255
274
CustomCache customCache = unwrap (sqlSessionFactory .getConfiguration ().getCache (CustomCacheMapper .class .getName ()));
@@ -274,23 +293,23 @@ void shouldApplyCustomCacheProperties() {
274
293
void shouldErrorUnsupportedProperties () {
275
294
when (() -> sqlSessionFactory .getConfiguration ().addMapper (CustomCacheUnsupportedPropertyMapper .class ));
276
295
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" );
278
297
}
279
298
280
299
@ Test
281
300
void shouldErrorInvalidCacheNamespaceRefAttributesSpecifyBoth () {
282
301
when (() -> sqlSessionFactory .getConfiguration ().getMapperRegistry ()
283
- .addMapper (InvalidCacheNamespaceRefBothMapper .class ));
302
+ .addMapper (InvalidCacheNamespaceRefBothMapper .class ));
284
303
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" );
286
305
}
287
306
288
307
@ Test
289
308
void shouldErrorInvalidCacheNamespaceRefAttributesIsEmpty () {
290
309
when (() -> sqlSessionFactory .getConfiguration ().getMapperRegistry ()
291
- .addMapper (InvalidCacheNamespaceRefEmptyMapper .class ));
310
+ .addMapper (InvalidCacheNamespaceRefEmptyMapper .class ));
292
311
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" );
294
313
}
295
314
296
315
private CustomCache unwrap (Cache cache ){
@@ -311,7 +330,7 @@ private CustomCache unwrap(Cache cache){
311
330
}
312
331
313
332
@ CacheNamespace (implementation = CustomCache .class , properties = {
314
- @ Property (name = "date" , value = "2016/11/21" )
333
+ @ Property (name = "date" , value = "2016/11/21" )
315
334
})
316
335
private interface CustomCacheUnsupportedPropertyMapper {
317
336
}
0 commit comments