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