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.compass.core.test.nullvalue.simple;
018:
019: import org.compass.core.CompassHits;
020: import org.compass.core.CompassSession;
021: import org.compass.core.CompassTransaction;
022: import org.compass.core.test.AbstractTestCase;
023:
024: /**
025: * @author kimchy
026: */
027: public class SimpleNullValueTests extends AbstractTestCase {
028:
029: protected String[] getMappings() {
030: return new String[] { "nullvalue/simple/mapping.cpm.xml" };
031: }
032:
033: public void testSimleNullValue() throws Exception {
034: CompassSession session = openSession();
035: CompassTransaction tr = session.beginTransaction();
036:
037: A a = new A();
038: a.id = 1;
039: a.value = null;
040: session.save("a", a);
041:
042: a = (A) session.load("a", "1");
043: assertEquals(1, a.id);
044: assertNull(a.value);
045:
046: CompassHits hits = session.find("moo");
047: assertEquals(1, hits.length());
048: hits = session.find("value:moo");
049: assertEquals(1, hits.length());
050:
051: tr.commit();
052: session.close();
053: }
054:
055: public void testManagedIdNullValueBothValuesNull() throws Exception {
056: CompassSession session = openSession();
057: CompassTransaction tr = session.beginTransaction();
058:
059: A a = new A();
060: a.id = 1;
061: a.value = null;
062: a.value2 = null;
063: session.save("a1", a);
064:
065: a = (A) session.load("a1", "1");
066: assertEquals(1, a.id);
067: assertNull(a.value);
068: assertNull(a.value2);
069:
070: CompassHits hits = session.find("moo");
071: assertEquals(1, hits.length());
072: hits = session.find("value:moo");
073: assertEquals(1, hits.length());
074:
075: tr.commit();
076: session.close();
077: }
078:
079: public void testManagedIdNullValueSingleValueNull()
080: throws Exception {
081: CompassSession session = openSession();
082: CompassTransaction tr = session.beginTransaction();
083:
084: A a = new A();
085: a.id = 1;
086: a.value = null;
087: a.value2 = "2";
088: session.save("a1", a);
089:
090: a = (A) session.load("a1", "1");
091: assertEquals(1, a.id);
092: assertNull(a.value);
093: assertEquals("2", a.value2);
094:
095: CompassHits hits = session.find("moo");
096: assertEquals(1, hits.length());
097: hits = session.find("value:moo");
098: assertEquals(1, hits.length());
099:
100: tr.commit();
101: session.close();
102: }
103: }
|