Search in sources :

Example 1 with KieModule

use of org.kie.workbench.common.services.shared.project.KieModule in project drools-wb by kiegroup.

the class ScenarioRunnerServiceTest method testRunEmptyScenario.

@Test
public void testRunEmptyScenario() throws Exception {
    initKieSession();
    TestScenarioResult result = service.run("userName", makeScenario("test.scenario"), new KieModule());
    assertNotNull(result);
    ArgumentCaptor<TestResultMessage> argumentCaptor = ArgumentCaptor.forClass(TestResultMessage.class);
    verify(defaultTestResultMessageEvent).fire(argumentCaptor.capture());
    assertEquals("userName", argumentCaptor.getValue().getIdentifier());
}
Also used : TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 2 with KieModule

use of org.kie.workbench.common.services.shared.project.KieModule in project drools-wb by kiegroup.

the class ScenarioTestEditorServiceImplTest method checkScenarioRunnerIsRan.

@Test
public void checkScenarioRunnerIsRan() throws Exception {
    final Imports imports = new Imports() {

        {
            addImport(new Import("java.sql.ClientInfoStatus"));
        }
    };
    when(dataModelService.getDataModel(path)).thenReturn(modelOracle);
    when(scenario.getImports()).thenCallRealMethod();
    doCallRealMethod().when(scenario).setImports(any(Imports.class));
    scenario.setImports(imports);
    testEditorService.runScenario("userName", path, scenario);
    KieModule module = mock(KieModule.class);
    when(moduleService.resolveModule(path)).thenReturn(module);
    testEditorService.runScenario("userName", path, scenario);
    verify(scenarioRunner).run("userName", scenario, module);
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) Imports(org.kie.soup.project.datamodel.imports.Imports) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 3 with KieModule

use of org.kie.workbench.common.services.shared.project.KieModule in project drools-wb by kiegroup.

the class EnumServiceImpl method doValidation.

private List<ValidationMessage> doValidation(final Path path, final String content) {
    try {
        final KieModule module = moduleService.resolveModule(path);
        final org.kie.api.builder.KieModule kieModule = buildInfoService.getBuildInfo(module).getKieModuleIgnoringErrors();
        final ClassLoader classLoader = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule).getClassLoader();
        final DataEnumLoader loader = new DataEnumLoader(content, classLoader, evaluator);
        if (!loader.hasErrors()) {
            return Collections.emptyList();
        } else {
            final List<ValidationMessage> validationMessages = new ArrayList<>();
            final List<String> loaderErrors = loader.getErrors();
            for (final String message : loaderErrors) {
                validationMessages.add(makeValidationMessages(path, message));
            }
            return validationMessages;
        }
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) ArrayList(java.util.ArrayList) DataEnumLoader(org.kie.workbench.common.services.datamodel.backend.server.builder.util.DataEnumLoader) KieModule(org.kie.workbench.common.services.shared.project.KieModule) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 4 with KieModule

use of org.kie.workbench.common.services.shared.project.KieModule in project drools-wb by kiegroup.

the class DecisionTableXLSToDecisionTableGuidedConverter method makeNewJavaTypes.

private void makeNewJavaTypes(final Path context, final List<String> declaredTypes, final ConversionResult result) {
    if (declaredTypes == null || declaredTypes.isEmpty()) {
        return;
    }
    final KieModule module = moduleService.resolveModule(context);
    for (String declaredType : declaredTypes) {
        final FactModels factModels = FactModelPersistence.unmarshal(declaredType);
        final String packageName = factModels.getPackageName();
        final DataModel dataModel = new DataModelImpl();
        for (FactMetaModel factMetaModel : factModels.getModels()) {
            final DataObject dataObject = new DataObjectImpl(packageName, factMetaModel.getName());
            dataObject.setSuperClassName(factMetaModel.getSuperType());
            final List<AnnotationMetaModel> annotationMetaModel = factMetaModel.getAnnotations();
            addAnnotations(dataObject, annotationMetaModel);
            final List<FieldMetaModel> fields = factMetaModel.getFields();
            for (FieldMetaModel fieldMetaModel : fields) {
                final String fieldName = fieldMetaModel.name;
                final String fieldType = fieldMetaModel.type;
                // Guvnor 5.5 (and earlier) does not have MultipleType
                boolean isMultiple = false;
                ObjectProperty property = new ObjectPropertyImpl(fieldName, fieldType, isMultiple);
                // field has no annotation in Guvnor 5.5 (and earlier)
                dataObject.addProperty(property);
                result.addMessage("Created Java Type " + getJavaTypeFQCN(dataObject), ConversionMessageType.INFO);
            }
            dataModel.getDataObjects().add(dataObject);
        }
        modellerService.saveModel(dataModel, module);
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) FactMetaModel(org.drools.workbench.screens.factmodel.model.FactMetaModel) FactModels(org.drools.workbench.screens.factmodel.model.FactModels) DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) FieldMetaModel(org.drools.workbench.screens.factmodel.model.FieldMetaModel) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl) AnnotationMetaModel(org.drools.workbench.screens.factmodel.model.AnnotationMetaModel) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 5 with KieModule

use of org.kie.workbench.common.services.shared.project.KieModule in project drools-wb by kiegroup.

the class ScenarioRunnerServiceTest method testScenario.

private void testScenario(String scenarioName, boolean isExpectedSuccess) throws Exception {
    final KieModule module = mock(KieModule.class);
    final URL scenarioResource = getClass().getResource(scenarioName);
    final Path scenarioPath = PathFactory.newPath(scenarioResource.getFile(), scenarioResource.toURI().toString());
    final Scenario scenario = testEditorService.load(scenarioPath);
    assertFalse(scenario.wasSuccessful());
    final TestScenarioResult result = service.run("userName", scenario, module);
    assertEquals(isExpectedSuccess, scenario.wasSuccessful());
    assertEquals(isExpectedSuccess, result.getScenario().wasSuccessful());
    verify(defaultTestResultMessageEvent).fire(testResultMessageCaptor.capture());
    final TestResultMessage resultMessage = testResultMessageCaptor.getValue();
    assertEquals(isExpectedSuccess, resultMessage.getFailures().size() == 0);
    assertEquals(isExpectedSuccess, resultMessage.wasSuccessful());
}
Also used : Path(org.uberfire.backend.vfs.Path) TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult) KieModule(org.kie.workbench.common.services.shared.project.KieModule) URL(java.net.URL) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Aggregations

KieModule (org.kie.workbench.common.services.shared.project.KieModule)6 ArrayList (java.util.ArrayList)2 TestScenarioResult (org.drools.workbench.screens.testscenario.model.TestScenarioResult)2 TestResultMessage (org.guvnor.common.services.shared.test.TestResultMessage)2 Test (org.junit.Test)2 Path (org.uberfire.backend.vfs.Path)2 URL (java.net.URL)1 Import (org.drools.template.model.Import)1 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)1 AnnotationMetaModel (org.drools.workbench.screens.factmodel.model.AnnotationMetaModel)1 FactMetaModel (org.drools.workbench.screens.factmodel.model.FactMetaModel)1 FactModels (org.drools.workbench.screens.factmodel.model.FactModels)1 FieldMetaModel (org.drools.workbench.screens.factmodel.model.FieldMetaModel)1 ProjectImports (org.guvnor.common.services.project.model.ProjectImports)1 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)1 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)1 Import (org.kie.soup.project.datamodel.imports.Import)1 Imports (org.kie.soup.project.datamodel.imports.Imports)1 DataEnumLoader (org.kie.workbench.common.services.datamodel.backend.server.builder.util.DataEnumLoader)1 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)1