use of org.contextmapper.dsl.contextMappingDSL.Feature in project context-mapper-dsl by ContextMapper.
the class SplitStoryByVerbTest method canSplitStoryFeature.
@Test
public void canSplitStoryFeature() {
// given
ContextMappingModel model = ContextMappingDSLFactory.eINSTANCE.createContextMappingModel();
UserStory story = ContextMappingDSLFactory.eINSTANCE.createUserStory();
story.setName("TestStory");
StoryFeature feature = ContextMappingDSLFactory.eINSTANCE.createStoryFeature();
// as a _
story.setRole("Tester");
// I want to _
feature.setVerb("develop");
// a _
feature.setEntity("UnitTest");
story.getFeatures().add(feature);
model.getUserRequirements().add(story);
// when
SplitStoryByVerb qf = new SplitStoryByVerb();
qf.setVerbs(Sets.newHashSet(Arrays.asList(new String[] { "create", "run", "evolve" })));
qf.applyQuickfix(feature);
// then
assertEquals(2, model.getUserRequirements().size());
UserStory originalStory = (UserStory) model.getUserRequirements().get(0);
UserStory splitStory = (UserStory) model.getUserRequirements().get(1);
assertEquals("TestStory", originalStory.getName());
assertEquals("TestStory_Split", splitStory.getName());
assertEquals("TestStory_Split", originalStory.getSplittingStory().getName());
assertEquals(3, splitStory.getFeatures().size());
Set<String> verbs = splitStory.getFeatures().stream().map(f -> f.getVerb()).collect(Collectors.toSet());
assertTrue(verbs.contains("create"));
assertTrue(verbs.contains("\"run\""));
assertTrue(verbs.contains("\"evolve\""));
}
use of org.contextmapper.dsl.contextMappingDSL.Feature in project context-mapper-dsl by ContextMapper.
the class SplitStoryByVerbCommandMapperTest method canThrowExceptionIfSelectedFeatureIsNotInAStory.
@Test
public void canThrowExceptionIfSelectedFeatureIsNotInAStory() {
// given
SplitStoryByVerbCommandMapper mapper = new SplitStoryByVerbCommandMapper(new SplitStoryByVerb());
UseCase useCase = ContextMappingDSLFactory.eINSTANCE.createUseCase();
useCase.setName("TestCase");
Feature feature = ContextMappingDSLFactory.eINSTANCE.createFeature();
useCase.getFeatures().add(feature);
// when, then
assertThrows(ContextMapperApplicationException.class, () -> {
mapper.getCodeAction(null, feature);
});
}
use of org.contextmapper.dsl.contextMappingDSL.Feature in project context-mapper-dsl by ContextMapper.
the class DeriveSubdomainFromUserRequirements method deriveSubdomainEntityReferences.
private void deriveSubdomainEntityReferences(Subdomain subdomain, List<Feature> features) {
for (Feature feature : features) {
if (feature.getContainerEntity() == null || "".equals(feature.getContainerEntity()))
continue;
String containerEntityName = mapEntityName(feature.getContainerEntity());
String referencedEntityName = mapEntityName(feature.getEntity());
Entity containerEntity = subdomain.getEntities().stream().filter(e -> e.getName().equals(containerEntityName)).findFirst().get();
Entity referencedEntity = subdomain.getEntities().stream().filter(e -> e.getName().equals(referencedEntityName)).findFirst().get();
String refName = referencedEntity.getName().toLowerCase() + "List";
if (containerEntity.getReferences().stream().filter(r -> r.getName().equals(refName)).findAny().isPresent())
continue;
Reference reference = TacticdslFactory.eINSTANCE.createReference();
reference.setName(refName);
reference.setCollectionType(CollectionType.LIST);
reference.setDomainObjectType(referencedEntity);
addElementToEList(containerEntity.getReferences(), reference);
}
}
use of org.contextmapper.dsl.contextMappingDSL.Feature in project context-mapper-dsl by ContextMapper.
the class DeriveSubdomainFromUserRequirements method deriveSubdomainEntities4Features.
private void deriveSubdomainEntities4Features(Subdomain subdomain, String urName, List<Feature> features) {
for (Feature feature : features) {
if (feature.getEntity() == null || "".equals(feature.getEntity()))
continue;
// create the entity
String entityName = createEntityIfNotExisting(feature.getEntity(), subdomain, feature.getEntityAttributes());
// create the service
String serviceName = urName.substring(0, 1).toUpperCase() + urName.substring(1) + "Service";
Optional<Service> alreadyExistingService = subdomain.getServices().stream().filter(s -> serviceName.equals(s.getName())).findFirst();
Service service;
if (!alreadyExistingService.isPresent()) {
service = createService(serviceName, entityName, feature.getVerb());
addElementToEList(subdomain.getServices(), service);
} else {
service = alreadyExistingService.get();
}
String operationName = feature.getVerb().replace(" ", "_") + entityName;
Optional<ServiceOperation> alreadyExistingServiceOperation = service.getOperations().stream().filter(o -> operationName.equals(o.getName())).findFirst();
if (!alreadyExistingServiceOperation.isPresent())
addElementToEList(service.getOperations(), createServiceOperation(operationName));
// create the entity that contains the one created above
if (feature.getContainerEntity() != null && !"".equals(feature.getContainerEntity()))
createEntityIfNotExisting(feature.getContainerEntity(), subdomain, Lists.newLinkedList());
}
}
use of org.contextmapper.dsl.contextMappingDSL.Feature in project context-mapper-dsl by ContextMapper.
the class SplitStoryByVerbCommandMapper method getCodeAction.
@Override
public CodeAction getCodeAction(CMLResource cmlResource, EObject selectedObject) {
if (!(selectedObject instanceof Feature))
throw new ContextMapperApplicationException("Mapping exception: this quickfix was mapped to an object that is not of the type 'Feature'.");
UserStory story = getSelectedStory((Feature) selectedObject);
CodeAction codeAction = new CodeAction(quickFix.getName());
codeAction.setKind(CodeActionKind.QuickFix);
Command command = new Command(quickFix.getName(), "cml.quickfix.command.splitStoryByVerb.proxy");
command.setArguments(Lists.newLinkedList(Arrays.asList(new String[] { cmlResource.getURI().toString(), story.getName() })));
codeAction.setCommand(command);
return codeAction;
}
Aggregations