ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1360068 - in /ace/sandbox/marrs: org.apache.ace.integrationtests/test/org/apache/ace/it/repository/ org.apache.ace.repository.itest/ org.apache.ace.repository.itest/.settings/ org.apache.ace.repository.itest/src/ org.apache.ace.repository....
Date Wed, 11 Jul 2012 08:53:12 GMT
Author: jawi
Date: Wed Jul 11 08:53:11 2012
New Revision: 1360068

URL: http://svn.apache.org/viewvc?rev=1360068&view=rev
Log:
Migrated repository itest to new bndtools project.

Added:
    ace/sandbox/marrs/org.apache.ace.repository.itest/   (with props)
    ace/sandbox/marrs/org.apache.ace.repository.itest/.classpath   (with props)
    ace/sandbox/marrs/org.apache.ace.repository.itest/.project   (with props)
    ace/sandbox/marrs/org.apache.ace.repository.itest/.settings/
    ace/sandbox/marrs/org.apache.ace.repository.itest/.settings/org.eclipse.jdt.core.prefs
    ace/sandbox/marrs/org.apache.ace.repository.itest/bnd.bnd
    ace/sandbox/marrs/org.apache.ace.repository.itest/build.xml   (with props)
    ace/sandbox/marrs/org.apache.ace.repository.itest/src/
    ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/
    ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/
    ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/
    ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/
    ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/
    ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/RepositoryTest.java
  (with props)
    ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/Utils.java
  (with props)
Removed:
    ace/sandbox/marrs/org.apache.ace.integrationtests/test/org/apache/ace/it/repository/

Propchange: ace/sandbox/marrs/org.apache.ace.repository.itest/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jul 11 08:53:11 2012
@@ -0,0 +1,4 @@
+bin
+bin_test
+generated
+

Added: ace/sandbox/marrs/org.apache.ace.repository.itest/.classpath
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.repository.itest/.classpath?rev=1360068&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.repository.itest/.classpath (added)
+++ ace/sandbox/marrs/org.apache.ace.repository.itest/.classpath Wed Jul 11 08:53:11 2012
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Propchange: ace/sandbox/marrs/org.apache.ace.repository.itest/.classpath
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ace/sandbox/marrs/org.apache.ace.repository.itest/.project
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.repository.itest/.project?rev=1360068&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.repository.itest/.project (added)
+++ ace/sandbox/marrs/org.apache.ace.repository.itest/.project Wed Jul 11 08:53:11 2012
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.apache.ace.repository.itest</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>bndtools.core.bndbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>bndtools.core.bndnature</nature>
+	</natures>
+</projectDescription>

Propchange: ace/sandbox/marrs/org.apache.ace.repository.itest/.project
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ace/sandbox/marrs/org.apache.ace.repository.itest/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.repository.itest/.settings/org.eclipse.jdt.core.prefs?rev=1360068&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.repository.itest/.settings/org.eclipse.jdt.core.prefs
(added)
+++ ace/sandbox/marrs/org.apache.ace.repository.itest/.settings/org.eclipse.jdt.core.prefs
Wed Jul 11 08:53:11 2012
@@ -0,0 +1,81 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=ignore
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.6

Added: ace/sandbox/marrs/org.apache.ace.repository.itest/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.repository.itest/bnd.bnd?rev=1360068&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.repository.itest/bnd.bnd (added)
+++ ace/sandbox/marrs/org.apache.ace.repository.itest/bnd.bnd Wed Jul 11 08:53:11 2012
@@ -0,0 +1,29 @@
+Test-Cases: ${classes;CONCRETE;EXTENDS;org.apache.ace.it.IntegrationTestBase}
+-buildpath: junit.osgi,\
+	osgi.core;version='[4.1,5)',\
+	osgi.cmpn,\
+	org.mockito.mockito-all,\
+	org.apache.ace.itest;version=latest,\
+	org.apache.ace.util;version=latest,\
+	org.apache.ace.httplistener;version=latest,\
+	org.apache.ace.repository.api;version=latest,\
+	org.apache.ace.repository.impl;version=latest,\
+	org.apache.ace.repository.servlet;version=latest,\
+	org.apache.felix.dependencymanager		
+-runfw: org.apache.felix.framework;version='[4,5)'
+-runbundles: \
+	osgi.cmpn;version='[4.2.1,4.2.2)',\
+	org.knopflerfish.log;version='[2.0.2,2.0.3)',\
+	org.apache.felix.dependencymanager;version='[3.1.0,3.1.1)',\
+	org.apache.felix.configadmin;version='[1.2.8,1.2.9)',\
+	org.apache.felix.prefs;version='[1.0.4,1.0.5)',\
+	org.apache.felix.http.jetty;version='[2.2.0,2.2.1)',\
+	org.apache.ace.authentication.api;version=latest,\
+	org.apache.ace.httplistener;version=latest,\
+	org.apache.ace.itest;version=latest,\
+	org.apache.ace.range.api;version=latest,\
+	org.apache.ace.repository.api;version=latest,\
+	org.apache.ace.repository.impl;version=latest,\
+	org.apache.ace.repository.servlet;version=latest
+Private-Package: org.apache.ace.it.repository
+-runvm: -Dorg.osgi.service.http.port=9000 -ea

Added: ace/sandbox/marrs/org.apache.ace.repository.itest/build.xml
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.repository.itest/build.xml?rev=1360068&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.repository.itest/build.xml (added)
+++ ace/sandbox/marrs/org.apache.ace.repository.itest/build.xml Wed Jul 11 08:53:11 2012
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="project" default="build"> 
+	<import file="../cnf/build.xml"/>
+</project>

Propchange: ace/sandbox/marrs/org.apache.ace.repository.itest/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/RepositoryTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/RepositoryTest.java?rev=1360068&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/RepositoryTest.java
(added)
+++ ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/RepositoryTest.java
Wed Jul 11 08:53:11 2012
@@ -0,0 +1,284 @@
+/*
+ * 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.ace.it.repository;
+
+import static org.apache.ace.it.repository.Utils.get;
+import static org.apache.ace.it.repository.Utils.put;
+import static org.apache.ace.it.repository.Utils.query;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Properties;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.ace.http.listener.constants.HttpConstants;
+import org.apache.ace.it.IntegrationTestBase;
+import org.apache.ace.repository.Repository;
+import org.apache.ace.repository.impl.constants.RepositoryConstants;
+import org.apache.ace.test.constants.TestConstants;
+import org.apache.felix.dm.Component;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * Integration test for our repositories, and the replication thereof.
+ */
+public class RepositoryTest extends IntegrationTestBase {
+
+	private volatile ConfigurationAdmin m_configAdmin;
+	
+    private URL m_host;
+
+    public void testBadRequests() throws Exception {
+        addRepository("testInstance", "apache", "test", false);
+
+        URL url = new URL(m_host, "replication/query?customer=apache&name=test&filter=test");
+        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+        int responseCode = connection.getResponseCode();
+        assertResponseCode(HttpURLConnection.HTTP_BAD_REQUEST, responseCode);
+
+        url = new URL(m_host, "repository/query?customer=apache&name=test&filter=test");
+        connection = (HttpURLConnection) url.openConnection();
+        responseCode = connection.getResponseCode();
+        assertResponseCode(HttpURLConnection.HTTP_BAD_REQUEST, responseCode);
+
+        removeRepository("testInstance");
+    }
+
+    public void testCheckoutAndCommit() throws Exception {
+        addRepository("testInstance", "apache", "test", true);
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        int responseCode = get(m_host, "repository/checkout", "apache", "test", "1", out);
+        assertResponseCode(HttpURLConnection.HTTP_NOT_FOUND, responseCode);
+
+        ByteArrayInputStream input = new ByteArrayInputStream("test".getBytes());
+        responseCode = put(m_host, "repository/commit", "apache", "test", "1", input);
+        assertResponseCode(HttpURLConnection.HTTP_INTERNAL_ERROR, responseCode);
+
+        input.reset();
+        responseCode = put(m_host, "repository/commit", "apache", "test", "0", input);
+        assertResponseCode(HttpURLConnection.HTTP_OK, responseCode);
+
+        out.reset();
+        responseCode = get(m_host, "repository/checkout", "apache", "test", "1", out);
+        assertResponseCode(HttpURLConnection.HTTP_OK, responseCode);
+
+        removeRepository("testInstance");
+    }
+
+    public void testCreation() throws Exception {
+        addRepository("testInstance", "apache", "test", true);
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        int responseCode = query(m_host, "replication/query", null, null, out);
+        assertResponseCode(HttpURLConnection.HTTP_OK, responseCode);
+        
+        assertEquals("Expected one repository without any versions as query result instead
of : " + out.toString(), "apache,test,\n", out.toString());
+
+        addRepository("testInstance2", "apache", "test2", true);
+
+        out.reset();
+        responseCode = query(m_host, "replication/query", null, null, out);
+        assertResponseCode(HttpURLConnection.HTTP_OK, responseCode);
+        assertTrue("Expected two repositories without any versions as query result instead
of : " + out.toString(), 
+        	"apache,test,\napache,test2,\n".equals(out.toString()) || "apache,test2,\napache,test,\n".equals(out.toString()));
+
+        removeRepository("testInstance2");
+
+        out.reset();
+        responseCode = query(m_host, "replication/query", null, null, out);
+        assertResponseCode(HttpURLConnection.HTTP_OK, responseCode);
+        assertEquals("Expected one repository without any versions as query result instead
of : " + out.toString(), "apache,test,\n", out.toString());
+
+        removeRepository("testInstance");
+
+        out.reset();
+        responseCode = query(m_host, "replication/query", null, null, out);
+        assertResponseCode(HttpURLConnection.HTTP_OK, responseCode);
+        assertEquals("Expected one repository without any versions as query result instead
of : " + out.toString(), "", out.toString());
+    }
+
+    public void testGetAndPut() throws Exception {
+        addRepository("testInstance", "apache", "test", true);
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        int responseCode = get(m_host, "replication/get", "apache", "test", "1", out);
+        assertResponseCode(HttpURLConnection.HTTP_NOT_FOUND, responseCode);
+
+        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("test".getBytes());
+        responseCode = put(m_host, "replication/put", "apache", "test", "1", byteArrayInputStream);
+        assertResponseCode(HttpURLConnection.HTTP_OK, responseCode);
+
+        out.reset();
+        responseCode = get(m_host, "replication/get", "apache", "test", "1", out);
+        assertResponseCode(HttpURLConnection.HTTP_OK, responseCode);
+        
+        assertEquals("test", out.toString());
+
+        removeRepository("testInstance");
+    }
+
+    public void testInitialContent() throws Exception {
+        addRepository("testInstance", "apache", "test", "somecontent", true);
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+        int responseCode = get(m_host, "repository/checkout", "apache", "test", "1", out);
+        assertResponseCode(HttpURLConnection.HTTP_OK, responseCode);
+
+        assertEquals("somecontent", out.toString());
+
+        removeRepository("testInstance");
+    }
+
+    public void testMaster() throws Exception {
+        addRepository("testInstance", "apache", "test", false);
+
+        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("test".getBytes());
+
+        int responseCode = put(m_host, "replication/put", "apache", "test", "1", byteArrayInputStream);
+        assertResponseCode(HttpURLConnection.HTTP_OK, responseCode);
+
+        byteArrayInputStream.reset();
+        
+        responseCode = put(m_host, "repository/commit", "apache", "test", "0", byteArrayInputStream);
+        assertResponseCode(HttpURLConnection.HTTP_INTERNAL_ERROR, responseCode);
+
+        removeRepository("testInstance");
+    }
+
+    protected void before() throws IOException {
+		m_host = new URL("http://localhost:" + TestConstants.PORT);
+
+        configure("org.apache.ace.repository.servlet.RepositoryReplicationServlet",
+                HttpConstants.ENDPOINT, "/replication", "authentication.enabled", "false");
+        configure("org.apache.ace.repository.servlet.RepositoryServlet",
+                HttpConstants.ENDPOINT, "/repository", "authentication.enabled", "false");
+    }
+
+    protected Component[] getDependencies() {
+        return new Component[] {
+            createComponent()
+                .setImplementation(this)
+                .add(createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true))
+        };
+    }
+
+    protected void tearDown() throws Exception {
+        // remove all repositories, in case a test case does not reach it's cleanup section
due to an exception
+        removeAllRepositories();
+    }
+
+    private void addRepository(String instanceName, String customer, String name, boolean
isMaster) throws IOException, InterruptedException, InvalidSyntaxException {
+        addRepository(instanceName, customer, name, null, isMaster);
+    }
+
+    /* Configure a new repository instance */
+    private void addRepository(String instanceName, String customer, String name, String
initial, boolean isMaster) throws IOException, InterruptedException, InvalidSyntaxException
{
+        // Publish configuration for a repository instance
+        Properties props = new Properties();
+        props.put(RepositoryConstants.REPOSITORY_CUSTOMER, customer);
+        props.put(RepositoryConstants.REPOSITORY_NAME, name);
+        props.put(RepositoryConstants.REPOSITORY_MASTER, String.valueOf(isMaster));
+        if (initial != null) {
+            props.put(RepositoryConstants.REPOSITORY_INITIAL_CONTENT, initial);
+        }
+        props.put("factory.instance.pid", instanceName);
+        Configuration config = m_configAdmin.createFactoryConfiguration("org.apache.ace.server.repository.factory",
null);
+
+        ServiceTracker tracker = new ServiceTracker(m_bundleContext, m_bundleContext.createFilter("(factory.instance.pid="
+ instanceName + ")"), null);
+        tracker.open();
+
+        config.update(props);
+
+        if (tracker.waitForService(1000) == null) {
+            throw new IOException("Did not get notified about new repository becoming available
in time.");
+        }
+        tracker.close();
+    }
+
+    private void removeAllRepositories() throws IOException, InvalidSyntaxException, InterruptedException
{
+        final Configuration[] configs = m_configAdmin.listConfigurations("(factory.instance.pid=*)");
+        if ((configs != null) && (configs.length > 0)) {
+            final Semaphore sem = new Semaphore(0);
+
+            ServiceTracker tracker = new ServiceTracker(m_bundleContext, m_bundleContext.createFilter("("
+ Constants.OBJECTCLASS + "=" + Repository.class.getName() + ")"), null) {
+                @Override
+                public void removedService(ServiceReference reference, Object service) {
+                    super.removedService(reference, service);
+                    // config.length times two because the service tracker also sees added
events for each instance
+                    if (size() == 0) {
+                        sem.release();
+                    }
+                }
+            };
+            tracker.open();
+
+            for (int i = 0; i < configs.length; i++) {
+                configs[i].delete();
+            }
+
+            if (!sem.tryAcquire(1, TimeUnit.SECONDS)) {
+                throw new IOException("Not all instances were removed in time.");
+            }
+            tracker.close();
+        }
+    }
+
+    private void removeRepository(String instanceName) throws IOException, InterruptedException,
InvalidSyntaxException {
+        Configuration[] configs = null;
+        try {
+            configs = m_configAdmin.listConfigurations("(factory.instance.pid=" + instanceName
+ ")");
+        }
+        catch (InvalidSyntaxException e) {
+            // should not happen
+        }
+        if ((configs != null) && (configs.length > 0)) {
+            final Semaphore sem = new Semaphore(0);
+            ServiceTracker tracker = new ServiceTracker(m_bundleContext, m_bundleContext.createFilter("(factory.instance.pid="
+ instanceName + ")"), null) {
+                @Override
+                public void removedService(ServiceReference reference, Object service) {
+                    super.removedService(reference, service);
+                    sem.release();
+                }
+            };
+            tracker.open();
+
+            configs[0].delete();
+
+            if (!sem.tryAcquire(1, TimeUnit.SECONDS)) {
+                throw new IOException("Instance did not get removed in time.");
+            }
+        }
+    }
+
+    private void assertResponseCode(int expectedCode, int responseCode) {
+    	assertEquals("Unexpected response code;", expectedCode, responseCode);
+    }
+}

Propchange: ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/RepositoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/Utils.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/Utils.java?rev=1360068&view=auto
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/Utils.java
(added)
+++ ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/Utils.java
Wed Jul 11 08:53:11 2012
@@ -0,0 +1,89 @@
+/*
+ * 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.ace.it.repository;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+/**
+ * @author Jan Willem Janssen <janwillem.janssen@luminis.eu>
+ *
+ */
+final class Utils {
+	
+    private static final int COPY_BUFFER_SIZE = 4096;
+    private static final String MIME_APPLICATION_OCTET_STREAM = "application/octet-stream";
          
+  
+    /* copy in to out */
+    static void copy(InputStream in, OutputStream out) throws IOException {
+        byte[] buffer = new byte[COPY_BUFFER_SIZE];
+        int bytes = in.read(buffer);
+        while (bytes != -1) {
+            out.write(buffer, 0, bytes);
+            bytes = in.read(buffer);
+        }
+    }
+    
+    static int get(URL host, String endpoint, String customer, String name, String version,
OutputStream out) throws IOException {
+        URL url = new URL(host, endpoint + "?customer=" + customer + "&name=" + name
+ "&version=" + version);
+        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+        int responseCode = connection.getResponseCode();
+        if (responseCode == HttpURLConnection.HTTP_OK) {
+            InputStream input = connection.getInputStream();
+            copy(input, out);
+            out.flush();
+        }
+        return responseCode;
+    }
+
+    static int put(URL host, String endpoint, String customer, String name, String version,
InputStream in) throws IOException {
+        URL url = new URL(host, endpoint + "?customer=" + customer + "&name=" + name
+ "&version=" + version);
+        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+        connection.setDoOutput(true);
+        connection.setRequestProperty("Content-Type", MIME_APPLICATION_OCTET_STREAM);
+        OutputStream out = connection.getOutputStream();
+        copy(in, out);
+        out.flush();
+        int responseCode = connection.getResponseCode();
+        if (responseCode == HttpURLConnection.HTTP_OK) {
+            InputStream is = (InputStream) connection.getContent();
+            is.close();
+        }
+        return responseCode;
+    }
+
+    static int query(URL host, String endpoint, String customer, String name, OutputStream
out) throws IOException {
+        String f1 = (customer == null) ? null : "customer=" + customer;
+        String f2 = (name == null) ? null : "name=" + name;
+        String filter = ((f1 == null) ? "?" : "?" + f1 + "&") + ((f2 == null) ? "" :
f2);
+        URL url = new URL(host, endpoint + filter);
+        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+        int responseCode = connection.getResponseCode();
+        if (responseCode == HttpURLConnection.HTTP_OK) {
+            InputStream input = connection.getInputStream();
+            copy(input, out);
+            out.flush();
+        }
+        return responseCode;
+    }
+}

Propchange: ace/sandbox/marrs/org.apache.ace.repository.itest/src/org/apache/ace/it/repository/Utils.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message