Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3b41dcbfc46153659de1ef9b5de8190c6e94a3b6 (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
/**
 * <copyright>
 *
 * Copyright (c) 2005, 2006, 2007, 2008 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: SimpleRentalAction.java,v 1.3 2010/10/29 09:35:22 mtaal Exp $
 */

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

import java.util.Date;
import java.util.List;

import org.eclipse.emf.teneo.rental.Manufacturer;
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.test.AbstractTestAction;
import org.eclipse.emf.teneo.test.stores.TestStore;

/**
 * Tests creating holes in a list index in the db
 * 
 * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
 * @version $Revision: 1.3 $
 */
public class SimpleRentalAction extends AbstractTestAction {
	/**
	 * Constructor for ClassHierarchyParsing.
	 * 
	 * @param arg0
	 */
	public SimpleRentalAction() {
		super(RentalPackage.eINSTANCE);
	}

	/** Test */
	@Override
	public void doAction(TestStore store) {
		final RentalFactory rf = RentalFactory.eINSTANCE;
		{
			RentalContract rcontract = rf.createRentalContract();
			RentalCar rcar1 = rf.createRentalCar();
			rcar1.setDescription("car1");
			rcar1.setSize(RentalCarSize.FAMILY);
			RentalCar rcar2 = rf.createRentalCar();
			rcar2.setDescription("car2");
			rcar2.setSize(RentalCarSize.FAMILY);
			RentalCar rcar3 = rf.createRentalCar();
			rcar3.setDescription("car3");
			rcar3.setSize(RentalCarSize.FAMILY);
			rcontract.getRentalUnits().add(rcar1);
			rcontract.getRentalUnits().add(rcar2);
			rcontract.getRentalUnits().add(rcar3);
			rcontract.setCost(4.5f);
			rcontract.setEndDate(new Date());
			rcontract.setStartDate(new Date());
			rcontract.setRentToBusinessPartner("business partner");
			store.beginTransaction();
			store.store(rcontract);
			
			Manufacturer man = rf.createManufacturer();
			man.setCode("code");
			man.setTrusted(false);
			store.store(man);
			
			store.commitTransaction();
		}

		{
			store.beginTransaction();
			List<?> cars = store.getObjects(RentalCar.class);
			for (Object o : cars) {
				final RentalCar rc = (RentalCar) o;
				if (rc.getDescription().compareTo("car2") == 0) {
					store.deleteObject(rc);
				}
			}
			store.commitTransaction();
		}

		{
			try {
				store.beginTransaction();
				final RentalContract rc = store.getObject(RentalContract.class);
				assertTrue(null == rc.getRentalUnits().get(1));
				store.commitTransaction();
				fail();
			} catch (NullPointerException npe) {
				// do nothing we should get here
			}
		}

	}
}

Back to the top