Search in sources :

Example 1 with Subdomain

use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.

the class DeriveSubdomainFromUserRequirementsTest method canDeriveSubdomainFromUserStory.

@ParameterizedTest
@ValueSource(strings = { "derive-subdomain-from-user-story-test-1-input.cml", "derive-subdomain-from-user-story-test-2-input.cml", "derive-subdomain-from-user-story-test-3-input.cml", "derive-subdomain-from-user-story-test-4-input.cml", "derive-subdomain-from-user-story-test-5-input.cml", "derive-subdomain-from-user-story-test-6-input.cml" })
public void canDeriveSubdomainFromUserStory(String inputFile) throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML(inputFile);
    // when
    Set<String> userStories = Sets.newHashSet(Arrays.asList(new String[] { "US1_Create", "Story_to_be_Ignored", "UseCase_to_be_Ignored" }));
    DeriveSubdomainFromUserRequirements ar = new DeriveSubdomainFromUserRequirements("InsuranceDomain", "Customers", userStories);
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    ContextMappingModel model = reloadResource(input).getContextMappingModel();
    assertEquals(1, model.getDomains().size());
    assertNotNull(model.getDomains().get(0));
    Domain domain = model.getDomains().get(0);
    assertEquals(1, domain.getSubdomains().size());
    assertNotNull(domain.getSubdomains().get(0));
    Subdomain subdomain = domain.getSubdomains().get(0);
    Set<String> supportedFeatures = subdomain.getSupportedFeatures().stream().map(f -> f.getName()).collect(Collectors.toSet());
    assertTrue(supportedFeatures.contains("US1_Create"));
    assertEquals("Customers", subdomain.getName());
    assertEquals("Aims at promoting the following benefit for a Insurance Employee: I am able to manage the customer data and offer contracts.", subdomain.getDomainVisionStatement());
    assertEquals(1, subdomain.getEntities().size());
    assertEquals(1, subdomain.getServices().size());
    Entity entity = subdomain.getEntities().get(0);
    assertEquals("Customer", entity.getName());
    Service service = subdomain.getServices().get(0);
    assertEquals("US1_CreateService", service.getName());
    assertEquals(1, service.getOperations().size());
    ServiceOperation operation = service.getOperations().get(0);
    assertEquals("createCustomer", operation.getName());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ValueSource(org.junit.jupiter.params.provider.ValueSource) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Set(java.util.Set) IOException(java.io.IOException) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) NullSource(org.junit.jupiter.params.provider.NullSource) CMLResource(org.contextmapper.dsl.cml.CMLResource) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) CMLResource(org.contextmapper.dsl.cml.CMLResource) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Subdomain

use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.

the class DeriveSubdomainFromUserRequirementsTest method canMergeDomainVisionStatements.

@Test
public void canMergeDomainVisionStatements() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("derive-subdomain-from-user-story-test-existing-dvs-1.cml");
    // when
    Set<String> userStories = Sets.newHashSet(Arrays.asList(new String[] { "US1_Create", "Story_to_be_Ignored" }));
    DeriveSubdomainFromUserRequirements ar = new DeriveSubdomainFromUserRequirements("InsuranceDomain", "Customers", userStories);
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    ContextMappingModel model = reloadResource(input).getContextMappingModel();
    assertEquals(1, model.getDomains().size());
    assertNotNull(model.getDomains().get(0));
    Domain domain = model.getDomains().get(0);
    assertEquals(1, domain.getSubdomains().size());
    assertNotNull(domain.getSubdomains().get(0));
    Subdomain subdomain = domain.getSubdomains().get(0);
    assertEquals("Customers", subdomain.getName());
    assertEquals("existing dvs 1; existing dvs 2; Aims at promoting the following benefit for a Insurance Employee: I am able to manage the customer data and offer contracts.", subdomain.getDomainVisionStatement());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) CMLResource(org.contextmapper.dsl.cml.CMLResource) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Subdomain

use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.

the class BoundedContextSemanticsValidator method validateThatAggregateContainsOnlyOneAggregateRoot.

@Check
public void validateThatAggregateContainsOnlyOneAggregateRoot(final BoundedContext boundedContext) {
    List<Domain> domains = boundedContext.getImplementedDomainParts().stream().filter(domainPart -> domainPart instanceof Domain).map(domainPart -> (Domain) domainPart).collect(Collectors.toList());
    if (domains.isEmpty())
        return;
    boundedContext.getImplementedDomainParts().stream().filter(domainPart -> domainPart instanceof Subdomain).map(domainPart -> (Subdomain) domainPart).forEach(subdomain -> {
        Domain parentDomain = (Domain) subdomain.eContainer();
        if (domains.contains(parentDomain))
            error(String.format(ALREADY_IMPLEMENTED_SUBDOMAIN, subdomain.getName(), parentDomain.getName()), boundedContext, ContextMappingDSLPackage.Literals.BOUNDED_CONTEXT__IMPLEMENTED_DOMAIN_PARTS, boundedContext.getImplementedDomainParts().indexOf(subdomain));
    });
}
Also used : List(java.util.List) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) MULTIPLE_DOMAINS_IMPLEMENTED(org.contextmapper.dsl.validation.ValidationMessages.MULTIPLE_DOMAINS_IMPLEMENTED) ContextMappingDSLPackage(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLPackage) ALREADY_IMPLEMENTED_SUBDOMAIN(org.contextmapper.dsl.validation.ValidationMessages.ALREADY_IMPLEMENTED_SUBDOMAIN) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Check(org.eclipse.xtext.validation.Check) EValidatorRegistrar(org.eclipse.xtext.validation.EValidatorRegistrar) Collectors(java.util.stream.Collectors) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) AbstractDeclarativeValidator(org.eclipse.xtext.validation.AbstractDeclarativeValidator) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) Check(org.eclipse.xtext.validation.Check)

Example 4 with Subdomain

use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.

the class GenerateBoundedContextFromSubdomainRefactoringHandler method executeRefactoring.

@Override
protected void executeRefactoring(CMLResource resource, ExecutionEvent event) {
    Set<Subdomain> subdomains = getAllSelectedElements().stream().filter(sd -> sd instanceof Subdomain).map(sd -> (Subdomain) sd).collect(Collectors.toSet());
    Set<String> boundedContexts = resource.getContextMappingModel().getBoundedContexts().stream().map(bc -> bc.getName()).collect(Collectors.toSet());
    Set<String> ids = subdomains.stream().map(sd -> sd.getName()).collect(Collectors.toSet());
    DeriveBoundedContextFromSubdomainsContext refactoringContext = new DeriveBoundedContextFromSubdomainsContext("NewContextFromSubdomains", boundedContexts);
    new WizardDialog(HandlerUtil.getActiveShell(event), new DeriveBoundedContextFromSubdomainsWizard(refactoringContext, executionContext -> {
        return finishRefactoring(new DeriveBoundedContextFromSubdomains(executionContext.getBoundedContextName(), ids), resource, event);
    })).open();
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) DeriveBoundedContextFromSubdomainsWizard(org.contextmapper.dsl.ui.handler.wizard.DeriveBoundedContextFromSubdomainsWizard) DeriveBoundedContextFromSubdomainsContext(org.contextmapper.dsl.ui.handler.wizard.DeriveBoundedContextFromSubdomainsContext) DeriveBoundedContextFromSubdomains(org.contextmapper.dsl.refactoring.DeriveBoundedContextFromSubdomains) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Optional(java.util.Optional) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Collectors(java.util.stream.Collectors) CMLResource(org.contextmapper.dsl.cml.CMLResource) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) DeriveBoundedContextFromSubdomains(org.contextmapper.dsl.refactoring.DeriveBoundedContextFromSubdomains) DeriveBoundedContextFromSubdomainsWizard(org.contextmapper.dsl.ui.handler.wizard.DeriveBoundedContextFromSubdomainsWizard) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) DeriveBoundedContextFromSubdomainsContext(org.contextmapper.dsl.ui.handler.wizard.DeriveBoundedContextFromSubdomainsContext) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 5 with Subdomain

use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.

the class PlantUMLSubdomainClassDiagramCreatorTest method canCreateLegend.

@Test
public void canCreateLegend() {
    // given
    Subdomain subdomain = ContextMappingDSLFactory.eINSTANCE.createSubdomain();
    subdomain.setName("MyTestSubdomain");
    String domainVisionStatement = "this is the vision of this test subdomain ...";
    subdomain.setDomainVisionStatement(domainVisionStatement);
    // when
    String plantUML = this.creator.createDiagram(subdomain);
    // then
    assertTrue(plantUML.contains("legend left"));
    assertTrue(plantUML.contains("  This subdomain is part of the 'TestDomain' domain."));
    assertTrue(plantUML.contains("  " + domainVisionStatement));
    assertTrue(plantUML.contains("end legend"));
}
Also used : Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Test(org.junit.jupiter.api.Test) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest)

Aggregations

Subdomain (org.contextmapper.dsl.contextMappingDSL.Subdomain)26 Domain (org.contextmapper.dsl.contextMappingDSL.Domain)14 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)13 Test (org.junit.jupiter.api.Test)10 Collectors (java.util.stream.Collectors)9 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)9 RefactoringInputException (org.contextmapper.dsl.refactoring.exception.RefactoringInputException)9 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)9 List (java.util.List)8 Optional (java.util.Optional)8 Set (java.util.Set)8 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)8 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)8 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)8 Sets (com.google.common.collect.Sets)7 CollectionType (org.contextmapper.tactic.dsl.tacticdsl.CollectionType)7 Service (org.contextmapper.tactic.dsl.tacticdsl.Service)7 ServiceOperation (org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)7 CMLResource (org.contextmapper.dsl.cml.CMLResource)6 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)6