~ubuntu-branches/ubuntu/saucy/commons-configuration/saucy

« back to all changes in this revision

Viewing changes to src/test/java/org/apache/commons/configuration/TestNullJNDIEnvironmentValues.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-07-01 16:29:44 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130701162944-98waq5gogha5gpn1
Tags: 1.9-1
* New upstream release
* debian/control:
  - Updated Standards-Version to 3.9.4 (no changes)
  - Use canonical URLs for the Vcs-* fields
  - Added new build dependencies (libjavacc-maven-plugin-java, junit4)
  - Upgraded the dependency on the Servlet API (2.5 -> 3.0)
  - Removed the dependency on the Activation Framework (glassfish-activation)
  - Replaced the dependency on glassfish-mail with libgnumail-java
  - Removed the unused dependencies:
    liblog4j1.2-java-doc, libmaven-assembly-plugin-java
  - Replaced the dependency on libcommons-jexl-java by libcommons-jexl2-java
* debian/watch: Changed to point the official Apache distribution server
* Removed the obsolete file debian/ant.properties
* Installed the upstream changelog in the binary packages
* Added the report plugins to maven.ignoreRules
* Added the classpath attribute to the jar manifest

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 * contributor license agreements.  See the NOTICE file distributed with
 
4
 * this work for additional information regarding copyright ownership.
 
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 * (the "License"); you may not use this file except in compliance with
 
7
 * the License.  You may obtain a copy of the License at
 
8
 *
 
9
 *     http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
11
 * Unless required by applicable law or agreed to in writing, software
 
12
 * distributed under the License is distributed on an "AS IS" BASIS,
 
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 * See the License for the specific language governing permissions and
 
15
 * limitations under the License.
 
16
 */
 
17
 
 
18
package org.apache.commons.configuration;
 
19
 
 
20
import static org.junit.Assert.assertEquals;
 
21
import static org.junit.Assert.assertFalse;
 
22
import static org.junit.Assert.assertNotNull;
 
23
import static org.junit.Assert.assertNull;
 
24
import static org.junit.Assert.assertTrue;
 
25
 
 
26
import java.util.Iterator;
 
27
 
 
28
import org.junit.Before;
 
29
import org.junit.Test;
 
30
 
 
31
public class TestNullJNDIEnvironmentValues
 
32
{
 
33
    private JNDIConfiguration conf = null;
 
34
 
 
35
    @Before
 
36
    public void setUp() throws Exception
 
37
    {
 
38
        System.setProperty("java.naming.factory.initial", TestJNDIConfiguration.CONTEXT_FACTORY);
 
39
 
 
40
        conf = new JNDIConfiguration();
 
41
        conf.setThrowExceptionOnMissing(false);
 
42
    }
 
43
 
 
44
    @Test
 
45
    public void testThrowExceptionOnMissing()
 
46
    {
 
47
        assertFalse("Throw Exception Property is set!", conf.isThrowExceptionOnMissing());
 
48
    }
 
49
 
 
50
    @Test
 
51
    public void testSimpleGet() throws Exception
 
52
    {
 
53
        String s = conf.getString("test.key");
 
54
        assertEquals("jndivalue", s);
 
55
    }
 
56
 
 
57
    @Test
 
58
    public void testMoreGets() throws Exception
 
59
    {
 
60
        String s = conf.getString("test.key");
 
61
        assertEquals("jndivalue", s);
 
62
        assertEquals("jndivalue2", conf.getString("test.key2"));
 
63
        assertEquals(1, conf.getShort("test.short"));
 
64
    }
 
65
 
 
66
    @Test
 
67
    public void testGetMissingKey() throws Exception
 
68
    {
 
69
        assertNull("Missing Key is not null!", conf.getString("test.imaginarykey"));
 
70
    }
 
71
 
 
72
    @Test
 
73
    public void testGetMissingKeyWithDefault() throws Exception
 
74
    {
 
75
        String result = conf.getString("test.imaginarykey", "bob");
 
76
        assertEquals("bob", result);
 
77
    }
 
78
 
 
79
    @Test
 
80
    public void testContainsKey() throws Exception
 
81
    {
 
82
        assertTrue(conf.containsKey("test.key"));
 
83
        assertTrue(!conf.containsKey("test.imaginarykey"));
 
84
    }
 
85
 
 
86
    @Test
 
87
    public void testClearProperty()
 
88
    {
 
89
        assertNotNull("null short for the 'test.short' key", conf.getShort("test.short", null));
 
90
        conf.clearProperty("test.short");
 
91
        assertNull("'test.short' property not cleared", conf.getShort("test.short", null));
 
92
    }
 
93
 
 
94
    @Test
 
95
    public void testIsEmpty()
 
96
    {
 
97
        assertFalse("the configuration shouldn't be empty", conf.isEmpty());
 
98
    }
 
99
 
 
100
    @Test
 
101
    public void testGetKeys() throws Exception
 
102
    {
 
103
        boolean found = false;
 
104
        Iterator<String> it = conf.getKeys();
 
105
 
 
106
        assertTrue("no key found", it.hasNext());
 
107
 
 
108
        while (it.hasNext() && !found)
 
109
        {
 
110
            found = "test.boolean".equals(it.next());
 
111
        }
 
112
 
 
113
        assertTrue("'test.boolean' key not found", found);
 
114
    }
 
115
 
 
116
    @Test
 
117
    public void testGetKeysWithUnknownPrefix()
 
118
    {
 
119
        // test for a unknown prefix
 
120
        Iterator<String> it = conf.getKeys("foo.bar");
 
121
        assertFalse("no key should be found", it.hasNext());
 
122
    }
 
123
 
 
124
    @Test
 
125
    public void testGetKeysWithExistingPrefix()
 
126
    {
 
127
        // test for an existing prefix
 
128
        Iterator<String> it = conf.getKeys("test");
 
129
        boolean found = false;
 
130
        while (it.hasNext() && !found)
 
131
        {
 
132
            found = "test.boolean".equals(it.next());
 
133
        }
 
134
 
 
135
        assertTrue("'test.boolean' key not found", found);
 
136
    }
 
137
 
 
138
    @Test
 
139
    public void testGetKeysWithKeyAsPrefix()
 
140
    {
 
141
        // test for a prefix matching exactly the key of a property
 
142
        Iterator<String> it = conf.getKeys("test.boolean");
 
143
        boolean found = false;
 
144
        while (it.hasNext() && !found)
 
145
        {
 
146
            found = "test.boolean".equals(it.next());
 
147
        }
 
148
 
 
149
        assertTrue("'test.boolean' key not found", found);
 
150
    }
 
151
}