summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-1.6.2/itest/conversations/src/test/java/org/apache/tuscany/sca/itest/conversational/ConversationLifetimeTestCase.java
blob: 326a833a42ee9f93bbe23c0536f4db66dc6a39da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */

package org.apache.tuscany.sca.itest.conversational;

import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class ConversationLifetimeTestCase {

    private SCADomain domain;

    @Before
    public void setUp() throws Exception {
        domain = SCADomain.newInstance("conversationLifetime.composite");
    }

    @After
    public void tearDown() throws Exception {
        if (domain != null) {
            domain.close();
        }
    }

    /**
     * Following a clarification re. the wording of the Java Common Annotations and APIs 1.00 Specification
     * (see TUSCANY-2055) the following is accepted to be the intended operation
     * 
     * Whether the conversation ID is chosen by the user or is generated by the system, the client
     * may access the conversation ID by calling getConversationID() on the current conversation object.
     * 
     * ServiceReference.getConversationID() - Returns the id supplied by the user that will be associated with
     * future conversations initiated through this reference, or null if no ID has been set by the user.
     * 
     * ServiceReference.setConversationID(Object conversationId) - Set an ID, supplied by the user, to associate with any future conversation
     * started through this reference. If the value supplied is null then the id will be generated
     * by the implementation. Throws an IllegalStateException if a conversation is currently
     * associated with this reference. 
     * 
     */

    /**
     * Verify that ServiceReference.getConversationID() returns null before a conversation
     * ID has been set manually.
     */
    @Test
    public void getConversationID() {
        CService service = domain.getService(CService.class, "ConversationalCComponent");
        service.getState();
        Assert.assertNull(service.getConversationID());
    }

    /**
     * Verify that ServiceReference.getConversationID() returns any value previous set through the
     * setConversationID() API.
     */
    @Test
    public void getConversationID2() {
        String userProvidedID = "A conversation ID";
        CService service = domain.getService(CService.class, "ConversationalCComponent");
        service.setConversationID(userProvidedID);
        service.getState();
        Assert.assertEquals(service.getConversationID(), userProvidedID);
    }
    
    /**
     * Whether the conversation ID is chosen by the user or is generated by the system, the client
     * may access the conversation ID by calling getConversationID() on the current conversation object.
     * Here test the manually set conversationID
     */
    @Test
    public void getConversationID3() {
        String userProvidedID = "A conversation ID";
        CService service = domain.getService(CService.class, "ConversationalCComponent");
        service.setConversationID(userProvidedID);
        service.getState();
        Assert.assertEquals(service.getConversationObjectConversationId(), userProvidedID);
    }
    
    /**
     * Whether the conversation ID is chosen by the user or is generated by the system, the client
     * may access the conversation ID by calling getConversationID() on the current conversation object.
     * Here test the auto generated conversationId
     */
    @Test
    public void getConversationID4() {
        CService service = domain.getService(CService.class, "ConversationalCComponent");
        service.getState();
        Assert.assertNotNull(service.getConversationObjectConversationId());
    }    
    
    /**
     * Java Common Annotations and APIs 1.00 Specification line 494-495 Verify:
     * If a method is invoked on a service reference after an
     * "@EndsConversation" method has been called then a new conversation will
     * automatically be started.
     */
    @Test
    public void implicitStartNewConversationAfterEnd() {
        CService service = domain.getService(CService.class, "ConversationalCComponent");
        service.getState();
        Object firstID = service.getConversationObjectConversationId();
        service.endConversationViaAnnotatedMethod();
        service.getState();
        Assert.assertNotSame(firstID, service.getConversationObjectConversationId());
    }

    /**
     * Java Common Annotations and APIs 1.00 Specification line 495-495 Verify: If a
     * method is invoked on a service reference after an "@EndsConversation"
     * method has been called then a new conversation will automatically be
     * started. Note: Uses Conversation.end() rather than "@EndsConversation"
     */
    @Test
    public void implicitStartNewConversationAfterEnd2() {
        CService service = domain.getService(CService.class, "ConversationalCComponent");
        service.getState();
        Object firstID = service.getConversationObjectConversationId();
        service.endConversation();
        service.getState();
        Assert.assertNotSame(firstID, service.getConversationObjectConversationId());
    }

    /**
     * Java Common Annotations and APIs 1.00 Specification line 495-497 Verify:
     * If ServiceReference.getConversationID() is called after the
     * "@EndsConversation" method is called, but before the next conversation
     * has been started, it will return null.
     */
    @Test
    public void nullConversationIDAfterEndConversation() {
        CService service = domain.getService(CService.class, "ConversationalCComponent");
        service.getState();
        service.endConversationViaAnnotatedMethod();
        Assert.assertNull(service.getConversationObjectConversationId());
    }
    
    /**
     * Java Common Annotations and APIs 1.00 Specification line 495-497 Verify:
     * If ServiceReference.getConversationID() is called after the
     * "@EndsConversation" method is called, but before the next conversation
     * has been started, it will return null.  Note: Uses explicit set of Conversation ID
     */
    @Test
    public void nullConversationIDAfterEndConversation1a() {
        CService service = domain.getService(CService.class, "ConversationalCComponent");
        service.setConversationID("User provided ID");
        service.getState();
        service.endConversationViaAnnotatedMethod();
        Assert.assertNull(service.getConversationObjectConversationId());
    }

    /**
     * Java Common Annotations and APIs 1.00 Specification line 495-497 Verify: If
     * ServiceReference.getConversationID() is called after the
     * "@EndsConversationmethod" is called, but before the next conversation has
     * been started, it will return null. Note: Uses Conversation.end() rather
     * than "@EndsConversation"
     */
    @Test
    public void nullConversationIDAfterEndConversation2() {
        CService service = domain.getService(CService.class, "ConversationalCComponent");
        service.getState();
        service.endConversation();
        Assert.assertNull(service.getConversationObjectConversationId());
    }
    
    /**
     * Java Common Annotations and APIs 1.00 Specification line 495-497 Verify: If
     * ServiceReference.getConversationID() is called after the
     * "@EndsConversationmethod" is called, but before the next conversation has
     * been started, it will return null. Note: Uses Conversation.end() rather
     * than "@EndsConversation".  Note 2: Uses explicit set of Conversation ID
     */
    @Test
    public void nullConversationIDAfterEndConversation2a() {
        CService service = domain.getService(CService.class, "ConversationalCComponent");
        service.setConversationID("User provided ID");
        service.getState();
        service.endConversation();
        Assert.assertNull(service.getConversationObjectConversationId());
    }

}