Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4b5291131d26a8784e1a92a1f4011946d0f3300d (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
/**
 * <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: AbstractActionTest.java,v 1.8 2008/02/28 07:08:16 mtaal Exp $
 */

package org.eclipse.emf.teneo.test;

import java.util.Properties;

import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.teneo.Constants;
import org.eclipse.emf.teneo.PersistenceOptions;
import org.eclipse.emf.teneo.extension.ExtensionManager;

/**
 * Hibernate test based on abstract action.
 * 
 * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
 * @version $Revision: 1.8 $
 */
public class AbstractActionTest extends AbstractTest {
	/** The action contains the real test */
	protected AbstractTestAction itsTestAction;

	private Properties properties;

	/** Constructor */
	public AbstractActionTest(Class<?> testActionClass) {
		super("testAction");
		try {
			itsTestAction = (AbstractTestAction) testActionClass.newInstance();
		} catch (Exception e) {
			throw new StoreTestException("Exception while instantiating " + testActionClass.getName(), e);
		}
	}

	/** Constructor */
	public AbstractActionTest(AbstractTestAction itsTestAction) {
		this(itsTestAction, null);
	}

	/**
	 * Constructs an instance with additional OR-mapping properties.
	 * 
	 * @param itsTestAction
	 * @param properties
	 */
	public AbstractActionTest(AbstractTestAction itsTestAction, Properties properties) {
		super("testAction");
		this.itsTestAction = itsTestAction;
		this.properties = properties;
	}

	/** returns the underlying test action */
	public AbstractTestAction getTestAction() {
		return itsTestAction;
	}

	/** The actual test run */
	public void testAction() {
		getTestAction().doAction(getStore());
	}

	/** Return the epackages for which this test is done */
	@Override
	public EPackage[] getEPackages() {
		return getTestAction().getEPackages();
	}

	/** Return the test package name */
	@Override
	public String getTestPackageName() {
		return getTestAction().getTestPackageName();
	}

	public Properties getProperties() {
		return properties;
	}

	public void setProperties(Properties props) {
		properties = props;
	}

	/** Return the test package name */
	@Override
	public Package getTestPackage() {
		return getTestAction().getClass().getPackage();
	}

	/** Returns extra properties which are passed to the or layer for additional configuration */
	@Override
	public Properties getExtraConfigurationProperties() {
		Properties allProperties = getTestAction().getExtraConfigurationProperties();

		if (!getTestAction().supportAuditing()) {
			allProperties.setProperty(Constants.ANNOTATION_AUDITING_NOT, "true");
		}

		allProperties.setProperty(PersistenceOptions.HIBERNATE_VERSION, "4.2.7SP1");
		
		// override some defaults
		if (allProperties.get(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT) == null) {
			allProperties.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
		}

		if (allProperties.get(PersistenceOptions.JOIN_TABLE_NAMING_STRATEGY) == null) {
			allProperties.setProperty(PersistenceOptions.JOIN_TABLE_NAMING_STRATEGY, "ejb3");
		}

		if (this.properties != null) {
			allProperties.putAll(this.properties);
		}
		
		return allProperties;
	}

	/** Add extensions if you want */
	@Override
	public void setExtensions(ExtensionManager extensionManager) {
		getTestAction().setExtensions(extensionManager);
	}

	/** Returns a unique name based on the class name of the testAction class */
	@Override
	public String getName() {
		return itsTestAction.getClass().getName();
	}

	/** Returns a simple name based on the class name of the testAction class. */
	@Override
	public String getSimpleName() {
		final String name = getName();
		return name.substring(name.lastIndexOf(".") + 1);
	}
}

Back to the top