22
22
import java .util .Map ;
23
23
24
24
import org .junit .Test ;
25
-
26
25
import org .springframework .data .keyvalue .annotation .KeySpace ;
27
26
import org .springframework .data .keyvalue .core .mapping .context .KeyValueMappingContext ;
28
27
import org .springframework .data .mapping .context .MappingContext ;
@@ -41,28 +40,38 @@ public class BasicKeyValuePersistentEntityUnitTests {
41
40
@ Test // DATAKV-268
42
41
public void shouldDeriveKeyspaceFromClassName () {
43
42
44
- KeyValuePersistentEntity <?, ?> persistentEntity = mappingContext .getPersistentEntity (KeyspaceEntity .class );
45
-
46
- assertThat (persistentEntity .getKeySpace ()).isEqualTo (KeyspaceEntity .class .getName ());
43
+ assertThat (mappingContext .getPersistentEntity (KeyspaceEntity .class ).getKeySpace ())
44
+ .isEqualTo (KeyspaceEntity .class .getName ());
47
45
}
48
46
49
47
@ Test // DATAKV-268
50
48
public void shouldEvaluateKeyspaceExpression () {
51
49
52
50
KeyValuePersistentEntity <?, ?> persistentEntity = mappingContext .getPersistentEntity (ExpressionEntity .class );
53
-
54
51
persistentEntity .setEvaluationContextProvider (
55
52
new ExtensionAwareEvaluationContextProvider (Collections .singletonList (new SampleExtension ())));
56
53
57
54
assertThat (persistentEntity .getKeySpace ()).isEqualTo ("some" );
58
55
}
59
56
57
+ @ Test // DATAKV-268
58
+ public void shouldEvaluateEntityWithoutKeyspace () {
59
+
60
+ KeyValuePersistentEntity <?, ?> persistentEntity = mappingContext .getPersistentEntity (NoKeyspaceEntity .class );
61
+ persistentEntity .setEvaluationContextProvider (
62
+ new ExtensionAwareEvaluationContextProvider (Collections .singletonList (new SampleExtension ())));
63
+
64
+ assertThat (persistentEntity .getKeySpace ()).isEqualTo (NoKeyspaceEntity .class .getName ());
65
+ }
66
+
60
67
@ KeySpace ("#{myProperty}" )
61
68
static class ExpressionEntity {}
62
69
63
70
@ KeySpace
64
71
static class KeyspaceEntity {}
65
72
73
+ static class NoKeyspaceEntity {}
74
+
66
75
static class SampleExtension implements EvaluationContextExtension {
67
76
68
77
@ Override
0 commit comments