Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6f102fb2f36c32b0ec60ae5dae6f3583b98d88a0 (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
/**
 * <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: HibernateAction.java,v 1.3 2008/08/11 20:46:34 mtaal Exp $
 */

package org.eclipse.emf.teneo.hibernate.test.emf.annotations;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.teneo.samples.emf.annotations.hibernate.City;
import org.eclipse.emf.teneo.samples.emf.annotations.hibernate.HibernateFactory;
import org.eclipse.emf.teneo.samples.emf.annotations.hibernate.HibernatePackage;
import org.eclipse.emf.teneo.samples.emf.annotations.hibernate.State;
import org.eclipse.emf.teneo.samples.emf.annotations.hibernate.StateDetail;
import org.eclipse.emf.teneo.samples.emf.annotations.hibernate.Street;
import org.eclipse.emf.teneo.test.AbstractTestAction;
import org.eclipse.emf.teneo.test.stores.TestStore;

/**
 * Test for several hibernate annotations. See bugzilla: 242895, 242897
 * 
 * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
 * @version $Revision: 1.3 $
 */
public class HibernateAction extends AbstractTestAction {
	/** How many test objects are created */
	private static final int NO_TEST_OBJECTS = 10;

	final HibernateFactory factory = HibernateFactory.eINSTANCE;

	public HibernateAction() {
		super(HibernatePackage.eINSTANCE);
	}

// @Override
// public Properties getExtraConfigurationProperties() {
// final Properties props = new Properties();
// props.setProperty(PersistenceOptions.DEFAULT_TEMPORAL_VALUE, "DATE");
// return props;
// }

	@Override
	public void doAction(TestStore store) {
		store.disableDrop();
		{
			store.beginTransaction();
			store.store(createCities());

			final State st = factory.createState();
			store.store(st);
			final StateDetail std = factory.createStateDetail();
			store.store(std);
			store.commitTransaction();
		}

		{
			store.beginTransaction();
			final State st = factory.createState();
			store.store(st);
			final StateDetail std = factory.createStateDetail();
			std.setState(st);
			store.store(std);
			store.commitTransaction();
		}

		{
			store.beginTransaction();
			final List<City> cities = store.getObjects(City.class);
			store.deleteObject(cities.get(0));
			store.commitTransaction();
		}

		{
			final List<State> states = store.getObjects(State.class);
			int cnt = 0;
			for (State st : states) {
				if (st.getStateDetail() != null) {
					cnt++;
				}
			}
			assertEquals(1, cnt);
		}
	}

	private List<City> createCities() {
		final List<City> cities = new ArrayList<City>();
		for (int i = 0; i < NO_TEST_OBJECTS; i++) {
			final City city = factory.createCity();
			city.setName("city " + i);
			city.getStreets().addAll(createStreets("city" + i));
			cities.add(city);
		}
		return cities;
	}

	private List<Street> createStreets(String prefix) {
		final List<Street> streets = new ArrayList<Street>();
		for (int i = 0; i < NO_TEST_OBJECTS; i++) {
			final Street street = factory.createStreet();
			street.setName(prefix + " - street " + i);
			streets.add(street);
		}
		return streets;
	}
}

Back to the top