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.component.poly2;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.compass.core.CompassSession;
023: import org.compass.core.CompassTransaction;
024: import org.compass.core.config.CompassConfiguration;
025: import org.compass.core.test.AbstractTestCase;
026:
027: /**
028: * @author kimchy
029: */
030: public class Poly2ComponentTests extends AbstractTestCase {
031:
032: protected String[] getMappings() {
033: return new String[0];
034: }
035:
036: protected void addExtraConf(CompassConfiguration conf) {
037: conf.addClass(Address.class).addClass(
038: AddressToPipeAssignment.class).addClass(
039: AddressToServiceAssignment.class).addClass(
040: Assignment.class);
041: }
042:
043: public void testPoly2() {
044: CompassSession session = openSession();
045: CompassTransaction tx = session.beginTransaction();
046:
047: Address pipeAddress = new Address();
048: pipeAddress.setId(1l);
049: pipeAddress.setName("pipe1");
050:
051: AddressToPipeAssignment pa1 = new AddressToPipeAssignment();
052: pa1.setPipeName("pipeName1");
053: pa1.setStatus("pipeStatus1");
054: AddressToServiceAssignment sa1 = new AddressToServiceAssignment();
055: sa1.setServiceName("serviceName1");
056: sa1.setStatus("serviceStatus1");
057: List<Assignment> ass1 = new ArrayList<Assignment>();
058: ass1.add(pa1);
059: ass1.add(sa1);
060:
061: pipeAddress.setAssignment(ass1);
062:
063: Address serviceAddress = new Address();
064: serviceAddress.setId(2l);
065: serviceAddress.setName("service1");
066:
067: AddressToPipeAssignment pa2 = new AddressToPipeAssignment();
068: pa2.setPipeName("pipeName2");
069: pa2.setStatus("pipeStatus2");
070: AddressToServiceAssignment sa2 = new AddressToServiceAssignment();
071: sa2.setServiceName("serviceName2");
072: sa2.setStatus("serviceStatus2");
073: List<Assignment> ass2 = new ArrayList<Assignment>();
074: ass2.add(pa2);
075: ass2.add(sa2);
076: serviceAddress.setAssignment(ass2);
077:
078: session.create(pipeAddress);
079: session.create(serviceAddress);
080:
081: pipeAddress = session.load(Address.class, "1");
082: assertEquals(2, pipeAddress.getAssignment().size());
083: assertEquals(AddressToPipeAssignment.class, pipeAddress
084: .getAssignment().get(0).getClass());
085: assertEquals("pipeStatus1", pipeAddress.getAssignment().get(0)
086: .getStatus());
087: assertEquals("pipeName1",
088: ((AddressToPipeAssignment) pipeAddress.getAssignment()
089: .get(0)).getPipeName());
090: assertEquals(AddressToServiceAssignment.class, pipeAddress
091: .getAssignment().get(1).getClass());
092: assertEquals("serviceStatus1", pipeAddress.getAssignment().get(
093: 1).getStatus());
094: assertEquals("serviceName1",
095: ((AddressToServiceAssignment) pipeAddress
096: .getAssignment().get(1)).getServiceName());
097:
098: serviceAddress = session.load(Address.class, "2");
099: assertEquals(2, serviceAddress.getAssignment().size());
100: assertEquals(AddressToPipeAssignment.class, serviceAddress
101: .getAssignment().get(0).getClass());
102: assertEquals(AddressToServiceAssignment.class, serviceAddress
103: .getAssignment().get(1).getClass());
104:
105: tx.commit();
106: session.close();
107: }
108: }
|