Java 类org.springframework.boot.WebApplicationType 实例源码

项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void springSocialUserInfo() {
    TestPropertyValues
            .of("security.oauth2.resource.userInfoUri:http://example.com",
                    "spring.social.facebook.app-id=foo",
                    "spring.social.facebook.app-secret=bar")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(SocialResourceConfiguration.class)
            .environment(this.environment).web(WebApplicationType.SERVLET).run();
    ConnectionFactoryLocator connectionFactory = this.context
            .getBean(ConnectionFactoryLocator.class);
    assertThat(connectionFactory).isNotNull();
    SpringSocialTokenServices services = this.context
            .getBean(SpringSocialTokenServices.class);
    assertThat(services).isNotNull();
}
项目:spring-cloud-stream-binder-rabbit    文件:RabbitBinderModuleTests.java   
@Test
public void testParentConnectionFactoryInheritedIfOverridden() {
    context = new SpringApplicationBuilder(SimpleProcessor.class, ConnectionFactoryConfiguration.class)
            .web(WebApplicationType.NONE)
            .run("--server.port=0");
    BinderFactory binderFactory = context.getBean(BinderFactory.class);
    Binder<?, ?, ?> binder = binderFactory.getBinder(null, MessageChannel.class);
    assertThat(binder).isInstanceOf(RabbitMessageChannelBinder.class);
    DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
    ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
            .getPropertyValue("connectionFactory");
    assertThat(binderConnectionFactory).isSameAs(MOCK_CONNECTION_FACTORY);
    ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
    assertThat(binderConnectionFactory).isSameAs(connectionFactory);
    CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
            CompositeHealthIndicator.class);
    assertThat(bindersHealthIndicator).isNotNull();
    DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
    @SuppressWarnings("unchecked")
    Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
            .getPropertyValue("indicators");
    assertThat(healthIndicators).containsKey("rabbit");
    // mock connection factory behaves as if down
    assertThat(healthIndicators.get("rabbit").health().getStatus()).isEqualTo(Status.DOWN);
}
项目:spring-cloud-stream    文件:HealthIndicatorsConfigurationTests.java   
public static ConfigurableApplicationContext createBinderTestContext(
        String[] additionalClasspathDirectories, String... properties)
        throws IOException {
    URL[] urls = ObjectUtils.isEmpty(additionalClasspathDirectories) ? new URL[0]
            : new URL[additionalClasspathDirectories.length];
    if (!ObjectUtils.isEmpty(additionalClasspathDirectories)) {
        for (int i = 0; i < additionalClasspathDirectories.length; i++) {
            urls[i] = new URL(new ClassPathResource(additionalClasspathDirectories[i])
                    .getURL().toString() + "/");
        }
    }
    ClassLoader classLoader = new URLClassLoader(urls,
            BinderFactoryConfigurationTests.class.getClassLoader());
    return new SpringApplicationBuilder(SimpleSource.class)
            .resourceLoader(new DefaultResourceLoader(classLoader))
            .properties(properties).web(WebApplicationType.NONE).run();
}
项目:spring-cloud-commons    文件:BootstrapConfigurationTests.java   
@Test
public void bootstrapPropertiesAvailableInInitializer() {
    this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
            .sources(BareConfiguration.class).initializers(
                    new ApplicationContextInitializer<ConfigurableApplicationContext>() {
                        @Override
                        public void initialize(
                                ConfigurableApplicationContext applicationContext) {
                            // This property is defined in bootstrap.properties
                            assertEquals("child", applicationContext.getEnvironment()
                                    .getProperty("info.name"));
                        }
                    })
            .run();
    assertTrue(this.context.getEnvironment().getPropertySources().contains(
            PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME));
}
项目:spring-cloud-commons    文件:BootstrapConfigurationTests.java   
@Test
public void applicationNameInBootstrapAndMain() {
    System.setProperty("expected.name", "main");
    this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
            .properties("spring.cloud.bootstrap.name:other",
                    "spring.config.name:plain")
            .sources(BareConfiguration.class).run();
    assertEquals("app",
            this.context.getEnvironment().getProperty("spring.application.name"));
    // The parent is called "main" because spring.application.name is specified in
    // other.properties (the bootstrap properties)
    assertEquals("main", this.context.getParent().getEnvironment()
            .getProperty("spring.application.name"));
    // The bootstrap context has the same "bootstrap" property source
    assertEquals(this.context.getEnvironment().getPropertySources().get("bootstrap"),
            ((ConfigurableEnvironment) this.context.getParent().getEnvironment())
                    .getPropertySources().get("bootstrap"));
    assertEquals("main-1", this.context.getId());
}
项目:spring-cloud-commons    文件:BootstrapConfigurationTests.java   
@Test
public void applicationNameOnlyInBootstrap() {
    System.setProperty("expected.name", "main");
    this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
            .properties("spring.cloud.bootstrap.name:other")
            .sources(BareConfiguration.class).run();
    // The main context is called "main" because spring.application.name is specified
    // in other.properties (and not in the main config file)
    assertEquals("main",
            this.context.getEnvironment().getProperty("spring.application.name"));
    // The parent is called "main" because spring.application.name is specified in
    // other.properties (the bootstrap properties this time)
    assertEquals("main", this.context.getParent().getEnvironment()
            .getProperty("spring.application.name"));
    assertEquals("main-1", this.context.getId());
}
项目:spring-cloud-commons    文件:BootstrapConfigurationTests.java   
@Test
public void bootstrapContextSharedBySiblings() {
    TestHigherPriorityBootstrapConfiguration.count.set(0);
    PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
    SpringApplicationBuilder builder = new SpringApplicationBuilder()
            .sources(BareConfiguration.class);
    this.sibling = builder.child(BareConfiguration.class)
            .properties("spring.application.name=sibling")
            .web(WebApplicationType.NONE).run();
    this.context = builder.child(BareConfiguration.class)
            .properties("spring.application.name=context")
            .web(WebApplicationType.NONE).run();
    assertEquals(1, TestHigherPriorityBootstrapConfiguration.count.get());
    assertNotNull(context.getParent());
    assertEquals("bootstrap", context.getParent().getParent().getId());
    assertNull(context.getParent().getParent().getParent());
    assertEquals("context", context.getEnvironment().getProperty("custom.foo"));
    assertEquals("context",
            context.getEnvironment().getProperty("spring.application.name"));
    assertNotNull(sibling.getParent());
    assertEquals("bootstrap", sibling.getParent().getParent().getId());
    assertNull(sibling.getParent().getParent().getParent());
    assertEquals("sibling", sibling.getEnvironment().getProperty("custom.foo"));
    assertEquals("sibling",
            sibling.getEnvironment().getProperty("spring.application.name"));
}
项目:spring-cloud-commons    文件:EncryptionBootstrapConfigurationTests.java   
@Test
public void nonExistentKeystoreLocationShouldNotBeAllowed() {
    try {
        new SpringApplicationBuilder(EncryptionBootstrapConfiguration.class)
                .web(WebApplicationType.NONE)
                .properties("encrypt.key-store.location:classpath:/server.jks1",
                        "encrypt.key-store.password:letmein",
                        "encrypt.key-store.alias:mytestkey",
                        "encrypt.key-store.secret:changeme")
                .run();
        assertThat(false).as(
                "Should not create an application context with invalid keystore location")
                .isTrue();
    }
    catch (Exception e) {
        assertThat(e).hasRootCauseInstanceOf(IllegalStateException.class);
    }
}
项目:spring-cloud-commons    文件:RefreshEndpointTests.java   
@Test
public void keysComputedWhenChangesInExternalProperties() throws Exception {
    this.context = new SpringApplicationBuilder(Empty.class)
            .web(WebApplicationType.NONE).bannerMode(Mode.OFF)
            .properties("spring.cloud.bootstrap.name:none").run();
    RefreshScope scope = new RefreshScope();
    scope.setApplicationContext(this.context);
    TestPropertyValues
            .of("spring.cloud.bootstrap.sources="
                    + ExternalPropertySourceLocator.class.getName())
            .applyTo(this.context.getEnvironment(), Type.MAP, "defaultProperties");
    ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
    RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
    Collection<String> keys = endpoint.refresh();
    assertTrue("Wrong keys: " + keys, keys.contains("external.message"));
}
项目:spring-cloud-commons    文件:RefreshEndpointTests.java   
@Test
public void springMainSourcesEmptyInRefreshCycle() throws Exception {
    this.context = new SpringApplicationBuilder(Empty.class)
            .web(WebApplicationType.NONE).bannerMode(Mode.OFF)
            .properties("spring.cloud.bootstrap.name:none").run();
    RefreshScope scope = new RefreshScope();
    scope.setApplicationContext(this.context);
    // spring.main.sources should be empty when the refresh cycle starts (we don't
    // want any config files from the application context getting into the one used to
    // construct the environment for refresh)
    TestPropertyValues
            .of("spring.main.sources="
                    + ExternalPropertySourceLocator.class.getName())
            .applyTo(this.context);
    ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
    RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
    Collection<String> keys = endpoint.refresh();
    assertFalse("Wrong keys: " + keys, keys.contains("external.message"));
}
项目:spring-boot-admin    文件:InstancesControllerIntegrationTest.java   
@Before
public void setUp() {
    instance = new SpringApplicationBuilder().sources(AdminApplicationTest.TestAdminApplication.class)
                                             .web(WebApplicationType.REACTIVE)
                                             .run("--server.port=0", "--eureka.client.enabled=false");

    localPort = instance.getEnvironment().getProperty("local.server.port", Integer.class, 0);

    this.client = WebTestClient.bindToServer().baseUrl("http://localhost:" + localPort).build();
    this.register_as_test = "{ \"name\": \"test\", \"healthUrl\": \"http://localhost:" +
                            localPort +
                            "/application/health\" }";
    this.register_as_twice = "{ \"name\": \"twice\", \"healthUrl\": \"http://localhost:" +
                             localPort +
                             "/application/health\" }";
}
项目:spring-boot-admin    文件:AdminApplicationHazelcastTest.java   
@Before
public void setUp() throws Exception {
    System.setProperty("hazelcast.wait.seconds.before.join", "0");
    instance1 = new SpringApplicationBuilder().sources(TestAdminApplication.class)
                                              .web(WebApplicationType.REACTIVE)
                                              .run("--server.port=0", "--management.endpoints.web.base-path=/mgmt",
                                                      "--endpoints.health.enabled=true", "--info.test=foobar",
                                                      "--spring.jmx.enabled=false",
                                                      "--eureka.client.enabled=false");

    instance2 = new SpringApplicationBuilder().sources(TestAdminApplication.class)
                                              .web(WebApplicationType.REACTIVE)
                                              .run("--server.port=0", "--management.endpoints.web.base-path=/mgmt",
                                                      "--endpoints.health.enabled=true", "--info.test=foobar",
                                                      "--spring.jmx.enabled=false",
                                                      "--eureka.client.enabled=false");

    super.setUp(instance1.getEnvironment().getProperty("local.server.port", Integer.class, 0));
    this.webClient2 = createWebClient(
            instance2.getEnvironment().getProperty("local.server.port", Integer.class, 0));
}
项目:spring-cloud-config    文件:NativeEnvironmentRepository.java   
@Override
public Environment findOne(String config, String profile, String label) {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(
            PropertyPlaceholderAutoConfiguration.class);
    ConfigurableEnvironment environment = getEnvironment(profile);
    builder.environment(environment);
    builder.web(WebApplicationType.NONE).bannerMode(Mode.OFF);
    if (!logger.isDebugEnabled()) {
        // Make the mini-application startup less verbose
        builder.logStartupInfo(false);
    }
    String[] args = getArgs(config, profile, label);
    // Explicitly set the listeners (to exclude logging listener which would change
    // log levels in the caller)
    builder.application()
            .setListeners(Arrays.asList(new ConfigFileApplicationListener()));
    ConfigurableApplicationContext context = builder.run(args);
    environment.getPropertySources().remove("profiles");
    try {
        return clean(new PassthruEnvironmentRepository(environment).findOne(config,
                profile, label));
    }
    finally {
        context.close();
    }
}
项目:spring-cloud-config    文件:MultipleJGitEnvironmentRepositoryIntegrationTests.java   
@Test
public void mappingRepo() throws IOException {
    String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
    String test1RepoUri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo");

    Map<String, Object> repoMapping = new LinkedHashMap<String, Object>();
    repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern", "*test1*");
    repoMapping.put("spring.cloud.config.server.git.repos[test1].uri", test1RepoUri);
    this.context = new SpringApplicationBuilder(TestConfiguration.class)
            .web(WebApplicationType.NONE)
            .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri)
            .properties(repoMapping).run();
    EnvironmentRepository repository = this.context
            .getBean(EnvironmentRepository.class);
    repository.findOne("test1-svc", "staging", "master");
    Environment environment = repository.findOne("test1-svc", "staging", "master");
    assertEquals(2, environment.getPropertySources().size());
}
项目:spring-cloud-config    文件:MultipleJGitEnvironmentRepositoryIntegrationTests.java   
@Test
public void mappingRepoWithProfile() throws IOException {
    String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
    String test1RepoUri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo");

    Map<String, Object> repoMapping = new LinkedHashMap<String, Object>();
    repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern",
            "*/staging");
    repoMapping.put("spring.cloud.config.server.git.repos[test1].uri", test1RepoUri);
    this.context = new SpringApplicationBuilder(TestConfiguration.class)
            .web(WebApplicationType.NONE)
            .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri)
            .properties(repoMapping).run();
    EnvironmentRepository repository = this.context
            .getBean(EnvironmentRepository.class);
    repository.findOne("test1-svc", "staging", "master");
    Environment environment = repository.findOne("test1-svc", "staging", "master");
    assertEquals(2, environment.getPropertySources().size());
}
项目:spring-cloud-config    文件:MultipleJGitEnvironmentRepositoryIntegrationTests.java   
@Test
public void mappingRepoWithProfileDefaultPatterns() throws IOException {
    String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
    String test1RepoUri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo");

    Map<String, Object> repoMapping = new LinkedHashMap<String, Object>();
    repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern",
            "*/staging");
    repoMapping.put("spring.cloud.config.server.git.repos[test1].uri", test1RepoUri);
    this.context = new SpringApplicationBuilder(TestConfiguration.class)
            .web(WebApplicationType.NONE)
            .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri)
            .properties(repoMapping).run();
    EnvironmentRepository repository = this.context
            .getBean(EnvironmentRepository.class);
    repository.findOne("test1-svc", "staging", "master");
    Environment environment = repository.findOne("test1-svc", "staging,cloud",
            "master");
    assertEquals(2, environment.getPropertySources().size());
}
项目:spring-cloud-config    文件:MultipleJGitEnvironmentRepositoryIntegrationTests.java   
@Test
public void mappingRepoWithProfiles() throws IOException {
    String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
    String test1RepoUri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo");

    Map<String, Object> repoMapping = new LinkedHashMap<String, Object>();
    repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[0]",
            "*/staging,*");
    repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[1]",
            "*/*,staging");
    repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[2]",
            "*/staging");
    repoMapping.put("spring.cloud.config.server.git.repos[test1].uri", test1RepoUri);
    this.context = new SpringApplicationBuilder(TestConfiguration.class)
            .web(WebApplicationType.NONE)
            .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri)
            .properties(repoMapping).run();
    EnvironmentRepository repository = this.context
            .getBean(EnvironmentRepository.class);
    repository.findOne("test1-svc", "staging", "master");
    Environment environment = repository.findOne("test1-svc", "cloud,staging",
            "master");
    assertEquals(2, environment.getPropertySources().size());
    environment = repository.findOne("test1-svc", "staging,cloud", "master");
    assertEquals(2, environment.getPropertySources().size());
}
项目:spring-cloud-config    文件:MultipleJGitEnvironmentRepositoryIntegrationTests.java   
@Test
public void mappingRepoWithJustUri() throws IOException {
    String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
    String test1RepoUri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo");

    Map<String, Object> repoMapping = new LinkedHashMap<String, Object>();
    repoMapping.put("spring.cloud.config.server.git.repos.test1-svc.uri", test1RepoUri);
    this.context = new SpringApplicationBuilder(TestConfiguration.class)
            .web(WebApplicationType.NONE)
            .properties("spring.cloud.config.server.git.uri:" + defaultRepoUri)
            .properties(repoMapping).run();
    EnvironmentRepository repository = this.context
            .getBean(EnvironmentRepository.class);
    repository.findOne("test1-svc", "staging", "master");
    Environment environment = repository.findOne("test1-svc", "staging", "master");
    assertEquals(2, environment.getPropertySources().size());
}
项目:spring-cloud-config    文件:SVNKitEnvironmentRepositoryIntegrationTests.java   
@Test
public void update() throws Exception {
    String uri = ConfigServerTestUtils.prepareLocalSvnRepo(
            "src/test/resources/svn-config-repo", "target/config");
    this.context = new SpringApplicationBuilder(TestConfiguration.class)
            .web(WebApplicationType.NONE).profiles("subversion")
            .run("--spring.cloud.config.server.svn.uri=" + uri);
    EnvironmentRepository repository = this.context
            .getBean(EnvironmentRepository.class);
    repository.findOne("bar", "staging", "trunk");
    Environment environment = repository.findOne("bar", "staging", "trunk");
    assertEquals("bar",
            environment.getPropertySources().get(0).getSource().get("foo"));
    updateRepoForUpdate(uri);
    environment = repository.findOne("bar", "staging", "trunk");
    assertEquals("foo",
            environment.getPropertySources().get(0).getSource().get("foo"));
}
项目:spring-cloud-config    文件:JGitEnvironmentRepositoryIntegrationTests.java   
@Test
public void pull() throws Exception {
    ConfigServerTestUtils.prepareLocalRepo();
    String uri = ConfigServerTestUtils.copyLocalRepo("config-copy");
    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
            .run("--spring.cloud.config.server.git.uri=" + uri);
    EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
    repository.findOne("bar", "staging", "master");
    Environment environment = repository.findOne("bar", "staging", "master");
    assertEquals("bar", environment.getPropertySources().get(0).getSource().get("foo"));
    Git git = Git.open(ResourceUtils.getFile(uri).getAbsoluteFile());
    git.checkout().setName("master").call();
    StreamUtils.copy("foo: foo", Charset.defaultCharset(),
            new FileOutputStream(ResourceUtils.getFile(uri + "/bar.properties")));
    git.add().addFilepattern("bar.properties").call();
    git.commit().setMessage("Updated for pull").call();
    environment = repository.findOne("bar", "staging", "master");
    assertEquals("foo", environment.getPropertySources().get(0).getSource().get("foo"));
}
项目:spring-cloud-config    文件:JGitEnvironmentRepositoryIntegrationTests.java   
@Test
public void findOne_CloneOnStartTrue_FindOneSuccess() throws Exception {
    ConfigServerTestUtils.prepareLocalRepo();
    String uri = ConfigServerTestUtils.copyLocalRepo("config-copy");
    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
            .run("--spring.cloud.config.server.git.uri=" + uri,
                    "--spring.cloud.config.server.git.cloneOnStart=true");
    EnvironmentRepository repository = this.context
            .getBean(JGitEnvironmentRepository.class);
    assertTrue(((JGitEnvironmentRepository) repository).isCloneOnStart());
    Environment environment = repository.findOne("bar", "staging", "master");
    assertEquals(2, environment.getPropertySources().size());
    assertEquals("bar", environment.getName());
    assertArrayEquals(new String[] { "staging" }, environment.getProfiles());
    assertEquals("master", environment.getLabel());
}
项目:spring-cloud-config    文件:JGitEnvironmentRepositoryIntegrationTests.java   
@Test
public void findOne_FileAddedToRepo_FindOneSuccess() throws Exception {
    ConfigServerTestUtils.prepareLocalRepo();
    String uri = ConfigServerTestUtils.copyLocalRepo("config-copy");
    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
            .run("--spring.cloud.config.server.git.uri=" + uri,
                    "--spring.cloud.config.server.git.cloneOnStart=true");
    EnvironmentRepository repository = this.context
            .getBean(EnvironmentRepository.class);
    repository.findOne("bar", "staging", "master");
    Environment environment = repository.findOne("bar", "staging", "master");
    assertEquals("bar", environment.getPropertySources().get(0).getSource().get("foo"));
    Git git = Git.open(ResourceUtils.getFile(uri).getAbsoluteFile());
    git.checkout().setName("master").call();
    StreamUtils.copy("foo: foo", Charset.defaultCharset(),
            new FileOutputStream(ResourceUtils.getFile(uri + "/bar.properties")));
    git.add().addFilepattern("bar.properties").call();
    git.commit().setMessage("Updated for pull").call();
    environment = repository.findOne("bar", "staging", "master");
    assertEquals("foo", environment.getPropertySources().get(0).getSource().get("foo"));
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void useRemoteTokenServices() {
    TestPropertyValues.of("security.oauth2.resource.tokenInfoUri:http://example.com")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(ResourceConfiguration.class)
            .environment(this.environment).web(WebApplicationType.NONE).run();
    RemoteTokenServices services = this.context.getBean(RemoteTokenServices.class);
    assertThat(services).isNotNull();
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void switchToUserInfo() {
    TestPropertyValues.of("security.oauth2.resource.userInfoUri:http://example.com")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(ResourceConfiguration.class)
            .environment(this.environment).web(WebApplicationType.NONE).run();
    UserInfoTokenServices services = this.context
            .getBean(UserInfoTokenServices.class);
    assertThat(services).isNotNull();
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void userInfoWithAuthorities() {
    TestPropertyValues.of("security.oauth2.resource.userInfoUri:http://example.com")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(AuthoritiesConfiguration.class)
            .environment(this.environment).web(WebApplicationType.NONE).run();
    UserInfoTokenServices services = this.context
            .getBean(UserInfoTokenServices.class);
    assertThat(services).isNotNull();
    assertThat(services).extracting("authoritiesExtractor")
            .containsExactly(this.context.getBean(AuthoritiesExtractor.class));
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void userInfoWithPrincipal() {
    TestPropertyValues.of("security.oauth2.resource.userInfoUri:http://example.com")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(PrincipalConfiguration.class)
            .environment(this.environment).web(WebApplicationType.NONE).run();
    UserInfoTokenServices services = this.context
            .getBean(UserInfoTokenServices.class);
    assertThat(services).isNotNull();
    assertThat(services).extracting("principalExtractor")
            .containsExactly(this.context.getBean(PrincipalExtractor.class));
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void userInfoWithClient() {
    TestPropertyValues.of("security.oauth2.client.client-id=acme",
            "security.oauth2.resource.userInfoUri:http://example.com",
            "server.port=-1", "debug=true").applyTo(this.environment);
    this.context = new SpringApplicationBuilder(ResourceNoClientConfiguration.class)
            .environment(this.environment).web(WebApplicationType.SERVLET).run();
    BeanDefinition bean = ((BeanDefinitionRegistry) this.context)
            .getBeanDefinition("scopedTarget.oauth2ClientContext");
    assertThat(bean.getScope()).isEqualTo("request");
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void preferUserInfo() {
    TestPropertyValues
            .of("security.oauth2.resource.userInfoUri:http://example.com",
                    "security.oauth2.resource.tokenInfoUri:http://example.com",
                    "security.oauth2.resource.preferTokenInfo:false")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(ResourceConfiguration.class)
            .environment(this.environment).web(WebApplicationType.NONE).run();
    UserInfoTokenServices services = this.context
            .getBean(UserInfoTokenServices.class);
    assertThat(services).isNotNull();
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void userInfoWithCustomizer() {
    TestPropertyValues
            .of("security.oauth2.resource.userInfoUri:http://example.com",
                    "security.oauth2.resource.tokenInfoUri:http://example.com",
                    "security.oauth2.resource.preferTokenInfo:false")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(ResourceConfiguration.class,
            Customizer.class).environment(this.environment)
                    .web(WebApplicationType.NONE).run();
    UserInfoTokenServices services = this.context
            .getBean(UserInfoTokenServices.class);
    assertThat(services).isNotNull();
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void switchToJwt() {
    TestPropertyValues.of("security.oauth2.resource.jwt.keyValue=FOOBAR")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(ResourceConfiguration.class)
            .environment(this.environment).web(WebApplicationType.NONE).run();
    DefaultTokenServices services = this.context.getBean(DefaultTokenServices.class);
    assertThat(services).isNotNull();
    this.thrown.expect(NoSuchBeanDefinitionException.class);
    this.context.getBean(RemoteTokenServices.class);
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void asymmetricJwt() {
    TestPropertyValues.of("security.oauth2.resource.jwt.keyValue=" + PUBLIC_KEY)
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(ResourceConfiguration.class)
            .environment(this.environment).web(WebApplicationType.NONE).run();
    DefaultTokenServices services = this.context.getBean(DefaultTokenServices.class);
    assertThat(services).isNotNull();
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void jwkConfiguration() throws Exception {
    TestPropertyValues
            .of("security.oauth2.resource.jwk.key-set-uri=http://my-auth-server/token_keys")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(ResourceConfiguration.class)
            .environment(this.environment).web(WebApplicationType.NONE).run();
    DefaultTokenServices services = this.context.getBean(DefaultTokenServices.class);
    assertThat(services).isNotNull();
    this.thrown.expect(NoSuchBeanDefinitionException.class);
    this.context.getBean(RemoteTokenServices.class);
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void customUserInfoRestTemplateFactory() {
    TestPropertyValues.of("security.oauth2.resource.userInfoUri:http://example.com")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(
            CustomUserInfoRestTemplateFactory.class, ResourceConfiguration.class)
                    .environment(this.environment).web(WebApplicationType.NONE).run();
    assertThat(this.context.getBeansOfType(UserInfoRestTemplateFactory.class))
            .hasSize(1);
    assertThat(this.context.getBean(UserInfoRestTemplateFactory.class))
            .isInstanceOf(CustomUserInfoRestTemplateFactory.class);
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void jwtAccessTokenConverterIsConfiguredWhenKeyUriIsProvided() {
    TestPropertyValues
            .of("security.oauth2.resource.jwt.key-uri=http://localhost:12345/banana")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(ResourceConfiguration.class,
            JwtAccessTokenConverterRestTemplateCustomizerConfiguration.class)
                    .environment(this.environment).web(WebApplicationType.NONE).run();
    assertThat(this.context.getBeansOfType(JwtAccessTokenConverter.class)).hasSize(1);
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void jwkTokenStoreShouldBeConditionalOnMissingBean() throws Exception {
    TestPropertyValues
            .of("security.oauth2.resource.jwk.key-set-uri=http://my-auth-server/token_keys")
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(JwkTokenStoreConfiguration.class,
            ResourceConfiguration.class).environment(this.environment)
                    .web(WebApplicationType.NONE).run();
    assertThat(this.context.getBeansOfType(JwkTokenStore.class)).hasSize(1);
}
项目:spring-security-oauth2-boot    文件:ResourceServerTokenServicesConfigurationTests.java   
@Test
public void jwtTokenStoreShouldBeConditionalOnMissingBean() throws Exception {
    TestPropertyValues.of("security.oauth2.resource.jwt.keyValue=" + PUBLIC_KEY)
            .applyTo(this.environment);
    this.context = new SpringApplicationBuilder(JwtTokenStoreConfiguration.class,
            ResourceConfiguration.class).environment(this.environment)
                    .web(WebApplicationType.NONE).run();
    assertThat(this.context.getBeansOfType(JwtTokenStore.class)).hasSize(1);
}
项目:streamdataio-spring-webflux    文件:StreamdataioSpringWebfluxApplication.java   
public static void main(String[] args) throws URISyntaxException {
    SpringApplication app = new SpringApplication(StreamdataioSpringWebfluxApplication.class);
    // prevent SpringBoot from starting a web server
    app.setWebApplicationType(WebApplicationType.NONE);
    app.run(args);

}
项目:jdbc    文件:PostgresTestSupport.java   
@Override
protected void obtainResource() {
    context = new SpringApplicationBuilder(Config.class)
            .web(WebApplicationType.NONE)
            .run();
    DataSource dataSource = context.getBean(DataSource.class);
    Connection con = DataSourceUtils.getConnection(dataSource);
    DataSourceUtils.releaseConnection(con, dataSource);
}
项目:spring-cloud-stream-binder-rabbit    文件:RabbitBinderModuleTests.java   
@Test
public void testParentConnectionFactoryInheritedByDefault() {
    context = new SpringApplicationBuilder(SimpleProcessor.class)
            .web(WebApplicationType.NONE)
            .run("--server.port=0");
    BinderFactory binderFactory = context.getBean(BinderFactory.class);
    Binder<?, ?, ?> binder = binderFactory.getBinder(null, MessageChannel.class);
    assertThat(binder).isInstanceOf(RabbitMessageChannelBinder.class);
    DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
    ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
            .getPropertyValue("connectionFactory");
    assertThat(binderConnectionFactory).isInstanceOf(CachingConnectionFactory.class);
    ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
    assertThat(binderConnectionFactory).isSameAs(connectionFactory);

    ConnectionFactory producerConnectionFactory = (ConnectionFactory) binderFieldAccessor
            .getPropertyValue("producerConnectionFactory");
    assertThat(producerConnectionFactory).isNotSameAs(connectionFactory);

    CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
            CompositeHealthIndicator.class);
    DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
    assertThat(bindersHealthIndicator).isNotNull();
    @SuppressWarnings("unchecked")
    Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
            .getPropertyValue("indicators");
    assertThat(healthIndicators).containsKey(("rabbit"));
    assertThat(healthIndicators.get("rabbit").health().getStatus()).isEqualTo((Status.UP));
}
项目:spring-cloud-stream-binder-rabbit    文件:RabbitBinderModuleTests.java   
@Test
@SuppressWarnings("unchecked")
public void testParentConnectionFactoryInheritedByDefaultAndRabbitSettingsPropagated() {
    context = new SpringApplicationBuilder(SimpleProcessor.class)
            .web(WebApplicationType.NONE)
            .run("--server.port=0",
                    "--spring.cloud.stream.rabbit.bindings.input.consumer.transacted=true",
                    "--spring.cloud.stream.rabbit.bindings.output.producer.transacted=true");
    BinderFactory binderFactory = context.getBean(BinderFactory.class);
    Binder<?, ?, ?> binder = binderFactory.getBinder(null, MessageChannel.class);
    assertThat(binder).isInstanceOf(RabbitMessageChannelBinder.class);
    BindingService bindingService = context.getBean(BindingService.class);
    DirectFieldAccessor channelBindingServiceAccessor = new DirectFieldAccessor(bindingService);
    Map<String, List<Binding<MessageChannel>>> consumerBindings = (Map<String, List<Binding<MessageChannel>>>) channelBindingServiceAccessor
            .getPropertyValue("consumerBindings");
    Binding<MessageChannel> inputBinding = consumerBindings.get("input").get(0);
    SimpleMessageListenerContainer container = TestUtils.getPropertyValue(inputBinding,
            "lifecycle.messageListenerContainer", SimpleMessageListenerContainer.class);
    assertThat(TestUtils.getPropertyValue(container, "transactional", Boolean.class)).isTrue();
    Map<String, Binding<MessageChannel>> producerBindings = (Map<String, Binding<MessageChannel>>) TestUtils
            .getPropertyValue(bindingService, "producerBindings");
    Binding<MessageChannel> outputBinding = producerBindings.get("output");
    assertThat(TestUtils.getPropertyValue(outputBinding, "lifecycle.amqpTemplate.transactional",
            Boolean.class)).isTrue();
    DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
    ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
            .getPropertyValue("connectionFactory");
    assertThat(binderConnectionFactory).isInstanceOf(CachingConnectionFactory.class);
    ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
    assertThat(binderConnectionFactory).isSameAs(connectionFactory);
    CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
            CompositeHealthIndicator.class);
    DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
    assertThat(bindersHealthIndicator).isNotNull();
    Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
            .getPropertyValue("indicators");
    assertThat(healthIndicators).containsKey("rabbit");
    assertThat(healthIndicators.get("rabbit").health().getStatus()).isEqualTo(Status.UP);
}