KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > jndi > ObjectFactoryTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.jndi;
19
20 import org.apache.activemq.ActiveMQConnectionFactory;
21 import org.apache.activemq.CombinationTestSupport;
22 import org.apache.activemq.command.ActiveMQDestination;
23 import org.apache.activemq.command.ActiveMQQueue;
24
25 import javax.naming.Reference JavaDoc;
26
27 public class ObjectFactoryTest extends CombinationTestSupport {
28     public void testConnectionFactory() throws Exception JavaDoc {
29         // Create sample connection factory
30
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
31         factory.setDispatchAsync(true);
32         factory.setBrokerURL("vm://test");
33         factory.setClientID("test");
34         factory.setCopyMessageOnSend(false);
35         factory.setDisableTimeStampsByDefault(true);
36         factory.setObjectMessageSerializationDefered(true);
37         factory.setOptimizedMessageDispatch(false);
38         factory.setPassword("pass");
39         factory.setUseAsyncSend(true);
40         factory.setUseCompression(true);
41         factory.setUseRetroactiveConsumer(true);
42         factory.setUserName("user");
43         factory.getPrefetchPolicy().setQueuePrefetch(777);
44         factory.getRedeliveryPolicy().setMaximumRedeliveries(15);
45         factory.getRedeliveryPolicy().setBackOffMultiplier((short) 32);
46         
47
48         // Create reference
49
Reference JavaDoc ref = JNDIReferenceFactory.createReference(factory.getClass().getName(), factory);
50
51         // Get object created based on reference
52
ActiveMQConnectionFactory temp;
53         JNDIReferenceFactory refFactory = new JNDIReferenceFactory();
54         temp = (ActiveMQConnectionFactory)refFactory.getObjectInstance(ref, null, null, null);
55
56         // Check settings
57
assertEquals(factory.isDispatchAsync(), temp.isDispatchAsync());
58         assertEquals(factory.getBrokerURL(), temp.getBrokerURL());
59         assertEquals(factory.getClientID(), temp.getClientID());
60         assertEquals(factory.isCopyMessageOnSend(), temp.isCopyMessageOnSend());
61         assertEquals(factory.isDisableTimeStampsByDefault(), temp.isDisableTimeStampsByDefault());
62         assertEquals(factory.isObjectMessageSerializationDefered(), temp.isObjectMessageSerializationDefered());
63         assertEquals(factory.isOptimizedMessageDispatch(), temp.isOptimizedMessageDispatch());
64         assertEquals(factory.getPassword(), temp.getPassword());
65         assertEquals(factory.isUseAsyncSend(), temp.isUseAsyncSend());
66         assertEquals(factory.isUseCompression(), temp.isUseCompression());
67         assertEquals(factory.isUseRetroactiveConsumer(), temp.isUseRetroactiveConsumer());
68         assertEquals(factory.getUserName(), temp.getUserName());
69         assertEquals(factory.getPrefetchPolicy().getQueuePrefetch(), temp.getPrefetchPolicy().getQueuePrefetch());
70         assertEquals(factory.getRedeliveryPolicy().getMaximumRedeliveries(), temp.getRedeliveryPolicy().getMaximumRedeliveries());
71         assertEquals(factory.getRedeliveryPolicy().getBackOffMultiplier(), temp.getRedeliveryPolicy().getBackOffMultiplier());
72     }
73
74     public void testDestination() throws Exception JavaDoc {
75         // Create sample destination
76
ActiveMQDestination dest = new ActiveMQQueue();
77         dest.setPhysicalName("TEST.FOO");
78
79         // Create reference
80
Reference JavaDoc ref = JNDIReferenceFactory.createReference(dest.getClass().getName(), dest);
81
82         // Get object created based on reference
83
ActiveMQDestination temp;
84         JNDIReferenceFactory refFactory = new JNDIReferenceFactory();
85         temp = (ActiveMQDestination)refFactory.getObjectInstance(ref, null, null, null);
86
87         // Check settings
88
assertEquals(dest.getPhysicalName(), temp.getPhysicalName());
89     }
90 }
91
Popular Tags