Search in sources :

Example 11 with ScenarioSimulationModel

use of org.drools.scenariosimulation.api.model.ScenarioSimulationModel in project drools by kiegroup.

the class ScenarioSimulationXMLPersistenceTest method commonCheckBackground.

private void commonCheckBackground(Document toCheck) throws Exception {
    String migrated = DOMParserUtil.getString(toCheck);
    ScenarioSimulationModel scenarioSimulationModel = instance.internalUnmarshal(migrated);
    commonCheckBackground(scenarioSimulationModel);
}
Also used : ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel)

Example 12 with ScenarioSimulationModel

use of org.drools.scenariosimulation.api.model.ScenarioSimulationModel in project drools by kiegroup.

the class ScenarioSimulationXMLPersistenceTest method versionAttributeExists.

@Test
public void versionAttributeExists() {
    final String xml = instance.marshal(new ScenarioSimulationModel());
    assertTrue(xml.startsWith("<ScenarioSimulationModel version=\"" + ScenarioSimulationXMLPersistence.getCurrentVersion() + "\">"));
}
Also used : ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) Test(org.junit.Test)

Example 13 with ScenarioSimulationModel

use of org.drools.scenariosimulation.api.model.ScenarioSimulationModel in project drools by kiegroup.

the class ScenarioSimulationXMLPersistenceTest method unmarshalDMN.

@Test
public void unmarshalDMN() throws Exception {
    String toUnmarshal = getFileContent("scesim-dmn.scesim");
    final ScenarioSimulationModel retrieved = ScenarioSimulationXMLPersistence.getInstance().unmarshal(toUnmarshal);
    assertEquals(ScenarioSimulationModel.Type.DMN, retrieved.getSettings().getType());
    commonCheckSimulation(retrieved);
}
Also used : ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) Test(org.junit.Test)

Example 14 with ScenarioSimulationModel

use of org.drools.scenariosimulation.api.model.ScenarioSimulationModel in project droolsjbpm-integration by kiegroup.

the class ScenarioSimulationResource method executeSimulation.

@ApiOperation(value = "Execute given test scenario against specified container", response = ServiceResponse.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Container not found"), @ApiResponse(code = 400, message = "Malformed test scenario file") })
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response executeSimulation(@Context HttpHeaders headers, @ApiParam(value = "Container id", required = true) @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "Test scenario file content to be executed", required = true) String rawContent) {
    KieContainer kieContainer = null;
    ScenarioSimulationModel model = null;
    Variant v = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, scenarioSimulationService.getKieServerRegistry(), headers);
    try {
        kieContainer = scenarioSimulationService.getKieContainerById(containerId);
    } catch (Exception e) {
        return createCorrectVariant(createFailedServiceResponse("Impossible to find container with id " + containerId, e), headers, Response.Status.NOT_FOUND, conversationIdHeader);
    }
    try {
        model = scenarioSimulationService.parseModel(rawContent);
    } catch (Exception e) {
        return createCorrectVariant(createFailedServiceResponse("Test scenario parsing error", e), headers, Response.Status.BAD_REQUEST, conversationIdHeader);
    }
    try {
        return createCorrectVariant(scenarioSimulationService.executeScenario(kieContainer, model), headers, Response.Status.OK, conversationIdHeader);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return internalServerError(e.getMessage(), v, conversationIdHeader);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) KieContainer(org.kie.api.runtime.KieContainer) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 15 with ScenarioSimulationModel

use of org.drools.scenariosimulation.api.model.ScenarioSimulationModel in project drools by kiegroup.

the class ScenarioSimulationXMLPersistenceTest method commonCheckSimulation.

private void commonCheckSimulation(Document toCheck) throws Exception {
    String migrated = DOMParserUtil.getString(toCheck);
    ScenarioSimulationModel scenarioSimulationModel = instance.internalUnmarshal(migrated);
    commonCheckSimulation(scenarioSimulationModel);
}
Also used : ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel)

Aggregations

ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)24 Test (org.junit.Test)12 Path (org.uberfire.backend.vfs.Path)5 Settings (org.drools.scenariosimulation.api.model.Settings)3 Simulation (org.drools.scenariosimulation.api.model.Simulation)3 ScenarioRunnerDTO (org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerDTO)2 ImpossibleToFindDMNException (org.drools.scenariosimulation.backend.util.ImpossibleToFindDMNException)2 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)2 ObservablePath (org.uberfire.backend.vfs.ObservablePath)2 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Scanner (java.util.Scanner)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1