Search in sources :

Example 1 with ServiceSpecification

use of org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification in project context-mapper-dsl by ContextMapper.

the class MDSLAPIDescriptionCreatorTest method canCreateCommentInCaseThereIsNoOperationInAnAPI.

@Test
void canCreateCommentInCaseThereIsNoOperationInAnAPI() throws IOException {
    // given
    String baseFilename = "mdsl-no-operation-in-one-api";
    String inputModelName = baseFilename + ".cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    MDSLModelCreator mdslCreator = new MDSLModelCreator(input.getContextMappingModel());
    // when
    List<ServiceSpecification> serviceSpecifications = mdslCreator.createServiceSpecifications();
    MDSLAPIDescriptionCreator dslTextCreator = new TestMDSLAPIDescriptionCreator(new ProtectedRegionContextFactory().createProtectedRegionContextForNewMDSLFile(), input.getURI().toFileString());
    ServiceSpecification spec = serviceSpecifications.stream().filter(s -> s.getName().equals("MyBoundedContextAPI")).findFirst().get();
    String dslText = dslTextCreator.createText(spec);
    // then
    File expectedResultFile = new File(Paths.get("").toAbsolutePath().toString(), "/integ-test-files/mdsl/" + baseFilename + ".mdsl");
    String expectedResult = FileUtils.readFileToString(expectedResultFile, Charset.forName("UTF-8"));
    assertEquals(expectedResult, dslText);
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) MDSLAPIDescriptionCreator(org.contextmapper.dsl.generator.mdsl.MDSLAPIDescriptionCreator) MDSLModelCreator(org.contextmapper.dsl.generator.mdsl.MDSLModelCreator) CMLResource(org.contextmapper.dsl.cml.CMLResource) ProtectedRegionContextFactory(org.contextmapper.dsl.generator.mdsl.ProtectedRegionContextFactory) File(java.io.File) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 2 with ServiceSpecification

use of org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreatorTest method canHandleMDSLKeywords.

@Test
void canHandleMDSLKeywords() throws IOException {
    // given
    String inputModelName = "mdsl-can-handle-keyword-clashes.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    MDSLModelCreator mdslCreator = new MDSLModelCreator(input.getContextMappingModel());
    // when
    List<ServiceSpecification> serviceSpecifications = mdslCreator.createServiceSpecifications();
    // then
    assertEquals(1, serviceSpecifications.size());
    ServiceSpecification spec = serviceSpecifications.get(0);
    assertEquals(2, spec.getDataTypes().size());
    DataType dataType1 = spec.getDataTypes().get(0);
    DataType dataType2 = spec.getDataTypes().get(1);
    assertEquals("ReturnType", dataType1.getName());
    assertEquals("^Link", dataType2.getName());
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) MDSLModelCreator(org.contextmapper.dsl.generator.mdsl.MDSLModelCreator) CMLResource(org.contextmapper.dsl.cml.CMLResource) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 3 with ServiceSpecification

use of org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreatorTest method canCreateUpdateAndReadModelWithScenarioAndStory.

@Test
void canCreateUpdateAndReadModelWithScenarioAndStory() {
    // given
    ServiceSpecification mdslModel = new ServiceSpecification();
    IntegrationScenario scenarioModel = new org.contextmapper.dsl.generator.mdsl.model.IntegrationScenario();
    scenarioModel.setName("SampleScenarioName");
    Story storyModel = new org.contextmapper.dsl.generator.mdsl.model.Story("SampleStoryName", "SampleActor", "SampleAction", "SampleGoal");
    // when
    scenarioModel.addStory(storyModel);
    mdslModel.addScenario(scenarioModel);
    assertEquals("SampleScenarioName", mdslModel.getScenarios().get(0).getName());
    assertEquals("SampleStoryName", scenarioModel.getStories().get(0).getName());
    // when
    storyModel.setName("NewName");
    storyModel.setPersona("NewActor");
    storyModel.setAction("NewAction");
    storyModel.setGoal("NewGoal");
    assertEquals("NewName", scenarioModel.getStories().get(0).getName());
    assertEquals("NewActor", scenarioModel.getStories().get(0).getPersona());
    assertEquals("NewAction", scenarioModel.getStories().get(0).getAction());
    assertEquals("NewGoal", scenarioModel.getStories().get(0).getGoal());
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) IntegrationScenario(org.contextmapper.dsl.generator.mdsl.model.IntegrationScenario) Story(org.contextmapper.dsl.generator.mdsl.model.Story) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 4 with ServiceSpecification

use of org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreatorTest method canCreateMDSLModelWithoutContextMap.

@Test
void canCreateMDSLModelWithoutContextMap() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("basic-mdsl-model-test-without-contextmap.cml");
    MDSLModelCreator mdslCreator = new MDSLModelCreator(input.getContextMappingModel());
    // when
    List<ServiceSpecification> serviceSpecifications = mdslCreator.createServiceSpecifications();
    // then
    assertEquals(1, serviceSpecifications.size());
    ServiceSpecification spec = serviceSpecifications.get(0);
    assertEquals("CustomerManagementContextAPI", spec.getName());
    assertEquals(1, spec.getEndpoints().size());
    EndpointContract endpoint = spec.getEndpoints().get(0);
    assertEquals("Customers", endpoint.getName());
    assertEquals(2, endpoint.getOperations().size());
    EndpointOperation operation1 = endpoint.getOperations().get(0);
    assertEquals("updateAddress", operation1.getName());
    EndpointOperation operation2 = endpoint.getOperations().get(1);
    assertEquals("anotherMethod", operation2.getName());
    assertEquals(5, spec.getDataTypes().size());
    DataType dataType1 = spec.getDataTypes().get(0);
    assertEquals("Address", dataType1.getName());
    DataType dataType2 = spec.getDataTypes().get(1);
    assertEquals("Parameter1Type", dataType2.getName());
    DataType dataType3 = spec.getDataTypes().get(2);
    assertEquals("Parameter2Type", dataType3.getName());
    DataType dataType4 = spec.getDataTypes().get(3);
    assertEquals("ReturnType", dataType4.getName());
    DataType dataType5 = spec.getDataTypes().get(4);
    assertEquals("anotherMethodParameter", dataType5.getName());
    assertEquals("Address", operation1.getExpectingPayload().getName());
    assertEquals("ReturnType", operation1.getDeliveringPayload().getName());
    assertEquals("anotherMethodParameter", operation2.getExpectingPayload().getName());
    assertEquals(1, spec.getProviders().size());
    EndpointProvider provider = spec.getProviders().get(0);
    assertEquals("CustomerManagementContextProvider", provider.getName());
    assertEquals(1, provider.getEndpointOffers().size());
    EndpointOffer contractOffered = provider.getEndpointOffers().get(0);
    assertEquals("Customers", contractOffered.getOfferedEndpoint().getName());
    assertEquals("http://localhost:8000", contractOffered.getLocation());
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) MDSLModelCreator(org.contextmapper.dsl.generator.mdsl.MDSLModelCreator) EndpointProvider(org.contextmapper.dsl.generator.mdsl.model.EndpointProvider) CMLResource(org.contextmapper.dsl.cml.CMLResource) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) EndpointOffer(org.contextmapper.dsl.generator.mdsl.model.EndpointOffer) EndpointOperation(org.contextmapper.dsl.generator.mdsl.model.EndpointOperation) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 5 with ServiceSpecification

use of org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreator method createServiceSpecifications.

public List<ServiceSpecification> createServiceSpecifications() {
    checkPreconditions();
    List<ServiceSpecification> specs = Lists.newArrayList();
    Map<String, UpstreamAPIContext> upstreamContexts = collectUpstreamContexts();
    for (String apiName : upstreamContexts.keySet()) {
        UpstreamAPIContext context = upstreamContexts.get(apiName);
        specs.add(createServiceSpecification(context.getApiName(), context));
    }
    return specs;
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) UpstreamAPIContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext)

Aggregations

ServiceSpecification (org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification)15 MDSLModelCreator (org.contextmapper.dsl.generator.mdsl.MDSLModelCreator)10 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)9 CMLResource (org.contextmapper.dsl.cml.CMLResource)9 Test (org.junit.jupiter.api.Test)9 DataType (org.contextmapper.dsl.generator.mdsl.model.DataType)7 EndpointContract (org.contextmapper.dsl.generator.mdsl.model.EndpointContract)5 EndpointOffer (org.contextmapper.dsl.generator.mdsl.model.EndpointOffer)4 EndpointOperation (org.contextmapper.dsl.generator.mdsl.model.EndpointOperation)4 EndpointProvider (org.contextmapper.dsl.generator.mdsl.model.EndpointProvider)4 OrchestrationFlow (org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow)4 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)3 Flow (org.contextmapper.dsl.contextMappingDSL.Flow)3 FlowStep (org.contextmapper.dsl.contextMappingDSL.FlowStep)3 EndpointClient (org.contextmapper.dsl.generator.mdsl.model.EndpointClient)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 InvalidParameterException (java.security.InvalidParameterException)2 List (java.util.List)2 Map (java.util.Map)2