Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a30b405
Fixed FileResource so that it supports file url. E.g. resulting outpu…
Jul 6, 2015
9ba73a6
removed usage of nio in test to fix 1.6 build
kenglxn Jul 6, 2015
19c8a1e
only do inject configuration in beans of scope singleton so as to avo…
Oct 20, 2015
b5378c9
test that no configuration injection happens when not a singleton bean
Oct 21, 2015
286a7d1
spring-test dependency should have test scope
stigkj Nov 27, 2015
1c07c9b
Merge pull request #60 from stigkj/patch-1
zapodot Dec 1, 2015
64fbc24
Fix build errors. We do need Spring-test in compile scope in constret…
Dec 1, 2015
97d5a30
update junit to v 4.12
Dec 1, 2015
6d04b03
improve test performance a lot by moving ApacheDS. Use embedded-ldap-…
zapodot Dec 1, 2015
7542b4f
Merge pull request #59 from nicolasyanncouturier/inject_configuration…
zapodot Dec 1, 2015
e499078
remove jdk 1.6 support :-)
zapodot Dec 1, 2015
0e06591
try to re-enable jdk6 support by using assumption to ignore tests req…
zapodot Dec 1, 2015
c610af8
use a BeforeClass hook to run the assumptions
zapodot Dec 1, 2015
48afa8a
Don't build with JDK1.6, but still provide 1.6-compatible bytecode
zapodot Dec 1, 2015
3b60301
update deps: sl4j,ini4j,snakeyml
zapodot Dec 1, 2015
9191f5a
Merge pull request #58 from kenglxn/master
zapodot Dec 1, 2015
25ca6c3
added nexus-staging-plugin
zapodot Dec 1, 2015
8ef5597
release 2.2.3
zapodot Dec 1, 2015
8fbdadf
prepare further development
zapodot Dec 1, 2015
672a497
add version description to readme
zapodot Dec 1, 2015
cca3c88
Update coveralls plugin
zapodot Dec 1, 2015
2bd281d
Update README.md
zapodot Dec 2, 2015
28475f6
Update README.md
zapodot Dec 2, 2015
d7e0d1a
Expose path in Resource.
Jun 1, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ env:
- secure: njJrgrBWrEHK86vEK8UlmM5SxlptsyU7ghWOPsQl5Dr0WvseZWtT/7A9bDPmcNxp2EJBx4xt0BAIDnhnqcHwdKDrYjpHPabneDipEchdm2p+vI96lqb1zZ5Du+xvQGzZlXPhf1VocWSFXRACAJ2+Nky6nbTrhKCr101kBA8oSe4=
language: java
jdk:
- openjdk6
- openjdk7
- oraclejdk7
- oraclejdk8
after_success:
- mvn clean cobertura:cobertura coveralls:cobertura
- mvn clean cobertura:cobertura coveralls:report
- echo "<settings><servers><server><id>sonatype-nexus-snapshots</id><username>\${env.REPO_USER}</username><password>\${env.REPO_PASSWORD}</password></server></servers></settings>" > ~/settings.xml
- mvn deploy --settings ~/settings.xml

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)

## 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
Expand Down
2 changes: 1 addition & 1 deletion constretto-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<artifactId>constretto</artifactId>
<groupId>org.constretto</groupId>
<version>2.2.3-SNAPSHOT</version>
<version>2.2.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>constretto-api</artifactId>
Expand Down
14 changes: 7 additions & 7 deletions constretto-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<artifactId>constretto</artifactId>
<groupId>org.constretto</groupId>
<version>2.2.3-SNAPSHOT</version>
<version>2.2.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>constretto-core</artifactId>
Expand All @@ -30,6 +30,12 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.zapodot</groupId>
<artifactId>embedded-ldap-junit</artifactId>
<version>${embedded-ldap-junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
Expand Down Expand Up @@ -70,12 +76,6 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-test-framework</artifactId>
<version>${apacheds.version}</version>
<scope>test</scope>
</dependency>
<!-- SLF4J is needed to run embedded ApacheDS -->
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="mailto:kaare.nilsen@gmail.com">Kaare Nilsen</a>
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ public String toString() {
sb.append('}');
return sb.toString();
}

public String getPath(){
return this.path;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -54,16 +42,14 @@ public static class ConfigurableType {
@Test
public void testParseConfigurationUsingAddDsn() throws Exception {

Hashtable<String, String> 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<TaggedPropertySet> 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")));
Expand All @@ -73,21 +59,22 @@ 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<String> members = configuration.evaluateToList(String.class, "uniquemember");
final List<String> members = configuration.evaluateToList(String.class, "uniqueMember");
assertEquals(2, members.size());


}

@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(
Expand All @@ -96,8 +83,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")));

}

Expand All @@ -106,15 +93,4 @@ private ConstrettoConfiguration createConfiguration(LdapConfigurationStore confi
configurationStore).getConfiguration();
}

private Hashtable<String, String> createLdapEnvironment() {
Hashtable<String, String> ldapEnvironment = new Hashtable<String, String>();
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ 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());
}

@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
* url encoding.
*/
@Test
public void testWithSpaces() throws Exception {
File file = new File("src/test/resources/dir with spaces/test.properties");

String string = file.toURI().toURL().toString();
final FileResource existing = new FileResource(string);
assertTrue(existing.exists());
}
}
Original file line number Diff line number Diff line change
@@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ 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 {
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");
}

}
26 changes: 26 additions & 0 deletions constretto-core/src/test/resources/dir with spaces/test.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion constretto-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<artifactId>constretto</artifactId>
<groupId>org.constretto</groupId>
<version>2.2.3-SNAPSHOT</version>
<version>2.2.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>constretto-spring</artifactId>
Expand Down
Loading