This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new d69d158 [OPENLDAP-CONTAINER] Run IT tests on Docker
d69d158 is described below
commit d69d15861857e76d21cea3e7962075204db6a205
Author: Federico Mariani <[email protected]>
AuthorDate: Wed May 19 16:54:17 2021 +0200
[OPENLDAP-CONTAINER] Run IT tests on Docker
---
components/camel-ldif/pom.xml | 14 ++
.../apache/camel/component/ldif/LdifRouteIT.java | 215 ++++++++++++---------
.../camel/component/ldif/LdifTestSupport.java | 40 ++++
.../apache/camel/component/ldif/AddDuplicate.ldif | 2 +-
.../camel/component/ldif/AddDuplicateSetup.ldif | 4 +-
.../org/apache/camel/component/ldif/AddOne.ldif | 4 +-
.../org/apache/camel/component/ldif/DeleteOne.ldif | 3 +-
.../camel/component/ldif/DeleteOneSetup.ldif | 4 +-
.../org/apache/camel/component/ldif/ModDn.ldif | 4 +-
.../apache/camel/component/ldif/ModDnSetup.ldif | 6 +-
.../org/apache/camel/component/ldif/ModRdn.ldif | 2 +-
.../apache/camel/component/ldif/ModRdnSetup.ldif | 4 +-
.../org/apache/camel/component/ldif/Modify.ldif | 2 +-
.../apache/camel/component/ldif/ModifySetup.ldif | 4 +-
test-infra/camel-test-infra-openldap/pom.xml | 58 ++++++
.../src/main/resources/META-INF/MANIFEST.MF | 0
.../infra/openldap/common/OpenldapProperties.java | 29 +++
.../services/OpenldapLocalContainerService.java | 117 +++++++++++
.../openldap/services/OpenldapRemoteService.java | 66 +++++++
.../infra/openldap/services/OpenldapService.java | 44 +++++
.../openldap/services/OpenldapServiceFactory.java | 36 ++++
test-infra/pom.xml | 3 +-
22 files changed, 545 insertions(+), 116 deletions(-)
diff --git a/components/camel-ldif/pom.xml b/components/camel-ldif/pom.xml
index ff2aa1b..82ec003 100644
--- a/components/camel-ldif/pom.xml
+++ b/components/camel-ldif/pom.xml
@@ -82,6 +82,20 @@
<artifactId>mina-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-common</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-openldap</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
<!-- logging -->
<dependency>
diff --git
a/components/camel-ldif/src/test/java/org/apache/camel/component/ldif/LdifRouteIT.java
b/components/camel-ldif/src/test/java/org/apache/camel/component/ldif/LdifRouteIT.java
index f7f7dbf..5341611 100644
---
a/components/camel-ldif/src/test/java/org/apache/camel/component/ldif/LdifRouteIT.java
+++
b/components/camel-ldif/src/test/java/org/apache/camel/component/ldif/LdifRouteIT.java
@@ -20,13 +20,18 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Hashtable;
import java.util.List;
+import javax.naming.Context;
import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
+import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import org.apache.camel.CamelContext;
@@ -36,34 +41,30 @@ import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.SimpleRegistry;
-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.integ.AbstractLdapTestUnit;
-import org.apache.directory.server.core.integ5.DirectoryExtension;
+import org.apache.camel.test.infra.openldap.services.OpenldapService;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.ldap.client.api.DefaultLdapConnectionFactory;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
-import org.junit.jupiter.api.extension.ExtendWith;
-import static
org.apache.directory.server.integ.ServerIntegrationUtils.getWiredConnection;
-import static
org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
+import static org.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-@ExtendWith(DirectoryExtension.class)
-@CreateLdapServer(transports = { @CreateTransport(protocol = "LDAP") })
-@EnabledIfSystemProperty(named = "enable.ldif.itests", matches = "true",
- disabledReason = "the tests does not work due to
complex ldap server environment")
-public class LdifRouteIT extends AbstractLdapTestUnit {
+public class LdifRouteIT extends LdifTestSupport {
// Constants
private static final String LDAP_CONN_NAME = "conn";
private static final String ENDPOINT_LDIF = "ldif:" + LDAP_CONN_NAME;
private static final String ENDPOINT_START = "direct:start";
+ private static final String ENDPOINT_SETUP_START = "direct:setup";
private static final SearchControls SEARCH_CONTROLS
= new SearchControls(SearchControls.SUBTREE_SCOPE, 0, 0, null,
true, true);
@@ -72,17 +73,43 @@ public class LdifRouteIT extends AbstractLdapTestUnit {
private ProducerTemplate template;
private LdapContext ldapContext;
+ private static LdapContext getWiredContext(OpenldapService ldapServer)
throws NamingException {
+ Hashtable<String, String> env = new Hashtable<>();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
+ env.put(Context.PROVIDER_URL, "ldap://" + ldapServer.getHost() + ":" +
ldapServer.getPort());
+ env.put(Context.SECURITY_PRINCIPAL, "cn=admin,dc=example,dc=org");
+ env.put(Context.SECURITY_CREDENTIALS, "admin");
+ env.put(Context.SECURITY_AUTHENTICATION, "simple");
+
+ return new InitialLdapContext(env, null);
+ }
+
@BeforeEach
public void setup() throws Exception {
// Create the LDAPConnection
- ldapContext = getWiredContext(ldapServer);
+ ldapContext = getWiredContext(service);
- SimpleRegistry reg = new SimpleRegistry();
- reg.bind(LDAP_CONN_NAME, getWiredConnection(ldapServer));
+ SimpleRegistry reg = getSimpleRegistry();
camel = new DefaultCamelContext(reg);
template = camel.createProducerTemplate();
}
+ private SimpleRegistry getSimpleRegistry() throws LdapException {
+ final LdapConnectionConfig ldapConnectionConfig = new
LdapConnectionConfig();
+ ldapConnectionConfig.setLdapHost(service.getHost());
+ ldapConnectionConfig.setLdapPort(service.getPort());
+ ldapConnectionConfig.setName("cn=admin,dc=example,dc=org");
+ ldapConnectionConfig.setCredentials("admin");
+ ldapConnectionConfig.setUseSsl(false);
+ ldapConnectionConfig.setUseTls(false);
+
+ LdapConnection ldapConnection = new
DefaultLdapConnectionFactory(ldapConnectionConfig).newLdapConnection();
+
+ SimpleRegistry reg = new SimpleRegistry();
+ reg.bind(LDAP_CONN_NAME, ldapConnection);
+ return reg;
+ }
+
@AfterEach
public void tearDown() throws Exception {
if (camel != null) {
@@ -115,50 +142,16 @@ public class LdifRouteIT extends AbstractLdapTestUnit {
// Check LDAP
SearchResult sr;
- NamingEnumeration<SearchResult> searchResults = ldapContext.search("",
"(uid=test*)", SEARCH_CONTROLS);
+ NamingEnumeration<SearchResult> searchResults =
ldapContext.search("dc=example,dc=org", "(uid=test*)", SEARCH_CONTROLS);
assertNotNull(searchResults);
- sr = searchResults.next();
- assertNotNull(sr);
- assertThat("uid=test1,ou=test,ou=system", equalTo(sr.getName()));
- assertThat(false, equalTo(searchResults.hasMore()));
- }
-
- @Test
- public void addOneInline() throws Exception {
- camel.addRoutes(createRouteBuilder(ENDPOINT_LDIF));
- camel.start();
-
- Endpoint endpoint = camel.getEndpoint(ENDPOINT_START);
- Exchange exchange = endpoint.createExchange();
-
- // then we set the LDAP filter on the in body
- URL loc =
this.getClass().getResource("/org/apache/camel/component/ldif/AddOne.ldif");
- exchange.getIn().setBody(readUrl(loc));
-
- // now we send the exchange to the endpoint, and receives the response
- // from Camel
- Exchange out = template.send(endpoint, exchange);
- // Check the results
- List<String> ldifResults = defaultLdapModuleOutAssertions(out);
- assertThat(ldifResults, notNullValue());
- assertThat(ldifResults.size(), equalTo(2)); // Container and user
- assertThat(ldifResults.get(0), equalTo("success"));
- assertThat(ldifResults.get(1), equalTo("success"));
-
- // Check LDAP
- SearchResult sr;
- NamingEnumeration<SearchResult> searchResults = ldapContext.search("",
"(uid=test*)", SEARCH_CONTROLS);
- assertNotNull(searchResults);
- sr = searchResults.next();
- assertNotNull(sr);
- assertThat("uid=test1,ou=test,ou=system", equalTo(sr.getName()));
- assertThat(false, equalTo(searchResults.hasMore()));
+ checkDN("uid=test1", searchResults);
}
@Test
- @ApplyLdifFiles({ "org/apache/camel/component/ldif/DeleteOneSetup.ldif" })
public void deleteOne() throws Exception {
+ setupData("/org/apache/camel/component/ldif/DeleteOneSetup.ldif");
+
camel.addRoutes(createRouteBuilder(ENDPOINT_LDIF));
camel.start();
@@ -180,13 +173,17 @@ public class LdifRouteIT extends AbstractLdapTestUnit {
assertThat(ldifResults.get(0), equalTo("success"));
// Check LDAP
- NamingEnumeration<SearchResult> searchResults = ldapContext.search("",
"(uid=test*)", SEARCH_CONTROLS);
- assertThat(false, equalTo(searchResults.hasMore()));
+ NamingEnumeration<SearchResult> searchResults =
ldapContext.search("dc=example,dc=org", "(uid=test*)", SEARCH_CONTROLS);
+ // test2
+ while (searchResults.hasMore()) {
+ assertThat(searchResults.next().getName(),
not(containsString("test2")));
+ }
}
@Test
- @ApplyLdifFiles({ "org/apache/camel/component/ldif/AddDuplicateSetup.ldif"
})
public void addDuplicate() throws Exception {
+ setupData("/org/apache/camel/component/ldif/AddDuplicateSetup.ldif");
+
camel.addRoutes(createRouteBuilder(ENDPOINT_LDIF));
camel.start();
@@ -209,8 +206,9 @@ public class LdifRouteIT extends AbstractLdapTestUnit {
}
@Test
- @ApplyLdifFiles({ "org/apache/camel/component/ldif/ModifySetup.ldif" })
public void modify() throws Exception {
+ setupData("/org/apache/camel/component/ldif/ModifySetup.ldif");
+
camel.addRoutes(createRouteBuilder(ENDPOINT_LDIF));
camel.start();
@@ -233,27 +231,32 @@ public class LdifRouteIT extends AbstractLdapTestUnit {
// Check LDAP
SearchResult sr;
- NamingEnumeration<SearchResult> searchResults = ldapContext.search("",
"(uid=test*)", SEARCH_CONTROLS);
+ NamingEnumeration<SearchResult> searchResults =
ldapContext.search("dc=example,dc=org", "(uid=test*)", SEARCH_CONTROLS);
assertNotNull(searchResults);
- sr = searchResults.next();
- assertNotNull(sr);
- assertThat("uid=test4,ou=test,ou=system", equalTo(sr.getName()));
-
- // Check the attributes of the search result
- Attributes attribs = sr.getAttributes();
- assertNotNull(attribs);
- Attribute attrib = attribs.get("sn");
- assertNotNull(attribs);
- assertThat(1, equalTo(attrib.size()));
- assertThat("5", equalTo(attrib.get(0).toString()));
-
- // Check no more results
- assertThat(false, equalTo(searchResults.hasMore()));
+
+ boolean uidFound = false;
+ while (searchResults.hasMore()) {
+ sr = searchResults.next();
+ if (sr.getName().contains("uid=test4")) {
+ uidFound = true;
+
+ // Check the attributes of the search result
+ Attributes attribs = sr.getAttributes();
+ assertNotNull(attribs);
+ Attribute attrib = attribs.get("sn");
+ assertNotNull(attribs);
+ assertThat(1, equalTo(attrib.size()));
+ assertThat("5", equalTo(attrib.get(0).toString()));
+ }
+ }
+
+ assertThat("uid=test4 not found", uidFound, equalTo(true));
}
@Test
- @ApplyLdifFiles({ "org/apache/camel/component/ldif/ModRdnSetup.ldif" })
public void modRdn() throws Exception {
+ setupData("/org/apache/camel/component/ldif/ModRdnSetup.ldif");
+
camel.addRoutes(createRouteBuilder(ENDPOINT_LDIF));
camel.start();
@@ -275,22 +278,16 @@ public class LdifRouteIT extends AbstractLdapTestUnit {
assertThat(ldifResults.get(0), equalTo("success"));
// Check LDAP
- SearchResult sr;
- NamingEnumeration<SearchResult> searchResults = ldapContext.search("",
"(uid=test*)", SEARCH_CONTROLS);
+ NamingEnumeration<SearchResult> searchResults =
ldapContext.search("dc=example,dc=org", "(uid=test*)", SEARCH_CONTROLS);
assertNotNull(searchResults);
- sr = searchResults.next();
- assertNotNull(sr);
- // Check the DN
- assertThat("uid=test6,ou=test,ou=system", equalTo(sr.getName()));
-
- // Check no more results
- assertThat(false, equalTo(searchResults.hasMore()));
+ checkDN("uid=test6", searchResults);
}
@Test
- @ApplyLdifFiles({ "org/apache/camel/component/ldif/ModDnSetup.ldif" })
public void modDn() throws Exception {
+ setupData("/org/apache/camel/component/ldif/ModDnSetup.ldif");
+
camel.addRoutes(createRouteBuilder(ENDPOINT_LDIF));
camel.start();
@@ -312,17 +309,10 @@ public class LdifRouteIT extends AbstractLdapTestUnit {
assertThat(ldifResults.get(0), equalTo("success"));
// Check LDAP
- SearchResult sr;
- NamingEnumeration<SearchResult> searchResults = ldapContext.search("",
"(uid=test*)", SEARCH_CONTROLS);
+ NamingEnumeration<SearchResult> searchResults =
ldapContext.search("dc=example,dc=org", "(uid=test*)", SEARCH_CONTROLS);
assertNotNull(searchResults);
- sr = searchResults.next();
- assertNotNull(sr);
-
- // Check the DN
- assertThat("uid=test7,ou=testnew,ou=system", equalTo(sr.getName()));
- // Check no more results
- assertThat(false, equalTo(searchResults.hasMore()));
+ checkDN("uid=test7", searchResults);
}
@SuppressWarnings("unchecked")
@@ -348,7 +338,7 @@ public class LdifRouteIT extends AbstractLdapTestUnit {
/**
* Read the contents of a URL into a String
- *
+ *
* @param in
* @return
* @throws IOException
@@ -364,4 +354,39 @@ public class LdifRouteIT extends AbstractLdapTestUnit {
}
return sb.toString();
}
+
+ private void setupData(String loc) throws Exception {
+ SimpleRegistry reg = getSimpleRegistry();
+ CamelContext setupCamel = new DefaultCamelContext(reg);
+ ProducerTemplate setupTemplate = setupCamel.createProducerTemplate();
+
+ setupCamel.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(ENDPOINT_SETUP_START).to(ENDPOINT_LDIF);
+ }
+ });
+ setupCamel.start();
+
+ Endpoint endpoint = setupCamel.getEndpoint(ENDPOINT_SETUP_START);
+ Exchange exchange = endpoint.createExchange();
+
+ URL setupLoc = this.getClass().getResource(loc);
+ exchange.getIn().setBody(readUrl(setupLoc));
+ Exchange setupOut = setupTemplate.send(endpoint, exchange);
+ List<String> setupResults = defaultLdapModuleOutAssertions(setupOut);
+
+ setupResults.forEach(result -> assertThat(result,
anyOf(equalTo("success"), equalTo(""))));
+
+ setupCamel.stop();
+ }
+
+ private void checkDN(String dn, NamingEnumeration<SearchResult>
searchResults) throws NamingException {
+ List<String> resultNames = new ArrayList<>();
+ while (searchResults.hasMore()) {
+ resultNames.add(searchResults.next().getName());
+ }
+
+ assertThat(resultNames, hasItem(containsString(dn)));
+ }
}
diff --git
a/components/camel-ldif/src/test/java/org/apache/camel/component/ldif/LdifTestSupport.java
b/components/camel-ldif/src/test/java/org/apache/camel/component/ldif/LdifTestSupport.java
new file mode 100644
index 0000000..de5b284
--- /dev/null
+++
b/components/camel-ldif/src/test/java/org/apache/camel/component/ldif/LdifTestSupport.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.component.ldif;
+
+import org.apache.camel.test.infra.openldap.services.OpenldapService;
+import org.apache.camel.test.infra.openldap.services.OpenldapServiceFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+public class LdifTestSupport extends CamelTestSupport {
+ @RegisterExtension
+ public static OpenldapService service =
OpenldapServiceFactory.createService();
+
+ protected int port;
+
+ @Override
+ protected boolean useJmx() {
+ return false;
+ }
+
+ @Override
+ public void doPreSetup() throws Exception {
+ super.doPreSetup();
+ port = service.getPort();
+ }
+}
diff --git
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddDuplicate.ldif
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddDuplicate.ldif
index 4a54d31..bb6ca6f 100644
---
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddDuplicate.ldif
+++
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddDuplicate.ldif
@@ -22,7 +22,7 @@ version: 1
# http://www.rfc-editor.org/rfc/rfc2606.txt
#
-dn: uid=test3,ou=test,ou=system
+dn: uid=test3,ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalPerson
diff --git
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddDuplicateSetup.ldif
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddDuplicateSetup.ldif
index 5a8c194..5dfb3f9 100644
---
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddDuplicateSetup.ldif
+++
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddDuplicateSetup.ldif
@@ -22,13 +22,13 @@ version: 1
# http://www.rfc-editor.org/rfc/rfc2606.txt
#
-dn: ou=test,ou=system
+dn: ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: test
-dn: uid=test3,ou=test,ou=system
+dn: uid=test3,ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalPerson
diff --git
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddOne.ldif
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddOne.ldif
index e9150bd..33b3629 100644
---
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddOne.ldif
+++
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/AddOne.ldif
@@ -22,13 +22,13 @@ version: 1
# http://www.rfc-editor.org/rfc/rfc2606.txt
#
-dn: ou=test,ou=system
+dn: ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: test
-dn: uid=test1,ou=test,ou=system
+dn: uid=test1,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalPerson
diff --git
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/DeleteOne.ldif
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/DeleteOne.ldif
index e4e63e2..5c6cf25 100644
---
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/DeleteOne.ldif
+++
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/DeleteOne.ldif
@@ -22,6 +22,5 @@ version: 1
# http://www.rfc-editor.org/rfc/rfc2606.txt
#
-dn: uid=test2,ou=test,ou=system
+dn: uid=test2,ou=test,dc=example,dc=org
changetype: delete
-
diff --git
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/DeleteOneSetup.ldif
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/DeleteOneSetup.ldif
index 9c1aef4..47b8082 100644
---
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/DeleteOneSetup.ldif
+++
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/DeleteOneSetup.ldif
@@ -22,13 +22,13 @@ version: 1
# http://www.rfc-editor.org/rfc/rfc2606.txt
#
-dn: ou=test,ou=system
+dn: ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: test
-dn: uid=test2,ou=test,ou=system
+dn: uid=test2,ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalPerson
diff --git
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModDn.ldif
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModDn.ldif
index decf63f..f401b0f 100644
---
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModDn.ldif
+++
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModDn.ldif
@@ -22,8 +22,8 @@ version: 1
# http://www.rfc-editor.org/rfc/rfc2606.txt
#
-dn: uid=test7,ou=test,ou=system
+dn: uid=test7,ou=test,dc=example,dc=org
changetype: moddn
newrdn: uid=test7
deleteoldrdn: 1
-newsuperior: ou=testnew,ou=system
+newsuperior: ou=testnew,dc=example,dc=org
diff --git
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModDnSetup.ldif
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModDnSetup.ldif
index 2caeac6..c47f505 100644
---
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModDnSetup.ldif
+++
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModDnSetup.ldif
@@ -22,19 +22,19 @@ version: 1
# http://www.rfc-editor.org/rfc/rfc2606.txt
#
-dn: ou=test,ou=system
+dn: ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: test
-dn: ou=testnew,ou=system
+dn: ou=testnew,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: testnew
-dn: uid=test7,ou=test,ou=system
+dn: uid=test7,ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalPerson
diff --git
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModRdn.ldif
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModRdn.ldif
index 4ec728d..874df3f 100644
---
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModRdn.ldif
+++
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModRdn.ldif
@@ -22,7 +22,7 @@ version: 1
# http://www.rfc-editor.org/rfc/rfc2606.txt
#
-dn: uid=test5,ou=test,ou=system
+dn: uid=test5,ou=test,dc=example,dc=org
changetype: modrdn
newrdn: uid=test6
deleteoldrdn: 1
diff --git
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModRdnSetup.ldif
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModRdnSetup.ldif
index 2562390..73fecc2 100644
---
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModRdnSetup.ldif
+++
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModRdnSetup.ldif
@@ -22,13 +22,13 @@ version: 1
# http://www.rfc-editor.org/rfc/rfc2606.txt
#
-dn: ou=test,ou=system
+dn: ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: test
-dn: uid=test5,ou=test,ou=system
+dn: uid=test5,ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalPerson
diff --git
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/Modify.ldif
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/Modify.ldif
index 920de29..f4e1e25 100644
---
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/Modify.ldif
+++
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/Modify.ldif
@@ -22,7 +22,7 @@ version: 1
# http://www.rfc-editor.org/rfc/rfc2606.txt
#
-dn: uid=test4,ou=test,ou=system
+dn: uid=test4,ou=test,dc=example,dc=org
changetype: modify
replace: sn
sn: 5
diff --git
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModifySetup.ldif
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModifySetup.ldif
index 2270a49..0d1b0bb 100644
---
a/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModifySetup.ldif
+++
b/components/camel-ldif/src/test/resources/org/apache/camel/component/ldif/ModifySetup.ldif
@@ -22,13 +22,13 @@ version: 1
# http://www.rfc-editor.org/rfc/rfc2606.txt
#
-dn: ou=test,ou=system
+dn: ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: test
-dn: uid=test4,ou=test,ou=system
+dn: uid=test4,ou=test,dc=example,dc=org
changetype: add
objectClass: top
objectClass: organizationalPerson
diff --git a/test-infra/camel-test-infra-openldap/pom.xml
b/test-infra/camel-test-infra-openldap/pom.xml
new file mode 100644
index 0000000..7980340
--- /dev/null
+++ b/test-infra/camel-test-infra-openldap/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>camel-test-infra-parent</artifactId>
+ <groupId>org.apache.camel</groupId>
+ <relativePath>../camel-test-infra-parent/pom.xml</relativePath>
+ <version>3.10.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>camel-test-infra-openldap</artifactId>
+ <name>Camel :: Test Infra :: Openladp</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-common</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git
a/test-infra/camel-test-infra-openldap/src/main/resources/META-INF/MANIFEST.MF
b/test-infra/camel-test-infra-openldap/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e69de29
diff --git
a/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/common/OpenldapProperties.java
b/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/common/OpenldapProperties.java
new file mode 100644
index 0000000..598cc5f
--- /dev/null
+++
b/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/common/OpenldapProperties.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.test.infra.openldap.common;
+
+public final class OpenldapProperties {
+ public static final String HOST = "openldap.host";
+ public static final String PORT_LDAP = "openldap.port.ldap";
+ public static final String PORT_LDAP_OVER_SSL = "openldap.port.ldap.ssl";
+ public static final String OPENLDAP_CONTAINER = "openldap.container";
+
+ private OpenldapProperties() {
+
+ }
+}
diff --git
a/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapLocalContainerService.java
b/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapLocalContainerService.java
new file mode 100644
index 0000000..dcb5eb7
--- /dev/null
+++
b/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapLocalContainerService.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.test.infra.openldap.services;
+
+import org.apache.camel.test.infra.common.services.ContainerService;
+import org.apache.camel.test.infra.openldap.common.OpenldapProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.FixedHostPortGenericContainer;
+import org.testcontainers.containers.GenericContainer;
+
+public class OpenldapLocalContainerService implements OpenldapService,
ContainerService<GenericContainer> {
+ public static final String CONTAINER_IMAGE = "osixia/openldap:1.5.0";
+ public static final String CONTAINER_NAME = "openldap";
+ public static final int CONTAINER_PORT_LDAP = 389;
+ public static final int CONTAINER_PORT_LDAP_OVER_SSL = 636;
+
+ private static final Logger LOG =
LoggerFactory.getLogger(OpenldapLocalContainerService.class);
+
+ private final GenericContainer container;
+
+ public OpenldapLocalContainerService() {
+ this(CONTAINER_IMAGE);
+ }
+
+ public OpenldapLocalContainerService(int port, int sslPort) {
+ String imageName =
System.getProperty(OpenldapProperties.OPENLDAP_CONTAINER, CONTAINER_IMAGE);
+
+ container = initContainer(imageName, port, sslPort);
+ }
+
+ public OpenldapLocalContainerService(String imageName) {
+ container = initContainer(imageName, null, null);
+ }
+
+ public OpenldapLocalContainerService(GenericContainer container) {
+ this.container = container;
+ }
+
+ protected GenericContainer initContainer(String imageName, Integer port,
Integer sslPort) {
+ GenericContainer ret;
+
+ if (port == null) {
+ ret = new GenericContainer(imageName)
+ .withExposedPorts(CONTAINER_PORT_LDAP,
CONTAINER_PORT_LDAP_OVER_SSL);
+ } else {
+ @SuppressWarnings("deprecation")
+ FixedHostPortGenericContainer fixedPortContainer = new
FixedHostPortGenericContainer(imageName)
+ .withFixedExposedPort(port, CONTAINER_PORT_LDAP);
+
+ if (sslPort != null) {
+ fixedPortContainer.withFixedExposedPort(sslPort,
CONTAINER_PORT_LDAP_OVER_SSL);
+ }
+
+ ret = fixedPortContainer;
+ }
+
+ ret.withNetworkAliases(CONTAINER_NAME);
+
+ return ret;
+ }
+
+ @Override
+ public void registerProperties() {
+ System.setProperty(OpenldapProperties.PORT_LDAP,
String.valueOf(getPort()));
+ System.setProperty(OpenldapProperties.PORT_LDAP_OVER_SSL,
String.valueOf(getSslPort()));
+ }
+
+ @Override
+ public void initialize() {
+ LOG.info("Trying to start the Openldap container");
+ container.start();
+
+ registerProperties();
+ LOG.info("Openldap instance running at {}", getPort());
+ }
+
+ @Override
+ public void shutdown() {
+ LOG.info("Stopping the Openldap container");
+ container.stop();
+ }
+
+ @Override
+ public GenericContainer getContainer() {
+ return container;
+ }
+
+ @Override
+ public Integer getPort() {
+ return container.getMappedPort(CONTAINER_PORT_LDAP);
+ }
+
+ @Override
+ public Integer getSslPort() {
+ return container.getMappedPort(CONTAINER_PORT_LDAP_OVER_SSL);
+ }
+
+ @Override
+ public String getHost() {
+ return container.getContainerIpAddress();
+ }
+}
diff --git
a/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapRemoteService.java
b/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapRemoteService.java
new file mode 100644
index 0000000..6611285
--- /dev/null
+++
b/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapRemoteService.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.test.infra.openldap.services;
+
+import org.apache.camel.test.infra.openldap.common.OpenldapProperties;
+
+public class OpenldapRemoteService implements OpenldapService {
+
+ public OpenldapRemoteService() {
+ }
+
+ public OpenldapRemoteService(String host, int port, int sslPort) {
+ System.setProperty(OpenldapProperties.HOST, host);
+ System.setProperty(OpenldapProperties.PORT_LDAP, String.valueOf(port));
+ System.setProperty(OpenldapProperties.PORT_LDAP_OVER_SSL,
String.valueOf(sslPort));
+ }
+
+ @Override
+ public void registerProperties() {
+ // NO-OP
+ }
+
+ @Override
+ public void initialize() {
+ registerProperties();
+ }
+
+ @Override
+ public void shutdown() {
+ // NO-OP
+ }
+
+ @Override
+ public Integer getPort() {
+ return getPort(OpenldapProperties.PORT_LDAP);
+ }
+
+ @Override
+ public Integer getSslPort() {
+ return getPort(OpenldapProperties.PORT_LDAP_OVER_SSL);
+ }
+
+ @Override
+ public String getHost() {
+ return System.getProperty(OpenldapProperties.HOST);
+ }
+
+ private Integer getPort(String prop) {
+ String value = System.getProperty(prop);
+ return Integer.valueOf(value);
+ }
+}
diff --git
a/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapService.java
b/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapService.java
new file mode 100644
index 0000000..2a8e701
--- /dev/null
+++
b/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapService.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.test.infra.openldap.services;
+
+import org.apache.camel.test.infra.common.services.TestService;
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/**
+ * Test infra service for Openldap
+ */
+public interface OpenldapService extends BeforeAllCallback, AfterAllCallback,
TestService {
+
+ Integer getPort();
+
+ Integer getSslPort();
+
+ String getHost();
+
+ @Override
+ default void beforeAll(ExtensionContext extensionContext) throws Exception
{
+ initialize();
+ }
+
+ @Override
+ default void afterAll(ExtensionContext extensionContext) throws Exception {
+ shutdown();
+ }
+}
diff --git
a/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapServiceFactory.java
b/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapServiceFactory.java
new file mode 100644
index 0000000..d4b3e6b
--- /dev/null
+++
b/test-infra/camel-test-infra-openldap/src/test/java/org/apache/camel/test/infra/openldap/services/OpenldapServiceFactory.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.test.infra.openldap.services;
+
+import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
+
+public final class OpenldapServiceFactory {
+ private OpenldapServiceFactory() {
+
+ }
+
+ public static SimpleTestServiceBuilder<OpenldapService> builder() {
+ return new SimpleTestServiceBuilder<>("openldap");
+ }
+
+ public static OpenldapService createService() {
+ return builder()
+ .addLocalMapping(OpenldapLocalContainerService::new)
+ .addRemoteMapping(OpenldapRemoteService::new)
+ .build();
+ }
+}
diff --git a/test-infra/pom.xml b/test-infra/pom.xml
index 5165474..05c00fc 100644
--- a/test-infra/pom.xml
+++ b/test-infra/pom.xml
@@ -72,7 +72,8 @@
<module>camel-test-infra-mosquitto</module>
<module>camel-test-infra-activemq</module>
<module>camel-test-infra-chatscript</module>
- </modules>
+ <module>camel-test-infra-openldap</module>
+ </modules>
<build>
<plugins>