Java Code Examples for org.springframework.stereotype.Component

The following examples show how to use org.springframework.stereotype.Component. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testWithComponentAnnotationOnly() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Repository.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Service.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(3, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
	assertFalse(containsBeanClass(candidates, StubFooDao.class));
	assertFalse(containsBeanClass(candidates, NamedStubDao.class));
}
 
Example 2
Source Project: tephra   Source File: ClassReloaderImpl.java    License: MIT License 6 votes vote down vote up
private String getBeanName(Class<?> clazz) {
    Component component = clazz.getAnnotation(Component.class);
    if (component != null)
        return component.value();

    Repository repository = clazz.getAnnotation(Repository.class);
    if (repository != null)
        return repository.value();

    Service service = clazz.getAnnotation(Service.class);
    if (service != null)
        return service.value();

    Controller controller = clazz.getAnnotation(Controller.class);
    if (controller != null)
        return controller.value();

    return null;
}
 
Example 3
Source Project: spring-analysis-note   Source File: AnnotationUtilsTests.java    License: MIT License 6 votes vote down vote up
@Test
public void synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases() throws Exception {
	// 1) Get an annotation
	Component component = WebController.class.getAnnotation(Component.class);
	assertNotNull(component);

	// 2) Convert the annotation into AnnotationAttributes
	AnnotationAttributes attributes = getAnnotationAttributes(WebController.class, component);
	assertNotNull(attributes);

	// 3) Synthesize the AnnotationAttributes back into an annotation
	Component synthesizedComponent = synthesizeAnnotation(attributes, Component.class, WebController.class);
	assertNotNull(synthesizedComponent);

	// 4) Verify that the original and synthesized annotations are equivalent
	assertNotSame(component, synthesizedComponent);
	assertEquals(component, synthesizedComponent);
	assertEquals("value from component: ", "webController", component.value());
	assertEquals("value from synthesized component: ", "webController", synthesizedComponent.value());
}
 
Example 4
Source Project: typescript-generator   Source File: SpringApplicationParser.java    License: MIT License 6 votes vote down vote up
public List<Class<?>> findRestControllers() {
    try (ConfigurableApplicationContext context = createApplicationContext()) {
        load(context, getAllSources().toArray());
        withSystemProperty("server.port", "0", () -> {
            context.refresh();
        });
        final List<Class<?>> classes = Stream.of(context.getBeanDefinitionNames())
            .map(beanName -> context.getBeanFactory().getBeanDefinition(beanName).getBeanClassName())
            .filter(Objects::nonNull)
            .filter(className -> isClassNameExcluded == null || !isClassNameExcluded.test(className))
            .map(className -> {
                try {
                    return classLoader.loadClass(className);
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
                }
            })
            .filter(instance -> AnnotationUtils.findAnnotation(instance, Component.class) != null)
            .collect(Collectors.toList());
        return classes;
    }
}
 
Example 5
Source Project: spring-analysis-note   Source File: AnnotationMetadataTests.java    License: MIT License 6 votes vote down vote up
private void doTestSubClassAnnotationInfo(AnnotationMetadata metadata) {
	assertThat(metadata.getClassName(), is(AnnotatedComponentSubClass.class.getName()));
	assertThat(metadata.isInterface(), is(false));
	assertThat(metadata.isAnnotation(), is(false));
	assertThat(metadata.isAbstract(), is(false));
	assertThat(metadata.isConcrete(), is(true));
	assertThat(metadata.hasSuperClass(), is(true));
	assertThat(metadata.getSuperClassName(), is(AnnotatedComponent.class.getName()));
	assertThat(metadata.getInterfaceNames().length, is(0));
	assertThat(metadata.isAnnotated(Component.class.getName()), is(false));
	assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
	assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Component.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.getAnnotationTypes().size(), is(0));
	assertThat(metadata.getAnnotationAttributes(Component.class.getName()), nullValue());
	assertThat(metadata.getAnnotatedMethods(DirectAnnotation.class.getName()).size(), equalTo(0));
	assertThat(metadata.isAnnotated(IsAnnotatedAnnotation.class.getName()), equalTo(false));
	assertThat(metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName()), nullValue());
}
 
Example 6
Source Project: java-technology-stack   Source File: AnnotationMetadataTests.java    License: MIT License 6 votes vote down vote up
private void doTestSubClassAnnotationInfo(AnnotationMetadata metadata) {
	assertThat(metadata.getClassName(), is(AnnotatedComponentSubClass.class.getName()));
	assertThat(metadata.isInterface(), is(false));
	assertThat(metadata.isAnnotation(), is(false));
	assertThat(metadata.isAbstract(), is(false));
	assertThat(metadata.isConcrete(), is(true));
	assertThat(metadata.hasSuperClass(), is(true));
	assertThat(metadata.getSuperClassName(), is(AnnotatedComponent.class.getName()));
	assertThat(metadata.getInterfaceNames().length, is(0));
	assertThat(metadata.isAnnotated(Component.class.getName()), is(false));
	assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
	assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Component.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.getAnnotationTypes().size(), is(0));
	assertThat(metadata.getAnnotationAttributes(Component.class.getName()), nullValue());
	assertThat(metadata.getAnnotatedMethods(DirectAnnotation.class.getName()).size(), equalTo(0));
	assertThat(metadata.isAnnotated(IsAnnotatedAnnotation.class.getName()), equalTo(false));
	assertThat(metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName()), nullValue());
}
 
Example 7
Source Project: spring-analysis-note   Source File: AnnotationMetadataTests.java    License: MIT License 6 votes vote down vote up
private void doTestMetadataForAnnotationClass(AnnotationMetadata metadata) {
	assertThat(metadata.getClassName(), is(Component.class.getName()));
	assertThat(metadata.isInterface(), is(true));
	assertThat(metadata.isAnnotation(), is(true));
	assertThat(metadata.isAbstract(), is(true));
	assertThat(metadata.isConcrete(), is(false));
	assertThat(metadata.hasSuperClass(), is(false));
	assertThat(metadata.getSuperClassName(), nullValue());
	assertThat(metadata.getInterfaceNames().length, is(1));
	assertThat(metadata.getInterfaceNames()[0], is(Annotation.class.getName()));
	assertThat(metadata.isAnnotated(Documented.class.getName()), is(false));
	assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
	assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Documented.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.getAnnotationTypes().size(), is(1));
}
 
Example 8
Source Project: spring-analysis-note   Source File: MetaAnnotationUtilsTests.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass,
		Class<?> rootDeclaringClass, Class<?> declaringClass, String name,
		Class<? extends Annotation> composedAnnotationType) {

	Class<Component> annotationType = Component.class;
	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
			startClass, Service.class, annotationType, Order.class, Transactional.class);

	assertNotNull("UntypedAnnotationDescriptor should not be null", descriptor);
	assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass());
	assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass());
	assertEquals("annotationType", annotationType, descriptor.getAnnotationType());
	assertEquals("component name", name, ((Component) descriptor.getAnnotation()).value());
	assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation());
	assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType());
}
 
Example 9
Source Project: java-technology-stack   Source File: AnnotationUtilsTests.java    License: MIT License 6 votes vote down vote up
@Test
public void synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases() throws Exception {
	// 1) Get an annotation
	Component component = WebController.class.getAnnotation(Component.class);
	assertNotNull(component);

	// 2) Convert the annotation into AnnotationAttributes
	AnnotationAttributes attributes = getAnnotationAttributes(WebController.class, component);
	assertNotNull(attributes);

	// 3) Synthesize the AnnotationAttributes back into an annotation
	Component synthesizedComponent = synthesizeAnnotation(attributes, Component.class, WebController.class);
	assertNotNull(synthesizedComponent);

	// 4) Verify that the original and synthesized annotations are equivalent
	assertNotSame(component, synthesizedComponent);
	assertEquals(component, synthesizedComponent);
	assertEquals("value from component: ", "webController", component.value());
	assertEquals("value from synthesized component: ", "webController", synthesizedComponent.value());
}
 
Example 10
private void doTestMetadataForAnnotationClass(AnnotationMetadata metadata) {
	assertThat(metadata.getClassName(), is(Component.class.getName()));
	assertThat(metadata.isInterface(), is(true));
	assertThat(metadata.isAnnotation(), is(true));
	assertThat(metadata.isAbstract(), is(true));
	assertThat(metadata.isConcrete(), is(false));
	assertThat(metadata.hasSuperClass(), is(false));
	assertThat(metadata.getSuperClassName(), nullValue());
	assertThat(metadata.getInterfaceNames().length, is(1));
	assertThat(metadata.getInterfaceNames()[0], is(Annotation.class.getName()));
	assertThat(metadata.isAnnotated(Documented.class.getName()), is(false));
	assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
	assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Documented.class.getName()), is(true));
	assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.getAnnotationTypes().size(), is(3));
}
 
Example 11
@Test
public void testWithComponentAnnotationOnly() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Repository.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Service.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(3, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
	assertFalse(containsBeanClass(candidates, StubFooDao.class));
	assertFalse(containsBeanClass(candidates, NamedStubDao.class));
}
 
Example 12
@Test
// Test for SPR-6268
public void testRefreshableFromTagProxyTargetClass() throws Exception {
	ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-proxy-target-class.xml",
			getClass());
	assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));

	Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");

	assertTrue(AopUtils.isAopProxy(messenger));
	assertTrue(messenger instanceof Refreshable);
	assertEquals("Hello World!", messenger.getMessage());

	assertTrue(ctx.getBeansOfType(ConcreteMessenger.class).values().contains(messenger));

	// Check that AnnotationUtils works with concrete proxied script classes
	assertNotNull(AnnotationUtils.findAnnotation(messenger.getClass(), Component.class));
}
 
Example 13
Source Project: zstack   Source File: ConfigurationManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void generateApiMessageGroovyClass(StringBuilder sb, List<String> basePkgs) {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.addIncludeFilter(new AssignableTypeFilter(APIMessage.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(APIReply.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(APIEvent.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Component.class));
    for (String pkg : basePkgs) {
        for (BeanDefinition bd : scanner.findCandidateComponents(pkg)) {
            try {
                Class<?> clazz = Class.forName(bd.getBeanClassName());
                //classToApiMessageGroovyClass(sb, clazz);
                classToApiMessageGroovyInformation(sb, clazz);
            } catch (ClassNotFoundException e) {
                logger.warn(String.format("Unable to generate groovy class for %s", bd.getBeanClassName()), e);
            }
        }
    }
}
 
Example 14
Source Project: echo   Source File: NexusArtifactExtractor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<Artifact> getArtifacts(String source, Map payloadMap) {
  NexusPayload payload = mapper.convertValue(payloadMap, NexusPayload.class);
  if (payload.getComponent() == null) {
    return Collections.emptyList();
  } else {
    Component component = payload.getComponent();
    return Collections.singletonList(
        Artifact.builder()
            .type("maven/file")
            .name(component.getGroup() + ":" + component.getName())
            .reference(
                component.getGroup() + ":" + component.getName() + ":" + component.getVersion())
            .version(component.getVersion())
            .provenance(payload.getRepositoryName())
            .build());
  }
}
 
Example 15
Source Project: java-technology-stack   Source File: MetaAnnotationUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() {
	Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class);

	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
			ClassWithMetaAnnotatedInterface.class, Service.class, Component.class, Order.class, Transactional.class);

	assertNotNull(descriptor);
	assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass());
	assertEquals(Meta1.class, descriptor.getDeclaringClass());
	assertEquals(rawAnnotation, descriptor.getAnnotation());
	assertEquals(Meta1.class, descriptor.getComposedAnnotation().annotationType());
}
 
Example 16
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() throws Exception {
	Class<Component> annotationType = Component.class;
	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
		HasLocalAndMetaComponentAnnotation.class, Transactional.class, annotationType, Order.class);
	assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass());
	assertEquals(annotationType, descriptor.getAnnotationType());
	assertNull(descriptor.getComposedAnnotation());
	assertNull(descriptor.getComposedAnnotationType());
}
 
Example 17
Source Project: super-csv-annotation   Source File: SpringBeanFactory.java    License: Apache License 2.0 5 votes vote down vote up
private String getBeanName(final Class<?> clazz) {

        final Component componentAnno = clazz.getAnnotation(Component.class);
        if(componentAnno != null && !componentAnno.value().isEmpty()) {
            return componentAnno.value();
        }

        final Service serviceAnno = clazz.getAnnotation(Service.class);
        if(serviceAnno != null && !serviceAnno.value().isEmpty()) {
            return serviceAnno.value();
        }

        final Repository repositoryAnno = clazz.getAnnotation(Repository.class);
        if(repositoryAnno != null && !repositoryAnno.value().isEmpty()) {
            return repositoryAnno.value();
        }

        final Controller controllerAnno = clazz.getAnnotation(Controller.class);
        if(controllerAnno != null && !controllerAnno.value().isEmpty()) {
            return controllerAnno.value();
        }

        // ステレオタイプのアノテーションでBean名の指定がない場合は、クラス名の先頭を小文字にした名称とする。
        String simpleName = uncapitalize(clazz.getSimpleName());

        String[] names = applicationContext.getBeanNamesForType(clazz);
        if(names.length == 0) {
            return simpleName;
        }

        // 複数存在する場合、候補の中から一番シンプルな形式の名前で一致するものを選択する
        for(String name : names) {
            if(name.equals(simpleName)) {
                return name;
            }
        }

        // 見つからない場合は、候補の先頭のものにする。
        return names[0];
    }
 
Example 18
@Test
public void testExcludeTakesPrecedence() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
	provider.addExcludeFilter(new AssignableTypeFilter(FooService.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(6, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
}
 
Example 19
@SuppressWarnings("unchecked")
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass,
		Class<?> rootDeclaringClass, Class<?> declaringClass, String name,
		Class<? extends Annotation> composedAnnotationType) {
	Class<Component> annotationType = Component.class;
	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class,
		annotationType, Order.class, Transactional.class);
	assertNotNull("UntypedAnnotationDescriptor should not be null", descriptor);
	assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass());
	assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass());
	assertEquals("annotationType", annotationType, descriptor.getAnnotationType());
	assertEquals("component name", name, ((Component) descriptor.getAnnotation()).value());
	assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation());
	assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType());
}
 
Example 20
Source Project: java-technology-stack   Source File: MetaAnnotationUtilsTests.java    License: MIT License 5 votes vote down vote up
/**
 * @since 4.0.3
 */
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() {
	// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component,
	// @Service, or @Order, but it is annotated with @Transactional.
	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
			InheritedAnnotationClass.class, Service.class, Component.class, Order.class);
	assertNull("Should not find @Component on InheritedAnnotationClass", descriptor);
}
 
Example 21
Source Project: cuba   Source File: DynamicAttributesGuiTools.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@code ValueChangeEventListener} for dynamic attribute that has one or more dependent attributes.
 * This listener recalculates values for all dependent dynamic attributes hierarchically. The listener uses
 * {@code recalculationInProgress} ThreadLocal variable to avoid unnecessary calculation.
 */
@SuppressWarnings("unchecked")
public Consumer<HasValue.ValueChangeEvent> getValueChangeEventListener(final CategoryAttribute attribute) {
    if (attribute.getConfiguration().getDependentAttributes() != null
            && !attribute.getConfiguration().getDependentAttributes().isEmpty()) {

        return valueChangeEvent -> {
            if (Boolean.TRUE.equals(recalculationInProgress.get())) {
                return;
            }
            try {
                recalculationInProgress.set(true);

                com.haulmont.cuba.gui.components.Component component = valueChangeEvent.getComponent();
                if (component instanceof HasValueSource
                        && ((HasValueSource) component).getValueSource() instanceof ContainerValueSource) {

                    ContainerValueSource valueSource = (ContainerValueSource) ((HasValueSource) component).getValueSource();
                    InstanceContainer container = valueSource.getContainer();

                    if (container.getItem() instanceof BaseGenericIdEntity) {
                        BaseGenericIdEntity entity = (BaseGenericIdEntity) container.getItem();
                        String attributeCode = DynamicAttributesUtils.encodeAttributeCode(attribute.getCode());

                        entity.setValue(attributeCode, valueChangeEvent.getValue());

                        recalculationTools.recalculateDynamicAttributes(entity, attribute);
                    }
                }
            } finally {
                recalculationInProgress.remove();
            }
        };
    }
    return null;
}
 
Example 22
Source Project: spring-analysis-note   Source File: AnnotationUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void synthesizeAnnotationFromMapWithoutAttributeAliases() throws Exception {
	Component component = WebController.class.getAnnotation(Component.class);
	assertNotNull(component);

	Map<String, Object> map = Collections.singletonMap(VALUE, "webController");
	Component synthesizedComponent = synthesizeAnnotation(map, Component.class, WebController.class);
	assertNotNull(synthesizedComponent);

	assertNotSame(component, synthesizedComponent);
	assertEquals("value from component: ", "webController", component.value());
	assertEquals("value from synthesized component: ", "webController", synthesizedComponent.value());
}
 
Example 23
Source Project: spring-analysis-note   Source File: AnnotatedElementUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void getMetaAnnotationTypesOnClassWithMetaDepth2() {
	Set<String> names = getMetaAnnotationTypes(ComposedTransactionalComponentClass.class, ComposedTransactionalComponent.class);
	assertEquals(names(TransactionalComponent.class, Transactional.class, Component.class, Indexed.class), names);

	names = getMetaAnnotationTypes(ComposedTransactionalComponentClass.class, ComposedTransactionalComponent.class.getName());
	assertEquals(names(TransactionalComponent.class, Transactional.class, Component.class, Indexed.class), names);
}
 
Example 24
Source Project: spring-analysis-note   Source File: AnnotatedElementUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void isAnnotatedWithNameOnClassWithMetaDepth() {
	assertTrue(isAnnotated(TransactionalComponentClass.class, TransactionalComponent.class.getName()));
	assertFalse("isAnnotated() does not search the class hierarchy.",
			isAnnotated(SubTransactionalComponentClass.class, TransactionalComponent.class.getName()));
	assertTrue(isAnnotated(TransactionalComponentClass.class, TX_NAME));
	assertTrue(isAnnotated(TransactionalComponentClass.class, Component.class.getName()));
	assertTrue(isAnnotated(ComposedTransactionalComponentClass.class, TX_NAME));
	assertTrue(isAnnotated(ComposedTransactionalComponentClass.class, Component.class.getName()));
	assertTrue(isAnnotated(ComposedTransactionalComponentClass.class, ComposedTransactionalComponent.class.getName()));
}
 
Example 25
Source Project: spring-analysis-note   Source File: AnnotatedElementUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void hasAnnotationOnClassWithMetaDepth() {
	assertTrue(hasAnnotation(TransactionalComponentClass.class, TransactionalComponent.class));
	assertTrue(hasAnnotation(SubTransactionalComponentClass.class, TransactionalComponent.class));
	assertTrue(hasAnnotation(TransactionalComponentClass.class, Transactional.class));
	assertTrue(hasAnnotation(TransactionalComponentClass.class, Component.class));
	assertTrue(hasAnnotation(ComposedTransactionalComponentClass.class, Transactional.class));
	assertTrue(hasAnnotation(ComposedTransactionalComponentClass.class, Component.class));
	assertTrue(hasAnnotation(ComposedTransactionalComponentClass.class, ComposedTransactionalComponent.class));
}
 
Example 26
/**
 * @since 4.0.3
 */
@Test
public void findAnnotationDescriptorOnAnnotatedClassWithMissingTargetMetaAnnotation() {
	// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component
	AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(InheritedAnnotationClass.class,
		Component.class);
	assertNull("Should not find @Component on InheritedAnnotationClass", descriptor);
}
 
Example 27
/**
 * @since 4.0.3
 */
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(MetaCycleAnnotatedClass.class,
		Service.class, Component.class, Order.class);
	assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor);
}
 
Example 28
/**
 * @since 4.0.3
 */
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() {
	// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component,
	// @Service, or @Order, but it is annotated with @Transactional.
	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(InheritedAnnotationClass.class,
		Service.class, Component.class, Order.class);
	assertNull("Should not find @Component on InheritedAnnotationClass", descriptor);
}
 
Example 29
Source Project: spring-analysis-note   Source File: MergedAnnotationsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void isPresentWhenFromAnnotationClassWithMetaDepth2() {
	MergedAnnotations annotations = MergedAnnotations.from(
			ComposedTransactionalComponent.class);
	assertThat(annotations.isPresent(Transactional.class)).isTrue();
	assertThat(annotations.isPresent(Component.class)).isTrue();
	assertThat(annotations.isPresent(ComposedTransactionalComponent.class)).isFalse();
}
 
Example 30
Source Project: spring-analysis-note   Source File: MergedAnnotationsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void isPresentWhenFromClassWithMetaDepth1() {
	MergedAnnotations annotations = MergedAnnotations.from(
			TransactionalComponentClass.class);
	assertThat(annotations.isPresent(Transactional.class)).isTrue();
	assertThat(annotations.isPresent(Component.class)).isTrue();
}