Search in sources :

Example 1 with Entity

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

the class ExtractIDValueObjectQuickFixTest method canExtractValueObjectFromPrimitiveAttributeInModule.

@Test
public void canExtractValueObjectFromPrimitiveAttributeInModule() throws IOException {
    // given
    CMLResource cmlResource = getResourceCopyOfTestCML("extract-vo-for-primitive-id-test-2.cml");
    ContextMappingModel model = cmlResource.getContextMappingModel();
    Attribute idAttr = EcoreUtil2.getAllContentsOfType(model, Attribute.class).stream().filter(a -> a.getName().equals("customerId")).findFirst().get();
    // when
    new ExtractIDValueObjectQuickFix().applyQuickfix(idAttr);
    // then
    SculptorModule module = model.getBoundedContexts().get(0).getModules().get(0);
    assertEquals("TestModule", module.getName());
    assertEquals(2, module.getDomainObjects().size());
    Entity entity = (Entity) module.getDomainObjects().stream().filter(o -> o.getName().equals("Customer")).findFirst().get();
    assertEquals(2, entity.getAttributes().size());
    assertEquals(1, entity.getReferences().size());
    ValueObject vo = (ValueObject) module.getDomainObjects().stream().filter(o -> o.getName().equals("CustomerId")).findFirst().get();
    assertNotNull(vo);
    assertEquals(1, vo.getAttributes().size());
    assertEquals("id", vo.getAttributes().get(0).getName());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) IOException(java.io.IOException) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Test(org.junit.jupiter.api.Test) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) CMLResource(org.contextmapper.dsl.cml.CMLResource) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) CMLResource(org.contextmapper.dsl.cml.CMLResource) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Test(org.junit.jupiter.api.Test)

Example 2 with Entity

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

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

the class ContextMappingModelToServiceCutterERDConverterTest method canCreateEntity4Entity.

@Test
public void canCreateEntity4Entity() {
    // given
    ContextMappingModel model = ContextMappingDSLFactory.eINSTANCE.createContextMappingModel();
    ContextMap contextMap = ContextMappingDSLFactory.eINSTANCE.createContextMap();
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    boundedContext.setName("testBC");
    contextMap.getBoundedContexts().add(boundedContext);
    model.getBoundedContexts().add(boundedContext);
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    boundedContext.getAggregates().add(aggregate);
    Entity entity = TacticdslFactory.eINSTANCE.createEntity();
    entity.setName("TestEntity");
    Attribute attribute = TacticdslFactory.eINSTANCE.createAttribute();
    attribute.setName("attribute1");
    aggregate.getDomainObjects().add(entity);
    entity.getAttributes().add(attribute);
    model.setMap(contextMap);
    // when
    EntityRelationDiagram scDiagram = this.converter.convert("TestModel", model);
    // then
    List<String> entityNames = scDiagram.getEntities().stream().map(e -> e.getName()).collect(Collectors.toList());
    assertTrue(entityNames.contains("TestEntity"));
    ch.hsr.servicecutter.api.model.Entity scEntity = getEntity(scDiagram.getEntities(), "TestEntity");
    assertEquals(1, scEntity.getNanoentities().size());
    assertEquals("attribute1", scEntity.getNanoentities().get(0));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) RelationType(ch.hsr.servicecutter.api.model.EntityRelation.RelationType) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Collectors(java.util.stream.Collectors) ContextMappingModelToServiceCutterERDConverter(org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter) Test(org.junit.jupiter.api.Test) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) List(java.util.List) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) BeforeEach(org.junit.jupiter.api.BeforeEach) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 4 with Entity

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

the class PlantUMLBoundedContextClassDiagramCreatorTest method createsNoteForImplementedSubdomainWithEntities.

@Test
public void createsNoteForImplementedSubdomainWithEntities() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Subdomain subdomain = ContextMappingDSLFactory.eINSTANCE.createSubdomain();
    subdomain.setName("mySubdomain");
    boundedContext.setName("myBoundedContext");
    boundedContext.getImplementedDomainParts().add(subdomain);
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    boundedContext.getAggregates().add(aggregate);
    aggregate.getDomainObjects().add(TacticdslFactory.eINSTANCE.createSimpleDomainObject());
    Entity entity1 = TacticdslFactory.eINSTANCE.createEntity();
    Entity entity2 = TacticdslFactory.eINSTANCE.createEntity();
    entity1.setName("TestEntity1");
    entity2.setName("TestEntity2");
    subdomain.getEntities().add(entity1);
    subdomain.getEntities().add(entity2);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("legend left"));
    assertTrue(plantUML.contains("  This bounded context implements the subdomain '" + subdomain.getName() + "', which contains the following entities:" + System.lineSeparator()));
    assertTrue(plantUML.contains("   - TestEntity1"));
    assertTrue(plantUML.contains("   - TestEntity2"));
    assertTrue(plantUML.contains("end legend"));
}
Also used : Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 5 with Entity

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

the class PlantUMLBoundedContextClassDiagramCreatorTest method canCreatePackageFromModuleWithBasePackage.

@Test
public void canCreatePackageFromModuleWithBasePackage() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    SculptorModule testModule = ContextMappingDSLFactory.eINSTANCE.createSculptorModule();
    testModule.setName("mySuperModule");
    testModule.setBasePackage("org.contextmapper");
    boundedContext.getModules().add(testModule);
    Entity testEntity = TacticdslFactory.eINSTANCE.createEntity();
    testEntity.setName("TestEntity");
    testModule.getDomainObjects().add(testEntity);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("package org.contextmapper.mySuperModule"));
}
Also used : Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Aggregations

Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)44 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)28 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)23 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)22 Test (org.junit.jupiter.api.Test)21 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)15 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)15 Subdomain (org.contextmapper.dsl.contextMappingDSL.Subdomain)14 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)13 Collectors (java.util.stream.Collectors)12 List (java.util.List)11 TacticdslFactory (org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory)11 Set (java.util.Set)10 CMLResource (org.contextmapper.dsl.cml.CMLResource)10 Sets (com.google.common.collect.Sets)9 ContextMappingDSLFactory (org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory)9 RefactoringInputException (org.contextmapper.dsl.refactoring.exception.RefactoringInputException)9 Service (org.contextmapper.tactic.dsl.tacticdsl.Service)9 ServiceOperation (org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)9 Domain (org.contextmapper.dsl.contextMappingDSL.Domain)8