diff --git a/test-support/pom.xml b/test-support/pom.xml
index 8b83e866..a9b96cc1 100644
--- a/test-support/pom.xml
+++ b/test-support/pom.xml
@@ -1,91 +1,91 @@
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
- org.springframework.ldap
- spring-ldap-parent
- 1.3-SNAPSHOT
-
- 4.0.0
- spring-ldap-test
- jar
- Spring LDAP Automated Test Support
+
+ org.springframework.ldap
+ spring-ldap-parent
+ 1.3-SNAPSHOT
+
+ 4.0.0
+ spring-ldap-test
+ jar
+ Spring LDAP Automated Test Support
-
-
-
- maven-compiler-plugin
-
- 1.5
- 1.5
-
-
-
-
-
-
- org.springframework.ldap
- spring-ldap-core
-
-
-
- org.opends
- openDS
- 1.0.0-build005
-
-
- commons-io
- commons-io
- 1.4
-
-
- org.apache.commons
- commons-io
- 1.3.2
-
-
- org.apache.directory.server
- apacheds-server-main
- 1.0.2
-
-
- org.slf4j
- nlog4j
-
-
-
-
- org.slf4j
- slf4j-log4j12
- 1.0.1
-
-
-
- org.springframework
- spring-core
-
-
- org.springframework
- spring-beans
-
-
- org.springframework
- spring-context
-
-
- org.springframework
- spring-test
-
-
- log4j
- log4j
-
-
- junit
- junit
- provided
-
-
+
+
+
+ maven-compiler-plugin
+
+ 1.5
+ 1.5
+
+
+
+
+
+
+ org.springframework.ldap
+ spring-ldap-core
+
+
+
+ com.google.code.typica
+ typica
+ 1.3
+
+
+ commons-io
+ commons-io
+ 1.4
+
+
+ org.apache.commons
+ commons-io
+ 1.3.2
+
+
+ org.apache.directory.server
+ apacheds-server-main
+ 1.0.2
+
+
+ org.slf4j
+ nlog4j
+
+
+
+
+ org.slf4j
+ slf4j-log4j12
+ 1.0.1
+
+
+
+ org.springframework
+ spring-core
+
+
+ org.springframework
+ spring-beans
+
+
+ org.springframework
+ spring-context
+
+
+ org.springframework
+ spring-test
+
+
+ log4j
+ log4j
+
+
+ junit
+ junit
+ provided
+
+
diff --git a/test-support/src/main/java/org/springframework/ldap/test/AbstractEc2InstanceLaunchingFactoryBean.java b/test-support/src/main/java/org/springframework/ldap/test/AbstractEc2InstanceLaunchingFactoryBean.java
new file mode 100644
index 00000000..49f38a96
--- /dev/null
+++ b/test-support/src/main/java/org/springframework/ldap/test/AbstractEc2InstanceLaunchingFactoryBean.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2005-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.
+ */
+package org.springframework.ldap.test;
+
+import java.util.Collections;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.config.AbstractFactoryBean;
+import org.springframework.util.Assert;
+
+import com.xerox.amazonws.ec2.Jec2;
+import com.xerox.amazonws.ec2.LaunchConfiguration;
+import com.xerox.amazonws.ec2.ReservationDescription;
+import com.xerox.amazonws.ec2.ReservationDescription.Instance;
+
+/**
+ * Abstract FactoryBean superclass to use for automatically launching an EC2 instance before creating the actual target object.
+ * This approach is particularly useful for integration testing purposes - the idea is to have particular EC2 images prepared
+ * for running integration tests against certain server configurations, enabling integration tests aimed at e.g. a particluar
+ * DB server to run transparently at the computer of each individual developer without having to have the actual server software
+ * installed on their computers.
+ *
+ * Public AMIs will need to be created, bundled and registered for each server setup. A subclass of this FactoryBean
+ * is then added to create the actual target object (e.g. a DataSource), implementing the {link #doCreateInstance} method.
+ * This method will be supplied the IP address of the instance that was created, enabling the subclass to configure the
+ * created instance appropriately.
+ *
+ * @author Mattias Hellborg Arthursson
+ */
+public abstract class AbstractEc2InstanceLaunchingFactoryBean extends AbstractFactoryBean {
+ private static final int INSTANCE_START_SLEEP_TIME = 1000;
+
+ private static final long DEFAULT_PREPARATION_SLEEP_TIME = 30000;
+
+ private static final Log log = LogFactory.getLog(AbstractEc2InstanceLaunchingFactoryBean.class);
+
+ private String imageName;
+
+ private String awsKey;
+
+ private String awsSecretKey;
+
+ private String keypairName;
+
+ private String groupName;
+
+ private Instance instance;
+
+ private long preparationSleepTime = DEFAULT_PREPARATION_SLEEP_TIME;
+
+ /**
+ * Set the name of the AMI image to be launched.
+ *
+ * @param imageName the AMI image name.
+ */
+ public void setImageName(String imageName) {
+ this.imageName = imageName;
+ }
+
+ /**
+ * Set the AWS key.
+ *
+ * @param awsKey the AWS key.
+ */
+ public void setAwsKey(String awsKey) {
+ this.awsKey = awsKey;
+ }
+
+ /**
+ * Set the AWS secret key.
+ *
+ * @param awsSecretKey the aws secret key.
+ */
+ public void setAwsSecretKey(String awsSecretKey) {
+ this.awsSecretKey = awsSecretKey;
+ }
+
+ /**
+ * Set the name of the keypair.
+ *
+ * @param keypairName The keypair name.
+ */
+ public void setKeypairName(String keypairName) {
+ this.keypairName = keypairName;
+ }
+
+ /**
+ * Set the name of the access group. This group should be configured with the appropriate ports open for this test case to execute.
+ *
+ * @param groupName the group name.
+ */
+ public void setGroupName(String groupName) {
+ this.groupName = groupName;
+ }
+
+ @Override
+ protected final Object createInstance() throws Exception {
+ Assert.hasLength(imageName, "ImageName must be set");
+ Assert.hasLength(awsKey, "AwsKey must be set");
+ Assert.hasLength(awsSecretKey, "AwsSecretKey must be set");
+ Assert.hasLength(keypairName, "KeyName must be set");
+ Assert.hasLength(groupName, "GroupName must be set");
+
+ log.info("Launching EC2 instance for image: " + imageName);
+
+ Jec2 jec2 = new Jec2(awsKey, awsSecretKey);
+ LaunchConfiguration launchConfiguration = new LaunchConfiguration(imageName);
+ launchConfiguration.setKeyName(keypairName);
+ launchConfiguration.setSecurityGroup(Collections.singletonList(groupName));
+
+ ReservationDescription reservationDescription = jec2.runInstances(launchConfiguration);
+ instance = reservationDescription.getInstances().get(0);
+ while (!instance.isRunning() && !instance.isTerminated()) {
+ log.info("Instance still starting up; sleeping " + INSTANCE_START_SLEEP_TIME + "ms");
+ Thread.sleep(INSTANCE_START_SLEEP_TIME);
+ reservationDescription = jec2.describeInstances(Collections.singletonList(instance.getInstanceId())).get(0);
+ instance = reservationDescription.getInstances().get(0);
+ }
+
+ if (instance.isRunning()) {
+ log.info("EC2 instance is now running");
+ if (preparationSleepTime > 0) {
+ log.info("Sleeping " + preparationSleepTime + "ms allowing instance services to start up properly.");
+ Thread.sleep(preparationSleepTime);
+ log.info("Instance prepared - proceeding");
+ }
+ return doCreateInstance(instance.getDnsName());
+ } else {
+ throw new IllegalStateException("Failed to start a new instance");
+ }
+
+ }
+
+ /**
+ * Implement to create the actual target object.
+ *
+ * @param ip the ip address of the launched EC2 image.
+ * @return the object to be returned by this FactoryBean.
+ * @throws Exception if an error occurs during initialization.
+ */
+ protected abstract Object doCreateInstance(String ip) throws Exception;
+
+ @Override
+ protected void destroyInstance(Object ignored) throws Exception {
+ if (this.instance != null) {
+ log.info("Shutting down instance");
+ Jec2 jec2 = new Jec2(awsKey, awsSecretKey);
+ jec2.terminateInstances(Collections.singletonList(this.instance.getInstanceId()));
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/test/integration-tests-openldap/etc/lib/typica-1.4.jar b/test/integration-tests-openldap/etc/lib/typica-1.4.jar
deleted file mode 100644
index e5665a2b..00000000
Binary files a/test/integration-tests-openldap/etc/lib/typica-1.4.jar and /dev/null differ
diff --git a/test/integration-tests-openldap/pom.xml b/test/integration-tests-openldap/pom.xml
index 21876bd6..e8e44dd9 100644
--- a/test/integration-tests-openldap/pom.xml
+++ b/test/integration-tests-openldap/pom.xml
@@ -30,13 +30,6 @@
org.springframework.ldapspring-ldap-core-tiger
-
- com.xerox.amazonws
- typica
- 1.3
- system
- ${basedir}/etc/lib/typica-1.4.jar
- commons-loggingcommons-logging
@@ -88,38 +81,6 @@
commons-codec1.3
-
-
- javax.xml
- jsr173
- 1.0
- true
-
-
-
- javax.activation
- activation
- 1.1
- true
-
-
- javax.xml
- jaxb-api
- 2.1
- true
-
-
- javax.xml
- jaxb-impl
- 2.1
- true
-
diff --git a/test/integration-tests-openldap/src/main/java/org/springframework/ldap/AbstractEc2InstanceLaunchingFactoryBean.java b/test/integration-tests-openldap/src/main/java/org/springframework/ldap/AbstractEc2InstanceLaunchingFactoryBean.java
deleted file mode 100644
index ab787c27..00000000
--- a/test/integration-tests-openldap/src/main/java/org/springframework/ldap/AbstractEc2InstanceLaunchingFactoryBean.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package org.springframework.ldap;
-
-import java.util.Collections;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.config.AbstractFactoryBean;
-import org.springframework.util.Assert;
-
-import com.xerox.amazonws.ec2.Jec2;
-import com.xerox.amazonws.ec2.LaunchConfiguration;
-import com.xerox.amazonws.ec2.ReservationDescription;
-import com.xerox.amazonws.ec2.ReservationDescription.Instance;
-
-public abstract class AbstractEc2InstanceLaunchingFactoryBean extends AbstractFactoryBean {
- private static final int SLEEP_TIME = 1000;
-
- private static final Log log = LogFactory.getLog(AbstractEc2InstanceLaunchingFactoryBean.class);
-
- private String imageName;
-
- private String awsKey;
-
- private String awsSecretKey;
-
- private String keyName;
-
- private String groupName;
-
- private Instance instance;
-
- public void setImageName(String imageName) {
- this.imageName = imageName;
- }
-
- public void setAwsKey(String awsKey) {
- this.awsKey = awsKey;
- }
-
- public void setAwsSecretKey(String awsSecretKey) {
- this.awsSecretKey = awsSecretKey;
- }
-
- public void setKeyName(String keyName) {
- this.keyName = keyName;
- }
-
- public void setGroupName(String groupName) {
- this.groupName = groupName;
- }
-
- @Override
- protected final Object createInstance() throws Exception {
- Assert.hasLength(imageName, "ImageName must be set");
- Assert.hasLength(awsKey, "AwsKey must be set");
- Assert.hasLength(awsSecretKey, "AwsSecretKey must be set");
- Assert.hasLength(keyName, "KeyName must be set");
- Assert.hasLength(groupName, "GroupName must be set");
-
- log.info("Launching EC2 instance for image: " + imageName);
-
- Jec2 jec2 = new Jec2(awsKey, awsSecretKey);
- LaunchConfiguration launchConfiguration = new LaunchConfiguration(imageName);
- launchConfiguration.setKeyName(keyName);
- launchConfiguration.setSecurityGroup(Collections.singletonList(groupName));
-
- ReservationDescription reservationDescription = jec2.runInstances(launchConfiguration);
- instance = reservationDescription.getInstances().get(0);
- while (!instance.isRunning() && !instance.isTerminated()) {
- log.info("Instance still starting up; sleeping " + SLEEP_TIME + "ms");
- Thread.sleep(SLEEP_TIME);
- reservationDescription = jec2.describeInstances(Collections.singletonList(instance.getInstanceId())).get(0);
- instance = reservationDescription.getInstances().get(0);
- }
-
- if (instance.isRunning()) {
- log.info("EC2 instance is now running");
- return doCreateInstance(instance.getDnsName());
- }
- else {
- throw new IllegalStateException("Failed to start a new instance");
- }
-
- }
-
- protected abstract Object doCreateInstance(String dnsName) throws Exception;
-
- @Override
- protected void destroyInstance(Object ignored) throws Exception {
- if (this.instance != null) {
- log.info("Shutting down instance");
- Jec2 jec2 = new Jec2(awsKey, awsSecretKey);
- jec2.terminateInstances(Collections.singletonList(this.instance.getInstanceId()));
- }
-
- }
-}
diff --git a/test/integration-tests-openldap/src/main/java/org/springframework/ldap/ContextSourceEc2InstanceLaunchingFactoryBean.java b/test/integration-tests-openldap/src/main/java/org/springframework/ldap/ContextSourceEc2InstanceLaunchingFactoryBean.java
index b87e6402..58a00096 100644
--- a/test/integration-tests-openldap/src/main/java/org/springframework/ldap/ContextSourceEc2InstanceLaunchingFactoryBean.java
+++ b/test/integration-tests-openldap/src/main/java/org/springframework/ldap/ContextSourceEc2InstanceLaunchingFactoryBean.java
@@ -1,8 +1,28 @@
+/*
+ * Copyright 2005-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.
+ */
package org.springframework.ldap;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.support.LdapContextSource;
+import org.springframework.ldap.test.AbstractEc2InstanceLaunchingFactoryBean;
+import org.springframework.util.Assert;
+/**
+ * FactoryBean to create a ContextSource using the EC2 instance created by superclass.
+ */
public class ContextSourceEc2InstanceLaunchingFactoryBean extends AbstractEc2InstanceLaunchingFactoryBean {
private String base;
@@ -18,6 +38,7 @@ public class ContextSourceEc2InstanceLaunchingFactoryBean extends AbstractEc2Ins
@Override
protected final Object doCreateInstance(final String dnsName) throws Exception {
+ Assert.hasText(userDn);
LdapContextSource instance = new LdapContextSource();
instance.setUrl("ldap://" + dnsName);
instance.setUserDn(userDn);
@@ -36,7 +57,7 @@ public class ContextSourceEc2InstanceLaunchingFactoryBean extends AbstractEc2Ins
* @param dnsName The dns name of the created Ec2 instance.
*/
protected void setAdditionalContextSourceProperties(LdapContextSource ctx, final String dnsName) {
-
+ //Nothing to do here
}
public void setBase(String base) {
diff --git a/test/integration-tests-openldap/src/main/java/org/springframework/ldap/TlsContextSourceEc2InstanceLaunchingFactoryBean.java b/test/integration-tests-openldap/src/main/java/org/springframework/ldap/TlsContextSourceEc2InstanceLaunchingFactoryBean.java
index 5cef2c4b..a84b9c44 100644
--- a/test/integration-tests-openldap/src/main/java/org/springframework/ldap/TlsContextSourceEc2InstanceLaunchingFactoryBean.java
+++ b/test/integration-tests-openldap/src/main/java/org/springframework/ldap/TlsContextSourceEc2InstanceLaunchingFactoryBean.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2005-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.
+ */
package org.springframework.ldap;
import javax.net.ssl.HostnameVerifier;
@@ -6,6 +21,9 @@ import javax.net.ssl.SSLSession;
import org.springframework.ldap.core.support.DefaultTlsDirContextAuthenticationStrategy;
import org.springframework.ldap.core.support.LdapContextSource;
+/**
+ * FactoryBean for testing LDAP TLS connections on an Amazon EC2 image launched by superclass.
+ */
public class TlsContextSourceEc2InstanceLaunchingFactoryBean extends ContextSourceEc2InstanceLaunchingFactoryBean {
protected void setAdditionalContextSourceProperties(LdapContextSource ctx, final String dnsName) {
diff --git a/test/integration-tests-openldap/src/test/resources/conf/ldapTemplateTestContext-tls.xml b/test/integration-tests-openldap/src/test/resources/conf/ldapTemplateTestContext-tls.xml
index ebe7a3aa..d1b6914b 100644
--- a/test/integration-tests-openldap/src/test/resources/conf/ldapTemplateTestContext-tls.xml
+++ b/test/integration-tests-openldap/src/test/resources/conf/ldapTemplateTestContext-tls.xml
@@ -15,7 +15,7 @@
-
+
diff --git a/test/integration-tests-openldap/src/test/resources/conf/ldapTemplateTestContext.xml b/test/integration-tests-openldap/src/test/resources/conf/ldapTemplateTestContext.xml
index 7ea93876..3c2f1cb0 100644
--- a/test/integration-tests-openldap/src/test/resources/conf/ldapTemplateTestContext.xml
+++ b/test/integration-tests-openldap/src/test/resources/conf/ldapTemplateTestContext.xml
@@ -14,7 +14,7 @@
-
+