From a30b4052ed584f328c15ccffbe87b8cbeedb9971 Mon Sep 17 00:00:00 2001 From: Ken Gullaksen Date: Mon, 6 Jul 2015 21:53:44 +0200 Subject: [PATCH 01/21] Fixed FileResource so that it supports file url. E.g. resulting output from org.springframework.core.io.Resource.getURL().toString() where path contains at least one space --- .../org/constretto/model/FileResource.java | 13 +++++++++- .../constretto/model/FileResourceTest.java | 15 +++++++++++ .../resources/dir with spaces/test.properties | 26 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 constretto-core/src/test/resources/dir with spaces/test.properties diff --git a/constretto-core/src/main/java/org/constretto/model/FileResource.java b/constretto-core/src/main/java/org/constretto/model/FileResource.java index f9c1058b..e2257fc6 100644 --- a/constretto-core/src/main/java/org/constretto/model/FileResource.java +++ b/constretto-core/src/main/java/org/constretto/model/FileResource.java @@ -16,6 +16,8 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; /** * @author Kaare Nilsen @@ -43,10 +45,19 @@ public InputStream getInputStream() { private String extractFileNameFromFileResource(String path) { String fileName; if (path.startsWith(FILE_PREFIX)) { - fileName = path.substring(FILE_PREFIX.length(), path.length()); + fileName = decode(path.substring(FILE_PREFIX.length(), path.length())); } else { fileName = path; } return fileName; } + + private String decode(String path) { + try { + return URLDecoder.decode(path, "UTF-8"); + } catch (UnsupportedEncodingException ignored) { + } + return path; + } + } diff --git a/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java b/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java index b8333550..c5d3aecf 100644 --- a/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java +++ b/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java @@ -4,6 +4,8 @@ import org.junit.Test; import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -57,6 +59,19 @@ public void testOpenFileResourceForFilePrefixOnlyPath() throws Exception { public void testToString() throws Exception { final FileResource fileResource = new FileResource("file:src/test/resources/cache1.ini"); assertEquals("FileResource{path='file:src/test/resources/cache1.ini'}", fileResource.toString()); + } + + /** + * If file name starts with file: chances are it is a file url. + * Constretto should decode this url since it uses new File(String) which does not support + * url encoding. + */ + @Test + public void testWithSpaces() throws Exception { + Path path = Paths.get("src/test/resources/dir with spaces/test.properties"); + String string = path.toFile().toURI().toURL().toString(); + final FileResource existing = new FileResource(string); + assertTrue(existing.exists()); } } diff --git a/constretto-core/src/test/resources/dir with spaces/test.properties b/constretto-core/src/test/resources/dir with spaces/test.properties new file mode 100644 index 00000000..b090a87e --- /dev/null +++ b/constretto-core/src/test/resources/dir with spaces/test.properties @@ -0,0 +1,26 @@ +# +# Copyright 2008 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. +# + +somedb.username=user0 + +@production.somedb.username=user1 + +@systest.somedb.username=user2 + +datasources.customer.password=password + +url.child=#{base-url}/child +@production.base-url=http://constretto.org \ No newline at end of file From 9ba73a6fdcea781d449a231847383a2c176f6132 Mon Sep 17 00:00:00 2001 From: Ken Gullaksen Date: Mon, 6 Jul 2015 23:59:23 +0200 Subject: [PATCH 02/21] removed usage of nio in test to fix 1.6 build --- .../test/java/org/constretto/model/FileResourceTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java b/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java index c5d3aecf..05461586 100644 --- a/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java +++ b/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java @@ -4,8 +4,6 @@ import org.junit.Test; import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -68,9 +66,9 @@ public void testToString() throws Exception { */ @Test public void testWithSpaces() throws Exception { - Path path = Paths.get("src/test/resources/dir with spaces/test.properties"); + File file = new File("src/test/resources/dir with spaces/test.properties"); - String string = path.toFile().toURI().toURL().toString(); + String string = file.toURI().toURL().toString(); final FileResource existing = new FileResource(string); assertTrue(existing.exists()); } From 19c8a1ec2e19f3af59cd2fe67643d92ecc9c5d52 Mon Sep 17 00:00:00 2001 From: niccoutu Date: Tue, 20 Oct 2015 10:15:07 +0200 Subject: [PATCH 03/21] only do inject configuration in beans of scope singleton so as to avoid resource starvation on request eller session scoped beans under heavy load --- .../ConfigurationAnnotationConfigurer.java | 19 ++++++- .../EnvironmentAnnotatedFieldTest.java | 57 +++++++++++++++++++ .../BasicConstrettoConfigurationTest.java | 33 +++++++---- .../test/ConstrettoRuleEnvironmentTest.java | 38 ++++++++++--- ...ConstrettoSpringJUnit4ClassRunnerTest.java | 19 +++++-- ...ttoSpringJUnit4ClassRunnerTest-context.xml | 2 + 6 files changed, 141 insertions(+), 27 deletions(-) diff --git a/constretto-spring/src/main/java/org/constretto/spring/ConfigurationAnnotationConfigurer.java b/constretto-spring/src/main/java/org/constretto/spring/ConfigurationAnnotationConfigurer.java index 994f3cd6..04a7de7c 100644 --- a/constretto-spring/src/main/java/org/constretto/spring/ConfigurationAnnotationConfigurer.java +++ b/constretto-spring/src/main/java/org/constretto/spring/ConfigurationAnnotationConfigurer.java @@ -25,6 +25,9 @@ import org.constretto.spring.resolver.AssemblyContextResolver; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.*; import java.lang.reflect.Constructor; @@ -50,11 +53,12 @@ * @see org.constretto.spring.annotation.Environment */ public class ConfigurationAnnotationConfigurer extends InstantiationAwareBeanPostProcessorAdapter implements - BeanFactoryPostProcessor { + BeanFactoryPostProcessor, BeanFactoryAware { private ConstrettoConfiguration configuration; private AssemblyContextResolver assemblyContextResolver; private Map, Constructor> configurableConstructorCache = Collections.synchronizedMap(new HashMap, Constructor>()); private final static Object constructorCacheLockObject = new Object(); + private BeanFactory beanFactory; public ConfigurationAnnotationConfigurer(ConstrettoConfiguration configuration, AssemblyContextResolver assemblyContextResolver) { @@ -76,8 +80,12 @@ public Constructor[] determineCandidateConstructors(final Class beanClass, @Override public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException { - injectConfiguration(bean); - injectEnvironment(bean); + try { + if (beanFactory != null && beanFactory.isSingleton(beanName)) { + injectConfiguration(bean); + injectEnvironment(bean); + } + } catch (NoSuchBeanDefinitionException e) {} return true; } @@ -144,4 +152,9 @@ private Constructor resolveConfigurableConstructor(Class beanClass) { return constructorsWithConfigureAnnotation[0]; } } + + @Override + public void setBeanFactory(final BeanFactory beanFactory) throws BeansException { + this.beanFactory = beanFactory; + } } diff --git a/constretto-spring/src/test/java/org/constretto/spring/configuration/EnvironmentAnnotatedFieldTest.java b/constretto-spring/src/test/java/org/constretto/spring/configuration/EnvironmentAnnotatedFieldTest.java index 790db05b..635f68a9 100644 --- a/constretto-spring/src/test/java/org/constretto/spring/configuration/EnvironmentAnnotatedFieldTest.java +++ b/constretto-spring/src/test/java/org/constretto/spring/configuration/EnvironmentAnnotatedFieldTest.java @@ -16,6 +16,9 @@ import org.constretto.spring.assembly.helper.AlwaysDevelopmentEnvironmentResolver; import org.junit.Assert; import org.junit.Test; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; import java.util.List; @@ -29,6 +32,7 @@ public void givenClassWithEnvironmentAnnotatedPropertyThenInjectEnvironment() th TestClazz testClazz = new TestClazz(); ConfigurationAnnotationConfigurer annotationConfigurer = new ConfigurationAnnotationConfigurer( new DefaultConstrettoConfiguration(null), new AlwaysDevelopmentEnvironmentResolver()); + annotationConfigurer.setBeanFactory(new TestBeanFactory()); annotationConfigurer.postProcessAfterInstantiation(testClazz, "testBean"); Assert.assertTrue(testClazz.getEnvironments().contains("development")); } @@ -42,4 +46,57 @@ public List getEnvironments() { return environments; } } + + private class TestBeanFactory implements BeanFactory { + + @Override + public Object getBean(final String name) throws BeansException { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public T getBean(final String name, final Class requiredType) throws BeansException { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public T getBean(final Class requiredType) throws BeansException { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public Object getBean(final String name, final Object... args) throws BeansException { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public boolean containsBean(final String name) { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public boolean isSingleton(final String name) throws NoSuchBeanDefinitionException { + return true; + } + + @Override + public boolean isPrototype(final String name) throws NoSuchBeanDefinitionException { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public boolean isTypeMatch(final String name, final Class targetType) throws NoSuchBeanDefinitionException { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public Class getType(final String name) throws NoSuchBeanDefinitionException { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public String[] getAliases(final String name) { + throw new UnsupportedOperationException("Not implemented"); + } + } } diff --git a/constretto-spring/src/test/java/org/constretto/spring/javaconfig/BasicConstrettoConfigurationTest.java b/constretto-spring/src/test/java/org/constretto/spring/javaconfig/BasicConstrettoConfigurationTest.java index 526bd7ca..67d4b6a7 100644 --- a/constretto-spring/src/test/java/org/constretto/spring/javaconfig/BasicConstrettoConfigurationTest.java +++ b/constretto-spring/src/test/java/org/constretto/spring/javaconfig/BasicConstrettoConfigurationTest.java @@ -5,7 +5,9 @@ import org.constretto.model.Resource; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -19,21 +21,16 @@ public class BasicConstrettoConfigurationTest { public static final String DEFAULT_VALUE = "Default"; - @Configuration(required = true) - private String key1; - @Value("${key1}") - private String key1AsValue; - - @Value("${nothere:" + DEFAULT_VALUE + "}") - private String defaultValue; + @Autowired + private TestBean testBean; @Test public void testKeyConfigured() throws Exception { final String expectedValue = "value1"; - assertEquals(expectedValue, key1); - assertEquals(expectedValue, key1AsValue); - assertEquals(DEFAULT_VALUE, defaultValue); + assertEquals(expectedValue, testBean.key1); + assertEquals(expectedValue, testBean.key1AsValue); + assertEquals(DEFAULT_VALUE, testBean.defaultValue); } @org.springframework.context.annotation.Configuration @@ -46,7 +43,23 @@ public org.constretto.ConstrettoConfiguration constrettoConfiguration() { .done() .getConfiguration(); } + + @Bean + public TestBean testBean() { + return new TestBean(); + } + } + private static class TestBean { + @Configuration(required = true) + private String key1; + + @Value("${key1}") + private String key1AsValue; + + @Value("${nothere:" + DEFAULT_VALUE + "}") + private String defaultValue; + } } diff --git a/constretto-test/src/test/java/org/constretto/test/ConstrettoRuleEnvironmentTest.java b/constretto-test/src/test/java/org/constretto/test/ConstrettoRuleEnvironmentTest.java index db646d94..784f9e2f 100644 --- a/constretto-test/src/test/java/org/constretto/test/ConstrettoRuleEnvironmentTest.java +++ b/constretto-test/src/test/java/org/constretto/test/ConstrettoRuleEnvironmentTest.java @@ -8,6 +8,8 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; @@ -28,30 +30,50 @@ public class ConstrettoRuleEnvironmentTest { public static final String ENVIRONMENT_VALUE = "junit"; + @Autowired + private TestBean testBean; + @Configuration public static class TestConfiguration { + @Autowired + private BeanFactory beanFactory; + @Bean - public static ConstrettoConfiguration constrettoConfiguration() { + public ConstrettoConfiguration constrettoConfiguration() { return new ConstrettoBuilder(true).getConfiguration(); } @Bean - public static ConfigurationAnnotationConfigurer configurationAnnotationConfigurer(final ConstrettoConfiguration configuration) { - return new ConfigurationAnnotationConfigurer(configuration, new DefaultAssemblyContextResolver()); + public ConfigurationAnnotationConfigurer configurationAnnotationConfigurer(final ConstrettoConfiguration configuration) { + final ConfigurationAnnotationConfigurer configurer = new ConfigurationAnnotationConfigurer(configuration, + new DefaultAssemblyContextResolver()); + configurer.setBeanFactory(beanFactory); + return configurer; + } + + @Bean + TestBean testBean() { + return new TestBean(); } } - @Environment - private List injectedEnvironment; - @ClassRule - public static ConstrettoRule constrettoRule = new ConstrettoRule(); @Test public void testApplyEnvironment() throws Exception { - assertArrayEquals(new String[]{ENVIRONMENT_VALUE}, injectedEnvironment.toArray(new String[1])); + assertArrayEquals(new String[]{ENVIRONMENT_VALUE}, testBean.injectedEnvironment.toArray(new String[1])); + + } + + static final class TestBean { + + @Environment + private List injectedEnvironment; + + @ClassRule + public static ConstrettoRule constrettoRule = new ConstrettoRule(); } } diff --git a/constretto-test/src/test/java/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest.java b/constretto-test/src/test/java/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest.java index 22217463..df9dcbef 100644 --- a/constretto-test/src/test/java/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest.java +++ b/constretto-test/src/test/java/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest.java @@ -17,6 +17,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.springframework.test.context.ContextConfiguration; import java.util.ArrayList; @@ -32,19 +33,25 @@ @ContextConfiguration public class ConstrettoSpringJUnit4ClassRunnerTest { - @Tags - List currentEnvironment; - @Autowired - Color color; + TestBean testBean; @Test public void givenEnvironmentAnnotationOnTestClassWhenRunningTestThenConstrettoKnowsEnvironment() { List expected = new ArrayList() {{ add("springjunit"); }}; - Assert.assertArrayEquals(expected.toArray(new String[0]), currentEnvironment.toArray(new String[0])); - Assert.assertEquals("green", color.name()); + Assert.assertArrayEquals(expected.toArray(new String[0]), testBean.currentEnvironment.toArray(new String[0])); + Assert.assertEquals("green", testBean.color.name()); + } + + static class TestBean { + + @Autowired + Color color; + + @Tags + List currentEnvironment; } } diff --git a/constretto-test/src/test/resources/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest-context.xml b/constretto-test/src/test/resources/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest-context.xml index 712415c6..279eddd8 100644 --- a/constretto-test/src/test/resources/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest-context.xml +++ b/constretto-test/src/test/resources/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest-context.xml @@ -18,4 +18,6 @@ + + From b5378c9282ccc6091b4ad881200d89ac4d88e3d1 Mon Sep 17 00:00:00 2001 From: niccoutu Date: Wed, 21 Oct 2015 16:04:53 +0200 Subject: [PATCH 04/21] test that no configuration injection happens when not a singleton bean --- .../EnvironmentAnnotatedFieldTest.java | 18 +++++++++++++--- .../BasicConstrettoConfigurationTest.java | 19 ++++++++++++++++- .../test/ConstrettoRuleEnvironmentTest.java | 21 ++++++++++++++++--- ...ConstrettoSpringJUnit4ClassRunnerTest.java | 15 ++++++++----- ...ttoSpringJUnit4ClassRunnerTest-context.xml | 4 +++- 5 files changed, 64 insertions(+), 13 deletions(-) diff --git a/constretto-spring/src/test/java/org/constretto/spring/configuration/EnvironmentAnnotatedFieldTest.java b/constretto-spring/src/test/java/org/constretto/spring/configuration/EnvironmentAnnotatedFieldTest.java index 635f68a9..a22f54ed 100644 --- a/constretto-spring/src/test/java/org/constretto/spring/configuration/EnvironmentAnnotatedFieldTest.java +++ b/constretto-spring/src/test/java/org/constretto/spring/configuration/EnvironmentAnnotatedFieldTest.java @@ -29,12 +29,18 @@ public class EnvironmentAnnotatedFieldTest { @Test public void givenClassWithEnvironmentAnnotatedPropertyThenInjectEnvironment() throws Exception { - TestClazz testClazz = new TestClazz(); ConfigurationAnnotationConfigurer annotationConfigurer = new ConfigurationAnnotationConfigurer( new DefaultConstrettoConfiguration(null), new AlwaysDevelopmentEnvironmentResolver()); - annotationConfigurer.setBeanFactory(new TestBeanFactory()); + + TestClazz testClazz = new TestClazz(); + annotationConfigurer.setBeanFactory(new TestBeanFactory(true)); annotationConfigurer.postProcessAfterInstantiation(testClazz, "testBean"); Assert.assertTrue(testClazz.getEnvironments().contains("development")); + + TestClazz notSingletonTestClazz = new TestClazz(); + annotationConfigurer.setBeanFactory(new TestBeanFactory(false)); + annotationConfigurer.postProcessAfterInstantiation(notSingletonTestClazz, "testBean"); + Assert.assertNull(notSingletonTestClazz.getEnvironments()); } private class TestClazz { @@ -49,6 +55,12 @@ public List getEnvironments() { private class TestBeanFactory implements BeanFactory { + private boolean singleton; + + TestBeanFactory(boolean singleton) { + this.singleton = singleton; + } + @Override public Object getBean(final String name) throws BeansException { throw new UnsupportedOperationException("Not implemented"); @@ -76,7 +88,7 @@ public boolean containsBean(final String name) { @Override public boolean isSingleton(final String name) throws NoSuchBeanDefinitionException { - return true; + return singleton; } @Override diff --git a/constretto-spring/src/test/java/org/constretto/spring/javaconfig/BasicConstrettoConfigurationTest.java b/constretto-spring/src/test/java/org/constretto/spring/javaconfig/BasicConstrettoConfigurationTest.java index 67d4b6a7..c0b63963 100644 --- a/constretto-spring/src/test/java/org/constretto/spring/javaconfig/BasicConstrettoConfigurationTest.java +++ b/constretto-spring/src/test/java/org/constretto/spring/javaconfig/BasicConstrettoConfigurationTest.java @@ -6,12 +6,16 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; /** * @author zapodot at gmail dot com @@ -25,12 +29,19 @@ public class BasicConstrettoConfigurationTest { @Autowired private TestBean testBean; + @Autowired + @Qualifier("requestScopedBean") + private TestBean requestScopedTestBean; + @Test public void testKeyConfigured() throws Exception { final String expectedValue = "value1"; assertEquals(expectedValue, testBean.key1); assertEquals(expectedValue, testBean.key1AsValue); assertEquals(DEFAULT_VALUE, testBean.defaultValue); + assertNull(requestScopedTestBean.key1); + assertNull(requestScopedTestBean.key1AsValue); + assertNull(requestScopedTestBean.defaultValue); } @org.springframework.context.annotation.Configuration @@ -49,9 +60,15 @@ public TestBean testBean() { return new TestBean(); } + @Bean(name = "requestScopedBean") + @Scope(value="request", proxyMode = ScopedProxyMode.TARGET_CLASS) + public TestBean requestScopedBean() { + return new TestBean(); + } + } - private static class TestBean { + public static class TestBean { @Configuration(required = true) private String key1; diff --git a/constretto-test/src/test/java/org/constretto/test/ConstrettoRuleEnvironmentTest.java b/constretto-test/src/test/java/org/constretto/test/ConstrettoRuleEnvironmentTest.java index 784f9e2f..c94cd067 100644 --- a/constretto-test/src/test/java/org/constretto/test/ConstrettoRuleEnvironmentTest.java +++ b/constretto-test/src/test/java/org/constretto/test/ConstrettoRuleEnvironmentTest.java @@ -1,5 +1,7 @@ package org.constretto.test; +import java.util.List; + import org.constretto.ConstrettoBuilder; import org.constretto.ConstrettoConfiguration; import org.constretto.spring.ConfigurationAnnotationConfigurer; @@ -10,13 +12,15 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.test.context.ContextConfiguration; -import java.util.List; - import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertNull; /** * This source code is the property of NextGenTel AS @@ -33,6 +37,10 @@ public class ConstrettoRuleEnvironmentTest { @Autowired private TestBean testBean; + @Autowired + @Qualifier("requestScopedBean") + private TestBean requestScopedBean; + @Configuration public static class TestConfiguration { @@ -56,6 +64,12 @@ public ConfigurationAnnotationConfigurer configurationAnnotationConfigurer(final TestBean testBean() { return new TestBean(); } + + @Bean(name = "requestScopedBean") + @Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS) + TestBean requestScopedBean() { + return new TestBean(); + } } @@ -65,9 +79,10 @@ public void testApplyEnvironment() throws Exception { assertArrayEquals(new String[]{ENVIRONMENT_VALUE}, testBean.injectedEnvironment.toArray(new String[1])); + assertNull(requestScopedBean.injectedEnvironment); } - static final class TestBean { + static class TestBean { @Environment private List injectedEnvironment; diff --git a/constretto-test/src/test/java/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest.java b/constretto-test/src/test/java/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest.java index df9dcbef..8a706cd0 100644 --- a/constretto-test/src/test/java/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest.java +++ b/constretto-test/src/test/java/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest.java @@ -10,6 +10,9 @@ */ package org.constretto.test; +import java.util.ArrayList; +import java.util.List; + import org.constretto.annotation.Tags; import org.constretto.spring.annotation.Environment; import org.constretto.test.helper.Color; @@ -17,12 +20,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; -import java.util.ArrayList; -import java.util.List; - /** * @author Kaare Nilsen * @author Thor Åge Eldby @@ -33,9 +33,12 @@ @ContextConfiguration public class ConstrettoSpringJUnit4ClassRunnerTest { - @Autowired + @Autowired @Qualifier("testBean") TestBean testBean; + @Autowired @Qualifier("prototypeScopedTestBean") + TestBean prototypeScopedTestBean; + @Test public void givenEnvironmentAnnotationOnTestClassWhenRunningTestThenConstrettoKnowsEnvironment() { List expected = new ArrayList() {{ @@ -43,6 +46,8 @@ public void givenEnvironmentAnnotationOnTestClassWhenRunningTestThenConstrettoKn }}; Assert.assertArrayEquals(expected.toArray(new String[0]), testBean.currentEnvironment.toArray(new String[0])); Assert.assertEquals("green", testBean.color.name()); + Assert.assertNull(prototypeScopedTestBean.currentEnvironment); + Assert.assertEquals("green", prototypeScopedTestBean.color.name()); } static class TestBean { diff --git a/constretto-test/src/test/resources/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest-context.xml b/constretto-test/src/test/resources/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest-context.xml index 279eddd8..29e4abc3 100644 --- a/constretto-test/src/test/resources/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest-context.xml +++ b/constretto-test/src/test/resources/org/constretto/test/ConstrettoSpringJUnit4ClassRunnerTest-context.xml @@ -18,6 +18,8 @@ - + + + From 286a7d1abed541b58f9c963adaae7a4f968608b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Kleppe-J=C3=B8rgensen?= Date: Fri, 27 Nov 2015 17:33:55 +0100 Subject: [PATCH 05/21] spring-test dependency should have test scope --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 43e4bab1..9699aafe 100644 --- a/pom.xml +++ b/pom.xml @@ -240,6 +240,7 @@ org.springframework spring-test ${spring.version} + test org.springframework From 64fbc2489a8811f150907afe13fdd8d6b9119544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 14:15:20 +0100 Subject: [PATCH 06/21] Fix build errors. We do need Spring-test in compile scope in constretto-test for now (restructuring is in progress) --- .../model/UrlResourceIntegrationTest.java | 23 +++++++++++++++++++ .../org/constretto/model/UrlResourceTest.java | 5 ---- constretto-test/pom.xml | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 constretto-core/src/test/java/org/constretto/model/UrlResourceIntegrationTest.java diff --git a/constretto-core/src/test/java/org/constretto/model/UrlResourceIntegrationTest.java b/constretto-core/src/test/java/org/constretto/model/UrlResourceIntegrationTest.java new file mode 100644 index 00000000..45666765 --- /dev/null +++ b/constretto-core/src/test/java/org/constretto/model/UrlResourceIntegrationTest.java @@ -0,0 +1,23 @@ +package org.constretto.model; + +import org.junit.Ignore; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * These tests will fail if run behind a enterprise proxy + * + * Created by zapodot on 01.12.2015. + */ +public class UrlResourceIntegrationTest { + + + @Test + @Ignore("Disabled for now. Set up test container that makes it posible to test without requiring access to the Internet") + public void validUrlsThatDoExistShouldWork() throws Exception { + final UrlResource urlResource = new UrlResource("https://github.com"); + assertTrue(urlResource.exists()); + } + +} diff --git a/constretto-core/src/test/java/org/constretto/model/UrlResourceTest.java b/constretto-core/src/test/java/org/constretto/model/UrlResourceTest.java index cb7cffd5..049e30c7 100644 --- a/constretto-core/src/test/java/org/constretto/model/UrlResourceTest.java +++ b/constretto-core/src/test/java/org/constretto/model/UrlResourceTest.java @@ -35,11 +35,6 @@ public void validUrlsThatDoNotExistShouldWork() throws Exception { assertFalse(urlResource.exists()); } - @Test - public void validUrlsThatDoExistShouldWork() throws Exception { - final UrlResource urlResource = new UrlResource("http://vg.no"); - assertTrue(urlResource.exists()); - } @Test public void testToString() throws Exception { diff --git a/constretto-test/pom.xml b/constretto-test/pom.xml index e6e58005..c58f6687 100644 --- a/constretto-test/pom.xml +++ b/constretto-test/pom.xml @@ -33,6 +33,7 @@ org.springframework spring-test + compile true From 97d5a30f9fdacb876c387b21813bfb730be6b571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 14:24:01 +0100 Subject: [PATCH 07/21] update junit to v 4.12 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9699aafe..b96ec44c 100644 --- a/pom.xml +++ b/pom.xml @@ -109,7 +109,7 @@ 1.9.2 2.5.2 3.2.11.RELEASE - 4.11 + 4.12 1.3.1.RELEASE 1.7.6 1.5.7 From 6d04b037892a6d4b457dde59e64d504b209b012c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 14:51:58 +0100 Subject: [PATCH 08/21] improve test performance a lot by moving ApacheDS. Use embedded-ldap-junit (UnboundID LDAP SDK) --- constretto-core/pom.xml | 12 ++-- ...dapConfigurationStoreEmbeddedLdapTest.java | 71 ++++++------------- pom.xml | 1 + 3 files changed, 30 insertions(+), 54 deletions(-) diff --git a/constretto-core/pom.xml b/constretto-core/pom.xml index 1d5d4219..0b7a94db 100644 --- a/constretto-core/pom.xml +++ b/constretto-core/pom.xml @@ -30,6 +30,12 @@ junit junit + + org.zapodot + embedded-ldap-junit + ${embedded-ldap-junit.version} + test + org.slf4j jcl-over-slf4j @@ -70,12 +76,6 @@ org.mockito mockito-all - - org.apache.directory.server - apacheds-test-framework - ${apacheds.version} - test - org.slf4j diff --git a/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java b/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java index e118dc97..4f693521 100644 --- a/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java +++ b/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java @@ -1,27 +1,17 @@ package org.constretto.internal.store.ldap; -import com.sun.jndi.ldap.DefaultResponseControlFactory; -import com.sun.jndi.ldap.LdapCtxFactory; -import org.apache.directory.server.annotations.CreateLdapServer; -import org.apache.directory.server.annotations.CreateTransport; -import org.apache.directory.server.core.annotations.ApplyLdifFiles; -import org.apache.directory.server.core.annotations.CreateDS; -import org.apache.directory.server.core.annotations.CreatePartition; -import org.apache.directory.server.core.integ.AbstractLdapTestUnit; -import org.apache.directory.server.core.integ.FrameworkRunner; import org.constretto.ConstrettoBuilder; import org.constretto.ConstrettoConfiguration; import org.constretto.annotation.Configuration; import org.constretto.model.TaggedPropertySet; +import org.junit.Rule; import org.junit.Test; -import org.junit.runner.RunWith; +import org.zapodot.junit.ldap.EmbeddedLdapRule; +import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; -import javax.naming.Context; -import javax.naming.directory.InitialDirContext; -import javax.naming.ldap.LdapContext; +import javax.naming.directory.DirContext; import java.util.Arrays; import java.util.Collection; -import java.util.Hashtable; import java.util.List; import static org.junit.Assert.assertEquals; @@ -30,16 +20,14 @@ /** * @author zapodot at gmail dot com */ -@RunWith(FrameworkRunner.class) -@CreateLdapServer( - transports = { - @CreateTransport(protocol = "LDAP", port = LdapConfigurationStoreEmbeddedLdapTest.LDAP_PORT) - } -) -@CreateDS( name = "LdapConfigurationStoreEmbeddedLdapTest", partitions = @CreatePartition(name = "constretto", suffix = "dc=constretto,dc=org")) -@ApplyLdifFiles("constretto.ldif") -public class LdapConfigurationStoreEmbeddedLdapTest extends AbstractLdapTestUnit { - +public class LdapConfigurationStoreEmbeddedLdapTest { + + @Rule + public EmbeddedLdapRule embeddedLdapRule = EmbeddedLdapRuleBuilder.newInstance() + .bindingToPort(LDAP_PORT) + .usingDomainDsn("dc=constretto,dc=org") + .importingLdifs("constretto.ldif") + .build(); public static final int LDAP_PORT = 27389; public static class ConfigurableType { @@ -54,16 +42,14 @@ public static class ConfigurableType { @Test public void testParseConfigurationUsingAddDsn() throws Exception { - Hashtable ldapEnvironment = createLdapEnvironment(); - - final InitialDirContext dirContext = new InitialDirContext(ldapEnvironment); + final DirContext dirContext = embeddedLdapRule.dirContext(); final LdapConfigurationStore configurationStore = LdapConfigurationStoreBuilder.usingDirContext(dirContext) - .addDsn("cn=Kaare Nilsen,dc=constretto,dc=org") - .addDsnWithKey("sidekick", "cn=Jon-Anders Teigen,dc=constretto,dc=org") - .done(); + .addDsn("cn=Kaare Nilsen,dc=constretto,dc=org") + .addDsnWithKey("sidekick", + "cn=Jon-Anders Teigen,dc=constretto,dc=org") + .done(); final Collection propertySets = configurationStore.parseConfiguration(); assertEquals(1, propertySets.size()); - dirContext.close(); ConstrettoConfiguration constrettoConfiguration = createConfiguration(configurationStore); final ConfigurableType configurationObject = constrettoConfiguration.as(ConfigurableType.class); assertTrue(configurationObject.names.containsAll(Arrays.asList("Kaare Nilsen", "Kåre Nilsen"))); @@ -73,13 +59,13 @@ public void testParseConfigurationUsingAddDsn() throws Exception { @Test public void testDsnMultiValue() throws Exception { - final InitialDirContext initialDirContext = new InitialDirContext(createLdapEnvironment()); + final DirContext initialDirContext = embeddedLdapRule.dirContext(); final ConstrettoConfiguration configuration = new ConstrettoBuilder(false) .createLdapConfigurationStore(initialDirContext) - .addDsn("cn=role_developer,ou=groups,dc=constretto,dc=org") + .addDsn("cn=role_developer,ou=groups,dc=constretto,dc=org") .done() .getConfiguration(); - final List members = configuration.evaluateToList(String.class, "uniquemember"); + final List members = configuration.evaluateToList(String.class, "uniqueMember"); assertEquals(2, members.size()); @@ -87,7 +73,7 @@ public void testDsnMultiValue() throws Exception { @Test public void testParseConfigurationUsingSearch() throws Exception { - final InitialDirContext initialDirContext = new InitialDirContext(createLdapEnvironment()); + final DirContext initialDirContext = embeddedLdapRule.dirContext(); final ConstrettoConfiguration configuration = new ConstrettoBuilder(false) .createLdapConfigurationStore(initialDirContext) .addUsingSearch( @@ -96,8 +82,8 @@ public void testParseConfigurationUsingSearch() throws Exception { "uid") .done() .getConfiguration(); - assertTrue(configuration.evaluateToList(String.class, "kaarenilsen.cn").containsAll(Arrays.asList("Kaare Nilsen", "Kåre Nilsen"))); - initialDirContext.close(); + assertTrue(configuration.evaluateToList(String.class, "kaarenilsen.cn") + .containsAll(Arrays.asList("Kaare Nilsen", "Kåre Nilsen"))); } @@ -106,15 +92,4 @@ private ConstrettoConfiguration createConfiguration(LdapConfigurationStore confi configurationStore).getConfiguration(); } - private Hashtable createLdapEnvironment() { - Hashtable ldapEnvironment = new Hashtable(); - ldapEnvironment.put(LdapContext.CONTROL_FACTORIES, DefaultResponseControlFactory.class.getName()); - ldapEnvironment.put(Context.PROVIDER_URL, String.format("ldap://localhost:%1$s", LDAP_PORT)); - ldapEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, LdapCtxFactory.class.getName()); - ldapEnvironment.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system"); - ldapEnvironment.put(Context.SECURITY_CREDENTIALS, "secret"); - ldapEnvironment.put(Context.SECURITY_PROTOCOL, "simple"); - return ldapEnvironment; - } - } diff --git a/pom.xml b/pom.xml index b96ec44c..7ca012b1 100644 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,7 @@ 1.7.6 1.5.7 1.6.0 + 0.5.2 2.9.1 2.3 1.5 From e499078c62d6f52bf2f3e331d0263b4cc71054b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 15:03:41 +0100 Subject: [PATCH 09/21] remove jdk 1.6 support :-) --- .travis.yml | 2 +- pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 393b7bb7..8b96480c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ env: - secure: njJrgrBWrEHK86vEK8UlmM5SxlptsyU7ghWOPsQl5Dr0WvseZWtT/7A9bDPmcNxp2EJBx4xt0BAIDnhnqcHwdKDrYjpHPabneDipEchdm2p+vI96lqb1zZ5Du+xvQGzZlXPhf1VocWSFXRACAJ2+Nky6nbTrhKCr101kBA8oSe4= language: java jdk: -- openjdk6 - openjdk7 - oraclejdk7 +- oraclejdk8 after_success: - mvn clean cobertura:cobertura coveralls:cobertura - echo "sonatype-nexus-snapshots\${env.REPO_USER}\${env.REPO_PASSWORD}" > ~/settings.xml diff --git a/pom.xml b/pom.xml index 7ca012b1..47a99405 100644 --- a/pom.xml +++ b/pom.xml @@ -321,8 +321,8 @@ maven-compiler-plugin ${maven-compiler-plugin.version} - 1.6 - 1.6 + 1.7 + 1.7 UTF-8 From 0e06591c3f29d3a8d6c4221697ae7676dde48367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 15:45:05 +0100 Subject: [PATCH 10/21] try to re-enable jdk6 support by using assumption to ignore tests requiring JDK 7 --- .travis.yml | 1 + .../ldap/LdapConfigurationStoreEmbeddedLdapTest.java | 10 ++++++++++ pom.xml | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8b96480c..a90c3187 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ env: - secure: njJrgrBWrEHK86vEK8UlmM5SxlptsyU7ghWOPsQl5Dr0WvseZWtT/7A9bDPmcNxp2EJBx4xt0BAIDnhnqcHwdKDrYjpHPabneDipEchdm2p+vI96lqb1zZ5Du+xvQGzZlXPhf1VocWSFXRACAJ2+Nky6nbTrhKCr101kBA8oSe4= language: java jdk: +- openjdk6 - openjdk7 - oraclejdk7 - oraclejdk8 diff --git a/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java b/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java index 4f693521..074cd1d1 100644 --- a/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java +++ b/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java @@ -6,6 +6,7 @@ import org.constretto.model.TaggedPropertySet; import org.junit.Rule; import org.junit.Test; +import org.mockito.internal.matchers.GreaterThan; import org.zapodot.junit.ldap.EmbeddedLdapRule; import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; @@ -16,6 +17,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeThat; /** * @author zapodot at gmail dot com @@ -42,6 +44,7 @@ public static class ConfigurableType { @Test public void testParseConfigurationUsingAddDsn() throws Exception { + assumeJdkHigherThan6(); final DirContext dirContext = embeddedLdapRule.dirContext(); final LdapConfigurationStore configurationStore = LdapConfigurationStoreBuilder.usingDirContext(dirContext) .addDsn("cn=Kaare Nilsen,dc=constretto,dc=org") @@ -59,6 +62,7 @@ public void testParseConfigurationUsingAddDsn() throws Exception { @Test public void testDsnMultiValue() throws Exception { + assumeJdkHigherThan6(); final DirContext initialDirContext = embeddedLdapRule.dirContext(); final ConstrettoConfiguration configuration = new ConstrettoBuilder(false) .createLdapConfigurationStore(initialDirContext) @@ -73,6 +77,8 @@ public void testDsnMultiValue() throws Exception { @Test public void testParseConfigurationUsingSearch() throws Exception { + + assumeJdkHigherThan6(); final DirContext initialDirContext = embeddedLdapRule.dirContext(); final ConstrettoConfiguration configuration = new ConstrettoBuilder(false) .createLdapConfigurationStore(initialDirContext) @@ -87,6 +93,10 @@ public void testParseConfigurationUsingSearch() throws Exception { } + private void assumeJdkHigherThan6() { + assumeThat(Integer.parseInt(System.getProperty("java.version").split("\\.")[1]), new GreaterThan(6)); + } + private ConstrettoConfiguration createConfiguration(LdapConfigurationStore configurationStore) { return new ConstrettoBuilder(false).addConfigurationStore( configurationStore).getConfiguration(); diff --git a/pom.xml b/pom.xml index 47a99405..7ca012b1 100644 --- a/pom.xml +++ b/pom.xml @@ -321,8 +321,8 @@ maven-compiler-plugin ${maven-compiler-plugin.version} - 1.7 - 1.7 + 1.6 + 1.6 UTF-8 From c610af805ff3bd4cfea667ba01eff9769e1071d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 15:51:53 +0100 Subject: [PATCH 11/21] use a BeforeClass hook to run the assumptions --- .../LdapConfigurationStoreEmbeddedLdapTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java b/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java index 074cd1d1..8991f848 100644 --- a/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java +++ b/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java @@ -4,6 +4,7 @@ import org.constretto.ConstrettoConfiguration; import org.constretto.annotation.Configuration; import org.constretto.model.TaggedPropertySet; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.mockito.internal.matchers.GreaterThan; @@ -32,6 +33,12 @@ public class LdapConfigurationStoreEmbeddedLdapTest { .build(); public static final int LDAP_PORT = 27389; + @BeforeClass + public static void assumeJavaVersionGreatherThan6() { + assumeThat(Integer.parseInt(System.getProperty("java.version").split("\\.")[1]), new GreaterThan(6)); + + } + public static class ConfigurableType { @Configuration("cn") @@ -44,7 +51,6 @@ public static class ConfigurableType { @Test public void testParseConfigurationUsingAddDsn() throws Exception { - assumeJdkHigherThan6(); final DirContext dirContext = embeddedLdapRule.dirContext(); final LdapConfigurationStore configurationStore = LdapConfigurationStoreBuilder.usingDirContext(dirContext) .addDsn("cn=Kaare Nilsen,dc=constretto,dc=org") @@ -62,7 +68,6 @@ public void testParseConfigurationUsingAddDsn() throws Exception { @Test public void testDsnMultiValue() throws Exception { - assumeJdkHigherThan6(); final DirContext initialDirContext = embeddedLdapRule.dirContext(); final ConstrettoConfiguration configuration = new ConstrettoBuilder(false) .createLdapConfigurationStore(initialDirContext) @@ -78,7 +83,6 @@ public void testDsnMultiValue() throws Exception { @Test public void testParseConfigurationUsingSearch() throws Exception { - assumeJdkHigherThan6(); final DirContext initialDirContext = embeddedLdapRule.dirContext(); final ConstrettoConfiguration configuration = new ConstrettoBuilder(false) .createLdapConfigurationStore(initialDirContext) @@ -93,10 +97,6 @@ public void testParseConfigurationUsingSearch() throws Exception { } - private void assumeJdkHigherThan6() { - assumeThat(Integer.parseInt(System.getProperty("java.version").split("\\.")[1]), new GreaterThan(6)); - } - private ConstrettoConfiguration createConfiguration(LdapConfigurationStore configurationStore) { return new ConstrettoBuilder(false).addConfigurationStore( configurationStore).getConfiguration(); From 48afa8a9effe9b51bc8dd001ffbff769700f76eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 16:09:54 +0100 Subject: [PATCH 12/21] Don't build with JDK1.6, but still provide 1.6-compatible bytecode --- .travis.yml | 1 - .../ldap/LdapConfigurationStoreEmbeddedLdapTest.java | 9 --------- 2 files changed, 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index a90c3187..8b96480c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ env: - secure: njJrgrBWrEHK86vEK8UlmM5SxlptsyU7ghWOPsQl5Dr0WvseZWtT/7A9bDPmcNxp2EJBx4xt0BAIDnhnqcHwdKDrYjpHPabneDipEchdm2p+vI96lqb1zZ5Du+xvQGzZlXPhf1VocWSFXRACAJ2+Nky6nbTrhKCr101kBA8oSe4= language: java jdk: -- openjdk6 - openjdk7 - oraclejdk7 - oraclejdk8 diff --git a/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java b/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java index 8991f848..bbad1179 100644 --- a/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java +++ b/constretto-core/src/test/java/org/constretto/internal/store/ldap/LdapConfigurationStoreEmbeddedLdapTest.java @@ -4,10 +4,8 @@ import org.constretto.ConstrettoConfiguration; import org.constretto.annotation.Configuration; import org.constretto.model.TaggedPropertySet; -import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; -import org.mockito.internal.matchers.GreaterThan; import org.zapodot.junit.ldap.EmbeddedLdapRule; import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; @@ -18,7 +16,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeThat; /** * @author zapodot at gmail dot com @@ -33,12 +30,6 @@ public class LdapConfigurationStoreEmbeddedLdapTest { .build(); public static final int LDAP_PORT = 27389; - @BeforeClass - public static void assumeJavaVersionGreatherThan6() { - assumeThat(Integer.parseInt(System.getProperty("java.version").split("\\.")[1]), new GreaterThan(6)); - - } - public static class ConfigurableType { @Configuration("cn") From 3b60301a39914cb4fd383544314ff732da215504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 16:24:32 +0100 Subject: [PATCH 13/21] update deps: sl4j,ini4j,snakeyml --- pom.xml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 7ca012b1..e0c2370e 100644 --- a/pom.xml +++ b/pom.xml @@ -101,8 +101,8 @@ 1.9.5 1.0 1.7.4 - 0.5.2 - 1.14 + 0.5.4 + 1.16 2.6 1.9.1 2.2.4 @@ -111,9 +111,8 @@ 3.2.11.RELEASE 4.12 1.3.1.RELEASE - 1.7.6 - 1.5.7 - 1.6.0 + 1.7.13 + 1.14.0 0.5.2 2.9.1 2.3 From 25ca6c361a0042cb818445549ec46fdc52f40364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 22:16:08 +0100 Subject: [PATCH 14/21] added nexus-staging-plugin --- pom.xml | 67 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index e0c2370e..db80b47e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,8 @@ either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - + 4.0.0 org.constretto constretto @@ -35,8 +36,8 @@ scm:git:git@github.com:constretto/constretto-core.git scm:git:git@github.com:constretto/constretto-core.git http://github.com/constretto/constretto-core - HEAD - + HEAD + github @@ -121,9 +122,43 @@ 2.6 1.3.1 2.17 + 1.6.6 + + release + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + sonatype-nexus-staging + https://oss.sonatype.org/ + true + + + + + + sonatype-oss-release @@ -325,6 +360,12 @@ UTF-8 + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + org.apache.maven.plugins maven-javadoc-plugin @@ -365,7 +406,7 @@ - org.apache.maven.plugins + org.apache.maven.plugins maven-resources-plugin ${maven-resources-plugin.version} @@ -400,14 +441,16 @@ org.apache.maven.plugins - maven-release-plugin - 2.5 - - true - false - sonatype-oss-release - deploy - + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + + jar-no-fork + + + From 8ef5597d50b4edf443e35a35fcbd47556e3e0989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 22:26:15 +0100 Subject: [PATCH 15/21] release 2.2.3 --- constretto-api/pom.xml | 2 +- constretto-core/pom.xml | 2 +- constretto-spring/pom.xml | 2 +- constretto-test/pom.xml | 2 +- pom.xml | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/constretto-api/pom.xml b/constretto-api/pom.xml index e68e7544..b2407781 100644 --- a/constretto-api/pom.xml +++ b/constretto-api/pom.xml @@ -11,7 +11,7 @@ constretto org.constretto - 2.2.3-SNAPSHOT + 2.2.3 4.0.0 constretto-api diff --git a/constretto-core/pom.xml b/constretto-core/pom.xml index 0b7a94db..60099902 100644 --- a/constretto-core/pom.xml +++ b/constretto-core/pom.xml @@ -11,7 +11,7 @@ constretto org.constretto - 2.2.3-SNAPSHOT + 2.2.3 4.0.0 constretto-core diff --git a/constretto-spring/pom.xml b/constretto-spring/pom.xml index f173b22a..6a18e1d5 100644 --- a/constretto-spring/pom.xml +++ b/constretto-spring/pom.xml @@ -11,7 +11,7 @@ constretto org.constretto - 2.2.3-SNAPSHOT + 2.2.3 4.0.0 constretto-spring diff --git a/constretto-test/pom.xml b/constretto-test/pom.xml index c58f6687..5d5324bc 100644 --- a/constretto-test/pom.xml +++ b/constretto-test/pom.xml @@ -10,7 +10,7 @@ constretto org.constretto - 2.2.3-SNAPSHOT + 2.2.3 4.0.0 constretto-test diff --git a/pom.xml b/pom.xml index db80b47e..2965ec79 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ 4.0.0 org.constretto constretto - 2.2.3-SNAPSHOT + 2.2.3 Constretto :: Parent - ${project.version} 2008 http://constretto.github.io @@ -373,13 +373,13 @@ javadoc:aggregate - site - aggregate + jar + -Xdoclint:none http://docs.oracle.com/javase/6/docs/api/ http://docs.oracle.com/javase/1.5.0/docs/api/ From 8fbdadfd2bffd7e06c4f63f4b6366060922798a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 22:33:18 +0100 Subject: [PATCH 16/21] prepare further development --- constretto-api/pom.xml | 2 +- constretto-core/pom.xml | 2 +- constretto-spring/pom.xml | 2 +- constretto-test/pom.xml | 2 +- pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/constretto-api/pom.xml b/constretto-api/pom.xml index b2407781..1248cb4c 100644 --- a/constretto-api/pom.xml +++ b/constretto-api/pom.xml @@ -11,7 +11,7 @@ constretto org.constretto - 2.2.3 + 2.2.4-SNAPSHOT 4.0.0 constretto-api diff --git a/constretto-core/pom.xml b/constretto-core/pom.xml index 60099902..b921e491 100644 --- a/constretto-core/pom.xml +++ b/constretto-core/pom.xml @@ -11,7 +11,7 @@ constretto org.constretto - 2.2.3 + 2.2.4-SNAPSHOT 4.0.0 constretto-core diff --git a/constretto-spring/pom.xml b/constretto-spring/pom.xml index 6a18e1d5..3245438f 100644 --- a/constretto-spring/pom.xml +++ b/constretto-spring/pom.xml @@ -11,7 +11,7 @@ constretto org.constretto - 2.2.3 + 2.2.4-SNAPSHOT 4.0.0 constretto-spring diff --git a/constretto-test/pom.xml b/constretto-test/pom.xml index 5d5324bc..5f95655c 100644 --- a/constretto-test/pom.xml +++ b/constretto-test/pom.xml @@ -10,7 +10,7 @@ constretto org.constretto - 2.2.3 + 2.2.4-SNAPSHOT 4.0.0 constretto-test diff --git a/pom.xml b/pom.xml index 2965ec79..9a3b54e5 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ 4.0.0 org.constretto constretto - 2.2.3 + 2.2.4-SNAPSHOT Constretto :: Parent - ${project.version} 2008 http://constretto.github.io From 672a497c1bf097e8b27918af883587deca9521e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 22:36:18 +0100 Subject: [PATCH 17/21] add version description to readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 9429d701..d51fc5ea 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,13 @@ All current releases are compiled with target JDK 1.6. Starting with Constretto [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.constretto/constretto-core/badge.svg)](http://mvnrepository.com/artifact/org.constretto/constretto-core) [![Coverage Status](https://img.shields.io/coveralls/constretto/constretto-core.svg)](https://coveralls.io/r/constretto/constretto-core) +## What's new in 2.2.3 +* fix issue affecting singleton in constretto-spring contributed by @nicolasyanncouturier in PR #59 +* add support for "file://"-urls in the FileResource class. Contributed by @kenglxn in PR #58 +* streamline build by removing the dependency on ApacheDS for building. Instead it will no use the [embedded-ldap-junit] (https://github.com/zapodot/embedded-ldap-junit) library for testing the LDAP integration +* stop building with JDK6 (though still providing JDK6-compatible bytecode) +* update deps: JUnit 4.12 (was 4.11), ini4j 0.5.4 (was 0.5.2) and snakeyml 1.16 (was 1.14) + ## What's new in 2.2.2 * Support for YAML store contributed by [hamnis](//github.com/hamnis) - pull request #48 * Change scope of Constretto-test in the Constretto Spring module to "test" - pull request #47 From cca3c885f9e2dd402f3f4eec2d857c95cc9b2944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Tue, 1 Dec 2015 22:42:57 +0100 Subject: [PATCH 18/21] Update coveralls plugin --- .travis.yml | 2 +- pom.xml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8b96480c..3951c9e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ jdk: - oraclejdk7 - oraclejdk8 after_success: -- mvn clean cobertura:cobertura coveralls:cobertura +- mvn clean cobertura:cobertura coveralls:report - echo "sonatype-nexus-snapshots\${env.REPO_USER}\${env.REPO_PASSWORD}" > ~/settings.xml - mvn deploy --settings ~/settings.xml diff --git a/pom.xml b/pom.xml index 9a3b54e5..cc808294 100644 --- a/pom.xml +++ b/pom.xml @@ -123,6 +123,7 @@ 1.3.1 2.17 1.6.6 + 4.1.0 @@ -393,7 +394,7 @@ org.eluder.coveralls coveralls-maven-plugin - 2.2.0 + ${maven-coverall-plugin.version} org.codehaus.mojo From 2bd281d573addc2c30a5ea230798a715806e81f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Wed, 2 Dec 2015 07:49:50 +0100 Subject: [PATCH 19/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d51fc5ea..15b84b5b 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ All current releases are compiled with target JDK 1.6. Starting with Constretto ## What's new in 2.2.3 * fix issue affecting singleton in constretto-spring contributed by @nicolasyanncouturier in PR #59 * add support for "file://"-urls in the FileResource class. Contributed by @kenglxn in PR #58 -* streamline build by removing the dependency on ApacheDS for building. Instead it will no use the [embedded-ldap-junit] (https://github.com/zapodot/embedded-ldap-junit) library for testing the LDAP integration +* streamline build by removing the build dependency on ApacheDS in favour of the [embedded-ldap-junit] (https://github.com/zapodot/embedded-ldap-junit) library. * stop building with JDK6 (though still providing JDK6-compatible bytecode) * update deps: JUnit 4.12 (was 4.11), ini4j 0.5.4 (was 0.5.2) and snakeyml 1.16 (was 1.14) From 28475f65c89f6d9ae618c3e3cd7d6e1a72ad3acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Eikanger=20Kval=C3=B8?= Date: Wed, 2 Dec 2015 07:50:36 +0100 Subject: [PATCH 20/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15b84b5b..0ac30501 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ All current releases are compiled with target JDK 1.6. Starting with Constretto ## What's new in 2.2.3 * fix issue affecting singleton in constretto-spring contributed by @nicolasyanncouturier in PR #59 * add support for "file://"-urls in the FileResource class. Contributed by @kenglxn in PR #58 -* streamline build by removing the build dependency on ApacheDS in favour of the [embedded-ldap-junit] (https://github.com/zapodot/embedded-ldap-junit) library. +* streamline build by removing the build dependency on [ApacheDS](https://directory.apache.org/apacheds/) in favour of the [embedded-ldap-junit] (https://github.com/zapodot/embedded-ldap-junit) library. * stop building with JDK6 (though still providing JDK6-compatible bytecode) * update deps: JUnit 4.12 (was 4.11), ini4j 0.5.4 (was 0.5.2) and snakeyml 1.16 (was 1.14) From d7e0d1a0746332c8286e1f5427fbde787b21a431 Mon Sep 17 00:00:00 2001 From: Joakim Date: Wed, 1 Jun 2016 14:55:45 +0200 Subject: [PATCH 21/21] Expose path in Resource. It is already exposed as part of the toString-method, but there shouldn't be a reason to use regex to get it. --- .../src/main/java/org/constretto/model/Resource.java | 4 ++++ .../java/org/constretto/model/ClassPathResourceTest.java | 5 +++++ .../test/java/org/constretto/model/FileResourceTest.java | 7 +++++++ .../test/java/org/constretto/model/UrlResourceTest.java | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/constretto-core/src/main/java/org/constretto/model/Resource.java b/constretto-core/src/main/java/org/constretto/model/Resource.java index 861224c2..de7ede53 100644 --- a/constretto-core/src/main/java/org/constretto/model/Resource.java +++ b/constretto-core/src/main/java/org/constretto/model/Resource.java @@ -52,4 +52,8 @@ public String toString() { sb.append('}'); return sb.toString(); } + + public String getPath(){ + return this.path; + } } diff --git a/constretto-core/src/test/java/org/constretto/model/ClassPathResourceTest.java b/constretto-core/src/test/java/org/constretto/model/ClassPathResourceTest.java index 728e40d3..29b1c82d 100644 --- a/constretto-core/src/test/java/org/constretto/model/ClassPathResourceTest.java +++ b/constretto-core/src/test/java/org/constretto/model/ClassPathResourceTest.java @@ -33,6 +33,11 @@ public void testOpenNoneExistingClassPathResource() throws Exception { public void testToString() throws Exception { final ClassPathResource classPathResource = new ClassPathResource(NON_EXISITING_CLASSPATH_RESOURCE); assertEquals("ClassPathResource{path='" + NON_EXISITING_CLASSPATH_RESOURCE + "'}", classPathResource.toString()); + } + @Test + public void testGetPath() throws Exception { + final ClassPathResource classPathResource = new ClassPathResource(NON_EXISITING_CLASSPATH_RESOURCE); + assertEquals(NON_EXISITING_CLASSPATH_RESOURCE, classPathResource.getPath()); } } diff --git a/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java b/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java index 05461586..2ab52f75 100644 --- a/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java +++ b/constretto-core/src/test/java/org/constretto/model/FileResourceTest.java @@ -59,6 +59,13 @@ public void testToString() throws Exception { assertEquals("FileResource{path='file:src/test/resources/cache1.ini'}", fileResource.toString()); } + @Test + public void testGetPath() throws Exception { + String testPath = "file:src/test/resources/cache1.ini"; + final FileResource fileResource = new FileResource(testPath); + assertEquals(fileResource.getPath(), testPath); + } + /** * If file name starts with file: chances are it is a file url. * Constretto should decode this url since it uses new File(String) which does not support diff --git a/constretto-core/src/test/java/org/constretto/model/UrlResourceTest.java b/constretto-core/src/test/java/org/constretto/model/UrlResourceTest.java index 049e30c7..879ad11e 100644 --- a/constretto-core/src/test/java/org/constretto/model/UrlResourceTest.java +++ b/constretto-core/src/test/java/org/constretto/model/UrlResourceTest.java @@ -40,7 +40,13 @@ public void validUrlsThatDoNotExistShouldWork() throws Exception { public void testToString() throws Exception { final UrlResource urlResource = new UrlResource("http://vg.no"); assertEquals("UrlResource{path='http://vg.no'}", urlResource.toString()); + } + + @Test + public void testGetPath() throws Exception { + final UrlResource urlResource = new UrlResource("http://vg.no"); + assertEquals(urlResource.getPath(), "http://vg.no"); } }