001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.harmony.jndi.tests.javax.naming;
018:
019: import javax.naming.Binding;
020:
021: import junit.framework.TestCase;
022: import org.apache.harmony.jndi.tests.javax.naming.util.Log;
023:
024: public class BindingTest extends TestCase {
025:
026: private static final Log log = new Log(BindingTest.class);
027:
028: /**
029: * Constructor for TestBinding.
030: *
031: * @param arg0
032: */
033: public BindingTest(String arg0) {
034: super (arg0);
035: }
036:
037: /*
038: * @see TestCase#setUp()
039: */
040: @Override
041: protected void setUp() throws Exception {
042: super .setUp();
043: }
044:
045: /*
046: * @see TestCase#tearDown()
047: */
048: @Override
049: protected void tearDown() throws Exception {
050: super .tearDown();
051: }
052:
053: public void testConstructor_Simple() {
054: Binding p;
055:
056: p = new Binding("name1", new Integer(1));
057: assertEquals("name1", p.getName());
058: assertEquals("java.lang.Integer", p.getClassName());
059: assertEquals(new Integer(1), p.getObject());
060: assertTrue(p.isRelative());
061: }
062:
063: public void testConstructor_NullValue() {
064: Binding p;
065:
066: p = new Binding("name1", null, null);
067: assertEquals("name1", p.getName());
068: assertNull(p.getClassName());
069: assertNull(p.getObject());
070: }
071:
072: public void testConstructor_DefaultRelativeValue() {
073: Binding p;
074:
075: p = new Binding("name1", null);
076: assertTrue(p.isRelative());
077: }
078:
079: public void testToString() {
080: log.setMethod("testToString");
081: Binding p;
082:
083: p = new Binding("name1", null, false);
084: assertTrue(p.toString().startsWith("(not relative"));
085: p = new Binding("name1", new Integer(3));
086: String str = p.toString();
087: assertTrue(str.indexOf("name1") > -1);
088: assertTrue(str.indexOf("3") > -1);
089: assertTrue(str.indexOf("java.lang.Integer") > -1);
090: }
091:
092: public void testGetSetObject() {
093: Binding p;
094: log.setMethod("testGetSetObject");
095: p = new Binding("name", null);
096: p.setObject(new Integer(2));
097: assertEquals(new Integer(2), p.getObject());
098: assertEquals("java.lang.Integer", p.getClassName());
099: p.setObject(null);
100: assertNull(p.getObject());
101: assertNull(p.getClassName());
102: p.setObject(new Float(2));
103: assertEquals(new Float(2), p.getObject());
104: assertEquals(Float.class.getName(), p.getClassName());
105: p.setObject(null);
106: assertNull(p.getObject());
107: assertNull(p.getClassName());
108: }
109:
110: public void testGetSetName() {
111: Binding p;
112:
113: p = new Binding("name", new Integer(1));
114: assertEquals("name", p.getName());
115: p.setName("name1");
116: assertEquals("name1", p.getName());
117: p.setName("");
118: assertEquals("", p.getName());
119: }
120:
121: public void testGetSetClassName() {
122: Binding p;
123:
124: p = new Binding("name", new Integer(1));
125: assertEquals(Integer.class.getName(), p.getClassName());
126: p.setClassName(Character.class.getName());
127: assertEquals(Character.class.getName(), p.getClassName());
128: }
129:
130: public void testGetSetRelative() {
131: Binding p;
132:
133: p = new Binding("name", new Integer(1));
134: assertTrue(p.isRelative());
135: p.setRelative(false);
136: assertFalse(p.isRelative());
137: }
138: }
|