ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1513834 [2/2] - in /ace/sandbox/bramk/org.apache.ace.agent: ./ src/org/apache/ace/agent/ src/org/apache/ace/agent/configuration/ src/org/apache/ace/agent/connection/ src/org/apache/ace/agent/deployment/ src/org/apache/ace/agent/discovery/ ...
Date Wed, 14 Aug 2013 12:22:11 GMT
Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandlerImpl.java?rev=1513834&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandlerImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandlerImpl.java Wed Aug 14 12:22:10 2013
@@ -0,0 +1,63 @@
+/*
+ * 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.agent.impl;
+
+import java.net.URL;
+import java.util.concurrent.ExecutorService;
+
+import org.apache.ace.agent.DownloadHandle;
+import org.apache.ace.agent.DownloadHandler;
+
+public class DownloadHandlerImpl implements DownloadHandler {
+
+    private final AgentContext m_agentContext;
+
+    public DownloadHandlerImpl(AgentContext agentContext) {
+        m_agentContext = agentContext;
+    }
+
+    @Override
+    public DownloadHandle getHandle(URL url) {
+        return new DownloadHandleImpl(this, url);
+    }
+
+    @Override
+    public DownloadHandle getHandle(URL url, int readBufferSize) {
+        return new DownloadHandleImpl(this, url, readBufferSize);
+    }
+
+    /*
+     * handle support methods
+     */
+    ExecutorService getExecutor() {
+        return m_agentContext.getExecutorService();
+    }
+
+    void logDebug(String message, Object... args) {
+        System.err.println(String.format(message, args));
+    }
+
+    void logInfo(String message, Object... args) {
+        System.err.println(String.format(message, args));
+    }
+
+    void logWarning(String message, Object... args) {
+        System.err.println(String.format(message, args));
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadResultImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadResultImpl.java?rev=1513834&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadResultImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadResultImpl.java Wed Aug 14 12:22:10 2013
@@ -0,0 +1,68 @@
+/*
+ * 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.agent.impl;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ace.agent.DownloadResult;
+import org.apache.ace.agent.DownloadState;
+
+public class DownloadResultImpl implements DownloadResult {
+
+    final DownloadState m_state;
+    final File m_file;
+    final int m_code;
+    final Map<String, List<String>> m_headers;
+    final Throwable m_cause;
+
+    DownloadResultImpl(DownloadState state, File file, int code, Map<String, List<String>> headers, Throwable cause) {
+        m_state = state;
+        m_file = file;
+        m_code = code;
+        m_headers = headers;
+        m_cause = cause;
+    }
+
+    @Override
+    public DownloadState getState() {
+        return m_state;
+    }
+
+    @Override
+    public File getFile() {
+        return m_file;
+    }
+
+    @Override
+    public int getCode() {
+        return m_code;
+    }
+
+    @Override
+    public Map<String, List<String>> getHeaders() {
+        return m_headers;
+    }
+
+    @Override
+    public Throwable getCause() {
+        return m_cause;
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java?rev=1513834&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java Wed Aug 14 12:22:10 2013
@@ -0,0 +1,36 @@
+package org.apache.ace.agent.impl;
+
+import org.apache.ace.agent.IdentificationHandler;
+
+/**
+ * Default identification handler that reads the identity from the configuration using key
+ * {@link IDENTIFICATION_CONFIG_KEY}.
+ * 
+ */
+public class IdentificationHandlerImpl implements IdentificationHandler {
+
+    /**
+     * Configuration key for the default identification handler. The value must be a single file-system and URL safe
+     * string.
+     */
+    // TODO move to and validate in configuration handler?
+    public static final String IDENTIFICATION_CONFIG_KEY = "agent.discovery";
+
+    private final AgentContext m_agentContext;
+
+    public IdentificationHandlerImpl(AgentContext agentContext) {
+        m_agentContext = agentContext;
+    }
+
+    // TODO add a default fallback?
+    @Override
+    public String getIdentification() {
+        String configValue = m_agentContext.getConfigurationHandler().getMap().get(IDENTIFICATION_CONFIG_KEY);
+        if (configValue == null)
+            return null;
+        configValue = configValue.trim();
+        if (configValue.equals(""))
+            return null;
+        return configValue;
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConnectionHandlerImplTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConnectionHandlerImplTest.java?rev=1513834&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConnectionHandlerImplTest.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConnectionHandlerImplTest.java Wed Aug 14 12:22:10 2013
@@ -0,0 +1,118 @@
+/*
+ * 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.agent.impl;
+
+import static org.easymock.EasyMock.expect;
+import static org.testng.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.ace.agent.ConfigurationHandler;
+import org.apache.ace.agent.ConnectionHandler;
+import org.apache.ace.agent.testutil.BaseAgentTest;
+import org.apache.ace.agent.testutil.TestWebServer;
+import org.apache.commons.codec.binary.Base64;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+/**
+ * Testing {@link ConnectionHandlerImpl}
+ * 
+ */
+// TODO test CLIENT_CERT
+public class ConnectionHandlerImplTest extends BaseAgentTest {
+
+    static class BasicAuthServlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        private final String m_authHeader;
+
+        public BasicAuthServlet(String username, String password) {
+            m_authHeader = "Basic " + new String(Base64.encodeBase64((username + ":" + password).getBytes()));
+        }
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+            String authHeader = req.getHeader("Authorization");
+            if (authHeader == null || !authHeader.equals(m_authHeader))
+                resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Requires Basic Auth");
+            resp.setStatus(HttpServletResponse.SC_OK);
+        }
+
+    }
+
+    Map<String, String> m_configuration = new HashMap<String, String>();
+    ConnectionHandler m_connectionHandler;
+    TestWebServer m_webServer;
+    String m_user = "Mickey";
+    String m_pass = "Mantle";
+    URL m_basicAuthURL;
+
+    @BeforeTest
+    public void setUpAgain() throws Exception {
+
+        int port = 8880;
+        m_basicAuthURL = new URL("http://localhost:" + port + "/basicauth");
+        m_webServer = new TestWebServer(port, "/", "generated");
+        m_webServer.addServlet(new BasicAuthServlet(m_user, m_pass), "/basicauth/*");
+        m_webServer.start();
+
+        ConfigurationHandler configurationHandler = addTestMock(ConfigurationHandler.class);
+        expect(configurationHandler.getMap()).andReturn(m_configuration).anyTimes();
+
+        AgentContext agentContext = addTestMock(AgentContext.class);
+        expect(agentContext.getConfigurationHandler()).andReturn(configurationHandler).anyTimes();
+
+        replayTestMocks();
+        m_connectionHandler = new ConnectionHandlerImpl(agentContext);
+    }
+
+    @AfterTest
+    public void tearDownAgain() throws Exception {
+        m_webServer.stop();
+        verifyTestMocks();
+    }
+
+    @Test
+    public void testBasicAuthFORBIDDEN() throws Exception {
+        m_configuration.clear();
+        HttpURLConnection connection = (HttpURLConnection) m_connectionHandler.getConnection(m_basicAuthURL);
+        assertEquals(connection.getResponseCode(), HttpServletResponse.SC_FORBIDDEN);
+    }
+
+    @Test
+    public void testBasicAuthOK() throws Exception {
+        m_configuration.put(ConnectionHandlerImpl.PROP_AUTHTYPE, "BASIC");
+        m_configuration.put(ConnectionHandlerImpl.PROP_AUTHUSER, m_user);
+        m_configuration.put(ConnectionHandlerImpl.PROP_AUTHPASS, m_pass);
+        HttpURLConnection connection = (HttpURLConnection) m_connectionHandler.getConnection(m_basicAuthURL);
+        assertEquals(connection.getResponseCode(), HttpServletResponse.SC_OK);
+    }
+}

Modified: ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/CustomControllerTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/CustomControllerTest.java?rev=1513834&r1=1513833&r2=1513834&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/CustomControllerTest.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/CustomControllerTest.java Wed Aug 14 12:22:10 2013
@@ -1,78 +1,87 @@
+/*
+ * 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.agent.impl;
 
-import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.expectLastCall;
 import static org.easymock.EasyMock.notNull;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.net.URL;
-import java.util.HashSet;
-import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
 import org.apache.ace.agent.AgentControl;
-import org.apache.ace.agent.deployment.DeploymentHandler;
-import org.apache.ace.agent.download.DownloadHandle;
-import org.apache.ace.agent.download.DownloadResult;
-import org.apache.ace.agent.download.DownloadState;
+import org.apache.ace.agent.DeploymentHandler;
+import org.apache.ace.agent.DownloadHandle;
+import org.apache.ace.agent.DownloadResult;
+import org.apache.ace.agent.DownloadState;
+import org.apache.ace.agent.testutil.BaseAgentTest;
 import org.osgi.framework.Version;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 
-public class CustomControllerTest {
+public class CustomControllerTest extends BaseAgentTest {
 
     AgentControl m_agentControl;
-
-    Version v1 = Version.parseVersion("1.0.0");
-    Version v2 = Version.parseVersion("2.0.0");
-    Version v3 = Version.parseVersion("3.0.0");
-
-    SortedSet<Version> availableVersion = new TreeSet<Version>();
-
-    File dummyFile;
-    URL dummyFileUrl;
-    InputStream dummyInputStream;
-
-    Set<Object> m_mocks = new HashSet<Object>();
+    Version m_version1 = Version.parseVersion("1.0.0");
+    Version m_version2 = Version.parseVersion("2.0.0");
+    Version m_version3 = Version.parseVersion("3.0.0");
+    SortedSet<Version> m_availableVersions = new TreeSet<Version>();
+    File m_dummyFile;
+    URL m_dummyFileUrl;
+    InputStream m_dummyInputStream;
 
     @BeforeTest
     public void setUpOnceAgain() throws Exception {
 
-        availableVersion.add(v1);
-        availableVersion.add(v2);
-        availableVersion.add(v3);
-
-        dummyFile = File.createTempFile("mock", ".txt");
-        dummyFile.deleteOnExit();
-        dummyFileUrl = dummyFile.toURI().toURL();
+        m_availableVersions.add(m_version1);
+        m_availableVersions.add(m_version2);
+        m_availableVersions.add(m_version3);
+
+        m_dummyFile = File.createTempFile("mock", ".txt");
+        m_dummyFile.deleteOnExit();
+        m_dummyFileUrl = m_dummyFile.toURI().toURL();
     }
 
     @BeforeMethod
     public void setUpAgain() throws Exception {
 
-        dummyInputStream = new FileInputStream(dummyFile);
+        m_dummyInputStream = new FileInputStream(m_dummyFile);
 
         DownloadResult downloadResult = addTestMock(DownloadResult.class);
         expect(downloadResult.getState()).andReturn(DownloadState.SUCCESSFUL).anyTimes();
-        expect(downloadResult.getFile()).andReturn(dummyFile).anyTimes();
+        expect(downloadResult.getFile()).andReturn(m_dummyFile).anyTimes();
 
         DownloadHandle downloadHandle = addTestMock(DownloadHandle.class);
         expect(downloadHandle.start()).andReturn(downloadHandle).anyTimes();
         expect(downloadHandle.result()).andReturn(downloadResult).anyTimes();
 
         DeploymentHandler deploymentHandler = addTestMock(DeploymentHandler.class);
-        expect(deploymentHandler.getInstalledVersion()).andReturn(v2).anyTimes();
-        expect(deploymentHandler.getAvailableVersions()).andReturn(availableVersion).anyTimes();
-        expect(deploymentHandler.getDownloadHandle(eq(v3), eq(true))).andReturn(downloadHandle).once();
+        expect(deploymentHandler.getInstalledVersion()).andReturn(m_version2).anyTimes();
+        expect(deploymentHandler.getAvailableVersions()).andReturn(m_availableVersions).anyTimes();
+        expect(deploymentHandler.getDownloadHandle(eq(m_version3), eq(true))).andReturn(downloadHandle).once();
         deploymentHandler.deployPackage(notNull(InputStream.class));
         expectLastCall().once();
 
@@ -87,7 +96,7 @@ public class CustomControllerTest {
     public void tearDownOnceAgain() throws Exception {
         verifyTestMocks();
         clearTestMocks();
-        dummyInputStream.close();
+        m_dummyInputStream.close();
     }
 
     @Test
@@ -111,24 +120,4 @@ public class CustomControllerTest {
             }
         }
     }
-
-    private <T extends Object> T addTestMock(Class<T> clazz) {
-        T mock = createMock(clazz);
-        m_mocks.add(mock);
-        return mock;
-    }
-
-    private void replayTestMocks() {
-        for (Object mock : m_mocks)
-            replay(mock);
-    }
-
-    private void verifyTestMocks() {
-        for (Object mock : m_mocks)
-            verify(mock);
-    }
-
-    private void clearTestMocks() {
-        m_mocks.clear();
-    }
 }

Added: ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DeploymentHandlerTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DeploymentHandlerTest.java?rev=1513834&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DeploymentHandlerTest.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DeploymentHandlerTest.java Wed Aug 14 12:22:10 2013
@@ -0,0 +1,214 @@
+/*
+ * 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.agent.impl;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.notNull;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.security.DigestOutputStream;
+import java.security.MessageDigest;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.ace.agent.AgentConstants;
+import org.apache.ace.agent.ConfigurationHandler;
+import org.apache.ace.agent.DiscoveryHandler;
+import org.apache.ace.agent.IdentificationHandler;
+import org.apache.ace.agent.testutil.BaseAgentTest;
+import org.apache.ace.agent.testutil.TestWebServer;
+import org.osgi.framework.Version;
+import org.osgi.service.deploymentadmin.DeploymentAdmin;
+import org.osgi.service.deploymentadmin.DeploymentPackage;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class DeploymentHandlerTest extends BaseAgentTest {
+
+    static class TestDeploymentServlet extends HttpServlet {
+        private static final long serialVersionUID = 1L;
+
+        private Map<String, File> m_packages = new HashMap<String, File>();
+
+        @SuppressWarnings("deprecation")
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+
+            String pathInfo = req.getPathInfo();
+            if (pathInfo != null && pathInfo.startsWith("/"))
+                pathInfo = pathInfo.substring(1);
+
+            if (pathInfo != null && m_packages.containsKey(pathInfo)) {
+                File file = m_packages.get(pathInfo);
+                resp.setHeader(AgentConstants.HEADER_DPSIZE, "" + file.length());
+                FileInputStream fis = new FileInputStream(file);
+                OutputStream os = resp.getOutputStream();
+                int b;
+                while ((b = fis.read()) != -1) {
+                    os.write(b);
+                }
+                fis.close();
+                os.close();
+            }
+            else {
+                PrintWriter writer = resp.getWriter();
+                for (String version : m_packages.keySet()) {
+                    writer.println(version);
+                }
+                writer.close();
+            }
+            resp.setStatus(200, "voila");
+        }
+
+        void addPackage(String version, File file) {
+            m_packages.put(version, file);
+        }
+    }
+
+    private DeploymentHandlerImpl m_deploymentHandler;
+    private TestWebServer m_webserver;
+    private File m_200file;
+    private Version m_version1 = Version.parseVersion("1.0.0");
+    private Version m_version2 = Version.parseVersion("2.0.0");
+    private Version m_version3 = Version.parseVersion("3.0.0");
+    long m_remotePackageSize = 0l;
+
+    @BeforeTest
+    public void setUpOnceAgain() throws Exception {
+
+        int port = 8881;
+        String identification = "agent";
+        URL serverURL = new URL("http://localhost:" + port + "/");
+
+        m_webserver = new TestWebServer(port, "/", "generated");
+        m_webserver.start();
+
+        m_200file = new File(new File("generated"), "testfile.txt");
+        DigestOutputStream dos = new DigestOutputStream(new FileOutputStream(m_200file), MessageDigest.getInstance("MD5"));
+        for (int i = 0; i < 10000; i++) {
+            dos.write(String.valueOf(System.currentTimeMillis()).getBytes());
+            dos.write(" Lorum Ipsum Lorum Ipsum Lorum Ipsum Lorum Ipsum Lorum Ipsum\n".getBytes());
+        }
+        dos.close();
+
+        TestDeploymentServlet servlet = new TestDeploymentServlet();
+        servlet.addPackage(m_version1.toString(), m_200file);
+        servlet.addPackage(m_version2.toString(), m_200file);
+        servlet.addPackage(m_version3.toString(), m_200file);
+
+        m_remotePackageSize = m_200file.length();
+        m_webserver.addServlet(servlet, "/deployment/" + identification + "/versions/*");
+
+        DeploymentPackage deploymentPackage1 = addTestMock(DeploymentPackage.class);
+        expect(deploymentPackage1.getName()).andReturn(identification).anyTimes();
+        expect(deploymentPackage1.getVersion()).andReturn(Version.parseVersion("1.0.0")).anyTimes();
+
+        DeploymentPackage deploymentPackage2 = addTestMock(DeploymentPackage.class);
+        expect(deploymentPackage2.getName()).andReturn(identification).anyTimes();
+        expect(deploymentPackage2.getVersion()).andReturn(Version.parseVersion("2.0.0")).anyTimes();
+
+        DeploymentPackage deploymentPackage3 = addTestMock(DeploymentPackage.class);
+        expect(deploymentPackage3.getName()).andReturn(identification).anyTimes();
+        expect(deploymentPackage3.getVersion()).andReturn(Version.parseVersion("3.0.0")).anyTimes();
+
+        IdentificationHandler identificationHandler = addTestMock(IdentificationHandler.class);
+        expect(identificationHandler.getIdentification()).andReturn(identification).anyTimes();
+
+        DiscoveryHandler discoveryHandler = addTestMock(DiscoveryHandler.class);
+        expect(discoveryHandler.getServerUrl()).andReturn(serverURL).anyTimes();
+
+        ConfigurationHandler configurationHandler = addTestMock(ConfigurationHandler.class);
+        expect(configurationHandler.getMap()).andReturn(new HashMap<String, String>()).anyTimes();
+
+        DeploymentAdmin deploymentAdmin = addTestMock(DeploymentAdmin.class);
+        expect(deploymentAdmin.listDeploymentPackages()).andReturn(
+            new DeploymentPackage[] { deploymentPackage2, deploymentPackage1 }).anyTimes();
+        expect(deploymentAdmin.installDeploymentPackage(notNull(InputStream.class)
+            )).andReturn(deploymentPackage3).once();
+
+        AgentContext agentContext = addTestMock(AgentContext.class);
+        expect(agentContext.getIdentificationHandler()).andReturn(identificationHandler).anyTimes();
+        expect(agentContext.getDiscoveryHandler()).andReturn(discoveryHandler).anyTimes();
+        expect(agentContext.getConfigurationHandler()).andReturn(configurationHandler).anyTimes();
+        expect(agentContext.getConnectionHandler()).andReturn(new ConnectionHandlerImpl(agentContext)).anyTimes();
+
+        replayTestMocks();
+        m_deploymentHandler = new DeploymentHandlerImpl(agentContext, deploymentAdmin);
+    }
+
+    @AfterTest
+    public void tearDownOnceAgain() throws Exception {
+        verifyTestMocks();
+        m_webserver.stop();
+    }
+
+    @Test
+    public void testCurrentVersion() throws Exception {
+        Version current = m_deploymentHandler.getInstalledVersion();
+        assertNotNull(current);
+        assertEquals(current, m_version2);
+    }
+
+    @Test
+    public void testAvailableVersions() throws Exception {
+        SortedSet<Version> expected = new TreeSet<Version>();
+        expected.add(m_version1);
+        expected.add(m_version2);
+        expected.add(m_version3);
+        SortedSet<Version> available = m_deploymentHandler.getAvailableVersions();
+        assertNotNull(available);
+        assertFalse(available.isEmpty());
+        assertEquals(available, expected);
+    }
+
+    @Test
+    public void testPackageSize() throws Exception {
+        long packageSize = m_deploymentHandler.getPackageSize(m_version1, true);
+        assertEquals(packageSize, m_remotePackageSize);
+    }
+
+    @Test
+    public void testDeployPackage() throws Exception {
+        InputStream inputStream = m_deploymentHandler.getInputStream(m_version3, true);
+        try {
+            m_deploymentHandler.deployPackage(inputStream);
+        }
+        finally {
+            inputStream.close();
+        }
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java?rev=1513834&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java Wed Aug 14 12:22:10 2013
@@ -0,0 +1,134 @@
+/*
+ * 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.agent.impl;
+
+import static org.easymock.EasyMock.expect;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ace.agent.ConfigurationHandler;
+import org.apache.ace.agent.ConnectionHandler;
+import org.apache.ace.agent.DiscoveryHandler;
+import org.apache.ace.agent.impl.AgentContext;
+import org.apache.ace.agent.impl.ConnectionHandlerImpl;
+import org.apache.ace.agent.impl.DiscoveryHandlerImpl;
+import org.apache.ace.agent.testutil.BaseAgentTest;
+import org.apache.ace.agent.testutil.TestWebServer;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class DiscoveryHandlerImplTest extends BaseAgentTest {
+
+    Map<String, String> configuration = new HashMap<String, String>();
+
+    DiscoveryHandler m_discoveryHandler;
+
+    TestWebServer m_webServer;
+    TestWebServer m_secondWebServer;
+
+    URL m_availableURL;
+    URL m_unavailableURL;
+
+    @BeforeTest
+    public void setUpAgain() throws Exception {
+
+        int port = 8882;
+        m_webServer = new TestWebServer(port, "/", "generated");
+        m_webServer.start();
+
+        m_availableURL = new URL("http://localhost:" + port);
+        m_unavailableURL = new URL("http://localhost:9999");
+
+        AgentContext agentContext = addTestMock(AgentContext.class);
+        m_discoveryHandler = new DiscoveryHandlerImpl(agentContext);
+
+        ConfigurationHandler configurationHandler = addTestMock(ConfigurationHandler.class);
+        expect(configurationHandler.getMap()).andReturn(configuration).anyTimes();
+
+        ConnectionHandler connectionHandler = new ConnectionHandlerImpl(agentContext);
+
+        expect(agentContext.getConfigurationHandler()).andReturn(configurationHandler).anyTimes();
+        expect(agentContext.getConnectionHandler()).andReturn(connectionHandler).anyTimes();
+
+        replayTestMocks();
+    }
+
+    @AfterTest
+    public void tearDownAgain() throws Exception {
+        m_webServer.stop();
+        verifyTestMocks();
+    }
+
+    @Test
+    public void testAvailableURL() throws Exception {
+        configuration.put(DiscoveryHandlerImpl.DISCOVERY_CONFIG_KEY, m_availableURL.toExternalForm());
+        assertEquals(m_discoveryHandler.getServerUrl(), m_availableURL);
+    }
+
+    @Test
+    public void testUnavailableURL_unavailable() throws Exception {
+        configuration.put(DiscoveryHandlerImpl.DISCOVERY_CONFIG_KEY, m_unavailableURL.toExternalForm());
+        assertNull(m_discoveryHandler.getServerUrl());
+    }
+
+    @Test
+    public void testUnavailableAfterConfigUpdate() throws Exception {
+        configuration.put(DiscoveryHandlerImpl.DISCOVERY_CONFIG_KEY, m_availableURL.toExternalForm());
+        assertEquals(m_discoveryHandler.getServerUrl(), m_availableURL);
+        configuration.put(DiscoveryHandlerImpl.DISCOVERY_CONFIG_KEY, m_unavailableURL.toExternalForm());
+        assertNull(m_discoveryHandler.getServerUrl());
+    }
+
+    @Test
+    public void testAvailableAfterConfigUpdate() throws Exception {
+        configuration.put(DiscoveryHandlerImpl.DISCOVERY_CONFIG_KEY, m_unavailableURL.toExternalForm());
+        assertNull(m_discoveryHandler.getServerUrl());
+        configuration.put(DiscoveryHandlerImpl.DISCOVERY_CONFIG_KEY, m_availableURL.toExternalForm());
+        assertEquals(m_discoveryHandler.getServerUrl(), m_availableURL);
+    }
+
+    @Test
+    public void testAvailableAfterUnavailableURL() throws Exception {
+        configuration.put(DiscoveryHandlerImpl.DISCOVERY_CONFIG_KEY, m_unavailableURL.toExternalForm() + "," + m_availableURL.toExternalForm());
+        assertEquals(m_discoveryHandler.getServerUrl(), m_availableURL);
+    }
+
+    @Test
+    public void testNoURLConfig() throws Exception {
+        configuration.clear();
+        assertNull(m_discoveryHandler.getServerUrl());
+    }
+
+    @Test
+    public void testEmptyURLConfig() throws Exception {
+        configuration.put(DiscoveryHandlerImpl.DISCOVERY_CONFIG_KEY, "");
+        assertNull(m_discoveryHandler.getServerUrl());
+    }
+
+    @Test
+    public void testBadURLConfig() throws Exception {
+        configuration.put(DiscoveryHandlerImpl.DISCOVERY_CONFIG_KEY, "fooBar");
+        assertNull(m_discoveryHandler.getServerUrl());
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandlerTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandlerTest.java?rev=1513834&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandlerTest.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandlerTest.java Wed Aug 14 12:22:10 2013
@@ -0,0 +1,233 @@
+/*
+ * 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.agent.impl;
+
+import static org.easymock.EasyMock.expect;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertSame;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.net.URL;
+import java.security.DigestInputStream;
+import java.security.DigestOutputStream;
+import java.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.ace.agent.DownloadHandle;
+import org.apache.ace.agent.DownloadHandle.CompletedListener;
+import org.apache.ace.agent.DownloadHandle.ProgressListener;
+import org.apache.ace.agent.DownloadResult;
+import org.apache.ace.agent.DownloadState;
+import org.apache.ace.agent.testutil.BaseAgentTest;
+import org.apache.ace.agent.testutil.TestWebServer;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class DownloadHandlerTest extends BaseAgentTest {
+
+    static class TestErrorServlet extends HttpServlet {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
+            String retry = req.getParameter("retry");
+            if (retry != null)
+                ((HttpServletResponse) res).setHeader("Retry-After", retry);
+            int code = 500;
+            String status = req.getParameter("status");
+            if (status != null)
+                code = Integer.parseInt(status);
+            ((HttpServletResponse) res).sendError(code, "You asked for it");
+        }
+    }
+
+    private DownloadHandlerImpl m_handler;
+    private TestWebServer m_webServer;
+    private URL m_200url;
+    private File m_200file;
+    private String m_200digest;
+
+    private URL m_404url;
+    private URL m_503url;
+
+    @BeforeTest
+    public void setUpOnceAgain() throws Exception {
+
+        int port = 8883;
+
+        m_200url = new URL("http://localhost:" + port + "/testfile.txt");
+        m_404url = new URL("http://localhost:" + port + "/error?status=404");
+        m_503url = new URL("http://localhost:" + port + "/error?status=503&retry=500");
+
+        m_200file = new File(new File("generated"), "testfile.txt");
+        DigestOutputStream dos = new DigestOutputStream(new FileOutputStream(m_200file), MessageDigest.getInstance("MD5"));
+        for (int i = 0; i < 10000; i++) {
+            dos.write(String.valueOf(System.currentTimeMillis()).getBytes());
+            dos.write(" Lorum Ipsum Lorum Ipsum Lorum Ipsum Lorum Ipsum Lorum Ipsum\n".getBytes());
+        }
+        dos.close();
+        m_200digest = new BigInteger(dos.getMessageDigest().digest()).toString();
+
+        m_webServer = new TestWebServer(port, "/", "generated");
+        m_webServer.addServlet(new TestErrorServlet(), "/error");
+        m_webServer.start();
+
+        ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
+        AgentContext agentContext = addTestMock(AgentContext.class);
+        expect(agentContext.getExecutorService()).andReturn(executorService).anyTimes();
+
+        replayTestMocks();
+        m_handler = new DownloadHandlerImpl(agentContext);
+    }
+
+    @AfterTest
+    public void tearDownOnceAgain() throws Exception {
+        verifyTestMocks();
+        m_webServer.stop();
+    }
+
+    @Test
+    public void testSuccessful_noresume_result() throws Exception {
+        final DownloadHandle handle = m_handler.getHandle(m_200url).start();
+        final DownloadResult result = handle.result();
+        assertSuccessFul(result, 200, m_200digest);
+    }
+
+    @Test
+    public void testSuccessful_noresume_listener() throws Exception {
+        final CountDownLatch latch = new CountDownLatch(1);
+        final List<DownloadResult> holder = new ArrayList<DownloadResult>();
+        final DownloadHandle handle = m_handler.getHandle(m_200url)
+            .setCompletionListener(new CompletedListener() {
+                @Override
+                public void completed(DownloadResult result) {
+                    holder.add(result);
+                    latch.countDown();
+                }
+            }).start();
+        latch.await();
+        assertSuccessFul(holder.get(0), 200, m_200digest);
+        assertSame(handle.result(), holder.get(0), "Await should return same result given to the completion handler.");
+    }
+
+    @Test
+    public void testSuccessful_resume_result() throws Exception {
+        final DownloadHandle handle = m_handler.getHandle(m_200url);
+        handle.setProgressListener(new ProgressListener() {
+            @Override
+            public void progress(long contentLength, long progress) {
+                handle.stop();
+            }
+        }).start();
+        assertStopped(handle.result(), 200);
+        assertStopped(handle.start().result(), 206);
+        assertSuccessFul(handle.setProgressListener(null).start().result(), 206, m_200digest);
+    }
+
+    @Test
+    public void testFailedIO_nostatus_result() throws Exception {
+        DownloadHandle handle = m_handler.getHandle(m_200url, 2048);
+
+        DownloadResult result = ((DownloadHandleImpl) handle).start(DownloadCallableImpl.FAIL_OPENCONNECTION).result();
+        assertFailed(result, 0);
+        assertNull(result.getHeaders());
+
+        result = ((DownloadHandleImpl) handle).start(DownloadCallableImpl.FAIL_OPENINPUTSTREAM).result();
+        assertFailed(result, 200);
+        assertNotNull(result.getHeaders());
+
+        result = ((DownloadHandleImpl) handle).start(DownloadCallableImpl.FAIL_OPENOUTPUTSTREAM).result();
+        assertFailed(result, 200);
+        assertNotNull(result.getHeaders());
+
+        result = ((DownloadHandleImpl) handle).start(DownloadCallableImpl.FAIL_AFTERFIRSTWRITE).result();
+        assertFailed(result, 200);
+        assertNotNull(result.getHeaders());
+
+        result = ((DownloadHandleImpl) handle).start(DownloadCallableImpl.FAIL_AFTERFIRSTWRITE).result();
+        assertFailed(result, 206);
+        assertNotNull(result.getHeaders());
+
+        result = handle.start().result();
+        assertSuccessFul(result, 206, m_200digest);
+    }
+
+    @Test
+    public void testFailed404_noresume_result() throws Exception {
+        final DownloadResult result = m_handler.getHandle(m_404url).start().result();
+        assertFailed(result, 404);
+    }
+
+    @Test
+    public void testFailed503_noresume_result() throws Exception {
+        DownloadResult result = m_handler.getHandle(m_503url).start().result();
+        assertFailed(result, 503);
+        assertNotNull(result.getHeaders().get("Retry-After"), "Expected a Retry-After header from error servlet");
+        assertNotNull(result.getHeaders().get("Retry-After").get(0), "Expected a Retry-After header from error servlet");
+        assertEquals(result.getHeaders().get("Retry-After").get(0), "500", "Expected a Retry-After header from error servlet");
+    }
+
+    private static void assertSuccessFul(final DownloadResult result, int statusCode, String digest) throws Exception {
+        assertEquals(result.getState(), DownloadState.SUCCESSFUL, "Expected state SUCCESSFUL after succesful completion");
+        assertEquals(result.getCode(), statusCode, "Expected statusCode " + statusCode + " after successful completion");
+        assertNotNull(result.getFile(), "Expected non null file after successful completion");
+        assertNotNull(result.getHeaders(), "Expected non null headers after successful completion");
+        assertNull(result.getCause(), "Excpected null cause after successful completion");
+        assertEquals(getDigest(result.getFile()), digest, "Expected same digest after successful completion");
+    }
+
+    private static void assertFailed(final DownloadResult result, int statusCode) throws Exception {
+        assertEquals(result.getState(), DownloadState.FAILED, "DownloadState must be FAILED after failed completion");
+        assertEquals(result.getCode(), statusCode, "Expected statusCode " + statusCode + " after failed completion");
+        assertNull(result.getFile(), "File must not be null after failed completion");
+    }
+
+    private static void assertStopped(final DownloadResult result, int statusCode) throws Exception {
+        assertEquals(result.getState(), DownloadState.STOPPED, "DownloadState must be STOPPED after stopped completion");
+        assertEquals(result.getCode(), statusCode, "Expected statusCode " + statusCode + " after stopped completion");
+        assertNotNull(result.getHeaders(), "Expected headers not to be null after stopped completion");
+        assertNull(result.getFile(), "File must not be null after failed download");
+        assertNull(result.getCause(), "Excpected cause to null null after stopped completion");
+    }
+
+    private static String getDigest(File file) throws Exception {
+        DigestInputStream dis = new DigestInputStream(new FileInputStream(file), MessageDigest.getInstance("MD5"));
+        while (dis.read() != -1) {
+        }
+        dis.close();
+        return new BigInteger(dis.getMessageDigest().digest()).toString();
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/IdentificationhandlerImplTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/IdentificationhandlerImplTest.java?rev=1513834&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/IdentificationhandlerImplTest.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/impl/IdentificationhandlerImplTest.java Wed Aug 14 12:22:10 2013
@@ -0,0 +1,80 @@
+/*
+ * 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.agent.impl;
+
+import static org.easymock.EasyMock.expect;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ace.agent.ConfigurationHandler;
+import org.apache.ace.agent.IdentificationHandler;
+import org.apache.ace.agent.testutil.BaseAgentTest;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class IdentificationhandlerImplTest extends BaseAgentTest {
+
+    Map<String, String> m_configuration = new HashMap<String, String>();
+    IdentificationHandler m_identificationHandler;
+
+    @BeforeTest
+    public void setUpAgain() throws Exception {
+        AgentContext agentContext = addTestMock(AgentContext.class);
+        m_identificationHandler = new IdentificationHandlerImpl(agentContext);
+        ConfigurationHandler configurationHandler = addTestMock(ConfigurationHandler.class);
+        expect(configurationHandler.getMap()).andReturn(m_configuration).anyTimes();
+        expect(agentContext.getConfigurationHandler()).andReturn(configurationHandler).anyTimes();
+        replayTestMocks();
+    }
+
+    @AfterTest
+    public void tearDownAgain() throws Exception {
+        verifyTestMocks();
+    }
+
+    @Test
+    public void testAvailableIdentification() throws Exception {
+        m_configuration.put(IdentificationHandlerImpl.IDENTIFICATION_CONFIG_KEY, "qqq");
+        assertEquals(m_identificationHandler.getIdentification(), "qqq");
+    }
+
+    @Test
+    public void testUpdatedIdentification() throws Exception {
+        m_configuration.put(IdentificationHandlerImpl.IDENTIFICATION_CONFIG_KEY, "qqq");
+        assertEquals(m_identificationHandler.getIdentification(), "qqq");
+        m_configuration.put(IdentificationHandlerImpl.IDENTIFICATION_CONFIG_KEY, "yyy");
+        assertEquals(m_identificationHandler.getIdentification(), "yyy");
+    }
+
+    @Test
+    public void testNoIdentification() throws Exception {
+        m_configuration.clear();
+        assertNull(m_identificationHandler.getIdentification());
+    }
+
+    @Test
+    public void testEmptyIdentification() throws Exception {
+        m_configuration.put(IdentificationHandlerImpl.IDENTIFICATION_CONFIG_KEY, " ");
+        assertNull(m_identificationHandler.getIdentification());
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java?rev=1513834&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java Wed Aug 14 12:22:10 2013
@@ -0,0 +1,51 @@
+/*
+ * 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.agent.testutil;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class BaseAgentTest {
+
+    Set<Object> m_mocks = new HashSet<Object>();
+
+    protected <T extends Object> T addTestMock(Class<T> clazz) {
+        T mock = createMock(clazz);
+        m_mocks.add(mock);
+        return mock;
+    }
+
+    protected void replayTestMocks() {
+        for (Object mock : m_mocks)
+            replay(mock);
+    }
+
+    protected void verifyTestMocks() {
+        for (Object mock : m_mocks)
+            verify(mock);
+    }
+
+    protected void clearTestMocks() {
+        m_mocks.clear();
+    }
+}

Modified: ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/TestWebServer.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/TestWebServer.java?rev=1513834&r1=1513833&r2=1513834&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/TestWebServer.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/TestWebServer.java Wed Aug 14 12:22:10 2013
@@ -1,3 +1,21 @@
+/*
+ * 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.agent.testutil;
 
 import java.io.IOException;
@@ -74,6 +92,7 @@ public class TestWebServer {
             HttpServletRequest hreq = (HttpServletRequest) req;
             HttpServletResponse hres = (HttpServletResponse) res;
 
+            @SuppressWarnings("unchecked")
             Enumeration<String> attrs = hreq.getHeaderNames();
             System.out.println("> " + hreq.getMethod() + " " + hreq.getRequestURI() + " " + req.getProtocol());
             while (attrs.hasMoreElements()) {



Mime
View raw message