Search in sources :

Example 1 with Feature

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\""));
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Arrays(java.util.Arrays) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Feature(org.contextmapper.dsl.contextMappingDSL.Feature) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) StoryFeature(org.contextmapper.dsl.contextMappingDSL.StoryFeature) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UserStory(org.contextmapper.dsl.contextMappingDSL.UserStory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) StoryFeature(org.contextmapper.dsl.contextMappingDSL.StoryFeature) UserStory(org.contextmapper.dsl.contextMappingDSL.UserStory) Test(org.junit.jupiter.api.Test)

Example 2 with Feature

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);
    });
}
Also used : UseCase(org.contextmapper.dsl.contextMappingDSL.UseCase) SplitStoryByVerb(org.contextmapper.dsl.quickfixes.SplitStoryByVerb) SplitStoryByVerbCommandMapper(org.contextmapper.dsl.ide.quickfix.impl.SplitStoryByVerbCommandMapper) Feature(org.contextmapper.dsl.contextMappingDSL.Feature) Test(org.junit.jupiter.api.Test)

Example 3 with 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);
    }
}
Also used : Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) Feature(org.contextmapper.dsl.contextMappingDSL.Feature)

Example 4 with Feature

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());
    }
}
Also used : Arrays(java.util.Arrays) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Feature(org.contextmapper.dsl.contextMappingDSL.Feature) Set(java.util.Set) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) List(java.util.List) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) UserRequirement(org.contextmapper.dsl.contextMappingDSL.UserRequirement) Lists(com.google.common.collect.Lists) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Optional(java.util.Optional) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Feature(org.contextmapper.dsl.contextMappingDSL.Feature)

Example 5 with Feature

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;
}
Also used : ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) Command(org.eclipse.lsp4j.Command) CodeAction(org.eclipse.lsp4j.CodeAction) Feature(org.contextmapper.dsl.contextMappingDSL.Feature) UserStory(org.contextmapper.dsl.contextMappingDSL.UserStory)

Aggregations

Feature (org.contextmapper.dsl.contextMappingDSL.Feature)6 Sets (com.google.common.collect.Sets)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 ContextMappingDSLFactory (org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory)3 ContextMapperApplicationException (org.contextmapper.dsl.exception.ContextMapperApplicationException)3 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)3 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)3 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 Domain (org.contextmapper.dsl.contextMappingDSL.Domain)2 Subdomain (org.contextmapper.dsl.contextMappingDSL.Subdomain)2 UserStory (org.contextmapper.dsl.contextMappingDSL.UserStory)2 RefactoringInputException (org.contextmapper.dsl.refactoring.exception.RefactoringInputException)2 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)2 CollectionType (org.contextmapper.tactic.dsl.tacticdsl.CollectionType)2 Service (org.contextmapper.tactic.dsl.tacticdsl.Service)2 ServiceOperation (org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)2 TacticdslFactory (org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory)2