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);
}
}
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;
}
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));
}
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));
}
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));
}
Aggregations