@ -28,6 +28,7 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException ;
import org.springframework.beans.factory.BeanCreationException ;
import org.springframework.boot.autoconfigure.AutoConfigurations ;
import org.springframework.boot.autoconfigure.AutoConfigurations ;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext ;
import org.springframework.boot.test.context.runner.ApplicationContextRunner ;
import org.springframework.boot.test.context.runner.ApplicationContextRunner ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Configuration ;
@ -63,35 +64,58 @@ public class HazelcastAutoConfigurationClientTests {
. withConfiguration ( AutoConfigurations . of ( HazelcastAutoConfiguration . class ) ) ;
. withConfiguration ( AutoConfigurations . of ( HazelcastAutoConfiguration . class ) ) ;
@Test
@Test
public void systemProperty ( ) {
public void systemPropertyWithXml ( ) {
this . contextRunner
systemProperty ( HazelcastClientConfiguration . CONFIG_SYSTEM_PROPERTY
. withSystemProperties ( HazelcastClientConfiguration . CONFIG_SYSTEM_PROPERTY
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/"
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/"
+ "hazelcast-client-specific.xml" )
+ "hazelcast-client-specific.xml" ) ;
. run ( ( context ) - > assertThat ( context ) . getBean ( HazelcastInstance . class )
. isInstanceOf ( HazelcastInstance . class )
. has ( nameStartingWith ( "hz.client_" ) ) ) ;
}
}
@Test
@Test
public void explicitConfigFile ( ) {
public void systemPropertyWithYaml ( ) {
this . contextRunner
systemProperty ( HazelcastClientConfiguration . CONFIG_SYSTEM_PROPERTY
. withPropertyValues (
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/"
"spring.hazelcast.config=org/springframework/boot/autoconfigure/"
+ "hazelcast-client-specific.yaml" ) ;
+ "hazelcast/hazelcast-client-specific.xml" )
}
. run ( ( context ) - > assertThat ( context ) . getBean ( HazelcastInstance . class )
. isInstanceOf ( HazelcastClientProxy . class )
private void systemProperty ( String systemProperty ) {
. has ( nameStartingWith ( "hz.client_" ) ) ) ;
this . contextRunner . withSystemProperties ( systemProperty )
. run ( ( context ) - > assertHazelcastClientSpecific ( context ) ) ;
}
}
@Test
@Test
public void explicitConfigUrl ( ) {
public void explicitConfigFileWithXml ( ) {
this . contextRunner
propertyValues ( "spring.hazelcast.config=org/springframework/boot/autoconfigure/"
. withPropertyValues (
+ "hazelcast/hazelcast-client-specific.xml" ) ;
"spring.hazelcast.config=hazelcast-client-default.xml" )
}
. run ( ( context ) - > assertThat ( context ) . getBean ( HazelcastInstance . class )
. isInstanceOf ( HazelcastClientProxy . class )
@Test
. has ( nameStartingWith ( "hz.client_" ) ) ) ;
public void explicitConfigFileWithYaml ( ) {
propertyValues ( "spring.hazelcast.config=org/springframework/boot/autoconfigure/"
+ "hazelcast/hazelcast-client-specific.yaml" ) ;
}
@Test
public void explicitConfigUrlWithXml ( ) {
propertyValues ( "spring.hazelcast.config=classpath:org/springframework/"
+ "boot/autoconfigure/hazelcast/hazelcast-client-specific.xml" ) ;
}
@Test
public void explicitConfigUrlWithYaml ( ) {
propertyValues ( "spring.hazelcast.config=classpath:org/springframework/"
+ "boot/autoconfigure/hazelcast/hazelcast-client-specific.yaml" ) ;
}
private void propertyValues ( String propertyValues ) {
this . contextRunner . withPropertyValues ( propertyValues )
. run ( ( context ) - > assertHazelcastClientSpecific ( context ) ) ;
}
private static void assertHazelcastClientSpecific (
AssertableApplicationContext context ) {
assertThat ( context ) . getBean ( HazelcastInstance . class )
. isInstanceOf ( HazelcastInstance . class )
. has ( labelEqualTo ( "configured-client" ) ) ;
}
}
@Test
@Test
@ -111,9 +135,10 @@ public class HazelcastAutoConfigurationClientTests {
. isInstanceOf ( HazelcastClientProxy . class ) ) ;
. isInstanceOf ( HazelcastClientProxy . class ) ) ;
}
}
private Condition < HazelcastInstance > nameStartingWith ( String prefix ) {
private static Condition < HazelcastInstance > labelEqualTo ( String label ) {
return new Condition < > ( ( o ) - > o . getName ( ) . startsWith ( prefix ) ,
return new Condition < > ( ( o ) - > ( ( HazelcastClientProxy ) o ) . getClientConfig ( )
"Name starts with " + prefix ) ;
. getLabels ( ) . stream ( ) . anyMatch ( ( e ) - > e . equals ( label ) ) ,
"Label equals to " + label ) ;
}
}
@Configuration ( proxyBeanMethods = false )
@Configuration ( proxyBeanMethods = false )