You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ja...@apache.org on 2012/07/11 09:55:06 UTC
svn commit: r1360046 - in /ace/sandbox/marrs:
org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/
org.apache.ace.configurator.useradmin.itest/src/org/apache/ace/it/useradminconfigurator/
org.apache.ace.http.itest/src/org/apache/ac...
Author: jawi
Date: Wed Jul 11 07:55:05 2012
New Revision: 1360046
URL: http://svn.apache.org/viewvc?rev=1360046&view=rev
Log:
Clean up of existing integration tests.
Modified:
ace/sandbox/marrs/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/LogAuthenticationTest.java
ace/sandbox/marrs/org.apache.ace.configurator.useradmin.itest/src/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java
ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/ServletConfiguratorIntegrationTest.java
ace/sandbox/marrs/org.apache.ace.itest/src/org/apache/ace/it/IntegrationTestBase.java
ace/sandbox/marrs/org.apache.ace.log.itest/src/org/apache/ace/it/log/LogIntegrationTest.java
Modified: ace/sandbox/marrs/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/LogAuthenticationTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/LogAuthenticationTest.java?rev=1360046&r1=1360045&r2=1360046&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/LogAuthenticationTest.java (original)
+++ ace/sandbox/marrs/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/LogAuthenticationTest.java Wed Jul 11 07:55:05 2012
@@ -79,7 +79,7 @@ public class LogAuthenticationTest exten
m_serverStore.put(events);
List<String> result = getResponse("http://localhost:" + TestConstants.PORT + "/auditlog/query");
- assert result.size() > 1 : "We expect at least two logs on the server.";
+ assertTrue("We expect at least two logs on the server.", result.size() > 1);
}
/**
@@ -151,8 +151,6 @@ public class LogAuthenticationTest exten
"authentication.user.password", password);
assertTrue("Failed to access auditlog in time!", waitForURL(m_connectionFactory, testURL, 200, 15000));
-
- before();
}
/**
@@ -213,15 +211,11 @@ public class LogAuthenticationTest exten
};
}
+ /**
+ * Overridden in order to use the connection factory for accessing URLs.
+ */
@Override
- protected void tearDown() throws Exception {
- super.tearDown();
-
- // Remove the configuration to start without any configured authentication...
- getConfiguration(m_configurationPID).delete();
- }
-
- private List<String> getResponse(String request) throws IOException {
+ protected List<String> getResponse(String request) throws IOException {
List<String> result = new ArrayList<String>();
InputStream in = null;
try {
@@ -251,4 +245,12 @@ public class LogAuthenticationTest exten
}
return result;
}
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ // Remove the configuration to start without any configured authentication...
+ getConfiguration(m_configurationPID).delete();
+ }
}
Modified: ace/sandbox/marrs/org.apache.ace.configurator.useradmin.itest/src/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.configurator.useradmin.itest/src/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java?rev=1360046&r1=1360045&r2=1360046&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.configurator.useradmin.itest/src/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java (original)
+++ ace/sandbox/marrs/org.apache.ace.configurator.useradmin.itest/src/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java Wed Jul 11 07:55:05 2012
@@ -30,67 +30,6 @@ import org.osgi.service.useradmin.UserAd
public class ConfiguratorTest extends IntegrationTestBase {
-// @Configuration
-// public Option[] configuration() {
-// return options(
-// systemProperty("org.osgi.service.http.port").value("" + TestConstants.PORT),
-// junitBundles(),
-// provision(
-// wrappedBundle(maven("org.apache.ace", "org.apache.ace.util")).overwriteManifest(WrappedUrlProvisionOption.OverwriteMode.FULL), // we do this because we need access to some test classes that aren't exported
-// Osgi.compendium(),
-// jetty(),
-// Felix.preferences(),
-// Felix.dependencyManager(),
-// Felix.configAdmin(),
-// Knopflerfish.useradmin(),
-// Knopflerfish.log(),
-// Ace.authenticationApi(),
-// Ace.connectionFactory(),
-// Ace.rangeApi(),
-// Ace.scheduler(),
-// Ace.httplistener(),
-// Ace.repositoryApi(),
-// Ace.repositoryImpl(),
-// Ace.repositoryServlet(),
-// Ace.resourceprocessorUseradmin(),
-// Ace.configuratorUseradminTask(),
-// Ace.deploymentProviderApi()
-// )
-// );
-// }
-
- protected Component[] getDependencies() {
- return new Component[] {
- createComponent()
- .setImplementation(this)
- .add(createServiceDependency()
- .setService(UserAdmin.class)
- .setRequired(true))
- .add(createServiceDependency()
- .setService(Repository.class, "(&(" + RepositoryConstants.REPOSITORY_NAME + "=users)(" + RepositoryConstants.REPOSITORY_CUSTOMER + "=apache))")
- .setRequired(true))
- };
- }
-
- @Override
- protected void before() throws Exception {
- configureFactory("org.apache.ace.server.repository.factory",
- RepositoryConstants.REPOSITORY_NAME, "users",
- RepositoryConstants.REPOSITORY_CUSTOMER, "apache",
- RepositoryConstants.REPOSITORY_MASTER, "true");
- configure("org.apache.ace.configurator.useradmin.task.UpdateUserAdminTask",
- "repositoryName", "users",
- "repositoryCustomer", "apache");
- configure("org.apache.ace.scheduler",
- "org.apache.ace.configurator.useradmin.task.UpdateUserAdminTask", "1000");
- configure("org.apache.ace.repository.servlet.RepositoryServlet",
- "org.apache.ace.server.servlet.endpoint", "/repository",
- "authentication.enabled", "false");
- configure("org.apache.ace.repository.servlet.RepositoryReplicationServlet",
- "org.apache.ace.server.servlet.endpoint", "/replication",
- "authentication.enabled", "false");
- }
-
private volatile Repository m_repository;
private volatile UserAdmin m_userAdmin;
@@ -137,4 +76,36 @@ public class ConfiguratorTest extends In
assertTrue("A second after our user becoming available, there is no (correct) password.", foundPassword);
assertTrue("A second after our user becoming available, there is no (correct) certificate.", foundCertificate);
}
+
+ @Override
+ protected void before() throws Exception {
+ configureFactory("org.apache.ace.server.repository.factory",
+ RepositoryConstants.REPOSITORY_NAME, "users",
+ RepositoryConstants.REPOSITORY_CUSTOMER, "apache",
+ RepositoryConstants.REPOSITORY_MASTER, "true");
+ configure("org.apache.ace.configurator.useradmin.task.UpdateUserAdminTask",
+ "repositoryName", "users",
+ "repositoryCustomer", "apache");
+ configure("org.apache.ace.scheduler",
+ "org.apache.ace.configurator.useradmin.task.UpdateUserAdminTask", "1000");
+ configure("org.apache.ace.repository.servlet.RepositoryServlet",
+ "org.apache.ace.server.servlet.endpoint", "/repository",
+ "authentication.enabled", "false");
+ configure("org.apache.ace.repository.servlet.RepositoryReplicationServlet",
+ "org.apache.ace.server.servlet.endpoint", "/replication",
+ "authentication.enabled", "false");
+ }
+
+ protected Component[] getDependencies() {
+ return new Component[] {
+ createComponent()
+ .setImplementation(this)
+ .add(createServiceDependency()
+ .setService(UserAdmin.class)
+ .setRequired(true))
+ .add(createServiceDependency()
+ .setService(Repository.class, "(&(" + RepositoryConstants.REPOSITORY_NAME + "=users)(" + RepositoryConstants.REPOSITORY_CUSTOMER + "=apache))")
+ .setRequired(true))
+ };
+ }
}
Modified: ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/ServletConfiguratorIntegrationTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/ServletConfiguratorIntegrationTest.java?rev=1360046&r1=1360045&r2=1360046&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/ServletConfiguratorIntegrationTest.java (original)
+++ ace/sandbox/marrs/org.apache.ace.http.itest/src/org/apache/ace/it/http/ServletConfiguratorIntegrationTest.java Wed Jul 11 07:55:05 2012
@@ -37,45 +37,9 @@ import org.osgi.service.http.HttpService
public class ServletConfiguratorIntegrationTest extends IntegrationTestBase {
-// @Configuration
-// public Option[] configuration() {
-// return options(
-// systemProperty("org.osgi.service.http.port").value("" + TestConstants.PORT),
-// new VMOption("-ea"),
-// junitBundles(),
-// provision(
-// Osgi.compendium(),
-// Felix.dependencyManager(),
-// jetty(),
-// Felix.configAdmin(),
-// Ace.httplistener()
-// )
-// );
-// }
-
- @Override
- protected void before() throws Exception {
- m_echoServlet = new EchoServlet();
- Dictionary<String, String> dictionary = new Hashtable<String, String>();
- dictionary.put(HttpConstants.ENDPOINT, "/echoServlet");
- m_echoServletService = m_dependencyManager.createComponent()
- .setImplementation(m_echoServlet)
- .setInterface(Servlet.class.getName(), dictionary);
-
- m_mockHttp = new MockHttpService();
- m_mockHttpService = m_dependencyManager.createComponent()
- .setImplementation(m_mockHttp)
- .setInterface(HttpService.class.getName(), null);
- }
-
- // the echo servlet
private HttpServlet m_echoServlet;
- // echo servlet service-reference
private Component m_echoServletService;
- // mock http service
private MockHttpService m_mockHttp;
-
- //mock http service-reference
private Component m_mockHttpService;
/**
@@ -84,10 +48,10 @@ public class ServletConfiguratorIntegrat
*/
public void testRegisterServlet() throws Exception {
m_dependencyManager.add(m_echoServletService);
- assert waitForEchoServlet(true) : "TestValue not echo'd back";
+ assertTrue("TestValue not echo'd back", waitForEchoServlet(true));
m_dependencyManager.remove(m_echoServletService);
- assert !waitForEchoServlet(false) : "The servlet should not be available anymore";
+ assertFalse("The servlet should not be available anymore", waitForEchoServlet(false));
}
/**
@@ -97,13 +61,29 @@ public class ServletConfiguratorIntegrat
// also use the mock version
m_dependencyManager.add(m_mockHttpService);
m_dependencyManager.add(m_echoServletService);
- assert waitForEchoServlet(true) : "TestValue not echo'd back";
- assert m_mockHttp.isRegisterCalled() : "Servlet not registered with the mock service";
+ assertTrue("TestValue not echo'd back", waitForEchoServlet(true));
+ assertTrue("Servlet not registered with the mock service", m_mockHttp.isRegisterCalled());
m_dependencyManager.remove(m_echoServletService);
- assert !waitForEchoServlet(false) : "The servlet should not be available anymore";
- assert m_mockHttp.isUnregisterCalled() : "Servlet not unregistered with the mock service";
+ assertFalse("The servlet should not be available anymore", waitForEchoServlet(false));
+ assertTrue("Servlet not unregistered with the mock service", m_mockHttp.isUnregisterCalled());
+ }
+
+ @Override
+ protected void before() throws Exception {
+ m_echoServlet = new EchoServlet();
+
+ Dictionary<String, String> dictionary = new Hashtable<String, String>();
+ dictionary.put(HttpConstants.ENDPOINT, "/echoServlet");
+ m_echoServletService = m_dependencyManager.createComponent()
+ .setImplementation(m_echoServlet)
+ .setInterface(Servlet.class.getName(), dictionary);
+
+ m_mockHttp = new MockHttpService();
+ m_mockHttpService = m_dependencyManager.createComponent()
+ .setImplementation(m_mockHttp)
+ .setInterface(HttpService.class.getName(), null);
}
/**
@@ -143,11 +123,11 @@ public class ServletConfiguratorIntegrat
}
}catch (MalformedURLException e) {
e.printStackTrace();
- assert false : "No MalformedURLException expected";
+ fail("No MalformedURLException expected");
}
catch (InterruptedException e) {
e.printStackTrace();
- assert false : "No interruptedException expected";
+ fail("No interruptedException expected");
} catch (Throwable t) {
t.printStackTrace();
} finally {
@@ -162,5 +142,4 @@ public class ServletConfiguratorIntegrat
}
return success;
}
-
}
Modified: ace/sandbox/marrs/org.apache.ace.itest/src/org/apache/ace/it/IntegrationTestBase.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.itest/src/org/apache/ace/it/IntegrationTestBase.java?rev=1360046&r1=1360045&r2=1360046&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.itest/src/org/apache/ace/it/IntegrationTestBase.java (original)
+++ ace/sandbox/marrs/org.apache.ace.itest/src/org/apache/ace/it/IntegrationTestBase.java Wed Jul 11 07:55:05 2012
@@ -22,6 +22,8 @@ import static java.util.concurrent.TimeU
import static org.apache.ace.test.utils.Util.properties;
import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -52,15 +54,68 @@ import org.osgi.util.tracker.ServiceTrac
*
*/
public class IntegrationTestBase extends TestCase {
+ private static class ComponentCounter implements ComponentStateListener {
+ private final List<Component> m_components = new ArrayList<Component>();
+ private final CountDownLatch m_latch;
+
+ public ComponentCounter(Component[] components) {
+ m_components.addAll(Arrays.asList(components));
+ m_latch = new CountDownLatch(components.length);
+ }
+
+ public String componentsString() {
+ StringBuilder result = new StringBuilder();
+ for (Component component : m_components) {
+ result.append(component).append('\n');
+ for (ComponentDependencyDeclaration dependency : (List<ComponentDependencyDeclaration>) component.getDependencies()) {
+ result.append(" ")
+ .append(dependency.toString())
+ .append(" ")
+ .append(ComponentDependencyDeclaration.STATE_NAMES[dependency.getState()])
+ .append('\n');
+ }
+ result.append('\n');
+ }
+ return result.toString();
+ }
+
+ public void started(Component component) {
+ m_components.remove(component);
+ m_latch.countDown();
+ }
+
+ public void starting(Component component) {
+ }
+
+ public void stopped(Component component) {
+ }
+
+ public void stopping(Component component) {
+ }
+
+ public boolean waitForEmpty(long timeout, TimeUnit unit) throws InterruptedException {
+ return m_latch.await(timeout, unit);
+ }
+ }
+
/**
* If we have to wait for a service, wait this amount of seconds.
*/
private static final int SERVICE_TIMEOUT = 5;
-
protected BundleContext m_bundleContext;
+
protected DependencyManager m_dependencyManager;
/**
+ * The 'after' callback will be called after all components from {@link #getDependencies} have been
+ * started.<br>
+ * <br>
+ * The {@link #after} callback is most useful for configuring additional services after all mandatory
+ * services are resolved.
+ */
+ protected void after() throws Exception {}
+
+ /**
* The 'before' callback will be called after the components from {@link #getDependencies} have been
* added, but you cannot necessarily rely on injected members here. You can use the {@link #configure} and
* {@link #configureFactory} methods, as well as the {@link #getService} methods.<br>
@@ -71,15 +126,6 @@ public class IntegrationTestBase extends
protected void before() throws Exception {}
/**
- * Gets a list of components that must be started before the test is started; this useful to
- * (a) add additional services, e.g. services that should be picked up by the service under
- * test, or (b) to declare 'this' as a component, and get services injected.
- */
- protected Component[] getDependencies() {
- return new Component[0];
- }
-
- /**
* Write configuration for a single service. For example,
* <pre>
* configure("org.apache.felix.http",
@@ -102,51 +148,130 @@ public class IntegrationTestBase extends
config.update(props);
return config.getPid();
}
+
+ /**
+ * Bridge method for dependency manager.
+ *
+ * @return a new {@link Component}.
+ */
+ protected Component createComponent() {
+ return m_dependencyManager.createComponent();
+ }
+
+ /**
+ * Creates a new factory configuration.
+ *
+ * @param factoryPid the PID of the factory to create a new configuration for.
+ * @return a new {@link Configuration} object, never <code>null</code>.
+ * @throws IOException if access to the persistent storage failed.
+ */
+ protected Configuration createFactoryConfiguration(String factoryPid) throws IOException {
+ ConfigurationAdmin admin = getService(ConfigurationAdmin.class);
+ return admin.createFactoryConfiguration(factoryPid, null);
+ }
- public final void setUp() throws Exception {
- m_bundleContext = FrameworkUtil.getBundle(IntegrationTestBase.class).getBundleContext();
- m_bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
- m_dependencyManager = new DependencyManager(m_bundleContext);
-
- Component[] components = getDependencies();
- ComponentCounter listener = new ComponentCounter(components);
+ /**
+ * Bridge method for dependency manager.
+ *
+ * @return a new {@link ServiceDependency}.
+ */
+ protected ServiceDependency createServiceDependency() {
+ return m_dependencyManager.createServiceDependency();
+ }
- // Register our listener for all the services...
- for (Component component : components) {
- component.addStateListener(listener);
- }
+ /**
+ * Gets an existing configuration or creates a new one, in case it does not exist.
+ *
+ * @param pid the PID of the configuration to return.
+ * @return a {@link Configuration} instance, never <code>null</code>.
+ * @throws IOException if access to the persistent storage failed.
+ */
+ protected Configuration getConfiguration(String pid) throws IOException {
+ ConfigurationAdmin admin = getService(ConfigurationAdmin.class);
+ return admin.getConfiguration(pid, null);
+ }
- // Then give them to the dependency manager...
- for (Component component : components) {
- m_dependencyManager.add(component);
- }
+ /**
+ * Gets a list of components that must be started before the test is started; this useful to
+ * (a) add additional services, e.g. services that should be picked up by the service under
+ * test, or (b) to declare 'this' as a component, and get services injected.
+ */
+ protected Component[] getDependencies() {
+ return new Component[0];
+ }
- // Call back the implementation...
- before();
+ /**
+ * Returns a list of strings representing the result of the given request URL.
+ *
+ * @param requestURL the URL to access and return the response as strings.
+ * @return a list of strings, never <code>null</code>.
+ * @throws IOException in case accessing the requested URL failed.
+ */
+ protected List<String> getResponse(String requestURL) throws IOException {
+ return getResponse(new URL(requestURL));
+ }
- // And wait for all components to come online.
+ /**
+ * Returns a list of strings representing the result of the given request URL.
+ *
+ * @param requestURL the URL to access and return the response as strings.
+ * @return a list of strings, never <code>null</code>.
+ * @throws IOException in case accessing the requested URL failed.
+ */
+ protected List<String> getResponse(URL requestURL) throws IOException {
+ List<String> result = new ArrayList<String>();
+ InputStream in = null;
try {
- if (!listener.waitForEmpty(SERVICE_TIMEOUT, SECONDS)) {
- fail("Not all components were started. Still missing the following:\n" + listener.componentsString());
+ in = requestURL.openConnection().getInputStream();
+ byte[] response = new byte[in.available()];
+ in.read(response);
+
+ final StringBuilder element = new StringBuilder();
+ for (byte b : response) {
+ switch(b) {
+ case '\n' :
+ result.add(element.toString());
+ element.delete(0, element.length());
+ break;
+ default :
+ element.append(b);
+ }
}
-
- after();
}
- catch (InterruptedException e) {
- fail("Interrupted while waiting for services to get started.");
+ finally {
+ try {
+ in.close();
+ }
+ catch (Exception e) {
+ // no problem.
+ }
}
+ return result;
}
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
+
+ /**
+ * Convenience method to return an OSGi service.
+ *
+ * @param serviceClass the service class to return.
+ * @return a service instance, can be <code>null</code>.
*/
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
+ protected <T> T getService(Class<T> serviceClass) {
+ try {
+ return getService(serviceClass, null);
+ }
+ catch (InvalidSyntaxException e) {
+ return null;
+ // Will not happen, since we don't pass in a filter.
+ }
}
-
- protected void after() throws Exception {}
+ /**
+ * Convenience method to return an OSGi service.
+ *
+ * @param serviceClass the service class to return;
+ * @param filterString the (optional) filter string, can be <code>null</code>.
+ * @return a service instance, can be <code>null</code>.
+ */
@SuppressWarnings("unchecked")
protected <T> T getService(Class<T> serviceClass, String filterString) throws InvalidSyntaxException {
T serviceInstance = null;
@@ -179,78 +304,39 @@ public class IntegrationTestBase extends
return serviceInstance;
}
- protected <T> T getService(Class<T> serviceClass) {
- try {
- return getService(serviceClass, null);
- }
- catch (InvalidSyntaxException e) {
- return null;
- // Will not happen, since we don't pass in a filter.
- }
- }
-
- protected Configuration getConfiguration(String pid) throws IOException {
- ConfigurationAdmin admin = getService(ConfigurationAdmin.class);
- return admin.getConfiguration(pid, null);
- }
-
- protected Configuration createFactoryConfiguration(String factoryPid) throws IOException {
- ConfigurationAdmin admin = getService(ConfigurationAdmin.class);
- return admin.createFactoryConfiguration(factoryPid, null);
- }
-
- // Dependency Manager bridge methods
-
- protected Component createComponent() {
- return m_dependencyManager.createComponent();
- }
-
- protected ServiceDependency createServiceDependency() {
- return m_dependencyManager.createServiceDependency();
- }
-
-
- private static class ComponentCounter implements ComponentStateListener {
- private final List<Component> m_components = new ArrayList<Component>();
- private final CountDownLatch m_latch;
-
- public ComponentCounter(Component[] components) {
- m_components.addAll(Arrays.asList(components));
- m_latch = new CountDownLatch(components.length);
- }
-
- public void starting(Component component) {
- }
+ /**
+ * Set up of this test case.
+ */
+ protected final void setUp() throws Exception {
+ m_bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
+ m_dependencyManager = new DependencyManager(m_bundleContext);
- public void started(Component component) {
- m_components.remove(component);
- m_latch.countDown();
- }
+ Component[] components = getDependencies();
+ ComponentCounter listener = new ComponentCounter(components);
- public void stopping(Component component) {
+ // Register our listener for all the services...
+ for (Component component : components) {
+ component.addStateListener(listener);
}
- public void stopped(Component component) {
+ // Then give them to the dependency manager...
+ for (Component component : components) {
+ m_dependencyManager.add(component);
}
- public boolean waitForEmpty(long timeout, TimeUnit unit) throws InterruptedException {
- return m_latch.await(timeout, unit);
- }
+ // Call back the implementation...
+ before();
- public String componentsString() {
- StringBuilder result = new StringBuilder();
- for (Component component : m_components) {
- result.append(component).append('\n');
- for (ComponentDependencyDeclaration dependency : (List<ComponentDependencyDeclaration>) component.getDependencies()) {
- result.append(" ")
- .append(dependency.toString())
- .append(" ")
- .append(ComponentDependencyDeclaration.STATE_NAMES[dependency.getState()])
- .append('\n');
- }
- result.append('\n');
+ // And wait for all components to come online.
+ try {
+ if (!listener.waitForEmpty(SERVICE_TIMEOUT, SECONDS)) {
+ fail("Not all components were started. Still missing the following:\n" + listener.componentsString());
}
- return result.toString();
+
+ after();
}
- };
+ catch (InterruptedException e) {
+ fail("Interrupted while waiting for services to get started.");
+ }
+ }
}
Modified: ace/sandbox/marrs/org.apache.ace.log.itest/src/org/apache/ace/it/log/LogIntegrationTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.log.itest/src/org/apache/ace/it/log/LogIntegrationTest.java?rev=1360046&r1=1360045&r2=1360046&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.log.itest/src/org/apache/ace/it/log/LogIntegrationTest.java (original)
+++ ace/sandbox/marrs/org.apache.ace.log.itest/src/org/apache/ace/it/log/LogIntegrationTest.java Wed Jul 11 07:55:05 2012
@@ -45,38 +45,25 @@ import org.osgi.service.http.HttpService
* replicated to the server.
*/
public class LogIntegrationTest extends IntegrationTestBase {
-// @Configuration
-// public Option[] configuration() {
-// return options(
-// systemProperty("org.osgi.service.http.port").value("" + TestConstants.PORT),
-// new VMOption("-ea"),
-// junitBundles(),
-// provision(
-// Osgi.compendium(),
-// Felix.dependencyManager(),
-// Felix.configAdmin(),
-// jetty(),
-// Ace.util(),
-// Ace.authenticationApi(),
-// Ace.rangeApi(),
-// Ace.discoveryApi(),
-// Ace.discoveryProperty(),
-// Ace.identificationApi(),
-// Ace.identificationProperty(),
-// Ace.httplistener(),
-// Ace.connectionFactory(),
-// Ace.log(),
-// Ace.logListener(),
-// Ace.logServlet(),
-// Ace.serverLogStore(),
-// Ace.logTask(),
-// Ace.targetLog(),
-// Ace.targetLogStore()
-// )
-// );
-// }
- @Override
+ private static final String AUDITLOG = "/auditlog";
+ private static final String DEPLOYMENT = "/deployment";
+
+ public static final String HOST = "localhost";
+ public static final String TARGET_ID = "target-id";
+
+ private volatile Log m_auditLog;
+ private volatile LogStore m_serverStore;
+
+ private volatile Runnable m_auditLogSyncTask;
+
+ public void testLog() throws Exception {
+ // XXX there appears to be a dependency between both these test-methods!!!
+ doTestReplication();
+ doTestServlet();
+ }
+
+ @Override
protected void before() throws Exception {
configure(DiscoveryConstants.DISCOVERY_PID,
DiscoveryConstants.DISCOVERY_URL_KEY, "http://" + HOST + ":" + TestConstants.PORT);
@@ -111,22 +98,7 @@ public class LogIntegrationTest extends
};
}
- private static final String AUDITLOG = "/auditlog";
- private static final String DEPLOYMENT = "/deployment";
-
- public static final String HOST = "localhost";
- public static final String TARGET_ID = "target-id";
-
- private volatile Log m_auditLog;
- private volatile LogStore m_serverStore;
- private volatile Runnable m_auditLogSyncTask;
-
- public void testLog() throws Exception {
- doReplication();
- doServlet();
- }
-
- public void doReplication() throws Exception {
+ private void doTestReplication() throws Exception {
// now log another event
Properties props = new Properties();
props.put("one", "value1");
@@ -142,14 +114,14 @@ public class LogIntegrationTest extends
// get and evaluate results (note that there is some concurrency that might interfere with this test)
List<LogDescriptor> ranges2 = m_serverStore.getDescriptors();
if (ranges2.size() > 0) {
-// assert ranges2.size() == 1 : "We should still have audit log events for one target on the server, but found " + ranges2.size();
+ assertEquals("We should still have audit log events for one target on the server, but found " + ranges2.size(), 1, ranges2.size());
LogDescriptor range = ranges2.get(0);
List<LogEvent> events = m_serverStore.get(range);
if (events.size() > 1) {
-// assert events.size() > 1 : "We should have a couple of events, at least more than the one we added ourselves.";
+ assertTrue("We should have a couple of events, at least more than the one we added ourselves.", events.size() > 1);
for (LogEvent event : events) {
if (event.getType() == 12345) {
- assert event.getProperties().get("two").equals("value2") : "We could not retrieve a property of our audit log event.";
+ assertEquals("We could not retrieve a property of our audit log event.", "value2", event.getProperties().get("two"));
found = true;
break;
}
@@ -159,13 +131,13 @@ public class LogIntegrationTest extends
// wait if we have not found anything yet
if (!found) {
- try { TimeUnit.MILLISECONDS.sleep(100); } catch (InterruptedException ie) {}
+ TimeUnit.MILLISECONDS.sleep(100);
}
}
- assert found : "We could not retrieve our audit log event (after 5 seconds).";
+ assertTrue("We could not retrieve our audit log event (after 5 seconds).", found);
}
- public void doServlet() throws Exception {
+ private void doTestServlet() throws Exception {
// prepare the store
List<LogEvent> events = new ArrayList<LogEvent>();
events.add(new LogEvent("42", 1, 1, 1, 1, new Properties()));
@@ -175,55 +147,24 @@ public class LogIntegrationTest extends
m_serverStore.put(events);
List<String> result = getResponse("http://localhost:" + TestConstants.PORT + "/auditlog/query");
- assert result.size() > 1 : "We expect at least two logs on the server.";
+ assertTrue("We expect at least two logs on the server.", result.size() > 1);
result = getResponse("http://localhost:" + TestConstants.PORT + "/auditlog/receive?tid=42");
- assert result.size() == 1 : "Target 42 has a single audit log event.";
+ assertEquals("Target 42 has a single audit log event.", 1, result.size());
result = getResponse("http://localhost:" + TestConstants.PORT + "/auditlog/receive?tid=47");
- assert result.size() == 3 : "Target 47 has 3 audit log events.";
+ assertEquals("Target 47 has 3 audit log events.", 3, result.size());
result = getResponse("http://localhost:" + TestConstants.PORT + "/auditlog/receive?tid=47&logid=1");
- assert result.size() == 1 : "Target 47, logid 1 has 1 audit log event.";
+ assertEquals("Target 47, logid 1 has 1 audit log event.", 1, result.size());
result = getResponse("http://localhost:" + TestConstants.PORT + "/auditlog/receive?tid=47&logid=2");
- assert result.size() == 2 : "Target 47, logid 2 has 2 audit log events.";
+ assertEquals("Target 47, logid 2 has 2 audit log events.", 2, result.size());
result = getResponse("http://localhost:" + TestConstants.PORT + "/auditlog/receive?tid=47&logid=2&range=1");
- assert result.size() == 1 : "Target 47, logid 2, range 1 has 1 audit log event.";
+ assertEquals("Target 47, logid 2, range 1 has 1 audit log event.", 1, result.size());
result = getResponse("http://localhost:" + TestConstants.PORT + "/auditlog/receive?tid=47&logid=2&range=3,5");
- assert result.size() == 0 : "Target 47, logid 2, range 3,5 has 0 audit log event.";
- }
-
- private List<String> getResponse(String request) throws IOException {
- List<String> result = new ArrayList<String>();
- InputStream in = null;
- try {
- in = new URL(request).openConnection().getInputStream();
- byte[] response = new byte[in.available()];
- in.read(response);
-
- StringBuilder element = new StringBuilder();
- for (byte b : response) {
- switch(b) {
- case '\n' :
- result.add(element.toString());
- element = new StringBuilder();
- break;
- default :
- element.append(b);
- }
- }
- }
- finally {
- try {
- in.close();
- }
- catch (Exception e) {
- // no problem.
- }
- }
- return result;
+ assertEquals("Target 47, logid 2, range 3,5 has 0 audit log event.", 0, result.size());
}
}