Java 类org.springframework.core.type.classreading.SimpleMetadataReaderFactory 实例源码

项目:spring-cloud-ribbon-extensions    文件:ExecutionContextPropagationImportTest.java   
@Test
public void selectImports() throws Exception {
    assertThat(imports.selectImports(metadata).length, is(0));

    when(metadata.getAnnotationAttributes(EnableContextPropagation.class.getName(), true)).thenReturn(null);
    assertThat(imports.selectImports(metadata).length, is(0));

    assertThat(imports.selectImports(metadata).length, is(0));

    List<String> actual = Arrays.asList(imports.selectImports(new SimpleMetadataReaderFactory().getMetadataReader(Annotated.class.getName()).getAnnotationMetadata()));
    assertThat(actual, Matchers.containsInAnyOrder(
            PreservesHeadersInboundHttpRequestStrategy.class.getName(),
            PreservesHttpHeadersFeignStrategy.class.getName(),
            PreservesExecutionContextExecutorStrategy.class.getName(),
            PreservesHttpHeadersZuulStrategy.class.getName(),
            PreservesExecutionContextHystrixStrategy.class.getName(),
            PreservesJmsMessagePropertiesStrategy.class.getName(),
            PreservesStompHeadersStrategy.class.getName()
    ));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:TypeExcludeFiltersContextCustomizerFactoryTests.java   
@Test
public void getContextCustomizerShouldAddExcludeFilters() throws Exception {
    ContextCustomizer customizer = this.factory
            .createContextCustomizer(WithExcludeFilters.class, null);
    customizer.customizeContext(this.context, this.mergedContextConfiguration);
    this.context.refresh();
    TypeExcludeFilter filter = this.context.getBean(TypeExcludeFilter.class);
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory
            .getMetadataReader(NoAnnotation.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isFalse();
    metadataReader = metadataReaderFactory
            .getMetadataReader(SimpleExclude.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
    metadataReader = metadataReaderFactory
            .getMetadataReader(TestClassAwareExclude.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:WebServletHandlerTests.java   
@SuppressWarnings("unchecked")
@Test
public void defaultServletConfiguration() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(
            new SimpleMetadataReaderFactory()
                    .getMetadataReader(DefaultConfigurationServlet.class.getName()));
    this.handler.handle(scanned, this.registry);
    BeanDefinition servletRegistrationBean = this.registry
            .getBeanDefinition(DefaultConfigurationServlet.class.getName());
    MutablePropertyValues propertyValues = servletRegistrationBean
            .getPropertyValues();
    assertThat(propertyValues.get("asyncSupported")).isEqualTo(false);
    assertThat(((Map<String, String>) propertyValues.get("initParameters")))
            .isEmpty();
    assertThat((Integer) propertyValues.get("loadOnStartup")).isEqualTo(-1);
    assertThat(propertyValues.get("name"))
            .isEqualTo(DefaultConfigurationServlet.class.getName());
    assertThat((String[]) propertyValues.get("urlMappings")).isEmpty();
    assertThat(propertyValues.get("servlet")).isEqualTo(scanned);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:WebFilterHandlerTests.java   
@SuppressWarnings("unchecked")
@Test
public void defaultFilterConfiguration() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(
            new SimpleMetadataReaderFactory()
                    .getMetadataReader(DefaultConfigurationFilter.class.getName()));
    this.handler.handle(scanned, this.registry);
    BeanDefinition filterRegistrationBean = this.registry
            .getBeanDefinition(DefaultConfigurationFilter.class.getName());
    MutablePropertyValues propertyValues = filterRegistrationBean.getPropertyValues();
    assertThat(propertyValues.get("asyncSupported")).isEqualTo(false);
    assertThat((EnumSet<DispatcherType>) propertyValues.get("dispatcherTypes"))
            .containsExactly(DispatcherType.REQUEST);
    assertThat(((Map<String, String>) propertyValues.get("initParameters")))
            .isEmpty();
    assertThat((String[]) propertyValues.get("servletNames")).isEmpty();
    assertThat((String[]) propertyValues.get("urlPatterns")).isEmpty();
    assertThat(propertyValues.get("name"))
            .isEqualTo(DefaultConfigurationFilter.class.getName());
    assertThat(propertyValues.get("filter")).isEqualTo(scanned);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AbstractConfigurationClassTests.java   
private Set<AnnotationMetadata> findConfigurationClasses() throws IOException {
    Set<AnnotationMetadata> configurationClasses = new HashSet<AnnotationMetadata>();
    Resource[] resources = this.resolver.getResources("classpath*:"
            + getClass().getPackage().getName().replace(".", "/") + "/**/*.class");
    for (Resource resource : resources) {
        if (!isTestClass(resource)) {
            MetadataReader metadataReader = new SimpleMetadataReaderFactory()
                    .getMetadataReader(resource);
            AnnotationMetadata annotationMetadata = metadataReader
                    .getAnnotationMetadata();
            if (annotationMetadata.getAnnotationTypes()
                    .contains(Configuration.class.getName())) {
                configurationClasses.add(annotationMetadata);
            }
        }
    }
    return configurationClasses;
}
项目:spring-boot-concourse    文件:TypeExcludeFiltersContextCustomizerFactoryTests.java   
@Test
public void getContextCustomizerShouldAddExcludeFilters() throws Exception {
    ContextCustomizer customizer = this.factory
            .createContextCustomizer(WithExcludeFilters.class, null);
    customizer.customizeContext(this.context, this.mergedContextConfiguration);
    this.context.refresh();
    TypeExcludeFilter filter = this.context.getBean(TypeExcludeFilter.class);
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory
            .getMetadataReader(NoAnnotation.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isFalse();
    metadataReader = metadataReaderFactory
            .getMetadataReader(SimpleExclude.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
    metadataReader = metadataReaderFactory
            .getMetadataReader(TestClassAwareExclude.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
}
项目:spring-boot-concourse    文件:WebServletHandlerTests.java   
@SuppressWarnings("unchecked")
@Test
public void defaultServletConfiguration() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(
            new SimpleMetadataReaderFactory()
                    .getMetadataReader(DefaultConfigurationServlet.class.getName()));
    this.handler.handle(scanned, this.registry);
    BeanDefinition servletRegistrationBean = this.registry
            .getBeanDefinition(DefaultConfigurationServlet.class.getName());
    MutablePropertyValues propertyValues = servletRegistrationBean
            .getPropertyValues();
    assertThat(propertyValues.get("asyncSupported")).isEqualTo(false);
    assertThat(((Map<String, String>) propertyValues.get("initParameters")))
            .isEmpty();
    assertThat((Integer) propertyValues.get("loadOnStartup")).isEqualTo(-1);
    assertThat(propertyValues.get("name"))
            .isEqualTo(DefaultConfigurationServlet.class.getName());
    assertThat((String[]) propertyValues.get("urlMappings")).isEmpty();
    assertThat(propertyValues.get("servlet")).isEqualTo(scanned);
}
项目:spring-boot-concourse    文件:WebFilterHandlerTests.java   
@SuppressWarnings("unchecked")
@Test
public void defaultFilterConfiguration() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(
            new SimpleMetadataReaderFactory()
                    .getMetadataReader(DefaultConfigurationFilter.class.getName()));
    this.handler.handle(scanned, this.registry);
    BeanDefinition filterRegistrationBean = this.registry
            .getBeanDefinition(DefaultConfigurationFilter.class.getName());
    MutablePropertyValues propertyValues = filterRegistrationBean.getPropertyValues();
    assertThat(propertyValues.get("asyncSupported")).isEqualTo(false);
    assertThat((EnumSet<DispatcherType>) propertyValues.get("dispatcherTypes"))
            .containsExactly(DispatcherType.REQUEST);
    assertThat(((Map<String, String>) propertyValues.get("initParameters")))
            .isEmpty();
    assertThat((String[]) propertyValues.get("servletNames")).isEmpty();
    assertThat((String[]) propertyValues.get("urlPatterns")).isEmpty();
    assertThat(propertyValues.get("name"))
            .isEqualTo(DefaultConfigurationFilter.class.getName());
    assertThat(propertyValues.get("filter")).isEqualTo(scanned);
}
项目:spring-boot-concourse    文件:AbstractConfigurationClassTests.java   
private Set<AnnotationMetadata> findConfigurationClasses() throws IOException {
    Set<AnnotationMetadata> configurationClasses = new HashSet<AnnotationMetadata>();
    Resource[] resources = this.resolver.getResources("classpath*:"
            + getClass().getPackage().getName().replace(".", "/") + "/**/*.class");
    for (Resource resource : resources) {
        if (!isTestClass(resource)) {
            MetadataReader metadataReader = new SimpleMetadataReaderFactory()
                    .getMetadataReader(resource);
            AnnotationMetadata annotationMetadata = metadataReader
                    .getAnnotationMetadata();
            if (annotationMetadata.getAnnotationTypes()
                    .contains(Configuration.class.getName())) {
                configurationClasses.add(annotationMetadata);
            }
        }
    }
    return configurationClasses;
}
项目:contestparser    文件:WebServletHandlerTests.java   
@SuppressWarnings("unchecked")
@Test
public void defaultServletConfiguration() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(
            new SimpleMetadataReaderFactory()
                    .getMetadataReader(DefaultConfigurationServlet.class.getName()));
    this.handler.handle(scanned, this.registry);
    BeanDefinition servletRegistrationBean = this.registry
            .getBeanDefinition(DefaultConfigurationServlet.class.getName());
    MutablePropertyValues propertyValues = servletRegistrationBean
            .getPropertyValues();
    assertThat(propertyValues.get("asyncSupported"), is((Object) false));
    assertThat(((Map<String, String>) propertyValues.get("initParameters")).size(),
            is(0));
    assertThat((Integer) propertyValues.get("loadOnStartup"), is(-1));
    assertThat(propertyValues.get("name"),
            is((Object) DefaultConfigurationServlet.class.getName()));
    assertThat((String[]) propertyValues.get("urlMappings"), is(arrayWithSize(0)));
    assertThat(propertyValues.get("servlet"), is(equalTo((Object) scanned)));
}
项目:contestparser    文件:WebFilterHandlerTests.java   
@SuppressWarnings("unchecked")
@Test
public void defaultFilterConfiguration() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(
            new SimpleMetadataReaderFactory()
                    .getMetadataReader(DefaultConfigurationFilter.class.getName()));
    this.handler.handle(scanned, this.registry);
    BeanDefinition filterRegistrationBean = this.registry
            .getBeanDefinition(DefaultConfigurationFilter.class.getName());
    MutablePropertyValues propertyValues = filterRegistrationBean.getPropertyValues();
    assertThat(propertyValues.get("asyncSupported"), is((Object) false));
    assertThat((EnumSet<DispatcherType>) propertyValues.get("dispatcherTypes"),
            is(EnumSet.of(DispatcherType.REQUEST)));
    assertThat(((Map<String, String>) propertyValues.get("initParameters")).size(),
            is(0));
    assertThat((String[]) propertyValues.get("servletNames"), is(arrayWithSize(0)));
    assertThat((String[]) propertyValues.get("urlPatterns"), is(arrayWithSize(0)));
    assertThat(propertyValues.get("name"),
            is((Object) DefaultConfigurationFilter.class.getName()));
    assertThat(propertyValues.get("filter"), is(equalTo((Object) scanned)));
}
项目:contestparser    文件:AbstractConfigurationClassTests.java   
private Set<AnnotationMetadata> findConfigurationClasses() throws IOException {
    Set<AnnotationMetadata> configurationClasses = new HashSet<AnnotationMetadata>();
    Resource[] resources = this.resolver.getResources("classpath*:"
            + getClass().getPackage().getName().replace(".", "/") + "/**/*.class");
    for (Resource resource : resources) {
        if (!isTestClass(resource)) {
            MetadataReader metadataReader = new SimpleMetadataReaderFactory()
                    .getMetadataReader(resource);
            AnnotationMetadata annotationMetadata = metadataReader
                    .getAnnotationMetadata();
            if (annotationMetadata.getAnnotationTypes()
                    .contains(Configuration.class.getName())) {
                configurationClasses.add(annotationMetadata);
            }
        }
    }
    return configurationClasses;
}
项目:guzz    文件:PackageScanTest.java   
public void testClassesInFileSystem() throws IOException{
    PathMatchingResourcePatternResolver pr = new PathMatchingResourcePatternResolver() ;
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(pr);

    Resource[] rs = pr.getResources("classpath*:nu/xom/*.class") ;
    System.out.println(rs.length) ;
    for(Resource r : rs){
        if(r.isReadable()){
            try{
                MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(r);
                String className = metadataReader.getClassMetadata().getClassName() ;

                System.out.println(className) ;
            }catch(Exception e){
                //Not a class

                System.out.println("file:" + r.getURL().toString()) ;
            }
        }else{
            System.out.println("no read:" + r.getFile().getAbsolutePath()) ;
        }
    }
}
项目:jsonrpc4j    文件:AutoJsonRpcClientProxyCreator.java   
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(applicationContext);
    DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) beanFactory;
    String resolvedPath = resolvePackageToScan();
    logger.debug("Scanning '{}' for JSON-RPC service interfaces.", resolvedPath);
    try {
        for (Resource resource : applicationContext.getResources(resolvedPath)) {
            if (resource.isReadable()) {
                MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                ClassMetadata classMetadata = metadataReader.getClassMetadata();
                AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
                String jsonRpcPathAnnotation = JsonRpcService.class.getName();
                if (annotationMetadata.isAnnotated(jsonRpcPathAnnotation)) {
                    String className = classMetadata.getClassName();
                    String path = (String) annotationMetadata.getAnnotationAttributes(jsonRpcPathAnnotation).get("value");
                    logger.debug("Found JSON-RPC service to proxy [{}] on path '{}'.", className, path);
                    registerJsonProxyBean(defaultListableBeanFactory, className, path);
                }
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(format("Cannot scan package '%s' for classes.", resolvedPath), e);
    }
}
项目:jsonrpc    文件:AutoJsonRpcClientProxyCreator.java   
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(applicationContext);
    DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) beanFactory;
    String resolvedPath = resolvePackageToScan();
    LOG.debug(format("Scanning '%s' for JSON-RPC service interfaces.", resolvedPath));
    try {
        for (Resource resource : applicationContext.getResources(resolvedPath)) {
            if (resource.isReadable()) {
                MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                ClassMetadata classMetadata = metadataReader.getClassMetadata();
                AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
                String jsonRpcPathAnnotation = JsonRpcService.class.getName();
                if (annotationMetadata.isAnnotated(jsonRpcPathAnnotation)) {
                    String className = classMetadata.getClassName();
                    String path = (String) annotationMetadata.getAnnotationAttributes(jsonRpcPathAnnotation).get("value");
                    boolean useNamedParams = (Boolean) annotationMetadata.getAnnotationAttributes(jsonRpcPathAnnotation).get("useNamedParams");
                    LOG.debug(format("Found JSON-RPC service to proxy [%s] on path '%s'.", className, path));
                    registerJsonProxyBean(dlbf, className, path, useNamedParams);
                }
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(format("Cannot scan package '%s' for classes.", resolvedPath), e);
    }
}
项目:lodsve-framework    文件:AbstractNestedCondition.java   
MemberConditions(ConditionContext context, String className) {
    this.context = context;
    this.readerFactory = new SimpleMetadataReaderFactory(
            context.getResourceLoader());
    String[] members = getMetadata(className).getMemberClassNames();
    this.memberConditions = getMemberConditions(members);
}
项目:spring4-understanding    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void customRequestScopeViaAsm() throws IOException {
    MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory();
    MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScope.class.getName());
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata());
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals("request", scopeMetadata.getScopeName());
    assertEquals(NO, scopeMetadata.getScopedProxyMode());
}
项目:spring4-understanding    文件:AnnotationScopeMetadataResolverTests.java   
@Test
public void customRequestScopeWithAttributeViaAsm() throws IOException {
    MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory();
    MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScopeWithAttributeOverride.class.getName());
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata());
    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
    assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
    assertEquals("request", scopeMetadata.getScopeName());
    assertEquals(TARGET_CLASS, scopeMetadata.getScopedProxyMode());
}
项目:spring4-understanding    文件:AnnotationTypeFilterTests.java   
@Test
public void testDirectAnnotationMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeComponent";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);

    AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class);
    assertTrue(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
项目:spring4-understanding    文件:AnnotationTypeFilterTests.java   
@Test
public void testInheritedAnnotationFromInterfaceDoesNotMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubClassOfSomeComponentInterface";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);

    AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class);
    // Must fail as annotation on interfaces should not be considered a match
    assertFalse(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
项目:spring4-understanding    文件:AnnotationTypeFilterTests.java   
@Test
public void testInheritedAnnotationFromBaseClassDoesMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubClassOfSomeComponent";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);

    AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class);
    assertTrue(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
项目:spring4-understanding    文件:AnnotationTypeFilterTests.java   
@Test
public void testNonInheritedAnnotationDoesNotMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubclassOfSomeClassMarkedWithNonInheritedAnnotation";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);

    AnnotationTypeFilter filter = new AnnotationTypeFilter(NonInheritedAnnotation.class);
    // Must fail as annotation isn't inherited
    assertFalse(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
项目:spring4-understanding    文件:AnnotationTypeFilterTests.java   
@Test
public void testNonAnnotatedClassDoesntMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeNonCandidateClass";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);

    AnnotationTypeFilter filter = new AnnotationTypeFilter(Component.class);
    assertFalse(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
项目:spring4-understanding    文件:AnnotationTypeFilterTests.java   
@Test
public void testMatchesInterfacesIfConfigured() throws Exception {

    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeComponentInterface";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);

    AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class, false, true);

    assertTrue(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
项目:spring4-understanding    文件:AnnotationMetadataTests.java   
@Test
public void asmAnnotationMetadata() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(AnnotatedComponent.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    doTestAnnotationInfo(metadata);
    doTestMethodAnnotationInfo(metadata);
}
项目:spring4-understanding    文件:AnnotationMetadataTests.java   
@Test
public void asmAnnotationMetadataForSubclass() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(AnnotatedComponentSubClass.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    doTestSubClassAnnotationInfo(metadata);
}
项目:spring4-understanding    文件:AnnotationMetadataTests.java   
@Test
public void asmAnnotationMetadataForInterface() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(AnnotationMetadata.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    doTestMetadataForInterfaceClass(metadata);
}
项目:spring4-understanding    文件:AnnotationMetadataTests.java   
@Test
public void asmAnnotationMetadataForAnnotation() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(Component.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    doTestMetadataForAnnotationClass(metadata);
}
项目:spring4-understanding    文件:AnnotationMetadataTests.java   
@Test
public void metaAnnotationOverridesUsingAnnotationMetadataReadingVisitor() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(ComposedConfigurationWithAttributeOverridesClass.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    assertMetaAnnotationOverrides(metadata);
}
项目:spring4-understanding    文件:AnnotationMetadataTests.java   
/**
 * https://jira.spring.io/browse/SPR-11649
 */
@Test
public void multipleAnnotationsWithIdenticalAttributeNamesUsingAnnotationMetadataReadingVisitor() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(NamedAnnotationsClass.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    assertMultipleAnnotationsWithIdenticalAttributeNames(metadata);
}
项目:spring4-understanding    文件:AnnotationMetadataTests.java   
/**
 * https://jira.spring.io/browse/SPR-11649
 */
@Test
public void composedAnnotationWithMetaAnnotationsWithIdenticalAttributeNamesUsingAnnotationMetadataReadingVisitor() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(NamedComposedAnnotationClass.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    assertMultipleAnnotationsWithIdenticalAttributeNames(metadata);
}
项目:spring4-understanding    文件:AssignableTypeFilterTests.java   
@Test
public void directMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$TestNonInheritingClass";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);

    AssignableTypeFilter matchingFilter = new AssignableTypeFilter(TestNonInheritingClass.class);
    AssignableTypeFilter notMatchingFilter = new AssignableTypeFilter(TestInterface.class);
    assertFalse(notMatchingFilter.match(metadataReader, metadataReaderFactory));
    assertTrue(matchingFilter.match(metadataReader, metadataReaderFactory));
}
项目:spring4-understanding    文件:AssignableTypeFilterTests.java   
@Test
public void interfaceMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$TestInterfaceImpl";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);

    AssignableTypeFilter filter = new AssignableTypeFilter(TestInterface.class);
    assertTrue(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
项目:spring4-understanding    文件:AssignableTypeFilterTests.java   
@Test
public void superClassMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);

    AssignableTypeFilter filter = new AssignableTypeFilter(SimpleJdbcDaoSupport.class);
    assertTrue(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
项目:spring4-understanding    文件:AssignableTypeFilterTests.java   
@Test
public void interfaceThroughSuperClassMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);

    AssignableTypeFilter filter = new AssignableTypeFilter(JdbcDaoSupport.class);
    assertTrue(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
项目:spring4-understanding    文件:AspectJTypeFilterTests.java   
private void assertMatch(String type, String typePattern) throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(type);

    AspectJTypeFilter filter = new AspectJTypeFilter(typePattern, getClass().getClassLoader());
    assertTrue(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(type);
}
项目:spring4-understanding    文件:AspectJTypeFilterTests.java   
private void assertNoMatch(String type, String typePattern) throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(type);

    AspectJTypeFilter filter = new AspectJTypeFilter(typePattern, getClass().getClassLoader());
    assertFalse(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(type);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:FilterAnnotationsTests.java   
private boolean match(FilterAnnotations filterAnnotations, Class<?> type)
        throws IOException {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory
            .getMetadataReader(type.getName());
    return filterAnnotations.anyMatches(metadataReader, metadataReaderFactory);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:WebListenerHandlerTests.java   
@Test
public void listener() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(
            new SimpleMetadataReaderFactory()
                    .getMetadataReader(TestListener.class.getName()));
    this.handler.handle(scanned, this.registry);
    this.registry.getBeanDefinition(TestListener.class.getName());
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:WebServletHandlerTests.java   
@Test
public void servletWithCustomName() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(
            new SimpleMetadataReaderFactory()
                    .getMetadataReader(CustomNameServlet.class.getName()));
    this.handler.handle(scanned, this.registry);
    BeanDefinition servletRegistrationBean = this.registry
            .getBeanDefinition("custom");
    MutablePropertyValues propertyValues = servletRegistrationBean
            .getPropertyValues();
    assertThat(propertyValues.get("name")).isEqualTo("custom");
}