@Test public void stereotypeComponent() { testComponent(SampleComponent.class); }
@Test public void stereotypeControllerMetaIndex() { testSingleComponent(SampleMetaIndexedController.class, Component.class, MetaControllerIndexed.class); }
@Test public void embeddedNonStaticCandidateAreIgnored() { CandidateComponentsMetadata metadata = compile(SampleNonStaticEmbedded.class); assertThat(metadata.getItems(), hasSize(0)); }
private CandidateComponentsMetadata compile(String... types) { CandidateComponentsIndexer processor = new CandidateComponentsIndexer(); this.compiler.getTask(types).call(processor); return readGeneratedMetadata(this.compiler.getOutputLocation()); }
@Test public void noCandidate() { CandidateComponentsMetadata metadata = compile(SampleNone.class); assertThat(metadata.getItems(), hasSize(0)); }
private CandidateComponentsMetadata compile(Class<?>... types) { CandidateComponentsIndexer processor = new CandidateComponentsIndexer(); this.compiler.getTask(types).call(processor); return readGeneratedMetadata(this.compiler.getOutputLocation()); }
@Test public void persistenceConverter() { testSingleComponent(SampleConverter.class, Converter.class); }
@Test public void noAnnotation() { CandidateComponentsMetadata metadata = compile(CandidateComponentsIndexerTests.class); assertThat(metadata.getItems(), hasSize(0)); }
@Test public void stereotypeService() { testComponent(SampleService.class); }
@Test public void typeStereotypeFromSeveralInterfaces() { testSingleComponent(SampleSmartRepo.class, Repo.class, SmartRepo.class); }
private void testSingleComponent(Class<?> target, Class<?>... stereotypes) { CandidateComponentsMetadata metadata = compile(target); assertThat(metadata, hasComponent(target, stereotypes)); assertThat(metadata.getItems(), hasSize(1)); }
@Test public void stereotypeController() { testComponent(SampleController.class); }
@Test public void persistenceEntity() { testSingleComponent(SampleEntity.class, Entity.class); }
@Test public void packageInfo() { CandidateComponentsMetadata metadata = compile( "org/springframework/context/index/sample/jpa/package-info"); assertThat(metadata, hasComponent( "org.springframework.context.index.sample.jpa", "package-info")); }
@Test public void stereotypeControllerMetaAnnotation() { testComponent(SampleMetaController.class); }
@Test public void persistenceMappedSuperClass() { testSingleComponent(SampleMappedSuperClass.class, MappedSuperclass.class); }
private void testComponent(Class<?>... classes) { CandidateComponentsMetadata metadata = compile(classes); for (Class<?> c : classes) { assertThat(metadata, hasComponent(c, Component.class)); } assertThat(metadata.getItems(), hasSize(classes.length)); }
@Test public void stereotypeOnAbstractClass() { testComponent(AbstractController.class); }
@Test public void stereotypeRepository() { testSingleComponent(SampleRepository.class, Component.class); }
@Test public void embeddedCandidatesAreDetected() throws IOException, ClassNotFoundException { // Validate nested type structure String nestedType = "org.springframework.context.index.sample.SampleEmbedded.Another$AnotherPublicCandidate"; Class<?> type = ClassUtils.forName(nestedType, getClass().getClassLoader()); assertThat(type, sameInstance(SampleEmbedded.Another.AnotherPublicCandidate.class)); CandidateComponentsMetadata metadata = compile(SampleEmbedded.class); assertThat(metadata, hasComponent( SampleEmbedded.PublicCandidate.class, Component.class)); assertThat(metadata, hasComponent(nestedType, Component.class.getName())); assertThat(metadata.getItems(), hasSize(2)); }