1   /*
2    * Copyright ${YEAR} the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.server.endpoint.mapping;
18  
19  import java.net.URI;
20  
21  import junit.framework.TestCase;
22  import org.easymock.MockControl;
23  
24  import org.springframework.ws.MockWebServiceMessageFactory;
25  import org.springframework.ws.context.DefaultMessageContext;
26  import org.springframework.ws.context.MessageContext;
27  import org.springframework.ws.transport.WebServiceConnection;
28  import org.springframework.ws.transport.context.DefaultTransportContext;
29  import org.springframework.ws.transport.context.TransportContextHolder;
30  
31  public class UriEndpointMappingTest extends TestCase {
32  
33      private UriEndpointMapping mapping;
34  
35      private MessageContext context;
36  
37      protected void setUp() throws Exception {
38          mapping = new UriEndpointMapping();
39          context = new DefaultMessageContext(new MockWebServiceMessageFactory());
40      }
41  
42      public void testGetLookupKeyForMessage() throws Exception {
43          MockControl control = MockControl.createControl(WebServiceConnection.class);
44          WebServiceConnection connectionMock = (WebServiceConnection) control.getMock();
45          TransportContextHolder.setTransportContext(new DefaultTransportContext(connectionMock));
46  
47          URI uri = new URI("jms://exampleQueue");
48          control.expectAndReturn(connectionMock.getUri(), uri);
49          control.replay();
50  
51          assertEquals("Invalid lookup key", uri.toString(), mapping.getLookupKeyForMessage(context));
52  
53          control.verify();
54          TransportContextHolder.setTransportContext(null);
55      }
56  
57      public void testValidateLookupKey() throws Exception {
58          assertTrue("URI not valid", mapping.validateLookupKey("http://example.com/services"));
59          assertFalse("URI not valid", mapping.validateLookupKey("some string"));
60      }
61  }