Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 620ec258a17f51964feb092b92ac9c43c4c2ba26 (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
/*******************************************************************************
 * Copyright (c) 2006, 2007 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.model;

import junit.framework.TestCase;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.jpt.core.internal.IJpaModel;
import org.eclipse.jpt.core.internal.IJpaProject;
import org.eclipse.jpt.core.internal.JptCorePlugin;
import org.eclipse.jpt.core.tests.internal.ProjectUtility;
import org.eclipse.jpt.core.tests.internal.projects.TestFacetedProject;
import org.eclipse.jpt.utility.internal.ClassTools;
import org.eclipse.jpt.utility.internal.CollectionTools;

public class ModelInitializationTests extends TestCase {
	private IJpaModel jpaModel;
	
	
	public ModelInitializationTests(String name) {
		super(name);
	}
	
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		ProjectUtility.deleteAllProjects();
		this.jpaModel = JptCorePlugin.getJpaModel();
	}
	
	@Override
	protected void tearDown() throws Exception {
		ProjectUtility.deleteAllProjects();
		this.jpaModel = null;
		super.tearDown();
	}

	/** 
	 * Builds a project with the java and utility facets installed, and with
	 * pre-existing entities added.
	 */
	private TestFacetedProject buildTestProject() throws CoreException {
		TestFacetedProject testProject = new TestFacetedProject(ClassTools.shortClassNameForObject(this), true);
		testProject.installFacet("jst.java", "5.0");
		testProject.installFacet("jst.utility", "1.0");
		testProject.createFile(
			new Path("src/test.pkg/TestEntity.java"),
			"package test.pkg; @Entity public class TestEntity {}");
		testProject.createFile(
			new Path("src/test.pkg/TestEntity2.java"),
			"package test.pkg; @Entity public class TestEntity2 {}");
		return testProject;
	}	
		
	public void testBasic() {
		assertNotNull(this.jpaModel);
	}
	
	public void testFacetInstallation() throws CoreException {
		TestFacetedProject testProject = buildTestProject();
		assertNull(this.jpaModel.getJpaProject(testProject.getProject()));
		testProject.installFacet("jpt.jpa", "1.0");
		assertEquals(1, CollectionTools.size(this.jpaModel.jpaProjects()));
		IJpaProject jpaProject = this.jpaModel.getJpaProject(testProject.getProject());
		assertNotNull(jpaProject);
		assertEquals(4, CollectionTools.size(jpaProject.jpaFiles()));
		assertNotNull(jpaProject.getJpaFile(testProject.getProject().getFile(new Path("src/test.pkg/TestEntity.java"))));
		assertNotNull(jpaProject.getJpaFile(testProject.getProject().getFile(new Path("src/test.pkg/TestEntity2.java"))));
	}
	
	public void testProjectOpening() throws CoreException {
		TestFacetedProject testProject = buildTestProject();
		testProject.installFacet("jpt.jpa", "1.0");
		testProject.close();
		assertTrue(! testProject.getProject().isOpen());
		testProject.open();
		IJpaProject jpaProject = this.jpaModel.getJpaProject(testProject.getProject());
		assertNotNull(jpaProject);
		assertNotNull(jpaProject.getJpaFile(testProject.getProject().getFile(new Path("src/test.pkg/TestEntity.java"))));
		assertNotNull(jpaProject.getJpaFile(testProject.getProject().getFile(new Path("src/test.pkg/TestEntity2.java"))));
	}
	
}

Back to the top