Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed May 14, 2016
1 parent a1ac934 commit 6cdbdf9
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
@Conditional(SessionCondition.class)
class RedisSessionConfiguration {

private static final Logger logger = LoggerFactory.getLogger(RedisSessionConfiguration.class);
private static final Logger logger = LoggerFactory
.getLogger(RedisSessionConfiguration.class);

@Configuration
public static class SpringBootRedisHttpSessionConfiguration
Expand All @@ -68,8 +69,8 @@ public void customize(SessionProperties sessionProperties) {
@PostConstruct
public void validate() {
if (this.sessionProperties.getStoreType() == null) {
logger.warn("Spring Session store type is mandatory: set " +
"'spring.session.store-type=redis' in your configuration");
logger.warn("Spring Session store type is mandatory: set "
+ "'spring.session.store-type=redis' in your configuration");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
@EnableConfigurationProperties(SessionProperties.class)
@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HazelcastAutoConfiguration.class,
MongoAutoConfiguration.class, RedisAutoConfiguration.class })
@Import({ SessionConfigurationImportSelector.class, SessionRepositoryValidator.class})
@Import({ SessionConfigurationImportSelector.class, SessionRepositoryValidator.class })
public class SessionAutoConfiguration {

/**
Expand All @@ -82,6 +82,7 @@ public String[] selectImports(AnnotationMetadata importingClassMetadata) {
static class SessionRepositoryValidator {

private SessionProperties sessionProperties;

private ObjectProvider<SessionRepository<?>> sessionRepositoryProvider;

SessionRepositoryValidator(SessionProperties sessionProperties,
Expand All @@ -95,9 +96,9 @@ public void checkSessionRepository() {
StoreType storeType = this.sessionProperties.getStoreType();
if (storeType != StoreType.NONE) {
Assert.notNull(this.sessionRepositoryProvider.getIfAvailable(),
"No session repository could "
+ "be auto-configured, check your configuration (session "
+ "store type is '" + storeType + "')");
"No session repository could be auto-configured, check your "
+ "configuration (session store type is '" + storeType
+ "')");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
class SessionCondition extends SpringBootCondition {

private static final boolean redisPresent = ClassUtils.isPresent(
"org.springframework.data.redis.core.RedisTemplate", SessionCondition.class.getClassLoader());
"org.springframework.data.redis.core.RedisTemplate",
SessionCondition.class.getClassLoader());

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
Expand All @@ -43,11 +44,10 @@ public ConditionOutcome getMatchOutcome(ConditionContext context,
.getType(((AnnotationMetadata) metadata).getClassName());
if (!resolver.containsProperty("store-type")) {
if (sessionStoreType == StoreType.REDIS && redisPresent) {
return ConditionOutcome.match("Session store type default to redis (deprecated)");
}
else {
return ConditionOutcome.noMatch("Session store type not set");
return ConditionOutcome
.match("Session store type default to redis (deprecated)");
}
return ConditionOutcome.noMatch("Session store type not set");
}
String value = resolver.getProperty("store-type").replace("-", "_").toUpperCase();
if (value.equals(sessionStoreType.name())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@
import static org.mockito.Mockito.verifyZeroInteractions;

/**
* Test to validate that a custom {@link RestTemplate} can be defined
* with OAuth2 SSO.
* Test to validate that a custom {@link RestTemplate} can be defined with OAuth2 SSO.
*
* @author Stephane Nicoll
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@SpringBootTest
@TestPropertySource(properties = {"security.oauth2.client.clientId=client",
@TestPropertySource(properties = { "security.oauth2.client.clientId=client",
"security.oauth2.client.clientSecret=secret",
"security.oauth2.client.userAuthorizationUri=http://example.com/oauth/authorize",
"security.oauth2.client.accessTokenUri=http://example.com/oauth/token",
"security.oauth2.resource.jwt.keyValue=SSSSHHH"})
"security.oauth2.resource.jwt.keyValue=SSSSHHH" })
public class CustomRestTemplateBasicOAuth2SsoConfigurationTests {

@Autowired
Expand Down Expand Up @@ -82,5 +81,3 @@ public RestTemplate myRestTemplate() {
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void contextFailsIfStoreTypeNotSet() {
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage("No session repository could be auto-configured");
this.thrown.expectMessage("session store type is 'null'");

load();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ public void doesNotAcceptNameMismatch() throws Exception {
assertThat(new TriggerFileFilter("thefile.txt").accept(file)).isFalse();
}

@Test
public void testName() throws Exception {
File file = this.temp.newFile(".triggerfile").getAbsoluteFile();
assertThat(new TriggerFileFilter(".triggerfile").accept(file)).isTrue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Review implements Serializable {
@Enumerated(EnumType.ORDINAL)
private Rating rating;

@Column(name= "CHECK_IN_DATE", nullable = false)
@Column(name = "CHECK_IN_DATE", nullable = false)
@Temporal(TemporalType.DATE)
private Date checkInDate;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package sample.test;

import org.junit.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Service;

public class SampleTest {

@Test
public void injection() throws Exception {
new AnnotationConfigApplicationContext(Config.class).close();
}

@Configuration
@Import(BeanC.class)
static class Config {

@Bean
public BeanA beanA() {
return new BeanA();
}

@Bean
public BeanB beanB() {
return new BeanB();
}

@Bean
public BeanC beanC() {
return new BeanC();
}

}

static class BeanA {

}

static class BeanB extends BeanA {

}

@Service
static class BeanC {

@Autowired
public void setBeanA(BeanA xxx) {
}

}

}

0 comments on commit 6cdbdf9

Please sign in to comment.