KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > wsn > SubscriptionTest


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

17 package org.apache.servicemix.wsn;
18
19 import java.io.IOException JavaDoc;
20 import java.io.InputStream JavaDoc;
21
22 import javax.xml.bind.JAXBContext;
23 import javax.xml.bind.JAXBException;
24 import javax.xml.bind.Unmarshaller;
25
26 import junit.framework.TestCase;
27
28 import org.apache.servicemix.wsn.jaxws.InvalidFilterFault;
29 import org.apache.servicemix.wsn.jaxws.InvalidProducerPropertiesExpressionFault;
30 import org.apache.servicemix.wsn.jaxws.UnacceptableInitialTerminationTimeFault;
31 import org.oasis_open.docs.wsn.b_2.Subscribe;
32
33 public class SubscriptionTest extends TestCase {
34
35     private JAXBContext context;
36     private Unmarshaller unmarshaller;
37     private AbstractSubscription subscription;
38     
39     protected void setUp() throws Exception JavaDoc {
40         context = JAXBContext.newInstance(Subscribe.class);
41         unmarshaller = context.createUnmarshaller();
42         subscription = new DummySubscription("mySubscription");
43     }
44     
45     protected Subscribe getSubscription(String JavaDoc file) throws JAXBException, IOException JavaDoc {
46         InputStream JavaDoc is = getClass().getResourceAsStream(file);
47         Subscribe subscribe = (Subscribe) unmarshaller.unmarshal(is);
48         is.close();
49         return subscribe;
50     }
51     
52     public void testWithNilITT() throws Exception JavaDoc {
53         Subscribe subscribe = getSubscription("subscribe-nil-itt.xml");
54         subscription.validateSubscription(subscribe);
55     }
56     
57     public void testWithAbsoluteITT() throws Exception JavaDoc {
58         Subscribe subscribe = getSubscription("subscribe-abs-itt.xml");
59         try {
60             subscription.validateSubscription(subscribe);
61             fail("Invalid initial termination time used. Fault was expected.");
62         } catch (UnacceptableInitialTerminationTimeFault e) {
63             // OK
64
}
65     }
66     
67     public void testWithEmptyITT() throws Exception JavaDoc {
68         Subscribe subscribe = getSubscription("subscribe-empty-itt.xml");
69         try {
70             subscription.validateSubscription(subscribe);
71             fail("Invalid initial termination time used. Fault was expected.");
72         } catch (UnacceptableInitialTerminationTimeFault e) {
73             // OK
74
}
75     }
76     
77     public void testWithNoITT() throws Exception JavaDoc {
78         Subscribe subscribe = getSubscription("subscribe-no-itt.xml");
79         subscription.validateSubscription(subscribe);
80     }
81     
82     public void testWithUseRaw() throws Exception JavaDoc {
83         Subscribe subscribe = getSubscription("subscribe-raw.xml");
84         subscription.validateSubscription(subscribe);
85     }
86     
87     public void testWithProducerProperties() throws Exception JavaDoc {
88         Subscribe subscribe = getSubscription("subscribe-pp.xml");
89         try {
90             subscription.validateSubscription(subscribe);
91             fail("ProducerProperties used. Fault was expected.");
92         } catch (InvalidProducerPropertiesExpressionFault e) {
93             // OK
94
}
95     }
96     
97     public void testWithNoTopic() throws Exception JavaDoc {
98         Subscribe subscribe = getSubscription("subscribe-no-topic.xml");
99         try {
100             subscription.validateSubscription(subscribe);
101             fail("ProducerProperties used. Fault was expected.");
102         } catch (InvalidFilterFault e) {
103             // OK
104
}
105     }
106     
107     public void testWithEPR() throws Exception JavaDoc {
108         Subscribe subscribe = getSubscription("subscribe-epr.xml");
109         subscription.validateSubscription(subscribe);
110     }
111     
112 }
113
Popular Tags