001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.lucene.store.jdbc;
018:
019: import junit.framework.TestCase;
020:
021: import org.apache.lucene.store.jdbc.handler.MarkDeleteFileEntryHandler;
022: import org.apache.lucene.store.jdbc.index.FetchOnBufferReadJdbcIndexInput;
023: import org.apache.lucene.store.jdbc.index.RAMAndFileJdbcIndexOutput;
024:
025: /**
026: * @author kimchy
027: */
028: public class JdbcFileEntrySettingsTests extends TestCase {
029:
030: public void testDefaultSettings() throws Exception {
031: JdbcFileEntrySettings settings = new JdbcFileEntrySettings();
032:
033: assertEquals(3, settings.getProperties().size());
034: assertEquals(MarkDeleteFileEntryHandler.class, settings
035: .getSettingAsClass(
036: JdbcFileEntrySettings.FILE_ENTRY_HANDLER_TYPE,
037: null));
038: assertEquals(FetchOnBufferReadJdbcIndexInput.class, settings
039: .getSettingAsClass(
040: JdbcFileEntrySettings.INDEX_INPUT_TYPE_SETTING,
041: null));
042: assertEquals(
043: RAMAndFileJdbcIndexOutput.class,
044: settings
045: .getSettingAsClass(
046: JdbcFileEntrySettings.INDEX_OUTPUT_TYPE_SETTING,
047: null));
048: }
049:
050: public void testSetting() {
051: JdbcFileEntrySettings settings = new JdbcFileEntrySettings();
052: String value1 = settings.getSetting("value1");
053: assertNull(value1);
054:
055: value1 = settings.getSetting("value1", "default");
056: assertEquals("default", value1);
057:
058: settings.setSetting("value1", "val");
059:
060: value1 = settings.getSetting("value1");
061: assertEquals("val", value1);
062:
063: value1 = settings.getSetting("value1", "default");
064: assertEquals("val", value1);
065: }
066:
067: public void testSettingFloat() {
068: JdbcFileEntrySettings settings = new JdbcFileEntrySettings();
069: float value1 = settings.getSettingAsFloat("value1", 0);
070: assertEquals(0f, value1, 0.01);
071:
072: settings.setFloatSetting("value1", 1.1f);
073:
074: value1 = settings.getSettingAsFloat("value1", 0.0f);
075: assertEquals(1.1f, value1, 0.01);
076: }
077:
078: public void testSettingLong() {
079: JdbcFileEntrySettings settings = new JdbcFileEntrySettings();
080: long value1 = settings.getSettingAsLong("value1", 0);
081: assertEquals(0, value1);
082:
083: settings.setLongSetting("value1", 1);
084:
085: value1 = settings.getSettingAsLong("value1", 0);
086: assertEquals(1, value1);
087: }
088:
089: public void testSettingInt() {
090: JdbcFileEntrySettings settings = new JdbcFileEntrySettings();
091: int value1 = settings.getSettingAsInt("value1", 0);
092: assertEquals(0, value1);
093:
094: settings.setIntSetting("value1", 1);
095:
096: value1 = settings.getSettingAsInt("value1", 0);
097: assertEquals(1, value1);
098: }
099:
100: public void testSettingBoolean() {
101: JdbcFileEntrySettings settings = new JdbcFileEntrySettings();
102: boolean value1 = settings.getSettingAsBoolean("value1", false);
103: assertFalse(value1);
104:
105: settings.setBooleanSetting("value1", true);
106:
107: value1 = settings.getSettingAsBoolean("value1", false);
108: assertTrue(value1);
109: }
110:
111: public void testSettingClass() throws Exception {
112: JdbcFileEntrySettings settings = new JdbcFileEntrySettings();
113: Class value1 = settings
114: .getSettingAsClass("value1", Class.class);
115: assertEquals(Class.class, value1);
116:
117: settings.setClassSetting("value1", Object.class);
118:
119: value1 = settings.getSettingAsClass("value1", Class.class);
120: assertEquals(Object.class, value1);
121: }
122: }
|