Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9491bb9364c2feb253ff58629f0a114e56c4ee0f (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
/*******************************************************************************
 * <copyright>
 *
 * Copyright (c) 2005, 2010 SAP AG.
 * 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:
 *    Stefan Dimov - initial API, implementation and documentation
 *
 * </copyright>
 *
 *******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.editor;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.concurrent.Semaphore;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.CreateDiagramJob;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory;
import org.junit.Test;

@SuppressWarnings("nls")
public class CreateDiagramTest {
	
	@Test
	public void testCreateDiagramWhenPersistenceUnitHasDifferentNameFromTheProject() throws InterruptedException, CoreException {		
		JPACreateFactory factory = JPACreateFactory.instance();
		JpaProject jpaProject = factory.createJPAProject("JPA_" + System.currentTimeMillis());
		assertNotNull(jpaProject);
		String persistenceUnitName = jpaProject.getName() + "_unit";
		PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpaProject); 
		pu.setName(persistenceUnitName);
		assertEquals(persistenceUnitName, pu.getName());
		
		
		final CreateDiagramJob createDiagramRunnable = new CreateDiagramJob(pu, 10, true);
		createDiagramRunnable.setRule(ResourcesPlugin.getWorkspace().getRoot());
		final Semaphore s = new Semaphore(0); 
		createDiagramRunnable.addJobChangeListener(new JobChangeAdapter(){
			@Override
			public void done(IJobChangeEvent event) {
				s.release();
			}
		});
		createDiagramRunnable.setUser(true);
		createDiagramRunnable.schedule();
		s.acquire();
		Diagram d = createDiagramRunnable.getDiagram();
		assertEquals(jpaProject.getName(), d.getName());
	}

}

Back to the top