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.annotations.test.extend;
018:
019: import org.compass.annotations.test.AbstractAnnotationsTestCase;
020: import org.compass.core.CompassHits;
021: import org.compass.core.CompassSession;
022: import org.compass.core.CompassTransaction;
023: import org.compass.core.config.CompassConfiguration;
024: import org.compass.core.mapping.ResourceMapping;
025: import org.compass.core.spi.InternalCompass;
026:
027: /**
028: * @author kimchy
029: */
030: public class ExtendTests extends AbstractAnnotationsTestCase {
031:
032: protected void addExtraConf(CompassConfiguration conf) {
033: conf.addClass(A.class);
034: }
035:
036: public void testExtendsAliases() {
037: ResourceMapping resourceMapping = ((InternalCompass) getCompass())
038: .getMapping().getMappingByAlias("A");
039: assertEquals(2, resourceMapping.getExtendedAliases().length);
040: }
041:
042: public void testCpmAndAnnotations() throws Exception {
043: CompassSession session = openSession();
044: CompassTransaction tr = session.beginTransaction();
045:
046: A a = new A();
047: a.setId(1);
048: a.setValue("value");
049: a.setValue2("value2");
050: session.save(a);
051:
052: a = (A) session.load(A.class, 1);
053: assertEquals("value", a.getValue());
054: assertEquals("value2", a.getValue2());
055:
056: CompassHits hits = session.find("value");
057: assertEquals(1, hits.length());
058:
059: hits = session.find("value2");
060: assertEquals(1, hits.length());
061:
062: tr.commit();
063: session.close();
064: }
065:
066: public void testPolyAliasQuery() {
067: CompassSession session = openSession();
068: CompassTransaction tr = session.beginTransaction();
069:
070: A a = new A();
071: a.setId(1);
072: a.setValue("value");
073: a.setValue2("value2");
074: session.save(a);
075:
076: CompassHits hits = session.queryBuilder().alias("A").hits();
077: assertEquals(1, hits.length());
078: hits = session.queryBuilder().polyAlias("A").hits();
079: assertEquals(1, hits.length());
080: hits = session.queryBuilder().polyAlias("A-contract").hits();
081: assertEquals(1, hits.length());
082: hits = session.queryBuilder().polyAlias("A-contract2").hits();
083: assertEquals(1, hits.length());
084:
085: tr.commit();
086: session.close();
087: }
088:
089: public void testSetAliases() {
090: CompassSession session = openSession();
091: CompassTransaction tr = session.beginTransaction();
092:
093: A a = new A();
094: a.setId(1);
095: a.setValue("value");
096: a.setValue2("value2");
097: session.save(a);
098:
099: CompassHits hits = session.queryBuilder().matchAll()
100: .setAliases(new String[] { "A" }).hits();
101: assertEquals(1, hits.length());
102:
103: tr.commit();
104: session.close();
105: }
106:
107: public void testSetClases() {
108: CompassSession session = openSession();
109: CompassTransaction tr = session.beginTransaction();
110:
111: A a = new A();
112: a.setId(1);
113: a.setValue("value");
114: a.setValue2("value2");
115: session.save(a);
116:
117: CompassHits hits = session.queryBuilder().matchAll().setTypes(
118: new Class[] { A.class }).hits();
119: assertEquals(1, hits.length());
120:
121: tr.commit();
122: session.close();
123: }
124: }
|