View Javadoc

1   package org.apache.onami.configuration;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.apache.onami.configuration.OnamiVariablesExpander.expandVariables;
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertTrue;
25  
26  import java.io.File;
27  import java.net.URI;
28  
29  import javax.inject.Inject;
30  
31  import org.apache.onami.test.OnamiRunner;
32  import org.apache.onami.test.annotation.GuiceProvidedModules;
33  import org.junit.Test;
34  import org.junit.runner.RunWith;
35  
36  import com.google.inject.Module;
37  
38  /**
39   * @since 6.0
40   */
41  @RunWith( OnamiRunner.class )
42  public final class ConfigurationModuleTestCase
43  {
44  
45      @GuiceProvidedModules
46      public static Module createTestModule()
47      {
48          return expandVariables( new ConfigurationModule()
49          {
50  
51              @Override
52              protected void bindConfigurations()
53              {
54                  bindEnvironmentVariables();
55                  bindSystemProperties();
56  
57                  bindProperty( "test.suites" ).toValue( "${user.dir}/src/test/resources/testng.xml" );
58  
59                  bindProperties( URI.create( "classpath:/org/apache/onami/configuration/ldap.properties" ) );
60                  bindProperties( "proxy.xml" ).inXMLFormat();
61  
62                  File parentConf = new File( "src/test/data/org/apache/onami" );
63                  bindProperties( new File( parentConf, "ibatis.properties" ) );
64                  bindProperties( new File( parentConf, "configuration/jdbc.properties" ) );
65                  bindProperties( new File( parentConf, "configuration/configuration/memcached.xml" ) ).inXMLFormat();
66              }
67  
68          } );
69      }
70  
71      @Inject
72      private MyBatisConfiguration myBatisConfiguration;
73  
74      @Inject
75      private JDBCConfiguration jdbcConfiguration;
76  
77      @Inject
78      private LdapConfiguration ldapConfiguration;
79  
80      @Inject
81      private MemcachedConfiguration memcachedConfiguration;
82  
83      @Inject
84      private ProxyConfiguration proxyConfiguration;
85  
86      public void setMyBatisConfiguration( MyBatisConfiguration myBatisConfiguration )
87      {
88          this.myBatisConfiguration = myBatisConfiguration;
89      }
90  
91      public void setJdbcConfiguration( JDBCConfiguration jdbcConfiguration )
92      {
93          this.jdbcConfiguration = jdbcConfiguration;
94      }
95  
96      public void setLdapConfiguration( LdapConfiguration ldapConfiguration )
97      {
98          this.ldapConfiguration = ldapConfiguration;
99      }
100 
101     public void setMemcachedConfiguration( MemcachedConfiguration memcachedConfiguration )
102     {
103         this.memcachedConfiguration = memcachedConfiguration;
104     }
105 
106     public void setProxyConfiguration( ProxyConfiguration proxyConfiguration )
107     {
108         this.proxyConfiguration = proxyConfiguration;
109     }
110 
111     @Test
112     public void verifyIBatisConfiguration()
113     {
114         assertEquals( "test", myBatisConfiguration.getEnvironmentId() );
115         assertTrue( myBatisConfiguration.isLazyLoadingEnabled() );
116     }
117 
118     @Test
119     public void verifyJDBCConfiguration()
120     {
121         assertEquals( "com.mysql.jdbc.Driver", jdbcConfiguration.getDriver() );
122         assertEquals( "jdbc:mysql://localhost:3306/rocoto", jdbcConfiguration.getUrl() );
123         assertEquals( "simone", jdbcConfiguration.getUsername() );
124         assertEquals( "rocoto2010", jdbcConfiguration.getPassword() );
125         assertTrue( jdbcConfiguration.isAutoCommit() );
126     }
127 
128     @Test
129     public void verifyLdapConfiguration()
130     {
131         assertEquals( "ldap.${not.found}", ldapConfiguration.getHost() );
132         assertEquals( 389, ldapConfiguration.getPort() );
133         assertTrue( ldapConfiguration.getBaseDN().indexOf( '$' ) < 0 );
134         assertEquals( "", ldapConfiguration.getUser() );
135     }
136 
137     @Test
138     public void verifyMemcachedConfiguration()
139     {
140         assertEquals( "test_", memcachedConfiguration.getKeyPrefix() );
141         assertTrue( memcachedConfiguration.isCompressionEnabled() );
142     }
143 
144     @Test
145     public void verifyProxyConfiguration()
146     {
147         assertEquals( "localhost", proxyConfiguration.getHost() );
148         assertEquals( 8180, proxyConfiguration.getPort() );
149     }
150 
151 }