blob: b8af374ef58fd93be3de5ed3cf023919fa98e47e [file] [log] [blame]
package org.eclipse.tigerstripe.workbench.base.test.refactor;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.tigerstripe.workbench.base.test.utils.ModelProjectHelper;
import org.eclipse.tigerstripe.workbench.internal.core.model.IAbstractArtifactInternal;
import org.eclipse.tigerstripe.workbench.model.deprecated_.IArtifactManagerSession;
import org.eclipse.tigerstripe.workbench.model.deprecated_.IField;
import org.eclipse.tigerstripe.workbench.model.deprecated_.IType;
import org.eclipse.tigerstripe.workbench.project.ITigerstripeModelProjectInternal;
import junit.framework.TestCase;
public abstract class AbstractRefactorTest extends TestCase{
protected ITigerstripeModelProjectInternal project = null;
protected final static String NAME = "model-refactoring";
protected final static String MODIFIED = "Modified";
protected final static String CHILD = ".child";
protected final static String FIRST_SUB_PACKAGE = ModelProjectHelper.DEFAULT_PKG+CHILD;
protected final static String M3 = ".M3";
protected final static String ATT_0 = "first";
protected final static String ATT_1 = "second";
protected final static String ATT_2 = "third";
protected final static String ATT_3 = "fourth";
protected IArtifactManagerSession session;
@Override
protected void setUp() throws Exception {
super.setUp();
createProjectAndEntities();
}
public void tearDown() throws Exception {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IResource proj = workspace.getRoot().findMember(NAME);
if (proj != null)
proj.delete(true, new NullProgressMonitor());
}
public void createProjectAndEntities() throws Exception {
project = (ITigerstripeModelProjectInternal) ModelProjectHelper.createModelProject(NAME, true);
// Need additional entities:
session = project.getArtifactManagerSession();
// Some attributes on M1 {
IAbstractArtifactInternal m1Art = (IAbstractArtifactInternal) session.getArtifactByFullyQualifiedName(ModelProjectHelper.M1);
IField attribute0 = m1Art.makeField();
attribute0.setName(ATT_0);
m1Art.addField(attribute0);
m1Art.doSave(null);
// Some attributes on M2
IAbstractArtifactInternal m2Art = (IAbstractArtifactInternal) session.getArtifactByFullyQualifiedName(ModelProjectHelper.M2);
IField attribute1 = m2Art.makeField();
attribute1.setName(ATT_1);
IType type = attribute1.makeType();
attribute1.setType(type);
type.setFullyQualifiedName(ModelProjectHelper.M1);
m2Art.addField(attribute1);
m2Art.doSave(null);
// Extend from the base ones..
IAbstractArtifactInternal m3 = (IAbstractArtifactInternal) session
.makeArtifact(org.eclipse.tigerstripe.workbench.model.deprecated_.IManagedEntityArtifact.class
.getName());
m3.setFullyQualifiedName(FIRST_SUB_PACKAGE+M3);
m3.setExtendedArtifact(m1Art);
m3.doSave(null);
}
}