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.reverse;
018:
019: import org.compass.core.CompassHits;
020: import org.compass.core.CompassSession;
021: import org.compass.core.CompassTransaction;
022: import org.compass.core.Resource;
023: import org.compass.core.test.AbstractTestCase;
024:
025: /**
026: * @author kimchy
027: */
028: public class ReverseTests extends AbstractTestCase {
029:
030: protected String[] getMappings() {
031: return new String[] { "reverse/reverse.cpm.xml" };
032: }
033:
034: public void testReverseAndInternalIdAnString() {
035: CompassSession session = openSession();
036: CompassTransaction tr = session.beginTransaction();
037:
038: Long id = new Long(1);
039: A a = new A();
040: a.setId(id);
041: a.setValue("12345");
042:
043: session.save("a1", a);
044:
045: Resource resource = session.loadResource("a1", id);
046: assertNotNull(resource.getProperty("$/a1/value"));
047: assertEquals("12345", resource.getProperty("$/a1/value")
048: .getStringValue());
049: assertEquals("54321", resource.getProperty("value")
050: .getStringValue());
051:
052: a = (A) session.load("a1", id);
053: assertEquals("12345", a.getValue());
054:
055: CompassHits hits = session.find("54*");
056: assertEquals(1, hits.length());
057:
058: hits = session.find("value:54*");
059: assertEquals(1, hits.length());
060:
061: tr.commit();
062: session.close();
063:
064: }
065:
066: public void testReverseReader() {
067: CompassSession session = openSession();
068: CompassTransaction tr = session.beginTransaction();
069:
070: Long id = new Long(1);
071: A a = new A();
072: a.setId(id);
073: a.setValue("12345");
074:
075: session.save("a2", a);
076:
077: a = (A) session.load("a2", id);
078: assertEquals("12345", a.getValue());
079:
080: session.loadResource("a2", id);
081:
082: CompassHits hits = session.find("valuerev:54*");
083: assertEquals(1, hits.length());
084:
085: hits = session.find("54321");
086: assertEquals(1, hits.length());
087:
088: hits = session.find("54*");
089: assertEquals(1, hits.length());
090:
091: hits = session.find("value:12*");
092: assertEquals(1, hits.length());
093:
094: hits = session.find("12*");
095: assertEquals(1, hits.length());
096:
097: tr.commit();
098: session.close();
099: }
100: }
|