Skip to main content
summaryrefslogtreecommitdiffstats
blob: 076b77a05b15035f4fe32efc79ce6d59a9a64f06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
 * <copyright>
 *
 * Copyright (c) 2005, 2006, 2007 Springsite BV (The Netherlands) and others
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Martin Taal
 * </copyright>
 *
 * $Id: RentalMapAsClassAction.java,v 1.2 2007/03/29 22:13:54 mtaal Exp $
 */

package org.eclipse.emf.teneo.test.emf.sample;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.teneo.PersistenceOptions;
import org.eclipse.emf.teneo.rental.Currency;
import org.eclipse.emf.teneo.rental.Manufacturer;
import org.eclipse.emf.teneo.rental.RentalBicycle;
import org.eclipse.emf.teneo.rental.RentalBicycleType;
import org.eclipse.emf.teneo.rental.RentalCar;
import org.eclipse.emf.teneo.rental.RentalCarSize;
import org.eclipse.emf.teneo.rental.RentalContract;
import org.eclipse.emf.teneo.rental.RentalFactory;
import org.eclipse.emf.teneo.rental.RentalPackage;
import org.eclipse.emf.teneo.rental.impl.RentalContractImpl;
import org.eclipse.emf.teneo.test.AbstractTestAction;
import org.eclipse.emf.teneo.test.StoreTestException;
import org.eclipse.emf.teneo.test.stores.TestStore;

/**
 * Tests mapping an eclass as a class.
 * 
 * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
 * @version $Revision: 1.2 $
 */
public class RentalMapAsClassAction extends AbstractTestAction {
	/**
	 * Constructor for ClassHierarchyParsing.
	 * 
	 * @param arg0
	 */
	public RentalMapAsClassAction() {
		super(RentalPackage.eINSTANCE);
	}

	/**
	 * Set the SET_PROXY property to true.
	 * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
	 */
	@Override
	public Properties getExtraConfigurationProperties() {
		final Properties props = new Properties();
		props.setProperty(PersistenceOptions.SET_PROXY, "true");
		return props;
	}

	/** Test */
	public void doAction(TestStore store) {
		final RentalFactory rf = RentalFactory.eINSTANCE;

		{
			RentalContract rcontract = rf.createRentalContract();
			RentalCar rcar = rf.createRentalCar();
			RentalBicycle rb = rf.createRentalBicycle();
			rcar.setDescription("car");
			rcar.setSize(RentalCarSize.FAMILY);
			rb.setDescription("bicycle");
			rb.setType(RentalBicycleType.MOUNTAIN_BIKE);
			Manufacturer m = rf.createManufacturer();
			m.setCode("gazelle");
			rb.setManufacturer(m);
			rcontract.getRentalUnits().add(rcar);
			rcontract.getRentalUnits().add(rb);
			rcontract.setCost(4.5f);
			rcontract.setStartDate(new Date());
			rcontract.setEndDate(new Date());
			rcontract.setRentToBusinessPartner("business partner");

			Currency c = rf.createCurrency();
			c.setCode("EUR");
			rcontract.setCurrency(c);
			store.beginTransaction();
			store.store(rcontract);
			store.commitTransaction();
		}

		{
			store.beginTransaction();
			final RentalContract rc = (RentalContract) store.query("select rc from RentalContract as rc").get(0);
			assertEquals(2, rc.getRentalUnits().size());
			final RentalCar rcar = (RentalCar) rc.getRentalUnits().get(0);
			final RentalBicycle rb = (RentalBicycle) rc.getRentalUnits().get(1);
			Currency c = rc.getCurrency();
			assertEquals("EUR", c.getCode());
			assertTrue(c.getClass().getSimpleName().indexOf("$$") != -1); // rough test, no dependencies on hibernate from this package
			assertEquals("car", rcar.getDescription());
			assertEquals(RentalBicycleType.MOUNTAIN_BIKE, rb.getType());
			assertEquals("bicycle", rb.getDescription());
			store.commitTransaction();
		}

		{
			store.beginTransaction();
			List<?> list = store.query("select rc from " + RentalContractImpl.class.getName() + " as rc");
			RentalContract rc = (RentalContract)list.get(0);
			assertEquals(2, rc.getRentalUnits().size());
			final RentalCar rcar = (RentalCar) rc.getRentalUnits().get(0);
			final RentalBicycle rb = (RentalBicycle) rc.getRentalUnits().get(1);
			Currency c = rc.getCurrency();
			assertEquals("EUR", c.getCode());
			assertTrue(c.getClass().getSimpleName().indexOf("$$") != -1); // rough test, no dependencies on hibernate from this package
			assertEquals("car", rcar.getDescription());
			assertEquals(RentalBicycleType.MOUNTAIN_BIKE, rb.getType());
			assertEquals("bicycle", rb.getDescription());
			store.commitTransaction();
		}

		{
			store.beginTransaction();
			List<?> list = store.query("select rc from " + RentalContract.class.getName() + " as rc");
			RentalContract rc = (RentalContract)list.get(0);
			assertEquals(2, rc.getRentalUnits().size());
			final RentalCar rcar = (RentalCar) rc.getRentalUnits().get(0);
			final RentalBicycle rb = (RentalBicycle) rc.getRentalUnits().get(1);
			Currency c = rc.getCurrency();
			assertEquals("EUR", c.getCode());
			assertTrue(c.getClass().getSimpleName().indexOf("$$") != -1); // rough test, no dependencies on hibernate from this package
			assertEquals("car", rcar.getDescription());
			assertEquals(RentalBicycleType.MOUNTAIN_BIKE, rb.getType());
			assertEquals("bicycle", rb.getDescription());
			store.commitTransaction();
		}
		
		try {
			Resource res = store.getResource();
			res.load(Collections.EMPTY_MAP);
			assertEquals(5, res.getContents().size());
		} catch (Exception e) {
			throw new StoreTestException(e.getMessage(), e);
		}
	}
}

Back to the top