| /******************************************************************************* |
| * Copyright (c) 2009 Cisco Systems, Inc. |
| * 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: |
| * Cisco Systems, Inc. - erdillon |
| *******************************************************************************/ |
| package org.eclipse.tigerstripe.workbench.base.test.refactor; |
| |
| import java.util.Collection; |
| import java.util.HashMap; |
| import java.util.List; |
| import java.util.Map; |
| import java.util.stream.Collectors; |
| |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.NullProgressMonitor; |
| import org.eclipse.tigerstripe.workbench.TigerstripeException; |
| import org.eclipse.tigerstripe.workbench.base.test.utils.ModelProjectHelper; |
| import org.eclipse.tigerstripe.workbench.internal.core.model.AssociationArtifactInternal; |
| import org.eclipse.tigerstripe.workbench.internal.core.model.IAbstractArtifactInternal; |
| import org.eclipse.tigerstripe.workbench.model.deprecated_.IAbstractArtifact; |
| import org.eclipse.tigerstripe.workbench.model.deprecated_.IAssociationArtifact; |
| import org.eclipse.tigerstripe.workbench.model.deprecated_.IAssociationEnd; |
| import org.eclipse.tigerstripe.workbench.model.deprecated_.IField; |
| import org.eclipse.tigerstripe.workbench.model.deprecated_.IType; |
| import org.eclipse.tigerstripe.workbench.refactor.IRefactorCommand; |
| import org.eclipse.tigerstripe.workbench.refactor.ModelRefactorRequest; |
| import org.eclipse.tigerstripe.workbench.refactor.PackageModelRefactorRefactorRequest; |
| |
| public class TestComplexPackageRefactorRequest extends AbstractRefactorTest { |
| |
| protected final static String GRANDCHILD = ".grandChild"; |
| protected final static String SECOND_SUB_PACKAGE = FIRST_SUB_PACKAGE+GRANDCHILD; |
| protected final static String M4 = ".M4"; |
| protected final static String AS2 = ".A2"; |
| |
| @Override |
| public void createProjectAndEntities() throws Exception { |
| super.createProjectAndEntities(); |
| |
| |
| // Now lets add some subPackages and Entities therein |
| /* |
| * com.mycompany * |
| * M1* |
| * M2 (with attribute of type M1)* |
| * AC1 (from M1)* |
| * child * |
| * M3 (Extends M1)* |
| * > grandChild |
| * > M4 (with attribute of type M1) |
| * > AS2 (M2 -> M4) |
| * |
| * Then we'll rename grandChild |
| * |
| * Followed by rename of mycompany .. |
| * |
| */ |
| |
| IAbstractArtifactInternal m4 = (IAbstractArtifactInternal) session |
| .makeArtifact(org.eclipse.tigerstripe.workbench.model.deprecated_.IManagedEntityArtifact.class |
| .getName()); |
| m4.setFullyQualifiedName(SECOND_SUB_PACKAGE+M4); |
| IField attribute3 = m4.makeField(); |
| attribute3.setName(ATT_3); |
| IType type = attribute3.makeType(); |
| type.setFullyQualifiedName(ModelProjectHelper.M1); |
| attribute3.setType(type); |
| m4.addField(attribute3); |
| m4.doSave(null); |
| |
| AssociationArtifactInternal as2 = (AssociationArtifactInternal) session |
| .makeArtifact(IAssociationArtifact.class.getName()); |
| IAssociationEnd aEnd = as2.makeAssociationEnd(); |
| IAssociationEnd zEnd = as2.makeAssociationEnd(); |
| IType aType = aEnd.makeType(); |
| IType zType = zEnd.makeType(); |
| |
| as2.setFullyQualifiedName(SECOND_SUB_PACKAGE+AS2); |
| aEnd = as2.makeAssociationEnd(); |
| aEnd.setName("aaEnd"); |
| aEnd.setNavigable(false); |
| aType = aEnd.makeType(); |
| aType.setFullyQualifiedName(ModelProjectHelper.M2); |
| aEnd.setType(aType); |
| as2.setAEnd(aEnd); |
| |
| zEnd = as2.makeAssociationEnd(); |
| zEnd.setName("zzEnd"); |
| zEnd.setNavigable(true); |
| zType = zEnd.makeType(); |
| zType.setFullyQualifiedName(SECOND_SUB_PACKAGE+M4); |
| zEnd.setType(zType); |
| as2.setZEnd(zEnd); |
| |
| as2.doSave(null); |
| |
| |
| } |
| |
| public void testComplesPackageRename() throws Exception { |
| |
| IAbstractArtifact pkg; |
| |
| // First up a simple package rename |
| pkg = project.getArtifactManagerSession() |
| .getArtifactByFullyQualifiedName(ModelProjectHelper.DEFAULT_PKG); |
| assertNotNull(pkg); |
| |
| |
| PackageModelRefactorRefactorRequest req = new PackageModelRefactorRefactorRequest(); |
| req.setOriginal(project,ModelProjectHelper.DEFAULT_PKG); |
| req.setDestination(project, ModelProjectHelper.DEFAULT_PKG+MODIFIED); |
| |
| IRefactorCommand cmd = req.getCommand(null); |
| cmd.execute(null); |
| |
| pkg = project.getArtifactManagerSession() |
| .getArtifactByFullyQualifiedName(ModelProjectHelper.DEFAULT_PKG+MODIFIED); |
| assertNotNull(pkg); |
| |
| // This should still be there as there are children! |
| pkg = project.getArtifactManagerSession() |
| .getArtifactByFullyQualifiedName(ModelProjectHelper.DEFAULT_PKG); |
| assertNotNull(pkg); |
| |
| |
| |
| req = new PackageModelRefactorRefactorRequest(); |
| req.setOriginal(project,ModelProjectHelper.DEFAULT_PKG); |
| req.setDestination(project, ModelProjectHelper.DEFAULT_PKG+MODIFIED); |
| req.setRenameSubpackages(true); |
| |
| cmd = req.getCommand(null); |
| cmd.execute(null); |
| |
| pkg = project.getArtifactManagerSession() |
| .getArtifactByFullyQualifiedName(ModelProjectHelper.DEFAULT_PKG+MODIFIED); |
| assertNotNull(pkg); |
| |
| // This should NO LONGER be there |
| pkg = project.getArtifactManagerSession() |
| .getArtifactByFullyQualifiedName(ModelProjectHelper.DEFAULT_PKG); |
| assertNull(pkg); |
| |
| } |
| |
| |
| } |