Source Code Cross Referenced for BasicClusterConfigurationStoreClientTest.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » farm » deployment » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » plugins » org.apache.geronimo.farm.deployment 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         *
010:         *  http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.geronimo.farm.deployment;
021:
022:        import java.io.File;
023:        import java.io.IOException;
024:        import java.net.MalformedURLException;
025:        import java.net.URL;
026:        import java.util.ArrayList;
027:        import java.util.Collection;
028:        import java.util.Collections;
029:        import java.util.Set;
030:
031:        import org.apache.geronimo.farm.config.ClusterInfo;
032:        import org.apache.geronimo.farm.config.ExtendedJMXConnectorInfo;
033:        import org.apache.geronimo.farm.config.NodeInfo;
034:        import org.apache.geronimo.deployment.plugin.remote.FileUploadClient;
035:        import org.apache.geronimo.deployment.plugin.remote.FileUploadProgress;
036:        import org.apache.geronimo.gbean.AbstractName;
037:        import org.apache.geronimo.gbean.AbstractNameQuery;
038:        import org.apache.geronimo.kernel.GBeanNotFoundException;
039:        import org.apache.geronimo.kernel.Jsr77Naming;
040:        import org.apache.geronimo.kernel.Kernel;
041:        import org.apache.geronimo.kernel.NoSuchOperationException;
042:        import org.apache.geronimo.kernel.config.ConfigurationData;
043:        import org.apache.geronimo.kernel.repository.Artifact;
044:        import org.apache.geronimo.kernel.repository.Environment;
045:
046:        import com.agical.rmock.core.describe.ExpressionDescriber;
047:        import com.agical.rmock.core.match.operator.AbstractExpression;
048:        import com.agical.rmock.extension.junit.RMockTestCase;
049:
050:        /**
051:         *
052:         * @version $Rev:$ $Date:$
053:         */
054:        public class BasicClusterConfigurationStoreClientTest extends
055:                RMockTestCase {
056:
057:            private ClusterInfo clusterInfo;
058:            private NodeInfo node1Info;
059:            private Kernel node1Kernel;
060:            private ExtendedJMXConnectorInfo connectorInfo1;
061:            private NodeInfo node2Info;
062:            private Kernel node2Kernel;
063:            private ExtendedJMXConnectorInfo connectorInfo2;
064:            private DirectoryPackager packager;
065:            private BasicClusterConfigurationStoreClient client;
066:            private FileUploadClient fileUploadClient;
067:            private AbstractNameQuery clusterConfigurationStoreNameQuery;
068:            private Artifact configId;
069:            private ConfigurationData configurationData;
070:
071:            @Override
072:            protected void setUp() throws Exception {
073:                configId = new Artifact("groupId", "artifactId", "2.0", "car");
074:                configurationData = new ConfigurationData(new Environment(
075:                        configId), new Jsr77Naming());
076:                File configurationDir = new File("configurationDir");
077:                configurationData.setConfigurationDir(configurationDir);
078:
079:                clusterInfo = (ClusterInfo) mock(ClusterInfo.class);
080:
081:                Collection<NodeInfo> nodeInfos = new ArrayList<NodeInfo>();
082:                setUpNode1Local(nodeInfos);
083:                setUpNode2Remote(nodeInfos);
084:
085:                clusterInfo.getNodeInfos();
086:                modify().multiplicity(expect.from(0)).returnValue(nodeInfos);
087:
088:                packager = (DirectoryPackager) mock(DirectoryPackager.class);
089:                fileUploadClient = (FileUploadClient) mock(FileUploadClient.class);
090:
091:                clusterConfigurationStoreNameQuery = new AbstractNameQuery(
092:                        "interfaceType");
093:
094:                client = new BasicClusterConfigurationStoreClient(
095:                        clusterConfigurationStoreNameQuery) {
096:                    @Override
097:                    protected DirectoryPackager newDirectoryPackager() {
098:                        return packager;
099:                    }
100:
101:                    @Override
102:                    protected FileUploadClient newFileUploadClient() {
103:                        return fileUploadClient;
104:                    }
105:                };
106:            }
107:
108:            private void setUpNode2Remote(Collection<NodeInfo> nodeInfos)
109:                    throws IOException {
110:                node2Info = (NodeInfo) mock(NodeInfo.class, "NodeInfo2");
111:                nodeInfos.add(node2Info);
112:                node2Kernel = node2Info.newKernel();
113:                modify().multiplicity(expect.from(0));
114:                connectorInfo2 = node2Info.getConnectorInfo();
115:                setUpConnectorInfo(connectorInfo2, false);
116:            }
117:
118:            private void setUpNode1Local(Collection<NodeInfo> nodeInfos)
119:                    throws IOException {
120:                node1Info = (NodeInfo) mock(NodeInfo.class, "NodeInfo1");
121:                nodeInfos.add(node1Info);
122:                node1Kernel = node1Info.newKernel();
123:                modify().multiplicity(expect.from(0));
124:                connectorInfo1 = node1Info.getConnectorInfo();
125:                setUpConnectorInfo(connectorInfo1, true);
126:            }
127:
128:            private void setUpConnectorInfo(
129:                    ExtendedJMXConnectorInfo connectorInfo, boolean local) {
130:                modify().multiplicity(expect.from(0));
131:                connectorInfo.isLocal();
132:                modify().multiplicity(expect.from(0)).returnValue(local);
133:                connectorInfo.getUsername();
134:                modify().multiplicity(expect.from(0)).returnValue("username");
135:                connectorInfo.getPassword();
136:                modify().multiplicity(expect.from(0)).returnValue("password");
137:            }
138:
139:            public void testInstallOK() throws Exception {
140:                packager.pack(configurationData.getConfigurationDir());
141:                File packedConfigurationDir = new File("packedConfigurationDir");
142:                modify().multiplicity(expect.exactly(2)).returnValue(
143:                        packedConfigurationDir);
144:
145:                File packedConfigurationDirRemote = updloadToNode2(packedConfigurationDir);
146:
147:                recordInstall(node1Kernel, packedConfigurationDir);
148:                recordInstall(node2Kernel, packedConfigurationDirRemote);
149:
150:                startVerification();
151:
152:                client.install(clusterInfo, configurationData);
153:            }
154:
155:            public void testInstallFailsTriggersUninstall() throws Exception {
156:                packager.pack(configurationData.getConfigurationDir());
157:                File packedConfigurationDir = new File("packedConfigurationDir");
158:                modify().returnValue(packedConfigurationDir);
159:
160:                recordInstall(node1Kernel, packedConfigurationDir);
161:
162:                node2Kernel.listGBeans(clusterConfigurationStoreNameQuery);
163:                modify().returnValue(Collections.EMPTY_SET);
164:
165:                recordUninstall(node1Kernel);
166:
167:                startVerification();
168:
169:                try {
170:                    client.install(clusterInfo, configurationData);
171:                    fail();
172:                } catch (IOException e) {
173:                }
174:            }
175:
176:            public void testUploadConfigurationFailsWithMessage()
177:                    throws Exception {
178:                packager.pack(configurationData.getConfigurationDir());
179:
180:                URL remoteDeployURL = recordGetDeployURL();
181:
182:                fileUploadClient.uploadFilesToServer(remoteDeployURL,
183:                        "username", "password", null, null);
184:                modify().args(is.AS_RECORDED, is.AS_RECORDED, is.AS_RECORDED,
185:                        is.NOT_NULL, new AbstractExpression() {
186:                            public void describeWith(ExpressionDescriber arg)
187:                                    throws IOException {
188:                            }
189:
190:                            public boolean passes(Object arg) {
191:                                FileUploadProgress progress = (FileUploadProgress) arg;
192:                                progress.fail("message");
193:                                return true;
194:                            }
195:                        });
196:
197:                startVerification();
198:
199:                try {
200:                    client.uploadConfiguration(node2Kernel, node2Info,
201:                            configurationData);
202:                    fail();
203:                } catch (IOException e) {
204:                }
205:            }
206:
207:            public void testUploadConfigurationFailsWithException()
208:                    throws Exception {
209:                packager.pack(configurationData.getConfigurationDir());
210:
211:                URL remoteDeployURL = recordGetDeployURL();
212:
213:                fileUploadClient.uploadFilesToServer(remoteDeployURL,
214:                        "username", "password", null, null);
215:                modify().args(is.AS_RECORDED, is.AS_RECORDED, is.AS_RECORDED,
216:                        is.NOT_NULL, new AbstractExpression() {
217:                            public void describeWith(ExpressionDescriber arg)
218:                                    throws IOException {
219:                            }
220:
221:                            public boolean passes(Object arg) {
222:                                FileUploadProgress progress = (FileUploadProgress) arg;
223:                                progress.fail(new Exception());
224:                                return true;
225:                            }
226:                        });
227:
228:                startVerification();
229:
230:                try {
231:                    client.uploadConfiguration(node2Kernel, node2Info,
232:                            configurationData);
233:                    fail();
234:                } catch (IOException e) {
235:                }
236:            }
237:
238:            public void testUninstall() throws Exception {
239:                recordUninstall(node1Kernel);
240:                recordUninstall(node2Kernel);
241:
242:                startVerification();
243:
244:                client.uninstall(clusterInfo, configId);
245:            }
246:
247:            private void recordUninstall(Kernel kernel)
248:                    throws GBeanNotFoundException, NoSuchOperationException,
249:                    Exception {
250:                AbstractName storeName = new AbstractName(configId, Collections
251:                        .singletonMap("name", "Store"));
252:                Set<AbstractName> storeNames = Collections.singleton(storeName);
253:
254:                kernel.listGBeans(clusterConfigurationStoreNameQuery);
255:                modify().returnValue(storeNames);
256:
257:                kernel.invoke(storeName, "uninstall",
258:                        new Object[] { configId },
259:                        new String[] { Artifact.class.getName() });
260:            }
261:
262:            private void recordInstall(Kernel kernel, File packedDir)
263:                    throws Exception {
264:                AbstractName storeName = new AbstractName(configId, Collections
265:                        .singletonMap("name", "Store"));
266:                Set<AbstractName> storeNames = Collections.singleton(storeName);
267:
268:                kernel.listGBeans(clusterConfigurationStoreNameQuery);
269:                modify().returnValue(storeNames);
270:                kernel.invoke(storeName, "install", new Object[] {
271:                        configurationData, packedDir },
272:                        new String[] { ConfigurationData.class.getName(),
273:                                File.class.getName() });
274:            }
275:
276:            private File updloadToNode2(final File packedConfigurationDir)
277:                    throws MalformedURLException {
278:                URL remoteDeployURL = recordGetDeployURL();
279:
280:                final File packedConfigurationDirRemote = new File(
281:                        "packedConfigurationDirRemote");
282:                fileUploadClient.uploadFilesToServer(remoteDeployURL,
283:                        "username", "password", null, null);
284:                modify().args(is.AS_RECORDED, is.AS_RECORDED, is.AS_RECORDED,
285:                        new AbstractExpression() {
286:                            public void describeWith(ExpressionDescriber arg)
287:                                    throws IOException {
288:                            }
289:
290:                            public boolean passes(Object arg) {
291:                                File[] files = (File[]) arg;
292:                                assertSame(packedConfigurationDir, files[0]);
293:                                files[0] = packedConfigurationDirRemote;
294:                                return true;
295:                            }
296:                        }, is.NOT_NULL);
297:                return packedConfigurationDirRemote;
298:            }
299:
300:            private URL recordGetDeployURL() throws MalformedURLException {
301:                fileUploadClient.getRemoteDeployUploadURL(node2Kernel);
302:                URL remoteDeployURL = new URL("http", "localhost", "file");
303:                modify().returnValue(remoteDeployURL);
304:                return remoteDeployURL;
305:            }
306:
307:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.