diff --git a/.gitignore b/.gitignore index 6550af0f..e39b5cd6 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ _site/ .idea *.iml *.swp -*.log \ No newline at end of file +*.log +.checkstyle \ No newline at end of file diff --git a/spring-cloud-zookeeper-core/src/test/groovy/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationSpec.groovy b/spring-cloud-zookeeper-core/src/test/groovy/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationSpec.groovy deleted file mode 100644 index e210937d..00000000 --- a/spring-cloud-zookeeper-core/src/test/groovy/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationSpec.groovy +++ /dev/null @@ -1,37 +0,0 @@ -package org.springframework.cloud.zookeeper - -import org.apache.curator.framework.CuratorFramework -import org.apache.curator.test.TestingServer -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.context.annotation.Bean -import org.springframework.test.context.ContextConfiguration -import spock.lang.Specification - -/** - * @author Spencer Gibb - */ -@ContextConfiguration(classes = [ TestConfig, ZookeeperAutoConfiguration ]) -class ZookeeperAutoConfigurationSpec extends Specification { - - @Autowired(required = false) - CuratorFramework curator - - def 'should successfully inject Curator as a Spring bean'() { - expect: - curator != null - } - - static class TestConfig { - @Bean - ZookeeperProperties zookeeperProperties() throws Exception { - ZookeeperProperties properties = new ZookeeperProperties() - properties.connectString = testingServer().connectString - return properties - } - - @Bean - TestingServer testingServer() throws Exception { - return new TestingServer() - } - } -} diff --git a/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationTests.java b/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationTests.java new file mode 100644 index 00000000..0fb6b7b1 --- /dev/null +++ b/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationTests.java @@ -0,0 +1,40 @@ +package org.springframework.cloud.zookeeper; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.test.TestingServer; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Marcin Grzejszczak + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { ZookeeperAutoConfigurationTests.TestConfig.class, ZookeeperAutoConfiguration.class }) +public class ZookeeperAutoConfigurationTests { + + @Autowired(required = false) CuratorFramework curator; + + @Test + public void should_successfully_inject_Curator_as_a_Spring_bean() { + assertNotNull(this.curator); + } + + static class TestConfig { + @Bean + ZookeeperProperties zookeeperProperties() throws Exception { + ZookeeperProperties properties = new ZookeeperProperties(); + properties.setConnectString(testingServer().getConnectString()); + return properties; + } + + @Bean TestingServer testingServer() throws Exception { + return new TestingServer(); + } + } +} diff --git a/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/CommonTestConfig.groovy b/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/CommonTestConfig.groovy deleted file mode 100644 index 675bbc0f..00000000 --- a/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/CommonTestConfig.groovy +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2013-2015 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 org.springframework.cloud.zookeeper.discovery.test - -import groovy.transform.CompileStatic -import groovy.transform.PackageScope -import org.apache.curator.test.TestingServer -import org.springframework.cloud.client.loadbalancer.LoadBalanced -import org.springframework.cloud.zookeeper.ZookeeperProperties -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.util.SocketUtils -import org.springframework.web.client.RestTemplate - -@PackageScope -@CompileStatic -@Configuration -class CommonTestConfig { - - @Bean - @LoadBalanced - RestTemplate loadBalancedRestTemplate() { - return new RestTemplate() - } - - @Bean(destroyMethod = 'close') - TestingServer testingServer() { - return new TestingServer(SocketUtils.findAvailableTcpPort()) - } - - @Bean ZookeeperProperties zookeeperProperties() { - return new ZookeeperProperties(connectString: "localhost:${testingServer().port}") - } -} diff --git a/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/CommonTestConfig.java b/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/CommonTestConfig.java new file mode 100644 index 00000000..9b3c0684 --- /dev/null +++ b/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/CommonTestConfig.java @@ -0,0 +1,28 @@ +package org.springframework.cloud.zookeeper.discovery.test; + +import org.apache.curator.test.TestingServer; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.zookeeper.ZookeeperProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.util.SocketUtils; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class CommonTestConfig { + + @Bean + @LoadBalanced RestTemplate loadBalancedRestTemplate() { + return new RestTemplate(); + } + + @Bean(destroyMethod = "close") TestingServer testingServer() throws Exception { + return new TestingServer(SocketUtils.findAvailableTcpPort()); + } + + @Bean ZookeeperProperties zookeeperProperties() throws Exception { + ZookeeperProperties zookeeperProperties = new ZookeeperProperties(); + zookeeperProperties.setConnectString("localhost:" + testingServer().getPort()); + return zookeeperProperties; + } +} diff --git a/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestRibbonClient.groovy b/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestRibbonClient.groovy deleted file mode 100644 index 61b7550c..00000000 --- a/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestRibbonClient.groovy +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2013-2015 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 org.springframework.cloud.zookeeper.discovery.test - -import org.springframework.web.client.RestTemplate - -class TestRibbonClient extends TestServiceRestClient { - - private final String thisAppName - - TestRibbonClient(RestTemplate restTemplate) { - super(restTemplate) - this.thisAppName = 'someName' - } - - TestRibbonClient(RestTemplate restTemplate, String thisAppName) { - super(restTemplate) - this.thisAppName = thisAppName - } - - String thisHealthCheck() { - return restTemplate.getForObject("http://$thisAppName/health", String) - } - - Integer thisPort() { - return restTemplate.getForObject("http://$thisAppName/port", Integer) - } - -} \ No newline at end of file diff --git a/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestRibbonClient.java b/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestRibbonClient.java new file mode 100644 index 00000000..7d6bbd75 --- /dev/null +++ b/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestRibbonClient.java @@ -0,0 +1,31 @@ +package org.springframework.cloud.zookeeper.discovery.test; + +import org.springframework.web.client.RestTemplate; + +/** + * @author Marcin Grzejszczak + */ +public class TestRibbonClient extends TestServiceRestClient { + + private final String thisAppName; + + TestRibbonClient(RestTemplate restTemplate) { + super(restTemplate); + this.thisAppName = "someName"; + } + + TestRibbonClient(RestTemplate restTemplate, String thisAppName) { + super(restTemplate); + this.thisAppName = thisAppName; + } + + String thisHealthCheck() { + return this.restTemplate + .getForObject("http://" + this.thisAppName + "/health", String.class); + } + + Integer thisPort() { + return this.restTemplate + .getForObject("http://" + this.thisAppName + "/port", Integer.class); + } +} diff --git a/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestServiceRestClient.groovy b/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestServiceRestClient.groovy deleted file mode 100644 index 76285955..00000000 --- a/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestServiceRestClient.groovy +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2013-2015 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 org.springframework.cloud.zookeeper.discovery.test - -import groovy.transform.CompileStatic -import groovy.util.logging.Commons -import org.springframework.web.client.RestTemplate - -@CompileStatic -@Commons -class TestServiceRestClient { - - final RestTemplate restTemplate; - - TestServiceRestClient(RestTemplate restTemplate) { - this.restTemplate = restTemplate - } - - public T callService(String alias, String endpoint, Class clazz) { - String url = "http://$alias/$endpoint" - log.info("Calling [$url]") - return restTemplate.getForObject(url, clazz) - } - - String callService(String alias, String endpoint) { - return callService(alias, endpoint, String) - } - - String callOnUrl(String url, String endpoint) { - return new RestTemplate().getForObject("http://$url/$endpoint", String) - } -} diff --git a/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestServiceRestClient.java b/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestServiceRestClient.java new file mode 100644 index 00000000..756df1b6 --- /dev/null +++ b/spring-cloud-zookeeper-discovery/src/test/groovy/org/springframework/cloud/zookeeper/discovery/test/TestServiceRestClient.java @@ -0,0 +1,32 @@ +package org.springframework.cloud.zookeeper.discovery.test; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.web.client.RestTemplate; + +/** + * @author Marcin Grzejszczak + */ +public class TestServiceRestClient { + private static final Log log = LogFactory.getLog(TestServiceRestClient.class); + + protected final RestTemplate restTemplate; + + TestServiceRestClient(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } + + public T callService(String alias, String endpoint, Class clazz) { + String url = "http://" + alias +"/" + endpoint; + log.info("Calling [" + url + "]"); + return this.restTemplate.getForObject(url, clazz); + } + + String callService(String alias, String endpoint) { + return callService(alias, endpoint, String.class); + } + + String callOnUrl(String url, String endpoint) { + return new RestTemplate().getForObject("http://" + url + "/" + endpoint, String.class); + } +}