|
1 | 1 | /*
|
2 |
| - * Copyright 2011-2014 by the original author(s). |
| 2 | + * Copyright 2011-2016 by the original author(s). |
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.
|
|
29 | 29 | import org.mockito.Mock;
|
30 | 30 | import org.mockito.runners.MockitoJUnitRunner;
|
31 | 31 | import org.springframework.context.ApplicationContext;
|
| 32 | +import org.springframework.core.annotation.AliasFor; |
32 | 33 | import org.springframework.data.mapping.model.MappingException;
|
33 | 34 | import org.springframework.data.util.ClassTypeInformation;
|
34 | 35 |
|
@@ -243,6 +244,18 @@ public void metaInformationShouldBeReadCorrectlyFromInheritedDocumentAnnotation(
|
243 | 244 | assertThat(entity.getCollection(), is("collection-1"));
|
244 | 245 | }
|
245 | 246 |
|
| 247 | + /** |
| 248 | + * @see DATAMONGO-1373 |
| 249 | + */ |
| 250 | + @Test |
| 251 | + public void metaInformationShouldBeReadCorrectlyFromComposedDocumentAnnotation() { |
| 252 | + |
| 253 | + BasicMongoPersistentEntity<DocumentWithComposedAnnotation> entity = new BasicMongoPersistentEntity<DocumentWithComposedAnnotation>( |
| 254 | + ClassTypeInformation.from(DocumentWithComposedAnnotation.class)); |
| 255 | + |
| 256 | + assertThat(entity.getCollection(), is("custom-collection")); |
| 257 | + } |
| 258 | + |
246 | 259 | @Document(collection = "contacts")
|
247 | 260 | class Contact {
|
248 | 261 |
|
@@ -284,9 +297,23 @@ static class DocumentWithCustomAnnotation {
|
284 | 297 |
|
285 | 298 | }
|
286 | 299 |
|
| 300 | + @ComposedDocumentAnnotation |
| 301 | + static class DocumentWithComposedAnnotation { |
| 302 | + |
| 303 | + } |
| 304 | + |
287 | 305 | @Retention(RetentionPolicy.RUNTIME)
|
288 | 306 | @Target({ ElementType.TYPE })
|
289 | 307 | @Document(collection = "collection-1")
|
290 | 308 | static @interface CustomDocumentAnnotation {
|
291 | 309 | }
|
| 310 | + |
| 311 | + @Retention(RetentionPolicy.RUNTIME) |
| 312 | + @Target({ ElementType.TYPE }) |
| 313 | + @Document |
| 314 | + static @interface ComposedDocumentAnnotation { |
| 315 | + |
| 316 | + @AliasFor(annotation = Document.class, attribute = "collection") |
| 317 | + String name() default "custom-collection"; |
| 318 | + } |
292 | 319 | }
|
0 commit comments