| /******************************************************************************* |
| * 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.Optional; |
| |
| import org.eclipse.core.resources.IResource; |
| import org.eclipse.core.resources.IWorkspace; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.NullProgressMonitor; |
| import org.eclipse.tigerstripe.workbench.TigerstripeCore; |
| 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_.IAbstractArtifact; |
| import org.eclipse.tigerstripe.workbench.model.deprecated_.IArtifactManagerSession; |
| import org.eclipse.tigerstripe.workbench.model.deprecated_.IAssociationArtifact; |
| import org.eclipse.tigerstripe.workbench.model.deprecated_.IField; |
| import org.eclipse.tigerstripe.workbench.model.deprecated_.IType; |
| import org.eclipse.tigerstripe.workbench.project.ITigerstripeModelProject; |
| import org.eclipse.tigerstripe.workbench.project.ITigerstripeModelProjectInternal; |
| import org.eclipse.tigerstripe.workbench.refactor.IRefactorCommand; |
| import org.eclipse.tigerstripe.workbench.refactor.ModelRefactorRequest; |
| |
| import junit.framework.TestCase; |
| |
| public class TestBasicModelRefactorRequest extends AbstractRefactorTest { |
| |
| |
| |
| |
| |
| public void testCreateValidModelRefactorRequests() throws Exception { |
| |
| assertNotNull(project); |
| IAbstractArtifact ent1 = project.getArtifactManagerSession() |
| .getArtifactByFullyQualifiedName(ModelProjectHelper.M1); |
| assertNotNull(ent1); |
| |
| ModelRefactorRequest req = new ModelRefactorRequest(); |
| req.setOriginal(project, ModelProjectHelper.M1); |
| req.setDestination(project, ModelProjectHelper.M1+MODIFIED); |
| assertEquals(IStatus.OK, req.isValid().getSeverity()); |
| |
| req.setOriginal(project, ModelProjectHelper.M1); |
| req.setDestination(project, ""); |
| assertEquals(IStatus.ERROR, req.isValid().getSeverity()); |
| |
| req.setOriginal(project, ModelProjectHelper.M1); |
| req.setDestination(project, ModelProjectHelper.M2); |
| assertEquals(IStatus.ERROR, req.isValid().getSeverity()); |
| |
| req.setOriginal(project, ModelProjectHelper.M1); |
| req.setDestination(project, ModelProjectHelper.DEFAULT_PKG+".m1"); |
| assertEquals(IStatus.ERROR, req.isValid().getSeverity()); |
| |
| } |
| |
| public void testTargetsForSimpleEntityRename() throws Exception { |
| |
| // Collect some into |
| int attrCount = project.getArtifactManagerSession() |
| .getArtifactByFullyQualifiedName(ModelProjectHelper.M1).getFields().size(); |
| |
| ModelRefactorRequest req = new ModelRefactorRequest(); |
| req.setOriginal(project, ModelProjectHelper.M1); |
| req.setDestination(project, ModelProjectHelper.M1+MODIFIED); |
| |
| IRefactorCommand cmd = req.getCommand(null); |
| cmd.execute(null); |
| |
| assertNull(project.getArtifactManagerSession() |
| .getArtifactByFullyQualifiedName(ModelProjectHelper.M1)); |
| IAbstractArtifact mod = |
| project.getArtifactManagerSession() |
| .getArtifactByFullyQualifiedName(ModelProjectHelper.M1+MODIFIED); |
| assertNotNull(mod); |
| |
| // ensure the attributes are copied - can we assume the same is true for methods etc? |
| // and stereos? |
| assertEquals(attrCount, mod.getFields().size()); |
| |
| // Check Types used in one ent |
| IAbstractArtifact m2Art = |
| project.getArtifactManagerSession() |
| .getArtifactByFullyQualifiedName(ModelProjectHelper.M2); |
| Collection<IField> m2Fields = m2Art.getFields(); |
| |
| Optional<IField> oldField = m2Fields.stream().filter(f -> f.getType().getFullyQualifiedName().equals(ModelProjectHelper.M1)).findFirst(); |
| Optional<IField> newField = m2Fields.stream().filter(f -> f.getType().getFullyQualifiedName().equals(ModelProjectHelper.M1+MODIFIED)).findFirst(); |
| |
| // check old one has been removed, as well as new one exists |
| |
| assertFalse(oldField.isPresent()); |
| assertTrue(newField.isPresent()); |
| |
| // check Association End Type changed |
| |
| IAssociationArtifact as1 = (IAssociationArtifact) session.getArtifactByFullyQualifiedName(ModelProjectHelper.AC1); |
| String aEndTypeNameMod = as1.getAEnd().getType().getFullyQualifiedName(); |
| assertEquals(ModelProjectHelper.M1+MODIFIED, aEndTypeNameMod); |
| |
| // check for extending |
| |
| IAbstractArtifactInternal m3 = (IAbstractArtifactInternal) session.getArtifactByFullyQualifiedName(FIRST_SUB_PACKAGE+M3); |
| assertEquals(ModelProjectHelper.M1+MODIFIED, m3.getExtendedArtifact().getFullyQualifiedName()); |
| |
| } |
| |
| } |