Commit 512b814b authored by Marco Konersmann's avatar Marco Konersmann

Removes unused code

parent 6ae40f44
package org.codeling.lang.ejbWithStatemachine.transformation
import de.mkonersmann.advert.java.embed.JDTUtils
import java.util.Arrays
import org.codeling.lang.ejbWithStatemachine.mm.ejbWithSM.StateMachine
import org.codeling.lang.ejbWithStatemachine.mm.ejbWithSM.ejbWithSMFactory
import org.codeling.utils.IDRegistry
import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.IPackageFragment
import org.junit.Test
import static org.junit.Assert.*
class StateMachineTransformationTest {
@Test
def toModel() {
// Prepare
val testName = "toModel";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).
createPackageFragment(projectName, true, null);
val contents = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.StateMachine;
@StateMachine
public class MyStateMachine {
}''';
val cu = testPackage.createCompilationUnit("MyStateMachine.java", contents, true, null)
val StateMachineTransformation t = new StateMachineTransformation(null);
t.codeElement = cu.getType("MyStateMachine");
t.parentCodeElement = testPackage;
t.IDRegistry = new IDRegistry();
t.parentModelElement = ejbWithSMFactory.eINSTANCE.createStateMachine();
// Execute
val StateMachine s = t.transformToModel();
// Evaluate
assertNotNull(s);
assertEquals("MyStateMachine", s.name);
assertEquals(0, s.states.size);
assertNull(s.initial);
}
@Test
def deleteCodeFragments() {
// Prepare
val testName = "deleteCodeFragments";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).
createPackageFragment(projectName, true, null);
val contents = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.StateMachine;
@StateMachine
public class MyStateMachine {
}''';
val cu = testPackage.createCompilationUnit("MyStateMachine.java", contents, true, null)
val StateMachine modelElement = ejbWithSMFactory.eINSTANCE.createStateMachine();
modelElement.name = "MyStateMachine";
val StateMachineTransformation t = new StateMachineTransformation(null);
t.codeElement = cu.getType("MyStateMachine");
// Execute
t.deleteCodeFragments();
// Evaluate
assertFalse(cu.exists);
}
@Test
def createCodeFragments() {
// Prepare
val testName = "createCodeFragments";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).createPackageFragment(projectName,
true, null);
val StateMachine modelElement = ejbWithSMFactory.eINSTANCE.createStateMachine();
modelElement.name = "MyStateMachine";
val StateMachineTransformation t = new StateMachineTransformation(null);
t.modelElement = modelElement;
t.codeRoot = Arrays.asList(project);
// Execute
t.createCodeFragments();
// Evaluate
val contents = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.StateMachine;
@StateMachine
public class MyStateMachine {}''';
val cu = testPackage.getCompilationUnit("MyStateMachine.java");
assertTrue(cu.exists());
assertEquals(contents, cu.source);
}
@Test
def updateCodeFragments() {
// Prepare
val testName = "updateCodeFragments";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).
createPackageFragment(projectName, true, null);
val contents = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.StateMachine;
@StateMachine
public class MyStateMachine {
}''';
val cu = testPackage.createCompilationUnit("MyStateMachine.java", contents, true, null)
val StateMachine priorModelElement = ejbWithSMFactory.eINSTANCE.createStateMachine();
priorModelElement.name = "MyStateMachine";
val StateMachine modelElement = ejbWithSMFactory.eINSTANCE.createStateMachine();
modelElement.name = "MyNewStateMachine";
val StateMachineTransformation t = new StateMachineTransformation(null);
t.codeElement = cu.getType("MyStateMachine");
t.priorModelElement = priorModelElement;
t.modelElement = modelElement;
// Execute
t.updateCodeFragments();
// Evaluate
val newCu = testPackage.getCompilationUnit("MyNewStateMachine.java")
assertFalse(cu.exists);
assertTrue(newCu.exists);
val newContents = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.StateMachine;
@StateMachine
public class MyNewStateMachine {
}''';
assertEquals(newContents, newCu.source);
}
}
package org.codeling.lang.ejbWithStatemachine.transformation
import de.mkonersmann.advert.java.embed.JDTUtils
import java.util.Arrays
import org.codeling.lang.ejbWithStatemachine.mm.ejbWithSM.State
import org.codeling.lang.ejbWithStatemachine.mm.ejbWithSM.ejbWithSMFactory
import org.codeling.utils.IDRegistry
import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.IPackageFragment
import org.junit.Test
import static org.junit.Assert.*
class StateTransformationTest {
@Test
def toModel() {
// Prepare
val testName = "toModel";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).
createPackageFragment(projectName, true, null);
val contents = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
public class MyState implements State {
}''';
val cu = testPackage.createCompilationUnit("MyState.java", contents, true, null)
val StateTransformation t = new StateTransformation(null);
t.codeElement = cu.getType("MyState");
t.parentCodeElement = testPackage;
t.IDRegistry = new IDRegistry();
t.parentModelElement = ejbWithSMFactory.eINSTANCE.createStateMachine();
// Execute
val State s = t.transformToModel();
// Evaluate
assertNotNull(s);
assertEquals("MyState", s.name);
assertEquals(0, s.transition.size);
}
@Test
def deleteCodeFragments() {
// Prepare
val testName = "deleteModelElement";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).
createPackageFragment(projectName, true, null);
val contents = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
public class MyState implements State {
}''';
val cu = testPackage.createCompilationUnit("MyState.java", contents, true, null)
val State modelElement = ejbWithSMFactory.eINSTANCE.createState();
modelElement.name = "MyState";
val StateTransformation t = new StateTransformation(null);
t.codeElement = cu.getType("MyState");
// Execute
t.deleteCodeFragments();
// Evaluate
assertFalse(cu.exists);
}
@Test
def createCodeFragments() {
// Prepare
val testName = "createCodeFragments";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).createPackageFragment(projectName,
true, null);
val State modelElement = ejbWithSMFactory.eINSTANCE.createState();
modelElement.name = "MyState";
val StateTransformation t = new StateTransformation(null);
t.modelElement = modelElement;
t.codeRoot = Arrays.asList(project);
// Execute
t.createCodeFragments();
// Evaluate
val contents = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
public class MyState implements State {}''';
val cu = testPackage.getCompilationUnit("MyState.java");
assertTrue(cu.exists());
assertEquals(contents, cu.source);
}
@Test
def updateCodeFragments() {
// Prepare
val testName = "updateCodeFragments";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).
createPackageFragment(projectName, true, null);
val contents = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
public class MyState implements State {
}''';
val cu = testPackage.createCompilationUnit("MyState.java", contents, true, null)
val State priorModelElement = ejbWithSMFactory.eINSTANCE.createState();
priorModelElement.name = "MyState";
val State modelElement = ejbWithSMFactory.eINSTANCE.createState();
modelElement.name = "MyNewState";
val StateTransformation t = new StateTransformation(null);
t.codeElement = cu.getType("MyState");
t.priorModelElement = priorModelElement;
t.modelElement = modelElement;
// Execute
t.updateCodeFragments();
// Evaluate
val newCu = testPackage.getCompilationUnit("MyNewState.java")
assertFalse(cu.exists);
assertTrue(newCu.exists);
val newContents = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
public class MyNewState implements State {
}''';
assertEquals(newContents, newCu.source);
}
}
package org.codeling.lang.ejbWithStatemachine.transformation.state_feature
import de.mkonersmann.advert.java.embed.JDTUtils
import org.codeling.lang.ejbWithStatemachine.mm.ejbWithSM.State
import org.codeling.lang.ejbWithStatemachine.mm.ejbWithSM.Transition
import org.codeling.lang.ejbWithStatemachine.mm.ejbWithSM.ejbWithSMFactory
import org.codeling.lang.ejbWithStatemachine.transformation.TransitionTransformation
import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.IPackageFragment
import org.junit.Test
import static org.junit.Assert.*
class TransitionsTransformationTest {
@Test
def toModel() {
// Prepare
val testName = "toModel";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).
createPackageFragment(projectName, true, null);
val contentsState = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
import org.codeling.lang.ejbWithStatemachine.mm.state_feature.Transition;
public class MyState implements State {
@Transition
public void doSomething(){
}
}''';
val originStateCU = testPackage.createCompilationUnit("MyState.java", contentsState, true, null);
val State state = ejbWithSMFactory.eINSTANCE.createState;
state.name = "MyState"
val TransitionsTransformation t = new TransitionsTransformation(null);
t.parentCodeElement = originStateCU.getType("MyState");
t.codeElement = originStateCU.getType("MyState");
t.modelElement = state;
// For reference transformations, it is necessary to first execute the target's transformation
val TransitionTransformation target = new TransitionTransformation(t);
target.parentCodeElement = originStateCU.getType("MyState");
target.codeElement = t.codeElement.getMethod("doSomething", {
});
// Execute
val Transition transition = target.transformToModel;
// Containment Transformations need the targets to be set prior to transform to model
t.targetObjects = newArrayList(transition);
val State s = t.transformToModel;
// Evaluate
assertNotNull(s);
assertNotNull(transition);
assertNotNull(s.transition);
assertEquals(1, s.transition.size);
assertEquals("doSomething", s.transition.get(0).name);
assertSame(transition, s.transition.get(0));
}
@Test
def deleteCodeFragments() {
fail("Not implemented yet")
}
@Test
def createCodeFragments() {
fail("Not implemented yet")
}
@Test
def updateCodeFragments() {
fail("Not implemented yet")
}
}
package org.codeling.lang.ejbWithStatemachine.transformation.statemachine_feature
import de.mkonersmann.advert.java.embed.JDTUtils
import de.mkonersmann.advert.java.embed.transformation.AbstractModelCodeTransformation
import java.util.LinkedList
import java.util.List
import org.codeling.lang.ejbWithStatemachine.mm.ejbWithSM.State
import org.codeling.lang.ejbWithStatemachine.mm.ejbWithSM.StateMachine
import org.codeling.lang.ejbWithStatemachine.mm.ejbWithSM.ejbWithSMFactory
import org.codeling.lang.ejbWithStatemachine.mm.ejbWithSM.ejbWithSMPackage
import org.codeling.lang.ejbWithStatemachine.transformation.StateTransformation
import org.codeling.mechanisms.MechanismsMapping
import org.codeling.mechanisms.classes.MarkerInterfaceMechanism
import org.eclipse.core.resources.IResource
import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.IPackageFragment
import org.junit.Test
import static org.junit.Assert.*
class StatesTransformationTest {
@Test
def toModel() {
// Prepare
val testName = "toModel";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).
createPackageFragment(projectName, true, null);
val contentsSM = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
import org.codeling.lang.ejbWithStatemachine.mm.StateMachine;
import org.codeling.lang.ejbWithStatemachine.mm.stateMachine_feature.States;
@StateMachine
public class MyStateMachine {
@States({MyState.class})
State[] states;
}''';
val stateMachineCU = testPackage.createCompilationUnit("MyStateMachine.java", contentsSM, true, null);
val contentsState = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
public class MyState implements State {
}''';
testPackage.createCompilationUnit("MyState.java", contentsState, true, null);
val StatesTransformation t = new StatesTransformation(null);
t.codeElement = stateMachineCU.getType("MyStateMachine");
t.modelElement = ejbWithSMFactory.eINSTANCE.createStateMachine();
// Execute
val List<State> targetStates = new LinkedList();
for (AbstractModelCodeTransformation<?,?> child : t.createChildTransformationsToModel) {
val StateTransformation stateTransformation = child as StateTransformation;
val State targetState = stateTransformation.transformToModel;
targetStates.add(targetState);
}
t.targetObjects = targetStates;
val StateMachine s = t.transformToModel;
// Evaluate
assertNotNull(s);
assertNotNull(s.states);
assertEquals(1, s.states.size);
assertEquals("MyState", s.states.get(0).name)
}
@Test
def deleteCodeFragments() {
// Prepare
val testName = "deleteCodeFragments";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).
createPackageFragment(projectName, true, null);
val contentsSM = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
import org.codeling.lang.ejbWithStatemachine.mm.StateMachine;
import org.codeling.lang.ejbWithStatemachine.mm.stateMachine_feature.States;
@StateMachine
public class MyStateMachine {
@States({MyState.class})
State[] states;
}''';
val stateMachineCU = testPackage.createCompilationUnit("MyStateMachine.java", contentsSM, true, null);
val contentsState = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
public class MyState implements State {
}''';
testPackage.createCompilationUnit("MyState.java", contentsState, true, null);
val StateMachine myStateMachine = ejbWithSMFactory.eINSTANCE.createStateMachine;
myStateMachine.name = "MyStateMachine";
val State myState = ejbWithSMFactory.eINSTANCE.createState;
myState.name = "MyState";
myStateMachine.states.add(myState);
val StatesTransformation t = new StatesTransformation(null);
t.parentCodeElement = stateMachineCU.getType("MyStateMachine");
t.codeElement = stateMachineCU.getType("MyStateMachine");
t.modelElement = myStateMachine;
// Execute
t.deleteCodeFragments;
// Evaluate
val expectedCode = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
import org.codeling.lang.ejbWithStatemachine.mm.StateMachine;
import org.codeling.lang.ejbWithStatemachine.mm.stateMachine_feature.States;
@StateMachine
public class MyStateMachine {
}'''
assertEquals(expectedCode, stateMachineCU.source)
}
@Test
def createCodeFragments() {
// Prepare
val testName = "createCodeFragments";
val projectName = this.class.simpleName + "_" + testName;
val IJavaProject project = JDTUtils.createSimpleProject(projectName);
val IPackageFragment testPackage = project.getPackageFragmentRoots().get(0).
createPackageFragment(projectName, true, null);
val contentsSM = '''
package «projectName»;
import org.codeling.lang.ejbWithStatemachine.mm.State;
import org.codeling.lang.ejbWithStatemachine.mm.StateMachine;
import org.codeling.lang.ejbWithStatemachine.mm.stateMachine_feature.States;
@StateMachine
public class MyStateMachine {
}''';
val stateMachineCU = testPackage.createCompilationUnit("MyStateMachine.java", contentsSM, true, null);
val contentsState = '''
package «projectName»;