geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdam...@apache.org
Subject svn commit: r594117 [2/2] - in /geronimo/server/trunk: assemblies/geronimo-jetty6-javaee5/src/main/assembly/ assemblies/geronimo-jetty6-javaee5/src/main/resources/cluster-repository/ assemblies/geronimo-jetty6-javaee5/src/main/resources/master-reposito...
Date Mon, 12 Nov 2007 13:35:51 GMT
Added: geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationControllerTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationControllerTest.java?rev=594117&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationControllerTest.java
(added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationControllerTest.java
Mon Nov 12 05:35:48 2007
@@ -0,0 +1,158 @@
+/*
+ * 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.geronimo.clustering.deployment;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.geronimo.clustering.config.ClusterInfo;
+import org.apache.geronimo.clustering.config.NodeInfo;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.NoSuchConfigException;
+import org.apache.geronimo.kernel.repository.Artifact;
+
+import com.agical.rmock.extension.junit.RMockTestCase;
+
+/**
+ *
+ * @version $Rev:$ $Date:$
+ */
+public class BasicClusterConfigurationControllerTest extends RMockTestCase {
+
+    private ClusterInfo clusterInfo;
+    private NodeInfo nodeInfo;
+    private String nodeName;
+    private Artifact configurationId;
+    private ConfigurationManager configurationManager;
+
+    @Override
+    protected void setUp() throws Exception {
+        nodeName = "nodeName";
+
+        clusterInfo = (ClusterInfo) mock(ClusterInfo.class);
+
+        Collection<NodeInfo> nodeInfos = new ArrayList<NodeInfo>();
+        
+        nodeInfo = (NodeInfo) mock(NodeInfo.class);
+        nodeInfos.add(nodeInfo);
+        nodeInfo.getName();
+        modify().multiplicity(expect.from(0)).returnValue(nodeName);
+        nodeInfo.newKernel();
+        modify().multiplicity(expect.from(0));
+        
+        NodeInfo secondNodeInfo = (NodeInfo) mock(NodeInfo.class);
+        nodeInfos.add(secondNodeInfo);
+        secondNodeInfo.getName();
+        modify().multiplicity(expect.from(0)).returnValue("unkown");
+        
+        clusterInfo.getNodeInfos();
+        modify().multiplicity(expect.from(0)).returnValue(nodeInfos);
+        
+        configurationId = new Artifact("groupId", "artifactId", "2.0", "car");
+        configurationManager = (ConfigurationManager) mock(ConfigurationManager.class);
+    }
+    
+    public void testDoNotStartConfigurationUponStart() throws Exception {
+        startVerification();
+
+        BasicClusterConfigurationController controller = newController(false, false);
+        
+        controller.doStart();
+    }
+
+    public void testStartConfigurationUponStartOK() throws Exception {
+        configurationManager.isLoaded(configurationId);
+        modify().returnValue(false);
+        configurationManager.loadConfiguration(configurationId);
+        configurationManager.startConfiguration(configurationId);
+        
+        startVerification();
+
+        BasicClusterConfigurationController controller = newController(true, false);
+        
+        controller.doStart();
+    }
+    
+    public void testStartConfigurationFailsUponStartAndIgnore() throws Exception {
+        configurationManager.isLoaded(configurationId);
+        modify().returnValue(true);
+        configurationManager.startConfiguration(configurationId);
+        modify().throwException(new NoSuchConfigException(configurationId));
+        
+        startVerification();
+
+        BasicClusterConfigurationController controller = newController(true, true);
+        
+        controller.doStart();
+    }
+    
+    public void testStartConfigurationFailsUponStart() throws Exception {
+        configurationManager.isLoaded(configurationId);
+        modify().returnValue(true);
+        configurationManager.startConfiguration(configurationId);
+        NoSuchConfigException expectedException = new NoSuchConfigException(configurationId);
+        modify().throwException(expectedException);
+        
+        startVerification();
+
+        BasicClusterConfigurationController controller = newController(true, false);
+
+        try {
+            controller.startConfiguration();
+            fail();
+        } catch (Exception e) {
+            assertSame(expectedException, e);
+        }
+    }
+    
+    public void testStopConfiguration() throws Exception {
+        configurationManager.stopConfiguration(configurationId);
+
+        startVerification();
+
+        BasicClusterConfigurationController controller = newController(true, false);
+        controller.doStop();
+    }
+
+    public void testFail() throws Exception {
+        configurationManager.stopConfiguration(configurationId);
+        
+        startVerification();
+        
+        BasicClusterConfigurationController controller = newController(true, false);
+        controller.doFail();
+    }
+    
+    private BasicClusterConfigurationController newController(boolean startConfigurationUponStart,
+            boolean ignoreStartConfigurationFailureUponStart) {
+        return new BasicClusterConfigurationController(clusterInfo,
+            nodeName,
+            configurationId,
+            startConfigurationUponStart,
+            ignoreStartConfigurationFailureUponStart) {
+            @Override
+            protected ConfigurationManager newConfigurationManager(Kernel kernel) {
+                return configurationManager;
+            }
+        };
+    }
+    
+}

Added: geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationStoreClientTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationStoreClientTest.java?rev=594117&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationStoreClientTest.java
(added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationStoreClientTest.java
Mon Nov 12 05:35:48 2007
@@ -0,0 +1,274 @@
+/*
+ * 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.geronimo.clustering.deployment;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.geronimo.clustering.config.ClusterInfo;
+import org.apache.geronimo.clustering.config.ExtendedJMXConnectorInfo;
+import org.apache.geronimo.clustering.config.NodeInfo;
+import org.apache.geronimo.deployment.plugin.remote.FileUploadClient;
+import org.apache.geronimo.deployment.plugin.remote.FileUploadProgress;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Jsr77Naming;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.NoSuchOperationException;
+import org.apache.geronimo.kernel.config.ConfigurationData;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.Environment;
+
+import com.agical.rmock.core.describe.ExpressionDescriber;
+import com.agical.rmock.core.match.operator.AbstractExpression;
+import com.agical.rmock.extension.junit.RMockTestCase;
+
+/**
+ *
+ * @version $Rev:$ $Date:$
+ */
+public class BasicClusterConfigurationStoreClientTest extends RMockTestCase {
+
+    private ClusterInfo clusterInfo;
+    private NodeInfo node1Info;
+    private Kernel node1Kernel;
+    private ExtendedJMXConnectorInfo connectorInfo1;
+    private NodeInfo node2Info;
+    private Kernel node2Kernel;
+    private ExtendedJMXConnectorInfo connectorInfo2;
+    private DirectoryPackager packager;
+    private BasicClusterConfigurationStoreClient client;
+    private FileUploadClient fileUploadClient;
+    private AbstractNameQuery clusterConfigurationStoreNameQuery;
+    private Artifact configId;
+    private ConfigurationData configurationData;
+
+    @Override
+    protected void setUp() throws Exception {
+        configId = new Artifact("groupId", "artifactId", "2.0", "car");
+        configurationData = new ConfigurationData(new Environment(configId), new Jsr77Naming());
+        File configurationDir = new File("configurationDir");
+        configurationData.setConfigurationDir(configurationDir);
+
+        clusterInfo = (ClusterInfo) mock(ClusterInfo.class);
+
+        Collection<NodeInfo> nodeInfos = new ArrayList<NodeInfo>();
+        setUpNode1Local(nodeInfos);
+        setUpNode2Remote(nodeInfos);
+        
+        clusterInfo.getNodeInfos();
+        modify().multiplicity(expect.from(0)).returnValue(nodeInfos);
+        
+        packager = (DirectoryPackager) mock(DirectoryPackager.class);
+        fileUploadClient = (FileUploadClient) mock(FileUploadClient.class);
+        
+        clusterConfigurationStoreNameQuery = new AbstractNameQuery("interfaceType");
+
+        client = new BasicClusterConfigurationStoreClient(clusterConfigurationStoreNameQuery)
{
+            @Override
+            protected DirectoryPackager newDirectoryPackager() {
+                return packager;
+            }
+            @Override
+            protected FileUploadClient newFileUploadClient() {
+                return fileUploadClient;
+            }
+        };
+    }
+
+    private void setUpNode2Remote(Collection<NodeInfo> nodeInfos) throws IOException
{
+        node2Info = (NodeInfo) mock(NodeInfo.class);
+        nodeInfos.add(node2Info);
+        node2Kernel = node2Info.newKernel();
+        modify().multiplicity(expect.from(0));
+        connectorInfo2 = node2Info.getConnectorInfo();
+        setUpConnectorInfo(connectorInfo2, false);
+    }
+
+    private void setUpNode1Local(Collection<NodeInfo> nodeInfos) throws IOException
{
+        node1Info = (NodeInfo) mock(NodeInfo.class);
+        nodeInfos.add(node1Info);
+        node1Kernel = node1Info.newKernel();
+        modify().multiplicity(expect.from(0));
+        connectorInfo1 = node1Info.getConnectorInfo();
+        setUpConnectorInfo(connectorInfo1, true);
+    }
+
+    private void setUpConnectorInfo(ExtendedJMXConnectorInfo connectorInfo, boolean local)
{
+        modify().multiplicity(expect.from(0));
+        connectorInfo.isLocal();
+        modify().multiplicity(expect.from(0)).returnValue(local);
+        connectorInfo.getUsername();
+        modify().multiplicity(expect.from(0)).returnValue("username");
+        connectorInfo.getPassword();
+        modify().multiplicity(expect.from(0)).returnValue("password");
+    }
+    
+    public void testInstallOK() throws Exception {
+        packager.pack(configurationData.getConfigurationDir());
+        File packedConfigurationDir = new File("packedConfigurationDir");
+        modify().multiplicity(expect.exactly(2)).returnValue(packedConfigurationDir);
+        
+        File packedConfigurationDirRemote = updloadToNode2(packedConfigurationDir);
+        
+        recordInstall(node1Kernel, packedConfigurationDir);
+        recordInstall(node2Kernel, packedConfigurationDirRemote);
+        
+        startVerification();
+        
+        client.install(clusterInfo, configurationData);   
+    }
+
+    public void testInstallFailsTriggersUninstall() throws Exception {
+        packager.pack(configurationData.getConfigurationDir());
+        File packedConfigurationDir = new File("packedConfigurationDir");
+        modify().returnValue(packedConfigurationDir);
+        
+        recordInstall(node1Kernel, packedConfigurationDir);
+        
+        node2Kernel.listGBeans(clusterConfigurationStoreNameQuery);
+        modify().returnValue(Collections.EMPTY_SET);
+        
+        recordUninstall(node1Kernel);
+
+        startVerification();
+
+        try {
+            client.install(clusterInfo, configurationData);
+            fail();
+        } catch (IOException e) {
+        }
+    }
+
+    public void testUploadConfigurationFailsWithMessage() throws Exception {
+        packager.pack(configurationData.getConfigurationDir());
+        
+        URL remoteDeployURL = recordGetDeployURL();
+        
+        fileUploadClient.uploadFilesToServer(remoteDeployURL, "username", "password", null,
null);
+        modify().args(is.AS_RECORDED, is.AS_RECORDED, is.AS_RECORDED, is.NOT_NULL, new AbstractExpression()
{
+            public void describeWith(ExpressionDescriber arg) throws IOException {
+            }
+
+            public boolean passes(Object arg) {
+                FileUploadProgress progress = (FileUploadProgress) arg;
+                progress.fail("message");
+                return true;
+            }
+        });
+        
+        startVerification();
+
+        try {
+            client.uploadConfiguration(node2Kernel, node2Info, configurationData);
+            fail();
+        } catch (IOException e) {
+        }
+    }
+
+    public void testUploadConfigurationFailsWithException() throws Exception {
+        packager.pack(configurationData.getConfigurationDir());
+        
+        URL remoteDeployURL = recordGetDeployURL();
+        
+        fileUploadClient.uploadFilesToServer(remoteDeployURL, "username", "password", null,
null);
+        modify().args(is.AS_RECORDED, is.AS_RECORDED, is.AS_RECORDED, is.NOT_NULL, new AbstractExpression()
{
+            public void describeWith(ExpressionDescriber arg) throws IOException {
+            }
+
+            public boolean passes(Object arg) {
+                FileUploadProgress progress = (FileUploadProgress) arg;
+                progress.fail(new Exception());
+                return true;
+            }
+        });
+        
+        startVerification();
+
+        try {
+            client.uploadConfiguration(node2Kernel, node2Info, configurationData);
+            fail();
+        } catch (IOException e) {
+        }
+    }
+    
+    public void testUninstall() throws Exception {
+        recordUninstall(node1Kernel);
+        recordUninstall(node2Kernel);
+
+        startVerification();
+
+        client.uninstall(clusterInfo, configId);
+    }
+    
+    private void recordUninstall(Kernel kernel) throws GBeanNotFoundException, NoSuchOperationException,
Exception {
+        AbstractName storeName = new AbstractName(configId, Collections.singletonMap("name",
"Store"));
+        Set<AbstractName> storeNames = Collections.singleton(storeName);
+
+        kernel.listGBeans(clusterConfigurationStoreNameQuery);
+        modify().returnValue(storeNames);
+        
+        kernel.invoke(storeName, "uninstall", new Object[] {configId}, new String[] {Artifact.class.getName()});
+    }
+    
+    private void recordInstall(Kernel kernel, File packedDir) throws Exception {
+        AbstractName storeName = new AbstractName(configId, Collections.singletonMap("name",
"Store"));
+        Set<AbstractName> storeNames = Collections.singleton(storeName);
+
+        kernel.listGBeans(clusterConfigurationStoreNameQuery);
+        modify().returnValue(storeNames);
+        kernel.invoke(storeName, "install", new Object[] {configurationData, packedDir},
+            new String[] {ConfigurationData.class.getName(), File.class.getName()});
+    }
+
+    private File updloadToNode2(final File packedConfigurationDir) throws MalformedURLException
{
+        URL remoteDeployURL = recordGetDeployURL();
+        
+        final File packedConfigurationDirRemote = new File("packedConfigurationDirRemote");
+        fileUploadClient.uploadFilesToServer(remoteDeployURL, "username", "password", null,
null);
+        modify().args(is.AS_RECORDED, is.AS_RECORDED, is.AS_RECORDED, new AbstractExpression()
{
+            public void describeWith(ExpressionDescriber arg) throws IOException {
+            }
+
+            public boolean passes(Object arg) {
+                File[] files = (File[]) arg;
+                assertSame(packedConfigurationDir, files[0]);
+                files[0] = packedConfigurationDirRemote;
+                return true;
+            }
+        },  is.NOT_NULL);
+        return packedConfigurationDirRemote;
+    }
+
+    private URL recordGetDeployURL() throws MalformedURLException {
+        fileUploadClient.getRemoteDeployUploadURL(node2Kernel);
+        URL remoteDeployURL = new URL("http", "localhost", "file");
+        modify().returnValue(remoteDeployURL);
+        return remoteDeployURL;
+    }
+
+}

Added: geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationStoreTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationStoreTest.java?rev=594117&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationStoreTest.java
(added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicClusterConfigurationStoreTest.java
Mon Nov 12 05:35:48 2007
@@ -0,0 +1,98 @@
+/*
+ * 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.geronimo.clustering.deployment;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.geronimo.kernel.Jsr77Naming;
+import org.apache.geronimo.kernel.config.ConfigurationData;
+import org.apache.geronimo.kernel.config.ConfigurationStore;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.Environment;
+
+import com.agical.rmock.core.describe.ExpressionDescriber;
+import com.agical.rmock.core.match.operator.AbstractExpression;
+import com.agical.rmock.extension.junit.RMockTestCase;
+
+/**
+ *
+ * @version $Rev:$ $Date:$
+ */
+public class BasicClusterConfigurationStoreTest extends RMockTestCase {
+
+    private ConfigurationStore actualConfigurationStore;
+    private DirectoryPackager directoryPackager;
+    private BasicClusterConfigurationStore store;
+    private Artifact configId;
+
+    @Override
+    protected void setUp() throws Exception {
+        actualConfigurationStore = (ConfigurationStore) mock(ConfigurationStore.class);
+        directoryPackager = (DirectoryPackager) mock(DirectoryPackager.class);
+        store = new BasicClusterConfigurationStore(actualConfigurationStore) {
+            @Override
+            protected DirectoryPackager newDirectoryPackager() {
+                return directoryPackager;
+            }
+            @Override
+            protected void deleteDir(File packedConfigurationDir) {
+            }
+        };
+        configId = new Artifact("groupId", "artifactId", "2.0", "car");
+    }
+    
+    public void testInstall() throws Exception {
+        ConfigurationData configurationData = new ConfigurationData(new Environment(configId),
new Jsr77Naming());
+        File packedConfigurationDir = new File("packedConfigurationDir");
+        final File configurationDir = new File("configurationDir");
+        
+        actualConfigurationStore.createNewConfigurationDir(configId);
+        modify().returnValue(configurationDir);
+
+        directoryPackager.unpack(configurationDir, packedConfigurationDir);
+        modify().returnValue(configurationDir);
+        
+        actualConfigurationStore.install(configurationData);
+        modify().args(new AbstractExpression() {
+            public void describeWith(ExpressionDescriber arg) throws IOException {
+            }
+
+            public boolean passes(Object arg) {
+                ConfigurationData configurationData = (ConfigurationData) arg;
+                assertSame(configurationDir, configurationData.getConfigurationDir());
+                return true;
+            }
+        });
+        
+        startVerification();
+        
+        store.install(configurationData, packedConfigurationDir);
+    }
+    
+    public void testUninstall() throws Exception {
+        actualConfigurationStore.uninstall(configId);
+        
+        startVerification();
+        
+        store.uninstall(configId);
+    }
+    
+}

Added: geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicMasterConfigurationNameBuilderTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicMasterConfigurationNameBuilderTest.java?rev=594117&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicMasterConfigurationNameBuilderTest.java
(added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/BasicMasterConfigurationNameBuilderTest.java
Mon Nov 12 05:35:48 2007
@@ -0,0 +1,65 @@
+/*
+ * 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.geronimo.clustering.deployment;
+
+import org.apache.geronimo.kernel.repository.Artifact;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @version $Rev:$ $Date:$
+ */
+public class BasicMasterConfigurationNameBuilderTest extends TestCase {
+
+    private BasicMasterConfigurationNameBuilder builder;
+
+    @Override
+    protected void setUp() throws Exception {
+        builder = new BasicMasterConfigurationNameBuilder();
+    }
+    
+    public void testIsMasterConfigurationName() throws Exception {
+        Artifact artifact = new Artifact("groupId", "artifactId", "2.0", "car");
+        assertFalse(builder.isMasterConfigurationName(artifact));
+        Artifact masterConfiguration = builder.buildMasterConfigurationName(artifact);
+        assertTrue(builder.isMasterConfigurationName(masterConfiguration));
+    }
+    
+    public void testBuildMasterConfigurationName() throws Exception {
+        Artifact artifact = new Artifact("groupId", "artifactId", "2.0", "car");
+        Artifact masterConfiguration = builder.buildMasterConfigurationName(artifact);
+        assertEquals(artifact.getGroupId(), masterConfiguration.getGroupId());
+        assertEquals(artifact.getArtifactId() + "_G_MASTER", masterConfiguration.getArtifactId());
+        assertEquals(artifact.getVersion(), masterConfiguration.getVersion());
+        assertEquals(artifact.getType(), masterConfiguration.getType());
+    }
+    
+    public void testBuildSlaveConfigurationName() throws Exception {
+        Artifact artifact = new Artifact("groupId", "artifactId", "2.0", "car");
+        Artifact masterConfiguration = builder.buildMasterConfigurationName(artifact);
+        Artifact actualArtifact = builder.buildSlaveConfigurationName(masterConfiguration);
+        assertEquals(artifact.getGroupId(), actualArtifact.getGroupId());
+        assertEquals(artifact.getArtifactId(), actualArtifact.getArtifactId());
+        assertEquals(artifact.getVersion(), actualArtifact.getVersion());
+        assertEquals(artifact.getType(), actualArtifact.getType());
+    }
+    
+}

Added: geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/MasterConfigurationStoreTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/MasterConfigurationStoreTest.java?rev=594117&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/MasterConfigurationStoreTest.java
(added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/MasterConfigurationStoreTest.java
Mon Nov 12 05:35:48 2007
@@ -0,0 +1,394 @@
+/*
+ * 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.geronimo.clustering.deployment;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+import junit.framework.AssertionFailedError;
+
+import org.apache.geronimo.clustering.config.ClusterInfo;
+import org.apache.geronimo.clustering.config.NodeInfo;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.kernel.Jsr77Naming;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.ConfigurationData;
+import org.apache.geronimo.kernel.config.ConfigurationInfo;
+import org.apache.geronimo.kernel.config.ConfigurationModuleType;
+import org.apache.geronimo.kernel.config.ConfigurationStore;
+import org.apache.geronimo.kernel.config.InvalidConfigException;
+import org.apache.geronimo.kernel.config.NoSuchConfigException;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.kernel.repository.WritableListableRepository;
+
+import com.agical.rmock.core.describe.ExpressionDescriber;
+import com.agical.rmock.core.match.operator.AbstractExpression;
+import com.agical.rmock.extension.junit.RMockTestCase;
+
+/**
+ *
+ * @version $Rev:$ $Date:$
+ */
+public class MasterConfigurationStoreTest extends RMockTestCase {
+
+    private Kernel kernel;
+    private WritableListableRepository repository;
+    private ClusterInfo clusterInfo;
+    private ClusterConfigurationStoreClient storeClient;
+    private AbstractName clusterInfoName;
+    private ConfigurationStore delegate;
+    private MasterConfigurationNameBuilder nameBuilder;
+    private Artifact configId;
+
+    @Override
+    protected void setUp() throws Exception {
+        kernel = (Kernel) mock(Kernel.class);
+        repository = (WritableListableRepository) mock(WritableListableRepository.class);
+        clusterInfo = (ClusterInfo) mock(ClusterInfo.class);
+        storeClient = (ClusterConfigurationStoreClient) mock(ClusterConfigurationStoreClient.class);
+        kernel.getAbstractNameFor(clusterInfo);
+        configId = new Artifact("groupId", "artifactId", "2.0", "car");
+        clusterInfoName = new AbstractName(configId, Collections.singletonMap("name", "ClusterInfo"));
+        modify().returnValue(clusterInfoName);
+        
+        delegate = (ConfigurationStore) mock(ConfigurationStore.class);
+        nameBuilder = (MasterConfigurationNameBuilder) mock(MasterConfigurationNameBuilder.class);
+    }
+
+    private MasterConfigurationStore newMasterConfigurationStore() {
+        return new MasterConfigurationStore(kernel,
+            "objectName",
+            repository,
+            new Environment(),
+            clusterInfo,
+            storeClient) {
+            @Override
+            protected ConfigurationStore newConfigurationStore(Kernel kernel,
+                String objectName,
+                WritableListableRepository repository) {
+                return delegate;
+            }
+            @Override
+            protected MasterConfigurationNameBuilder newMasterConfigurationBuilder() {
+                return nameBuilder;
+            }
+        };
+    }
+    
+    public void testContainsConfigurationOK() throws Exception {
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(true);
+
+        delegate.containsConfiguration(configId);
+        modify().returnValue(true);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        assertTrue(store.containsConfiguration(configId));
+    }
+    
+    public void testContainsConfigurationFailsWhenNotMasterConfigId() throws Exception {
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(false);
+
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        assertFalse(store.containsConfiguration(configId));
+    }
+
+    public void testDelegateCreateNewConfigurationDir() throws Exception {
+        delegate.createNewConfigurationDir(configId);
+        File expectedFile = new File("confDir");
+        modify().returnValue(expectedFile);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        assertSame(expectedFile, store.createNewConfigurationDir(configId));
+    }
+    
+    public void testExportFailsWhenNotMasterConfigId() throws Exception {
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(false);
+
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        try {
+            store.exportConfiguration(configId, null);
+            fail();
+        } catch (NoSuchConfigException e) {
+        }
+    }
+    
+    public void testDelegateExport() throws Exception {
+        OutputStream out = new ByteArrayOutputStream();
+        
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(true);
+        
+        delegate.exportConfiguration(configId, out);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        store.exportConfiguration(configId, out);
+    }
+
+    public void testDelegateGetAbstractName() throws Exception {
+        delegate.getAbstractName();
+        modify().returnValue(clusterInfoName);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        assertSame(clusterInfoName, store.getAbstractName());
+    }
+    
+    public void testDelegateGetObjectName() throws Exception {
+        delegate.getObjectName();
+        String expectedName = "name";
+        modify().returnValue(expectedName);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        assertSame(expectedName, store.getObjectName());
+    }
+    
+    public void testIsInPlaceConfigurationWhenNotMasterConfigId() throws Exception {
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(false);
+
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        try {
+            store.isInPlaceConfiguration(configId);
+            fail();
+        } catch (NoSuchConfigException e) {
+        }
+    }
+
+    public void testIsInPlaceConfigurationReturnsFalse() throws Exception {
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(true);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        assertFalse(store.isInPlaceConfiguration(configId));
+    }
+    
+    public void testListConfigurationFilterNoneMasterConfigIds() throws Exception {
+        List<ConfigurationInfo> configurationInfos = new ArrayList<ConfigurationInfo>();
+
+        ConfigurationInfo configurationInfo =  newConfigurationInfo(configId);
+        configurationInfos.add(configurationInfo);
+        
+        Artifact configId2 = new Artifact("groupId", "artifactId2", "2.0", "car");
+        ConfigurationInfo configurationInfo2 =  newConfigurationInfo(configId2);
+        configurationInfos.add(configurationInfo2);
+        
+        delegate.listConfigurations();
+        modify().returnValue(configurationInfos);
+        
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(true);
+        
+        nameBuilder.isMasterConfigurationName(configId2);
+        modify().returnValue(false);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        List<ConfigurationInfo> listedConfigurations = store.listConfigurations();
+        assertEquals(1, listedConfigurations.size());
+        assertTrue(listedConfigurations.contains(configurationInfo));
+    }
+
+    public void testLoadConfigurationWhenNotMasterConfigId() throws Exception {
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(false);
+
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        try {
+            store.loadConfiguration(configId);
+            fail();
+        } catch (NoSuchConfigException e) {
+        }
+    }
+
+    public void testDelegateLoadConfiguration() throws Exception {
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(true);
+        
+        delegate.loadConfiguration(configId);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        store.loadConfiguration(configId);
+    }
+
+    public void testResolveWhenNotMasterConfigId() throws Exception {
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(false);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        try {
+            store.resolve(configId, null, null);
+            fail();
+        } catch (NoSuchConfigException e) {
+        }
+    }
+    
+    public void testDelegateResolve() throws Exception {
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(true);
+        
+        delegate.resolve(configId, null, null);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        store.resolve(configId, null, null);
+    }
+    
+    public void testUninstall() throws Exception {
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(true);
+        
+        nameBuilder.buildSlaveConfigurationName(configId);
+        Artifact slaveId = new Artifact("groupId", "slaveId", "2.0", "car");
+        modify().returnValue(slaveId);
+
+        storeClient.uninstall(clusterInfo, slaveId);
+        
+        delegate.uninstall(slaveId);
+        delegate.uninstall(configId);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        store.uninstall(configId);
+    }
+    
+    public void testUninstallWhenNotMasterConfigId() throws Exception {
+        nameBuilder.isMasterConfigurationName(configId);
+        modify().returnValue(false);
+        
+        startVerification();
+        
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        try {
+            store.uninstall(configId);
+            fail();
+        } catch (NoSuchConfigException e) {
+        }
+    }
+    
+    public void testInstallOK() throws Exception {
+        ConfigurationData configurationData = new ConfigurationData(ConfigurationModuleType.CAR,
+            new LinkedHashSet(),
+            new ArrayList(),
+            Collections.EMPTY_MAP,
+            new Environment(configId),
+            new File("configurationDir"),
+            null,
+            new Jsr77Naming());
+        
+        final Artifact masterId = new Artifact("groupId", "masterId", "2.0", "car");
+        nameBuilder.buildMasterConfigurationName(configId);
+        modify().returnValue(masterId);
+        
+        storeClient.install(clusterInfo, configurationData);
+        
+        delegate.install(configurationData);
+        
+        NodeInfo nodeInfo = (NodeInfo) mock(NodeInfo.class);
+        nodeInfo.getName();
+        final String nodeName = "nodeName";
+        modify().multiplicity(expect.from(0)).returnValue(nodeName);
+        clusterInfo.getNodeInfos();
+        modify().returnValue(Collections.singleton(nodeInfo));
+        
+        delegate.createNewConfigurationDir(masterId);
+        final File masterDir = new File("masterDir");
+        modify().returnValue(masterDir);
+        
+        delegate.install(null);
+        modify().args(new AbstractExpression() {
+            public void describeWith(ExpressionDescriber arg) throws IOException {
+            }
+
+            public boolean passes(Object arg) {
+                ConfigurationData configurationData = (ConfigurationData) arg;
+                assertSame(masterId, configurationData.getId());
+                assertSame(masterDir, configurationData.getConfigurationDir());
+                
+                List<GBeanData> gbeans;
+                try {
+                    gbeans = configurationData.getGBeans(getClass().getClassLoader());
+                } catch (InvalidConfigException e) {
+                    throw new AssertionFailedError();
+                }
+                assertEquals(1, gbeans.size());
+                GBeanData gbean = gbeans.get(0);
+                assertEquals(BasicClusterConfigurationController.GBEAN_INFO, gbean.getGBeanInfo());
+                assertEquals(configId, gbean.getAttribute(BasicClusterConfigurationController.GBEAN_ATTR_ARTIFACT));
+                assertEquals(nodeName, gbean.getAttribute(BasicClusterConfigurationController.GBEAN_ATTR_NODE_NAME));
+                return true;
+            }
+        });
+        
+        startVerification();
+
+        MasterConfigurationStore store = newMasterConfigurationStore();
+        store.install(configurationData);
+    }
+    
+    private ConfigurationInfo newConfigurationInfo(Artifact configId) {
+        return new ConfigurationInfo(
+            clusterInfoName, 
+            configId,
+            ConfigurationModuleType.CAR,
+            1l, 
+            Collections.EMPTY_SET, 
+            Collections.EMPTY_SET,
+            null);
+    }
+    
+    
+}

Added: geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/ZipDirectoryPackagerTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/ZipDirectoryPackagerTest.java?rev=594117&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/ZipDirectoryPackagerTest.java
(added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/java/org/apache/geronimo/clustering/deployment/ZipDirectoryPackagerTest.java
Mon Nov 12 05:35:48 2007
@@ -0,0 +1,60 @@
+/*
+ * 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.geronimo.clustering.deployment;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.apache.geronimo.testsupport.TestSupport;
+
+/**
+ *
+ * @version $Rev:$ $Date:$
+ */
+public class ZipDirectoryPackagerTest extends TestSupport {
+
+    public void testPackAndUnpack() throws Exception {
+        ZipDirectoryPackager packager = new ZipDirectoryPackager();
+        File packedDir = packager.pack(new File(BASEDIR, "src/test/resources/folderToZip"));
+        
+        File unpackedDir = packager.unpack(packedDir);
+        
+        assertFile(unpackedDir, "folder1/file1");
+        assertFile(unpackedDir, "folder1/file2");
+        assertFile(unpackedDir, "folder2/file1");
+    }
+
+    private void assertFile(File unpackedDir, String fileName) throws FileNotFoundException,
IOException {
+        File file = new File(unpackedDir, fileName);
+        assertTrue(file.exists());
+        
+        InputStream in = new FileInputStream(file);
+        BufferedReader reader2 = new BufferedReader(new InputStreamReader(in));
+        String line = reader2.readLine();
+        assertEquals(fileName, line);
+        in.close();
+    }
+    
+}

Added: geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder1/file1
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder1/file1?rev=594117&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder1/file1
(added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder1/file1
Mon Nov 12 05:35:48 2007
@@ -0,0 +1 @@
+folder1/file1
\ No newline at end of file

Added: geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder1/file2
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder1/file2?rev=594117&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder1/file2
(added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder1/file2
Mon Nov 12 05:35:48 2007
@@ -0,0 +1 @@
+folder1/file2
\ No newline at end of file

Added: geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder2/file1
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder2/file1?rev=594117&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder2/file1
(added)
+++ geronimo/server/trunk/plugins/clustering/geronimo-clustering/src/test/resources/folderToZip/folder2/file1
Mon Nov 12 05:35:48 2007
@@ -0,0 +1 @@
+folder2/file1
\ No newline at end of file



Mime
View raw message