Search in sources :

Example 26 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.

the class ScenarioSimulationEditorPresenterTest method getImportCallback.

@Test
public void getImportCallback() {
    List<AbstractScesimModel> toTest = Arrays.asList(new Simulation(), new Background());
    for (AbstractScesimModel abstractScesimModel : toTest) {
        FactMapping factMapping = abstractScesimModel.getScesimModelDescriptor().addFactMapping(FactIdentifier.EMPTY, ExpressionIdentifier.create("empty", FactMappingType.GIVEN));
        FactMappingValue toBeRemoved = abstractScesimModel.addData().addOrUpdateMappingValue(factMapping.getFactIdentifier(), factMapping.getExpressionIdentifier(), "toBeRemoved");
        presenterSpy.getImportCallBack().callback(abstractScesimModel);
        verify(presenterSpy, times(1)).cleanReadOnlyColumn(eq(abstractScesimModel));
        assertNull(toBeRemoved.getRawValue());
        reset(presenterSpy);
    }
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) Test(org.junit.Test)

Example 27 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.

the class AbstractScenarioSimulationEditorTest method getSimulation.

protected Simulation getSimulation() {
    Simulation toReturn = new Simulation();
    ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX);
    simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    Scenario scenario = toReturn.addData();
    int row = toReturn.getUnmodifiableData().indexOf(scenario);
    scenario.setDescription(null);
    // Add GIVEN Fact
    int id = 1;
    ExpressionIdentifier givenExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.GIVEN);
    final FactMapping givenFactMapping = simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, givenExpression);
    givenFactMapping.setExpressionAlias(FactMapping.getPropertyPlaceHolder(id));
    scenario.addMappingValue(FactIdentifier.EMPTY, givenExpression, null);
    // Add EXPECT Fact
    id = 2;
    ExpressionIdentifier expectedExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.EXPECT);
    final FactMapping expectedFactMapping = simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, expectedExpression);
    expectedFactMapping.setExpressionAlias(FactMapping.getPropertyPlaceHolder(id));
    scenario.addMappingValue(FactIdentifier.EMPTY, expectedExpression, null);
    return toReturn;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Example 28 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.

the class AbstractScesimGridModelTest method updateFactMappingProperty.

@Test
public void updateFactMappingProperty() {
    final int INDEX = 0;
    final String ALIAS_1 = "ALIAS_1";
    final String ALIAS_2 = "ALIAS_2";
    FactMapping factMappingReference = mock(FactMapping.class);
    FactMapping factMappingToCheck = mock(FactMapping.class);
    FactIdentifier factIdentifier1 = mock(FactIdentifier.class);
    // Should execute
    when(factMappingReference.getFactIdentifier()).thenReturn(FactIdentifier.EMPTY);
    when(factMappingToCheck.getFactIdentifier()).thenReturn(FactIdentifier.EMPTY);
    when(factMappingReference.getFactAlias()).thenReturn(ALIAS_1);
    when(factMappingToCheck.getFactAlias()).thenReturn(ALIAS_1);
    when(factMappingReference.getFullExpression()).thenReturn(ALIAS_1);
    when(factMappingToCheck.getFullExpression()).thenReturn(ALIAS_1);
    when(simulationDescriptorMock.getFactMappingByIndex(INDEX)).thenReturn(factMappingToCheck);
    abstractScesimGridModelSpy.updateFactMapping(simulationDescriptorMock, factMappingReference, INDEX, MULTIPART_VALUE, ScenarioHeaderMetaData.MetadataType.PROPERTY);
    verify(propertyHeaderMetaDataMock, times(1)).setTitle(eq(MULTIPART_VALUE));
    verify(factMappingToCheck, times(1)).setExpressionAlias(eq(MULTIPART_VALUE));
    reset(propertyHeaderMetaDataMock);
    reset(factMappingToCheck);
    // Should not execute
    when(factMappingToCheck.getFactAlias()).thenReturn(ALIAS_2);
    abstractScesimGridModelSpy.updateFactMapping(simulationDescriptorMock, factMappingReference, INDEX, MULTIPART_VALUE, ScenarioHeaderMetaData.MetadataType.PROPERTY);
    verify(propertyHeaderMetaDataMock, never()).setTitle(eq(MULTIPART_VALUE));
    verify(factMappingToCheck, never()).setExpressionAlias(eq(MULTIPART_VALUE));
    reset(propertyHeaderMetaDataMock);
    reset(factMappingToCheck);
    // Should not execute
    when(factMappingReference.getFactIdentifier()).thenReturn(factIdentifier1);
    when(factMappingToCheck.getFactAlias()).thenReturn(ALIAS_1);
    when(factMappingToCheck.getFullExpression()).thenReturn(ALIAS_2);
    abstractScesimGridModelSpy.updateFactMapping(simulationDescriptorMock, factMappingReference, INDEX, MULTIPART_VALUE, ScenarioHeaderMetaData.MetadataType.PROPERTY);
    verify(propertyHeaderMetaDataMock, never()).setTitle(eq(MULTIPART_VALUE));
    verify(factMappingToCheck, never()).setExpressionAlias(eq(MULTIPART_VALUE));
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) AbstractScenarioSimulationTest(org.drools.workbench.screens.scenariosimulation.client.AbstractScenarioSimulationTest) Test(org.junit.Test)

Example 29 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.

the class AbstractScesimGridModelTest method updateFactMappingInstance.

@Test
public void updateFactMappingInstance() {
    final int INDEX = 0;
    final String ALIAS_1 = "ALIAS_1";
    final String ALIAS_2 = "ALIAS_2";
    FactMapping factMappingReference = mock(FactMapping.class);
    FactMapping factMappingToCheck = mock(FactMapping.class);
    FactIdentifier factIdentifier1 = mock(FactIdentifier.class);
    FactIdentifier factIdentifier2 = mock(FactIdentifier.class);
    // Should execute the if in the first if
    when(factMappingReference.getFactIdentifier()).thenReturn(FactIdentifier.EMPTY);
    when(factMappingToCheck.getFactIdentifier()).thenReturn(FactIdentifier.EMPTY);
    when(factMappingReference.getFactAlias()).thenReturn(ALIAS_1);
    when(factMappingToCheck.getFactAlias()).thenReturn(ALIAS_1);
    when(simulationDescriptorMock.getFactMappingByIndex(INDEX)).thenReturn(factMappingToCheck);
    abstractScesimGridModelSpy.updateFactMapping(simulationDescriptorMock, factMappingReference, INDEX, MULTIPART_VALUE, ScenarioHeaderMetaData.MetadataType.INSTANCE);
    verify(informationHeaderMetaDataMock, times(1)).setTitle(eq(MULTIPART_VALUE));
    verify(factMappingToCheck, times(1)).setFactAlias(eq(MULTIPART_VALUE));
    reset(informationHeaderMetaDataMock);
    reset(factMappingToCheck);
    // Should not execute the if in the first if
    when(factMappingToCheck.getFactAlias()).thenReturn(ALIAS_2);
    abstractScesimGridModelSpy.updateFactMapping(simulationDescriptorMock, factMappingReference, INDEX, MULTIPART_VALUE, ScenarioHeaderMetaData.MetadataType.INSTANCE);
    verify(informationHeaderMetaDataMock, never()).setTitle(eq(MULTIPART_VALUE));
    verify(factMappingToCheck, never()).setFactAlias(eq(MULTIPART_VALUE));
    reset(informationHeaderMetaDataMock);
    reset(factMappingToCheck);
    // Should not execute the if in the first if
    when(factMappingReference.getFactIdentifier()).thenReturn(factIdentifier1);
    when(factMappingToCheck.getFactAlias()).thenReturn(ALIAS_1);
    abstractScesimGridModelSpy.updateFactMapping(simulationDescriptorMock, factMappingReference, INDEX, MULTIPART_VALUE, ScenarioHeaderMetaData.MetadataType.INSTANCE);
    verify(informationHeaderMetaDataMock, never()).setTitle(eq(MULTIPART_VALUE));
    verify(factMappingToCheck, never()).setFactAlias(eq(MULTIPART_VALUE));
    reset(informationHeaderMetaDataMock);
    reset(factMappingToCheck);
    // Should execute the second if
    when(factMappingToCheck.getFactIdentifier()).thenReturn(factIdentifier1);
    abstractScesimGridModelSpy.updateFactMapping(simulationDescriptorMock, factMappingReference, INDEX, MULTIPART_VALUE, ScenarioHeaderMetaData.MetadataType.INSTANCE);
    verify(informationHeaderMetaDataMock, times(1)).setTitle(eq(MULTIPART_VALUE));
    verify(factMappingToCheck, times(1)).setFactAlias(eq(MULTIPART_VALUE));
    reset(informationHeaderMetaDataMock);
    reset(factMappingToCheck);
    // Should not execute the second if
    when(factMappingToCheck.getFactIdentifier()).thenReturn(factIdentifier2);
    abstractScesimGridModelSpy.updateFactMapping(simulationDescriptorMock, factMappingReference, INDEX, MULTIPART_VALUE, ScenarioHeaderMetaData.MetadataType.INSTANCE);
    verify(informationHeaderMetaDataMock, never()).setTitle(eq(MULTIPART_VALUE));
    verify(factMappingToCheck, never()).setFactAlias(eq(MULTIPART_VALUE));
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) AbstractScenarioSimulationTest(org.drools.workbench.screens.scenariosimulation.client.AbstractScenarioSimulationTest) Test(org.junit.Test)

Example 30 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.

the class BackgroundGridModelTest method insertRowGridOnly.

@Test
public void insertRowGridOnly() {
    int setCellInvocations = backgroundDataMock.getUnmodifiableFactMappingValues().size();
    backgroundGridModelSpy.insertRowGridOnly(ROW_INDEX, gridRowMock, backgroundDataMock);
    verify(backgroundGridModelSpy, atLeast(1)).checkSimulation();
    verify(backgroundGridModelSpy, never()).insertRow(eq(ROW_INDEX), eq(gridRowMock));
    verify(backgroundGridModelSpy, times(setCellInvocations)).setCell(anyInt(), anyInt(), isA(Supplier.class));
    reset(backgroundGridModelSpy);
    FactMapping factMappingByIndexMock = mock(FactMapping.class);
    when(factMappingByIndexMock.getClassName()).thenReturn(List.class.getName());
    when(simulationDescriptorMock.getFactMappingByIndex(2)).thenReturn(factMappingByIndexMock);
    backgroundGridModelSpy.insertRowGridOnly(ROW_INDEX, gridRowMock, backgroundDataMock);
    verify(backgroundGridModelSpy, atLeast(1)).checkSimulation();
    verify(backgroundGridModelSpy, never()).insertRow(eq(ROW_INDEX), eq(gridRowMock));
    verify(backgroundGridModelSpy, times(setCellInvocations)).setCell(anyInt(), anyInt(), isA(Supplier.class));
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Supplier(java.util.function.Supplier) List(java.util.List) AbstractScenarioSimulationTest(org.drools.workbench.screens.scenariosimulation.client.AbstractScenarioSimulationTest) Test(org.junit.Test)

Aggregations

FactMapping (org.drools.scenariosimulation.api.model.FactMapping)55 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)11 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)10 List (java.util.List)9 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)8 Simulation (org.drools.scenariosimulation.api.model.Simulation)8 HashMap (java.util.HashMap)6 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)6 ScenarioGridCellValue (org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)6 ScenarioGridCell (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)6 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)5 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)5 FactModelTree (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)5 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 FactMappingValidationError (org.drools.workbench.screens.scenariosimulation.model.FactMappingValidationError)4 Before (org.junit.Before)4 Map (java.util.Map)3