Search in sources :

Example 1 with Service

use of org.contextmapper.tactic.dsl.tacticdsl.Service in project context-mapper-dsl by ContextMapper.

the class DeriveBoundedContextFromSubdomainsTest method canCopyAndEnhanceServices.

@ParameterizedTest
@ValueSource(strings = { "derive-bc-from-subdomain-test-1-input.cml", "derive-bc-from-subdomain-test-6-input.cml", "derive-bc-from-subdomain-test-7-input.cml" })
public void canCopyAndEnhanceServices(String inputFile) throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML(inputFile);
    // when
    Set<String> subdomains = Sets.newHashSet(Arrays.asList(new String[] { "CustomerDomain" }));
    DeriveBoundedContextFromSubdomains ar = new DeriveBoundedContextFromSubdomains("NewTestBC", subdomains);
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    ContextMappingModel model = reloadResource(input).getContextMappingModel();
    assertEquals(1, model.getBoundedContexts().size());
    assertNotNull(model.getBoundedContexts().get(0));
    BoundedContext bc = model.getBoundedContexts().get(0);
    assertEquals("NewTestBC", bc.getName());
    assertEquals(BoundedContextType.FEATURE, bc.getType());
    assertEquals(1, bc.getAggregates().size());
    assertNotNull(bc.getAggregates().get(0));
    Aggregate aggregate = bc.getAggregates().get(0);
    assertEquals(1, aggregate.getServices().size());
    Service service = aggregate.getServices().get(0);
    assertEquals("CustomerService", service.getName());
    assertEquals(2, service.getOperations().size());
    ServiceOperation operation = service.getOperations().stream().filter(o -> o.getName().equals("createCustomer")).findFirst().get();
    assertEquals("createCustomer", operation.getName());
    assertEquals("boolean", operation.getReturnType().getType());
    assertEquals(1, operation.getParameters().size());
    Parameter parameter = operation.getParameters().get(0);
    assertEquals("createCustomerInput", parameter.getName());
    assertEquals("CreateCustomerInput", parameter.getParameterType().getType());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) CMLResource(org.contextmapper.dsl.cml.CMLResource) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Service

use of org.contextmapper.tactic.dsl.tacticdsl.Service in project context-mapper-dsl by ContextMapper.

the class DeriveBoundedContextFromSubdomainsTest method canCreateServiceOperationParametersFromFeaturesInModule.

@ParameterizedTest
@ValueSource(strings = { "derive-bc-from-subdomain-test-10-input.cml" })
public void canCreateServiceOperationParametersFromFeaturesInModule(String inputFile) throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML(inputFile);
    // when
    Set<String> subdomains = Sets.newHashSet(Arrays.asList(new String[] { "CustomerDomain" }));
    DeriveBoundedContextFromSubdomains ar = new DeriveBoundedContextFromSubdomains("NewTestBC", subdomains);
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    ContextMappingModel model = reloadResource(input).getContextMappingModel();
    assertEquals(1, model.getBoundedContexts().size());
    assertNotNull(model.getBoundedContexts().get(0));
    BoundedContext bc = model.getBoundedContexts().get(0);
    assertEquals("NewTestBC", bc.getName());
    assertEquals(BoundedContextType.FEATURE, bc.getType());
    assertEquals(1, bc.getModules().get(0).getAggregates().size());
    assertNotNull(bc.getModules().get(0).getAggregates().get(0));
    Aggregate aggregate = bc.getModules().get(0).getAggregates().get(0);
    assertEquals(1, aggregate.getServices().size());
    Service service = aggregate.getServices().get(0);
    assertEquals("CustomerService", service.getName());
    assertEquals(2, service.getOperations().size());
    ServiceOperation createOperation = service.getOperations().stream().filter(o -> o.getName().equals("createCustomer")).findFirst().get();
    assertEquals("createCustomer", createOperation.getName());
    assertEquals("String", createOperation.getReturnType().getType());
    assertEquals(1, createOperation.getParameters().size());
    Parameter parameter = createOperation.getParameters().get(0);
    assertEquals("customer", parameter.getName());
    assertEquals("Customer", parameter.getParameterType().getDomainObjectType().getName());
    ServiceOperation readOperation = service.getOperations().stream().filter(o -> o.getName().equals("readCustomer")).findFirst().get();
    assertEquals("readCustomer", readOperation.getName());
    assertEquals("Customer", readOperation.getReturnType().getDomainObjectType().getName());
    assertEquals(1, readOperation.getParameters().size());
    parameter = readOperation.getParameters().get(0);
    assertEquals("id", parameter.getName());
    assertEquals("String", parameter.getParameterType().getType());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) CMLResource(org.contextmapper.dsl.cml.CMLResource) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Service

use of org.contextmapper.tactic.dsl.tacticdsl.Service in project context-mapper-dsl by ContextMapper.

the class DeriveBoundedContextFromSubdomainsTest method canCreateServiceOperationParametersFromFeatures.

@ParameterizedTest
@ValueSource(strings = { "derive-bc-from-subdomain-test-9-input.cml" })
public void canCreateServiceOperationParametersFromFeatures(String inputFile) throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML(inputFile);
    // when
    Set<String> subdomains = Sets.newHashSet(Arrays.asList(new String[] { "CustomerDomain" }));
    DeriveBoundedContextFromSubdomains ar = new DeriveBoundedContextFromSubdomains("NewTestBC", subdomains);
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    ContextMappingModel model = reloadResource(input).getContextMappingModel();
    assertEquals(1, model.getBoundedContexts().size());
    assertNotNull(model.getBoundedContexts().get(0));
    BoundedContext bc = model.getBoundedContexts().get(0);
    assertEquals("NewTestBC", bc.getName());
    assertEquals(BoundedContextType.FEATURE, bc.getType());
    assertEquals(1, bc.getAggregates().size());
    assertNotNull(bc.getAggregates().get(0));
    Aggregate aggregate = bc.getAggregates().get(0);
    assertEquals(1, aggregate.getServices().size());
    Service service = aggregate.getServices().get(0);
    assertEquals("CustomerService", service.getName());
    assertEquals(2, service.getOperations().size());
    ServiceOperation createOperation = service.getOperations().stream().filter(o -> o.getName().equals("createCustomer")).findFirst().get();
    assertEquals("createCustomer", createOperation.getName());
    assertEquals("String", createOperation.getReturnType().getType());
    assertEquals(1, createOperation.getParameters().size());
    Parameter parameter = createOperation.getParameters().get(0);
    assertEquals("customer", parameter.getName());
    assertEquals("Customer", parameter.getParameterType().getDomainObjectType().getName());
    ServiceOperation readOperation = service.getOperations().stream().filter(o -> o.getName().equals("readCustomer")).findFirst().get();
    assertEquals("readCustomer", readOperation.getName());
    assertEquals("Customer", readOperation.getReturnType().getDomainObjectType().getName());
    assertEquals(1, readOperation.getParameters().size());
    parameter = readOperation.getParameters().get(0);
    assertEquals("id", parameter.getName());
    assertEquals("String", parameter.getParameterType().getType());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) CMLResource(org.contextmapper.dsl.cml.CMLResource) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Service

use of org.contextmapper.tactic.dsl.tacticdsl.Service 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 5 with Service

use of org.contextmapper.tactic.dsl.tacticdsl.Service in project context-mapper-dsl by ContextMapper.

the class PlantUMLBoundedContextClassDiagramCreatorTest method respectEventsAndCommandsAndServicesFromApplicationLayer.

@Test
public void respectEventsAndCommandsAndServicesFromApplicationLayer() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Application app = ContextMappingDSLFactory.eINSTANCE.createApplication();
    boundedContext.setApplication(app);
    DomainEvent testEvent = TacticdslFactory.eINSTANCE.createDomainEvent();
    testEvent.setName("TestEvent");
    app.getEvents().add(testEvent);
    CommandEvent testCommand = TacticdslFactory.eINSTANCE.createCommandEvent();
    testCommand.setName("TestCommand");
    app.getCommands().add(testCommand);
    Service testService = TacticdslFactory.eINSTANCE.createService();
    testService.setName("TestService");
    app.getServices().add(testService);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("package \"'Application'\" <<Rectangle>> {" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class TestEvent <<(E,#ff9f4b) Domain Event>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class TestCommand <<(C,#3bc5e9) Command>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class TestService <<(S,DarkSeaGreen) Service>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
}
Also used : DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Application(org.contextmapper.dsl.contextMappingDSL.Application) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Aggregations

Service (org.contextmapper.tactic.dsl.tacticdsl.Service)15 ServiceOperation (org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)7 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)6 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)6 Parameter (org.contextmapper.tactic.dsl.tacticdsl.Parameter)5 Sets (com.google.common.collect.Sets)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 CMLResource (org.contextmapper.dsl.cml.CMLResource)4 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)4 Domain (org.contextmapper.dsl.contextMappingDSL.Domain)4 Subdomain (org.contextmapper.dsl.contextMappingDSL.Subdomain)4 RefactoringInputException (org.contextmapper.dsl.refactoring.exception.RefactoringInputException)4 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)4 CollectionType (org.contextmapper.tactic.dsl.tacticdsl.CollectionType)4 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)4 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)4 SimpleDomainObject (org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ValueSource (org.junit.jupiter.params.provider.ValueSource)4