KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > test > XMLAttributePersistenceManagerUnitTestCase


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.jmx.test;
23
24 import javax.management.Attribute JavaDoc;
25 import javax.management.AttributeList JavaDoc;
26 import javax.management.MBeanServerConnection JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28
29 import org.jboss.logging.Logger;
30 import org.jboss.test.JBossTestCase;
31 import org.jboss.test.jmx.xmbean.CustomType;
32
33 /**
34  * Tests for XMLAttributePersistenceManager
35  *
36  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
37  * @version $Revision: 58115 $
38  */

39 public class XMLAttributePersistenceManagerUnitTestCase extends JBossTestCase
40 {
41    public XMLAttributePersistenceManagerUnitTestCase(String JavaDoc name)
42    {
43       super(name);
44    }
45
46    /**
47     * JBAS-3463, persist custom mbean attributes using the default setup
48     * of the AttributePersistenceService / XMLAttributePersistenceManager.
49     */

50    public void testPersistCustomMBeanAttributes() throws Exception JavaDoc
51    {
52       Logger log = getLog();
53       log.info("+++ testPersistCustomMBeanAttributes");
54       
55       String JavaDoc testService = "xmbean-custom-attr-pers.sar";
56       String JavaDoc customMBean = "jboss.test:service=ServiceUsingCustomAttribute";
57       
58       MBeanServerConnection JavaDoc server = super.getServer();
59       // This works when AttributePersistenceService is setup by default
60
ObjectName JavaDoc aps = new ObjectName JavaDoc("jboss:service=AttributePersistenceService");
61       // Cleanup persisted image
62
server.invoke(aps, "apmRemove", new Object JavaDoc[] { customMBean }, new String JavaDoc[] { "java.lang.String" });
63       try
64       {
65          deploy(testService);
66          ObjectName JavaDoc target = new ObjectName JavaDoc(customMBean);
67          CustomType ct = new CustomType(777, 888);
68          // Attribute must be set and persisted
69
server.setAttribute(target, new Attribute JavaDoc("Attr", ct));
70          // redeploy
71
undeploy(testService);
72          // this fails if deserialization of the custom attribute fails
73
deploy(testService);
74          // otherwise we should be aple to read back the persisted attribute
75
ct = (CustomType)server.getAttribute(target, "Attr");
76          assertTrue("CustomType.x == 777", ct.getX() == 777);
77          assertTrue("CustomType.y == 888", ct.getY() == 888);
78          // Cleanup persisted image
79
server.invoke(aps, "apmRemove", new Object JavaDoc[] { customMBean }, new String JavaDoc[] { "java.lang.String" });
80       }
81       catch (Exception JavaDoc e)
82       {
83          getLog().warn("Caught exception", e);
84          fail("Unexcepted Exception, see the Log file");
85       }
86       finally
87       {
88          undeploy(testService);
89       }
90    }
91    
92    /**
93     * JBAS-1988, test we can write/read to a directory that contains spaces in its name.
94     *
95     * @see org.jboss.test.jmx.xmbean.XMLAttributePersistenceManagerTestService
96     */

97    public void testWriteToPathNameContainingSpaces() throws Exception JavaDoc
98    {
99       Logger log = getLog();
100       log.info("+++ testWriteToPathNameContainingSpaces");
101
102       String JavaDoc testService = "xmlapm-xmbean.sar";
103       
104       try
105       {
106          deploy(testService);
107          
108          MBeanServerConnection JavaDoc server = super.getServer();
109          ObjectName JavaDoc target = new ObjectName JavaDoc("jboss.test:service=XMLAttributePersistenceManagerTestService");
110          
111          // Store some attributes under an id
112
AttributeList JavaDoc atlist = new AttributeList JavaDoc();
113          String JavaDoc storeId = "testId";
114          Integer JavaDoc anInteger = new Integer JavaDoc(666);
115          String JavaDoc aString = new String JavaDoc("Evil Test");
116          atlist.add(new Attribute JavaDoc("Attr1", anInteger));
117          atlist.add(new Attribute JavaDoc("Attr2", aString));
118        
119          getLog().info("Storing AttributeList");
120          server.invoke(
121                target,
122                "store",
123                new Object JavaDoc[] { storeId, atlist },
124                new String JavaDoc[] { storeId.getClass().getName(), atlist.getClass().getName() }
125                );
126          
127          getLog().info("Loading AttributeList");
128          server.invoke(
129                target,
130                "load",
131                new Object JavaDoc[] { storeId },
132                new String JavaDoc[] { storeId.getClass().getName() }
133                );
134          
135       }
136       catch (Exception JavaDoc e)
137       {
138          getLog().warn("Caught exception", e);
139          fail("Unexcepted Exception, see the Log file");
140       }
141       finally
142       {
143          undeploy(testService);
144       }
145    }
146 }
Popular Tags