View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.jdbc;
8   
9   import org.mule.api.endpoint.EndpointURI;
10  import org.mule.endpoint.MuleEndpointURI;
11  import org.mule.tck.junit4.AbstractMuleContextTestCase;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  import static org.junit.Assert.assertNotNull;
17  
18  public class JdbcEndpointTestCase extends AbstractMuleContextTestCase
19  {
20  
21      @Test
22      public void testWithoutEndpointName() throws Exception
23      {
24          EndpointURI url = new MuleEndpointURI("jdbc:/?sql=SELECT * FROM TABLE", muleContext);
25          url.initialise();
26          assertEquals("jdbc", url.getScheme());
27          assertEquals("", url.getAddress());
28          assertNotNull(url.getParams());
29          assertEquals("SELECT * FROM TABLE", url.getParams().get("sql"));
30          assertEquals("jdbc:/?sql=SELECT%20*%20FROM%20TABLE", url.toString());
31      }
32  
33      @Test
34      public void testWithoutEndpointName2() throws Exception
35      {
36          EndpointURI url = new MuleEndpointURI("jdbc://?sql=SELECT * FROM TABLE", muleContext);
37          url.initialise();
38          assertEquals("jdbc", url.getScheme());
39          assertEquals("jdbc", url.getAddress());
40          assertNotNull(url.getParams());
41          assertEquals("SELECT * FROM TABLE", url.getParams().get("sql"));
42          assertEquals("jdbc://?sql=SELECT%20*%20FROM%20TABLE", url.toString());
43      }
44  
45      @Test
46      public void testWithEndpointName() throws Exception
47      {
48          EndpointURI url = new MuleEndpointURI("jdbc://writeTests?type=2", muleContext);
49          url.initialise();
50          assertEquals("jdbc", url.getScheme());
51          assertEquals("writeTests", url.getAddress());
52          assertNotNull(url.getParams());
53          assertEquals("2", url.getParams().get("type"));
54          assertEquals("jdbc://writeTests?type=2", url.toString());
55      }
56  
57  }