1 package org.codehaus.plexus.redback.configuration;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import junit.framework.TestCase;
23 import org.apache.archiva.redback.configuration.UserConfiguration;
24 import org.codehaus.plexus.util.StringUtils;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.springframework.test.context.ContextConfiguration;
28 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30 import javax.inject.Inject;
31 import javax.inject.Named;
34 * UserConfigurationTest
36 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
39 @RunWith( SpringJUnit4ClassRunner.class )
40 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
41 public class UserConfigurationTest
45 @Inject @Named(value = "test")
46 UserConfiguration config;
48 private void assertEmpty( String str )
50 if ( StringUtils.isNotEmpty( str ) )
52 fail( "Expected String to be empty." );
57 public void testLoad()
60 assertNotNull( config );
61 // check that the configuration loaded correctly - if this fails, maybe you aren't in the right basedir
62 assertNotNull( config.getString( "test.value" ) );
66 public void testGetString()
69 // Test default configuration entry
70 assertEquals( "25", config.getString( "email.smtp.port" ) );
71 // Test overlaid configuration entry
72 assertEquals( "127.0.2.2", config.getString( "email.smtp.host" ) );
74 assertEquals( "127.0.0.1", config.getString( "email.smtp.host.bad", "127.0.0.1" ) );
75 /* Requires commons-configuration 1.4
77 assertEquals( "jdbc:derby:" + System.getProperty( "plexus.home" ) + "/database;create=true",
78 config.getString( "jdbc.url" ) );
79 assertEquals( "foo/bar", config.getString( "test.expression" ) );
82 assertEmpty( config.getString( "email.smtp.foo.foo" ) );
86 public void testGetBoolean()
89 assertFalse( config.getBoolean( "email.smtp.ssl.enabled" ) );
90 assertFalse( config.getBoolean( "email.smtp.tls.enabled" ) );
94 public void testGetInt()
97 assertEquals( 25, config.getInt( "email.smtp.port" ) );
98 assertEquals( 8080, config.getInt( "email.smtp.port.bad", 8080 ) );
102 public void testConcatenatedList()
104 assertEquals( "uid=brett,dc=codehaus,dc=org", config.getConcatenatedList( "ldap.bind.dn", null ) );
105 assertEquals( "dc=codehaus,dc=org", config.getConcatenatedList( "ldap.base.dn", null ) );
106 assertEquals( "foo", config.getConcatenatedList( "short.list", null ) );
107 assertEquals( "bar,baz", config.getConcatenatedList( "no.list", "bar,baz" ) );