Search in sources :

Example 1 with ExtractIDValueObjectQuickFix

use of org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix in project context-mapper-dsl by ContextMapper.

the class ExtractIDValueObjectQuickFixTest method canCheckThatAttributeIsContainedInDomainObject.

@Test
public void canCheckThatAttributeIsContainedInDomainObject() {
    // given
    Attribute attr = TacticdslFactory.eINSTANCE.createAttribute();
    attr.setName("singleAttr");
    // when, then
    assertThrows(ContextMapperApplicationException.class, () -> {
        new ExtractIDValueObjectQuickFix().applyQuickfix(attr);
    });
}
Also used : Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) Test(org.junit.jupiter.api.Test)

Example 2 with ExtractIDValueObjectQuickFix

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

use of org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix in project context-mapper-dsl by ContextMapper.

the class CMLActionRegistry method registerAllQuickFixes.

private void registerAllQuickFixes() {
    // register quick fixes here:
    registerActionQuickFix(DomainObjectValidator.ID_IS_PRIMITIVE_CODE, new ExtractIDValueObjectQuickFix());
    registerCommandQuickFix(UserRequirementsValidator.ID_SPLIT_FEATURE_BY_VERB_SUGGESTION, new SplitStoryByVerbCommandMapper(new SplitStoryByVerb()));
    registerCommandQuickFix(ApplicationFlowSemanticsValidator.SKETCH_MINER_INFO_ID, new OpenFlowInSketchMinerCommandMapper());
}
Also used : OpenFlowInSketchMinerCommandMapper(org.contextmapper.dsl.ide.quickfix.impl.OpenFlowInSketchMinerCommandMapper) ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) SplitStoryByVerb(org.contextmapper.dsl.quickfixes.SplitStoryByVerb) SplitStoryByVerbCommandMapper(org.contextmapper.dsl.ide.quickfix.impl.SplitStoryByVerbCommandMapper)

Example 4 with ExtractIDValueObjectQuickFix

use of org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix in project context-mapper-dsl by ContextMapper.

the class ExtractIDValueObjectQuickFixTest method canExtractValueObjectFromPrimitiveAttribute.

@Test
public void canExtractValueObjectFromPrimitiveAttribute() throws IOException {
    // given
    CMLResource cmlResource = getResourceCopyOfTestCML("extract-vo-for-primitive-id-test-1.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
    Aggregate aggregate = model.getBoundedContexts().get(0).getAggregates().get(0);
    assertEquals("TestAggregate", aggregate.getName());
    assertEquals(2, aggregate.getDomainObjects().size());
    Entity entity = (Entity) aggregate.getDomainObjects().stream().filter(o -> o.getName().equals("Customer")).findFirst().get();
    assertEquals(2, entity.getAttributes().size());
    assertEquals(1, entity.getReferences().size());
    ValueObject vo = (ValueObject) aggregate.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) CMLResource(org.contextmapper.dsl.cml.CMLResource) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 5 with ExtractIDValueObjectQuickFix

use of org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix in project context-mapper-dsl by ContextMapper.

the class ExtractIDValueObjectQuickFixTest method canProvideName.

@Test
public void canProvideName() {
    // given
    ExtractIDValueObjectQuickFix quickFix = new ExtractIDValueObjectQuickFix();
    // when
    String name = quickFix.getName();
    // then
    assertEquals("Extract Value Object", name);
}
Also used : ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) Test(org.junit.jupiter.api.Test)

Aggregations

ExtractIDValueObjectQuickFix (org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix)6 Test (org.junit.jupiter.api.Test)5 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)3 IOException (java.io.IOException)2 CMLResource (org.contextmapper.dsl.cml.CMLResource)2 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)2 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)2 SculptorModule (org.contextmapper.dsl.contextMappingDSL.SculptorModule)2 ContextMapperApplicationException (org.contextmapper.dsl.exception.ContextMapperApplicationException)2 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)2 TacticdslFactory (org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory)2 ValueObject (org.contextmapper.tactic.dsl.tacticdsl.ValueObject)2 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2 OpenFlowInSketchMinerCommandMapper (org.contextmapper.dsl.ide.quickfix.impl.OpenFlowInSketchMinerCommandMapper)1 SplitStoryByVerbCommandMapper (org.contextmapper.dsl.ide.quickfix.impl.SplitStoryByVerbCommandMapper)1 SplitStoryByVerb (org.contextmapper.dsl.quickfixes.SplitStoryByVerb)1