001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TestComponentQueryImpl.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.management.registry.xml;
030:
031: import com.sun.jbi.ComponentState;
032: import com.sun.jbi.ComponentInfo;
033: import com.sun.jbi.ComponentType;
034: import com.sun.jbi.ComponentQuery;
035: import com.sun.jbi.management.registry.Registry;
036: import com.sun.jbi.management.registry.RegistryBuilder;
037: import com.sun.jbi.management.registry.RegistryException;
038:
039: import com.sun.jbi.management.repository.Repository;
040: import com.sun.jbi.management.repository.ArchiveType;
041:
042: import com.sun.jbi.management.system.Util;
043:
044: import java.io.File;
045: import java.util.List;
046:
047: public class TestComponentQueryImpl extends junit.framework.TestCase {
048: /**
049: * The sample Configuration Directory.
050: */
051: private String mConfigDir = null;
052: private File mRegFile;
053: String mRegFilePath;
054: String mRegGoodFilePath;
055: String mEngineZipPath;
056: String mBindingZipPath;
057: String mSharedLibraryZipPath;
058: String mServiceAssemblyZipPath;
059:
060: static final String ENGINE_NAME = "SunSequencingEngine";
061: static final String BINDING_NAME = "SunJMSBinding";
062: static final String SHARED_LIBRARY_NAME = "SunWSDLSharedLibrary";
063: static final String SERVICE_ASSEMBLY_NAME = "CompositeApplication";
064:
065: public TestComponentQueryImpl(String aTestName) {
066: super (aTestName);
067:
068: String srcroot = System.getProperty("junit.srcroot");
069: String manage = "/runtime/manage"; // open-esb build
070: mConfigDir = srcroot + manage + "/bld/test-classes/testdata/";
071:
072: java.io.File f = new java.io.File(srcroot + manage);
073: if (!f.exists()) {
074: manage = "/shasta/manage"; // mainline/whitney build
075: mConfigDir = srcroot + manage + "/bld/regress/testdata/";
076: }
077:
078: mRegFilePath = mConfigDir + File.separator + "jbi-registry.xml";
079: mRegGoodFilePath = mConfigDir + File.separator
080: + "jbi-registry-good.xml";
081: mEngineZipPath = mConfigDir + "component.zip";
082: mServiceAssemblyZipPath = mConfigDir + "service-assembly.zip";
083: mSharedLibraryZipPath = mConfigDir + "wsdlsl.jar";
084: mBindingZipPath = mConfigDir + "jmsbinding.jar";
085:
086: mRegFile = new File(mRegFilePath);
087:
088: }
089:
090: public void setUp() throws Exception {
091: super .setUp();
092: if (mRegFile.exists()) {
093: mRegFile.delete();
094: }
095: Util.fileCopy(mRegGoodFilePath, mRegFilePath);
096: }
097:
098: public void tearDown() throws Exception {
099: // -- restore registry.xml
100: RegistryBuilder.destroyRegistry();
101: Util.fileCopy(mRegGoodFilePath, mRegFilePath);
102: }
103:
104: public void testGetEngineComponentIds() throws Exception {
105: Registry reg = Util.createRegistry(true);
106: ComponentQuery query = reg.getComponentQuery("server");
107:
108: Repository repository = reg.getRegistrySpec()
109: .getManagementContext().getRepository();
110:
111: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
112: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
113:
114: List<String> comps = query
115: .getComponentIds(ComponentType.ENGINE);
116: System.out.println(comps.toString());
117: assertTrue(comps.contains(ENGINE_NAME));
118: repository.purge();
119: }
120:
121: public void testGetBindingComponentIds() throws Exception {
122: Registry reg = Util.createRegistry(true);
123: ComponentQuery query = reg.getComponentQuery("server");
124:
125: Repository repository = reg.getRegistrySpec()
126: .getManagementContext().getRepository();
127:
128: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
129: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
130:
131: List<String> comps = query
132: .getComponentIds(ComponentType.BINDING);
133: System.out.println(comps.toString());
134: assertTrue(comps.contains(BINDING_NAME));
135: repository.purge();
136: }
137:
138: /**
139: * Test getting the binding components for the domain target.
140: */
141: public void testGetBindingComponentIds2() throws Exception {
142: Registry reg = Util.createRegistry(true);
143: ComponentQuery query = reg.getComponentQuery("domain");
144:
145: Repository repository = reg.getRegistrySpec()
146: .getManagementContext().getRepository();
147:
148: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
149: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
150:
151: List<String> comps = query
152: .getComponentIds(ComponentType.BINDING);
153: System.out.println(" Domain Binding Components "
154: + comps.toString());
155: assertTrue(comps.contains(BINDING_NAME));
156: repository.purge();
157: }
158:
159: public void testGetBindingsAndEngineComponentIds() throws Exception {
160: Registry reg = Util.createRegistry(true);
161: ComponentQuery query = reg.getComponentQuery("server");
162:
163: Repository repository = reg.getRegistrySpec()
164: .getManagementContext().getRepository();
165:
166: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
167: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
168:
169: List<String> comps = query
170: .getComponentIds(ComponentType.BINDINGS_AND_ENGINES);
171: System.out.println(comps.toString());
172: assertTrue(comps.contains(BINDING_NAME));
173: assertTrue(comps.contains(ENGINE_NAME));
174: repository.purge();
175: }
176:
177: public void testGetSharedLibraryComponentIds() throws Exception {
178: Registry reg = Util.createRegistry(true);
179: ComponentQuery query = reg.getComponentQuery("server");
180:
181: Repository repository = reg.getRegistrySpec()
182: .getManagementContext().getRepository();
183:
184: repository.addArchive(ArchiveType.SHARED_LIBRARY,
185: mSharedLibraryZipPath);
186:
187: List<String> sls = query
188: .getComponentIds(ComponentType.SHARED_LIBRARY);
189: System.out.println(sls.toString());
190: assertTrue(sls.contains(SHARED_LIBRARY_NAME));
191: assertEquals(1, sls.size());
192: repository.purge();
193: }
194:
195: public void testGetAllComponentIds() throws Exception {
196: Registry reg = Util.createRegistry(true);
197: ComponentQuery query = reg.getComponentQuery("server");
198:
199: Repository repository = reg.getRegistrySpec()
200: .getManagementContext().getRepository();
201:
202: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
203: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
204: repository.addArchive(ArchiveType.SHARED_LIBRARY,
205: mSharedLibraryZipPath);
206:
207: List<String> list = query.getComponentIds(ComponentType.ALL);
208: System.out.println(list.toString());
209: assertTrue(list.contains(SHARED_LIBRARY_NAME));
210: assertTrue(list.contains(ENGINE_NAME));
211: assertTrue(list.contains(BINDING_NAME));
212: repository.purge();
213: }
214:
215: public void testGetAllStartedComponentIds() throws Exception {
216: Registry reg = Util.createRegistry(true);
217: ComponentQuery query = reg.getComponentQuery("server");
218:
219: Repository repository = reg.getRegistrySpec()
220: .getManagementContext().getRepository();
221:
222: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
223: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
224: repository.addArchive(ArchiveType.SHARED_LIBRARY,
225: mSharedLibraryZipPath);
226:
227: List<String> list = query.getComponentIds(ComponentType.ALL,
228: ComponentState.STARTED);
229: System.out.println(list.toString());
230: assertTrue(list.contains(ENGINE_NAME));
231: assertTrue(list.contains(BINDING_NAME));
232: repository.purge();
233: }
234:
235: public void testGetComponentInfo() throws Exception {
236: Registry reg = Util.createRegistry(true);
237: ComponentQuery query = reg.getComponentQuery("server");
238:
239: Repository repository = reg.getRegistrySpec()
240: .getManagementContext().getRepository();
241:
242: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
243:
244: ComponentInfo comp = query.getComponentInfo(BINDING_NAME);
245:
246: if (comp == null)
247: System.out.println("This is null");
248: else
249: System.out.println("This is not null");
250:
251: assertNotNull(comp);
252: System.out.println(comp.getName());
253: System.out.println(comp.getDescription());
254: System.out.println(comp.getInstallRoot());
255: System.out.println(comp.getClassPathElements().toString());
256: comp.getComponentType().toString().equals("BINDING");
257: assertTrue(comp.getSharedLibraryNames().toString().equals(
258: "[SunWSDLSharedLibrary]"));
259: repository.purge();
260: }
261:
262: /**
263: * Test getting from the domain
264: */
265: public void testGetComponentInfo2() throws Exception {
266: Registry reg = Util.createRegistry(true);
267: ComponentQuery query = reg.getComponentQuery("domain");
268:
269: Repository repository = reg.getRegistrySpec()
270: .getManagementContext().getRepository();
271:
272: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
273:
274: ComponentInfo comp = query.getComponentInfo(BINDING_NAME);
275:
276: System.out.println("Domain Component");
277: System.out.println(comp.getName());
278: System.out.println(comp.getDescription());
279: System.out.println(comp.getInstallRoot());
280: System.out.println(comp.getClassPathElements().toString());
281: comp.getComponentType().toString().equals("BINDING");
282: assertTrue(comp.getSharedLibraryNames().toString().equals(
283: "[SunWSDLSharedLibrary]"));
284: assertTrue("Started".equals(comp.getStatus().toString()));
285: repository.purge();
286: }
287:
288: public void testGetDependentComponentIds() throws Exception {
289: Registry reg = Util.createRegistry(true);
290: ComponentQuery query = reg.getComponentQuery("server");
291:
292: Repository repository = reg.getRegistrySpec()
293: .getManagementContext().getRepository();
294:
295: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
296: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
297: repository.addArchive(ArchiveType.SHARED_LIBRARY,
298: mSharedLibraryZipPath);
299:
300: List<String> depComps = query
301: .getDependentComponentIds(SHARED_LIBRARY_NAME);
302: assertTrue(BINDING_NAME.equals(depComps.get(0)));
303: repository.purge();
304: }
305:
306: public void testGetDependentComponentIds2() throws Exception {
307: Registry reg = Util.createRegistry(true);
308: ComponentQuery query = reg.getComponentQuery("domain");
309:
310: Repository repository = reg.getRegistrySpec()
311: .getManagementContext().getRepository();
312:
313: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
314: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
315: repository.addArchive(ArchiveType.SHARED_LIBRARY,
316: mSharedLibraryZipPath);
317:
318: List<String> depComps = query
319: .getDependentComponentIds(SHARED_LIBRARY_NAME);
320: assertTrue(BINDING_NAME.equals(depComps.get(0)));
321: repository.purge();
322: }
323:
324: public void testGetSharedLibraryInstallationDescriptor()
325: throws Exception {
326: Registry reg = Util.createRegistry(true);
327: ComponentQuery query = reg.getComponentQuery("server");
328:
329: Repository repository = reg.getRepository();
330:
331: repository.addArchive(ArchiveType.SHARED_LIBRARY,
332: mSharedLibraryZipPath);
333: ComponentInfo comp = query
334: .getSharedLibraryInfo(SHARED_LIBRARY_NAME);
335:
336: assertNotNull(comp);
337: assertNotNull(comp.getInstallationDescriptor());
338: assertTrue(comp.getInstallationDescriptor().indexOf(
339: SHARED_LIBRARY_NAME) > 0);
340: repository.purge();
341: }
342:
343: public void testGetComponentInstallationDescriptor()
344: throws Exception {
345: Registry reg = Util.createRegistry(true);
346: ComponentQuery query = reg.getComponentQuery("server");
347:
348: Repository repository = reg.getRegistrySpec()
349: .getManagementContext().getRepository();
350:
351: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
352: ComponentInfo comp = query.getComponentInfo(BINDING_NAME);
353:
354: assertNotNull(comp.getInstallationDescriptor());
355: assertTrue(comp.getInstallationDescriptor().indexOf(
356: BINDING_NAME) > 0);
357: repository.purge();
358: }
359:
360: /**
361: * This tests the fix for CR 6548857. For non-domain targets if the server-ref or
362: * cluster-ref is missing in a fresh registry, the component query operations to
363: * get components/shared libraries for that target should return an empty list
364: * instead of throwing an "Unknown target : XXX " exception.
365: *
366: * This tests the private getTarget() operation in ComponentQueryImpl. If the target
367: * is missing a null value is expected and not an exception.
368: */
369: public void testGetTarget() throws Exception {
370: // Start with a blank registry
371: RegistryBuilder.destroyRegistry();
372: if (mRegFile.exists()) {
373: mRegFile.delete();
374: }
375: Registry reg = Util.createRegistry(true);
376: try {
377: ComponentQueryImpl query = (ComponentQueryImpl) reg
378: .getComponentQuery("someTarget");
379: Class clazz = query.getClass();
380:
381: java.lang.reflect.Method getTargetMtd = clazz
382: .getDeclaredMethod("getTarget", new Class[] { Class
383: .forName("java.lang.String") });
384: getTargetMtd.setAccessible(true);
385: Object target = getTargetMtd.invoke(query,
386: new Object[] { "someTarget" });
387: assertNull(target);
388: } catch (Exception ex) {
389: fail();
390: }
391: }
392:
393: /**
394: * Test getting component configuration properties.
395: */
396: public void testGetComponentConfiguration() throws Exception {
397: Registry reg = Util.createRegistry(true);
398: ComponentQuery query = reg.getComponentQuery("server");
399:
400: Repository repository = reg.getRegistrySpec()
401: .getManagementContext().getRepository();
402:
403: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
404:
405: com.sun.jbi.management.ComponentInfo compInfo = (com.sun.jbi.management.ComponentInfo) query
406: .getComponentInfo(ENGINE_NAME);
407: assertNotNull(compInfo);
408: java.util.Properties props = compInfo.getConfiguration();
409: assertNotNull(props);
410: assertEquals(props.get("HostName"), "tango");
411: assertEquals(props.get("Port"), "5656");
412: repository.purge();
413: }
414:
415: /**
416: * Test getting component configuration properties.
417: */
418: public void testGetComponentConfigurationForClusterTarget()
419: throws Exception {
420: Registry reg = Util.createRegistry(true);
421: ComponentQuery query = reg.getComponentQuery("clusterA");
422:
423: Repository repository = reg.getRegistrySpec()
424: .getManagementContext().getRepository();
425:
426: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
427:
428: com.sun.jbi.management.ComponentInfo compInfo = (com.sun.jbi.management.ComponentInfo) query
429: .getComponentInfo(ENGINE_NAME);
430: assertNotNull(compInfo);
431: java.util.Properties props = compInfo.getConfiguration();
432: assertNotNull(props);
433: assertFalse(props.isEmpty());
434: assertEquals(props.get("HostName"), "Eight");
435: assertEquals(props.get("Port"), "8888");
436: repository.purge();
437: }
438:
439: /**
440: * Test getting non-existant component configuration properties.
441: */
442: public void testGetEmptyComponentConfiguration() throws Exception {
443: Registry reg = Util.createRegistry(true);
444: ComponentQuery query = reg.getComponentQuery("server");
445:
446: Repository repository = reg.getRegistrySpec()
447: .getManagementContext().getRepository();
448:
449: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
450:
451: com.sun.jbi.management.ComponentInfo compInfo = (com.sun.jbi.management.ComponentInfo) query
452: .getComponentInfo(BINDING_NAME);
453: assertNotNull(compInfo);
454: java.util.Properties props = compInfo.getConfiguration();
455: assertNotNull(props);
456: assertTrue(props.isEmpty());
457: repository.purge();
458: }
459:
460: /**
461: * Test getting component application variables
462: */
463: public void testGetComponentApplicationVariables() throws Exception {
464: Registry reg = Util.createRegistry(true);
465: ComponentQuery query = reg.getComponentQuery("server");
466:
467: Repository repository = reg.getRegistrySpec()
468: .getManagementContext().getRepository();
469:
470: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
471:
472: com.sun.jbi.management.ComponentInfo compInfo = (com.sun.jbi.management.ComponentInfo) query
473: .getComponentInfo(ENGINE_NAME);
474: assertNotNull(compInfo);
475:
476: com.sun.jbi.management.ComponentInfo.Variable[] vars = compInfo
477: .getVariables();
478:
479: assertNotNull(vars);
480: assertEquals(2, vars.length);
481:
482: repository.purge();
483: }
484:
485: /**
486: * Test getting component application variables
487: */
488: public void testGetEmptyComponentApplicationVariables()
489: throws Exception {
490: Registry reg = Util.createRegistry(true);
491: ComponentQuery query = reg.getComponentQuery("server");
492:
493: Repository repository = reg.getRegistrySpec()
494: .getManagementContext().getRepository();
495:
496: repository.addArchive(ArchiveType.COMPONENT, mBindingZipPath);
497:
498: com.sun.jbi.management.ComponentInfo compInfo = (com.sun.jbi.management.ComponentInfo) query
499: .getComponentInfo(BINDING_NAME);
500: assertNotNull(compInfo);
501:
502: com.sun.jbi.management.ComponentInfo.Variable[] vars = compInfo
503: .getVariables();
504:
505: assertNotNull(vars);
506: assertEquals(0, vars.length);
507:
508: repository.purge();
509: }
510:
511: /**
512: * Test getting component application configuration names.
513: */
514: public void testGetComponentApplicationConfigurationNames()
515: throws Exception {
516: Registry reg = Util.createRegistry(true);
517: ComponentQuery query = reg.getComponentQuery("server");
518:
519: Repository repository = reg.getRegistrySpec()
520: .getManagementContext().getRepository();
521:
522: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
523:
524: com.sun.jbi.management.ComponentInfo compInfo = (com.sun.jbi.management.ComponentInfo) query
525: .getComponentInfo(ENGINE_NAME);
526: assertNotNull(compInfo);
527:
528: String[] configNames = compInfo
529: .getApplicationConfigurationNames();
530:
531: assertNotNull(configNames);
532: assertEquals(2, configNames.length);
533:
534: repository.purge();
535: }
536:
537: /**
538: * Test getting component application configuration.
539: */
540: public void testGetComponentApplicationConfiguration()
541: throws Exception {
542: Registry reg = Util.createRegistry(true);
543: ComponentQuery query = reg.getComponentQuery("server");
544:
545: Repository repository = reg.getRegistrySpec()
546: .getManagementContext().getRepository();
547:
548: repository.addArchive(ArchiveType.COMPONENT, mEngineZipPath);
549:
550: com.sun.jbi.management.ComponentInfo compInfo = (com.sun.jbi.management.ComponentInfo) query
551: .getComponentInfo(ENGINE_NAME);
552: assertNotNull(compInfo);
553:
554: // -- Test whether the property values are read correctly
555: java.util.Properties config1 = compInfo
556: .getApplicationConfiguration("SEQ_CONFIG1");
557: assertTrue(config1.getProperty("configurationName").equals(
558: "SEQ_CONFIG1"));
559: assertTrue(config1.getProperty("initialContextFactory").equals(
560: "com.sonicsw.jndi.mfcontext.MFContextFactory"));
561: assertTrue(config1.getProperty("connectionURL").equals(
562: "jndi://cfg1"));
563:
564: java.util.Properties config2 = compInfo
565: .getApplicationConfiguration("SEQ_CONFIG2");
566: assertTrue(config2.getProperty("configurationName").equals(
567: "SEQ_CONFIG2"));
568: assertTrue(config2.getProperty("initialContextFactory").equals(
569: "com.sonicsw.jndi.mfcontext.MFContextFactory"));
570: assertTrue(config2.getProperty("connectionURL").equals(
571: "jndi://cfg2"));
572:
573: repository.purge();
574: }
575: }
|