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.map;
18:
19: import java.util.HashMap;
20:
21: import org.compass.core.CompassHits;
22: import org.compass.core.CompassSession;
23: import org.compass.core.CompassTransaction;
24: import org.compass.core.config.CompassConfiguration;
25: import org.compass.core.test.AbstractTestCase;
26:
27: /**
28: * @author kimchy
29: */
30: public class MapTests extends AbstractTestCase {
31:
32: protected String[] getMappings() {
33: return new String[] { "map/Map.cpm.xml" };
34: }
35:
36: protected void addExtraConf(CompassConfiguration conf) {
37: MapConverter mapConverter = new MapConverter();
38: conf.registerConverter("map", mapConverter);
39: }
40:
41: public void testMapConverter() throws Exception {
42: CompassSession session = openSession();
43: CompassTransaction tr = session.beginTransaction();
44:
45: A a = new A();
46: a.id = new Long(1);
47: a.data = new HashMap();
48: a.data.put("entry1", "value1");
49: a.data.put("entry2", "value2");
50:
51: session.save("a1", a);
52:
53: CompassHits hits = session.find("entry1:value1");
54: assertEquals(1, hits.length());
55:
56: // here we test that it is part of the all property as well
57: hits = session.find("value1");
58: assertEquals(1, hits.length());
59:
60: hits = session.find("value2");
61: assertEquals(1, hits.length());
62:
63: hits = session.find("entry1:value2");
64: assertEquals(0, hits.length());
65:
66: a = (A) session.load("a1", new Long(1));
67: assertNotNull(a.data);
68: assertEquals(2, a.data.size());
69: assertEquals("value1", a.data.get("entry1"));
70: assertEquals("value2", a.data.get("entry2"));
71:
72: tr.commit();
73: session.close();
74: }
75: }
|