Skip to main content
summaryrefslogtreecommitdiffstats
blob: 807e2b6c572635f3b8b324a03dbd44a426338c2a (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
/*******************************************************************************
 * Copyright (c) 2007, 2009 Oracle. 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:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.core.tests.internal.context.persistence;

import org.eclipse.jpt.core.context.JpaRootContextNode;
import org.eclipse.jpt.core.internal.operations.PersistenceFileCreationDataModelProperties;
import org.eclipse.jpt.core.internal.operations.PersistenceFileCreationDataModelProvider;
import org.eclipse.jpt.core.resource.xml.JpaXmlResource;
import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase;
import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;

public class RootContextNodeTests extends ContextModelTestCase
{
	public RootContextNodeTests(String name) {
		super(name);
	}
	
	public void testUpdateAddPersistenceXml() throws Exception {
		deleteResource(getPersistenceXmlResource());
		JpaRootContextNode baseJpaContent = getJavaProject().getJpaProject().getRootContextNode();
		
		assertFalse(getPersistenceXmlResource().fileExists());
		assertNull(baseJpaContent.getPersistenceXml());
		
		IDataModel config =
			DataModelFactory.createDataModel(new PersistenceFileCreationDataModelProvider());
		config.setProperty(PersistenceFileCreationDataModelProperties.PROJECT_NAME, getJpaProject().getProject().getName());
		config.getDefaultOperation().execute(null, null);
		
		assertNotNull(baseJpaContent.getPersistenceXml());
	}
	
	public void testUpdateRemovePersistenceXml() throws Exception {
		JpaXmlResource pr = getPersistenceXmlResource();
		JpaRootContextNode baseJpaContent = getJavaProject().getJpaProject().getRootContextNode();
		
		assertNotNull(baseJpaContent.getPersistenceXml());
		
		deleteResource(pr);
		
		assertNull(baseJpaContent.getPersistenceXml());
	}
}

Back to the top