-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
....tests/src/org/contextmapper/dsl/ide/tests/actions/MoveStakeholderToGroupActionTest.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2024 The Context Mapper Project Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.contextmapper.dsl.ide.tests.actions | ||
|
||
import org.junit.jupiter.api.Test | ||
|
||
class MoveStakeholderToGroupActionTest extends AbstractBoundedContextCodeActionTest { | ||
|
||
@Test | ||
def void canOfferAction2MoveStakeholderToGroup() { | ||
testCodeAction [ | ||
model = ''' | ||
Stakeholders { | ||
Stakeholder Tester | ||
} | ||
''' | ||
line = 1 | ||
expectedCodeActions = ''' | ||
command : cml.ar.moveStakeholderToGroup.proxy | ||
title : Move Stakeholder To New Group | ||
args : | ||
file://«this.root»/MyModel.cml,Tester | ||
''' | ||
] | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
.../contextmapper/dsl/ide/tests/commands/refactoring/MoveStakeholderToGroupCommandTest.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2024 The Context Mapper Project Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.contextmapper.dsl.ide.tests.commands.refactoring | ||
|
||
import com.google.gson.JsonArray | ||
import com.google.gson.JsonPrimitive | ||
import org.contextmapper.dsl.ide.commands.CMLCommandService | ||
import org.contextmapper.dsl.ide.tests.commands.AbstractCMLCommandTest | ||
import org.eclipse.lsp4j.ExecuteCommandParams | ||
import org.junit.jupiter.api.Test | ||
|
||
class MoveStakeholderToGroupCommandTest extends AbstractCMLCommandTest { | ||
|
||
@Test | ||
def void testARCommandExecution() { | ||
// given | ||
initializeCommandsDynamically() | ||
val model = ''' | ||
Stakeholders { | ||
Stakeholder Tester | ||
} | ||
''' | ||
val fileURI = 'test.cml'.writeFile(model) | ||
|
||
// when | ||
val refactoringParams = new JsonArray | ||
refactoringParams.add("Tester") | ||
val result = languageServer.executeCommand( | ||
new ExecuteCommandParams("cml.ar.moveStakeholderToGroup", #[new JsonPrimitive(fileURI), refactoringParams])) | ||
val resultVal = result.get as String | ||
|
||
// then | ||
CMLCommandService.COMMAND_EXECUTED_RETURN_VALUE.assertEquals(resultVal) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...pper.dsl.ide/src/org/contextmapper/dsl/ide/actions/impl/MoveStakeholderToGroupAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2024 The Context Mapper Project Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.contextmapper.dsl.ide.actions.impl; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.contextmapper.dsl.cml.CMLResource; | ||
import org.contextmapper.dsl.contextMappingDSL.Stakeholder; | ||
import org.contextmapper.dsl.ide.actions.CMLCodeAction; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.lsp4j.Command; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
/** | ||
* Action that calls the "Move Stakeholder to new Group" refactoring. | ||
* | ||
* @author Stefan Kapferer | ||
* | ||
*/ | ||
public class MoveStakeholderToGroupAction implements CMLCodeAction { | ||
|
||
private CMLResource cmlResource; | ||
private List<EObject> editorSelection; | ||
|
||
public MoveStakeholderToGroupAction(CMLResource cmlResource, List<EObject> editorSelection) { | ||
this.cmlResource = cmlResource; | ||
this.editorSelection = editorSelection; | ||
} | ||
|
||
@Override | ||
public boolean isApplicable() { | ||
Set<Stakeholder> stakeholders = getSelectedStakeholders(); | ||
return !(stakeholders.isEmpty() || stakeholders.size() > 1); | ||
} | ||
|
||
@Override | ||
public Command getCommand() { | ||
Stakeholder stakeholder = getSelectedStakeholder(); | ||
List<Object> commandArguments = Lists.newLinkedList(); | ||
commandArguments.add(cmlResource.getURI().toString()); | ||
commandArguments.add(stakeholder.getName()); | ||
return new Command("Move Stakeholder To New Group", "cml.ar.moveStakeholderToGroup.proxy", commandArguments); | ||
} | ||
|
||
private Stakeholder getSelectedStakeholder() { | ||
return getSelectedStakeholders().iterator().next(); | ||
} | ||
|
||
private Set<Stakeholder> getSelectedStakeholders() { | ||
return editorSelection.stream().filter(o -> o instanceof Stakeholder).map(o -> (Stakeholder) o) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...rc/org/contextmapper/dsl/ide/commands/impl/refactoring/MoveStakeholderToGroupCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2024 The Context Mapper Project Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.contextmapper.dsl.ide.commands.impl.refactoring; | ||
|
||
import org.contextmapper.dsl.ide.edit.WorkspaceEditRecorder; | ||
import org.contextmapper.dsl.refactoring.SemanticCMLRefactoring; | ||
import org.contextmapper.dsl.refactoring.stakeholders.MoveStakeholderToNewStakeholderGroupRefactoring; | ||
import org.eclipse.lsp4j.ExecuteCommandParams; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonPrimitive; | ||
|
||
public class MoveStakeholderToGroupCommand extends AbstractRefactoringCommand { | ||
|
||
public MoveStakeholderToGroupCommand(WorkspaceEditRecorder editRecorder) { | ||
super(editRecorder); | ||
} | ||
|
||
@Override | ||
protected SemanticCMLRefactoring getRefactoring(ExecuteCommandParams params) { | ||
JsonArray refactoringParams = (JsonArray) params.getArguments().get(1); | ||
JsonPrimitive stakeholderName = (JsonPrimitive) refactoringParams.get(0); | ||
return new MoveStakeholderToNewStakeholderGroupRefactoring(stakeholderName.getAsString()); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
org.contextmapper.dsl.tests/integ-test-files/refactorings/move-stakeholder-to-group-1.cml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
Stakeholders { | ||
Stakeholder Tester | ||
} |
6 changes: 6 additions & 0 deletions
6
org.contextmapper.dsl.tests/integ-test-files/refactorings/move-stakeholder-to-group-2.cml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
Stakeholders { | ||
StakeholderGroup Testers { | ||
Stakeholder Tester | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...per/dsl/refactoring/stakeholders/MoveStakeholderToNewStakeholderGroupRefactoringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.contextmapper.dsl.refactoring.stakeholders; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
|
||
import org.contextmapper.dsl.cml.CMLResource; | ||
import org.contextmapper.dsl.contextMappingDSL.ContextMappingModel; | ||
import org.contextmapper.dsl.contextMappingDSL.StakeholderGroup; | ||
import org.contextmapper.dsl.refactoring.AbstractRefactoringTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class MoveStakeholderToNewStakeholderGroupRefactoringTest extends AbstractRefactoringTest { | ||
|
||
@Test | ||
void canMoveStakeholderIntoGroup() throws IOException { | ||
// given | ||
String inputModelName = "move-stakeholder-to-group-1.cml"; | ||
CMLResource input = getResourceCopyOfTestCML(inputModelName); | ||
|
||
// when | ||
new MoveStakeholderToNewStakeholderGroupRefactoring("Tester").refactor(input); | ||
|
||
// then | ||
ContextMappingModel model = input.getContextMappingModel(); | ||
assertEquals(1, model.getStakeholders().get(0).getStakeholders().size()); | ||
assertEquals("Groupname_To_Be_Changed", model.getStakeholders().get(0).getStakeholders().get(0).getName()); | ||
assertTrue(model.getStakeholders().get(0).getStakeholders().get(0) instanceof StakeholderGroup); | ||
assertEquals(1, | ||
((StakeholderGroup) model.getStakeholders().get(0).getStakeholders().get(0)).getStakeholders().size()); | ||
assertEquals("Tester", ((StakeholderGroup) model.getStakeholders().get(0).getStakeholders().get(0)) | ||
.getStakeholders().get(0).getName()); | ||
} | ||
|
||
@Test | ||
void canMoveStakeholderFromOneGroupToOther() throws IOException { | ||
// given | ||
String inputModelName = "move-stakeholder-to-group-2.cml"; | ||
CMLResource input = getResourceCopyOfTestCML(inputModelName); | ||
|
||
// when | ||
new MoveStakeholderToNewStakeholderGroupRefactoring("Tester").refactor(input); | ||
|
||
// then | ||
ContextMappingModel model = input.getContextMappingModel(); | ||
assertEquals(2, model.getStakeholders().get(0).getStakeholders().size()); | ||
assertTrue(model.getStakeholders().get(0).getStakeholders().get(0) instanceof StakeholderGroup); | ||
assertTrue(model.getStakeholders().get(0).getStakeholders().get(1) instanceof StakeholderGroup); | ||
StakeholderGroup newGroup = (StakeholderGroup) model.getStakeholders().get(0).getStakeholders().stream() | ||
.filter(s -> s.getName().equals("Groupname_To_Be_Changed")).findFirst().get(); | ||
assertEquals("Tester", newGroup.getStakeholders().get(0).getName()); | ||
} | ||
|
||
} |