01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.test.nullvalue.global;
18:
19: import org.compass.core.CompassHits;
20: import org.compass.core.CompassSession;
21: import org.compass.core.CompassTransaction;
22: import org.compass.core.Resource;
23: import org.compass.core.config.CompassConfiguration;
24: import org.compass.core.config.CompassEnvironment;
25: import org.compass.core.test.AbstractTestCase;
26:
27: /**
28: * @author kimchy
29: */
30: public class GlobalNullValueTests extends AbstractTestCase {
31:
32: protected String[] getMappings() {
33: return new String[] { "nullvalue/global/mapping.cpm.xml" };
34: }
35:
36: protected void addExtraConf(CompassConfiguration conf) {
37: conf.setSetting(CompassEnvironment.NullValue.NULL_VALUE, "koo");
38: }
39:
40: public void testGlobalNullValueSettingsAllNulls() throws Exception {
41: CompassSession session = openSession();
42: CompassTransaction tr = session.beginTransaction();
43:
44: A a = new A();
45: a.id = 1;
46: session.save("a", a);
47:
48: a = (A) session.load("a", 1);
49: assertNull(a.value1);
50: assertNull(a.value2);
51: assertNull(a.value3);
52:
53: Resource resource = session.loadResource("a", 1);
54: // value1 uses the global setting
55: assertEquals("koo", resource.getValue("value1"));
56: // value2 defines his own
57: assertEquals("moo", resource.getValue("value2"));
58: // value3 defines $disable$ which means it needs to be disabled
59: assertNull(resource.getValue("value3"));
60:
61: CompassHits hits = session.find("value1:koo");
62: assertEquals(1, hits.length());
63: hits = session.find("value2:moo");
64: assertEquals(1, hits.length());
65: hits = session.find("value3:moo");
66: assertEquals(0, hits.length());
67:
68: tr.commit();
69: session.close();
70: }
71: }
|