Search in sources :

Example 1 with FlashMessage

use of org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage in project kie-wb-common by kiegroup.

the class IncludedModelErrorMessageFactoryTest method testGetNameIsBlankFlashMessage.

@Test
public void testGetNameIsBlankFlashMessage() {
    final BaseIncludedModelActiveRecord includedModel = mock(BaseIncludedModelActiveRecord.class);
    final Type expectedType = ERROR;
    final String expectedStrongMessage = "StrongMessage";
    final String expectedRegularMessage = "RegularMessage";
    final String expectedElementSelector = "[data-card-uuid=\"1234\"] [data-field=\"title-input\"]";
    when(includedModel.getUUID()).thenReturn("1234");
    when(translationService.format(IncludedModelNameIsBlankErrorMessage_StrongMessage)).thenReturn(expectedStrongMessage);
    when(translationService.format(IncludedModelNameIsBlankErrorMessage_RegularMessage)).thenReturn(expectedRegularMessage);
    final FlashMessage flashMessage = factory.getNameIsBlankFlashMessage(includedModel);
    assertEquals(expectedType, flashMessage.getType());
    assertEquals(expectedStrongMessage, flashMessage.getStrongMessage());
    assertEquals(expectedRegularMessage, flashMessage.getRegularMessage());
    assertEquals(expectedElementSelector, flashMessage.getElementSelector());
}
Also used : Type(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage.Type) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Test(org.junit.Test)

Example 2 with FlashMessage

use of org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage in project kie-wb-common by kiegroup.

the class ImportRecordEngineTest method testIsValidWhenNameIsUnique.

@Test
public void testIsValidWhenNameIsUnique() {
    final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
    final Import import1 = mock(Import.class);
    final Import import2 = mock(Import.class);
    final Name name1 = mock(Name.class);
    final Name name2 = mock(Name.class);
    final FlashMessage flashMessage = mock(FlashMessage.class);
    final List<Import> imports = new ArrayList<>(asList(import1, import2));
    when(name1.getValue()).thenReturn("file1");
    when(name2.getValue()).thenReturn("file2");
    when(record.getName()).thenReturn("file-new");
    when(import1.getName()).thenReturn(name1);
    when(import2.getName()).thenReturn(name2);
    when(includedModelsIndex.getImport(record)).thenReturn(import2);
    when(stateProvider.getImports()).thenReturn(imports);
    when(messageFactory.getNameIsNotUniqueFlashMessage(record)).thenReturn(flashMessage);
    final boolean valid = recordEngine.isValid(record);
    assertTrue(valid);
    verifyZeroInteractions(flashMessageEvent);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) ArrayList(java.util.ArrayList) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 3 with FlashMessage

use of org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage in project kie-wb-common by kiegroup.

the class ImportRecordEngineTest method testIsValidWhenNameIsUnchanged.

@Test
public void testIsValidWhenNameIsUnchanged() {
    final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
    final Import import1 = mock(Import.class);
    final Import import2 = mock(Import.class);
    final Name name1 = mock(Name.class);
    final Name name2 = mock(Name.class);
    final FlashMessage flashMessage = mock(FlashMessage.class);
    final List<Import> imports = new ArrayList<>(asList(import1, import2));
    when(name1.getValue()).thenReturn("file1");
    when(name2.getValue()).thenReturn("file2");
    when(record.getName()).thenReturn("file2");
    when(import1.getName()).thenReturn(name1);
    when(import2.getName()).thenReturn(name2);
    when(includedModelsIndex.getImport(record)).thenReturn(import2);
    when(stateProvider.getImports()).thenReturn(imports);
    when(messageFactory.getNameIsNotUniqueFlashMessage(record)).thenReturn(flashMessage);
    final boolean valid = recordEngine.isValid(record);
    assertTrue(valid);
    verifyZeroInteractions(flashMessageEvent);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) ArrayList(java.util.ArrayList) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 4 with FlashMessage

use of org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage in project kie-wb-common by kiegroup.

the class ImportRecordEngineTest method testIsValidWhenNameIsBlank.

@Test
public void testIsValidWhenNameIsBlank() {
    final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
    final Import anImport = mock(Import.class);
    final Name name = mock(Name.class);
    final FlashMessage flashMessage = mock(FlashMessage.class);
    final List<Import> imports = new ArrayList<>(singletonList(anImport));
    when(name.getValue()).thenReturn("file");
    when(record.getName()).thenReturn("");
    when(anImport.getName()).thenReturn(name);
    when(includedModelsIndex.getImport(record)).thenReturn(anImport);
    when(stateProvider.getImports()).thenReturn(imports);
    when(messageFactory.getNameIsBlankFlashMessage(record)).thenReturn(flashMessage);
    final boolean valid = recordEngine.isValid(record);
    assertFalse(valid);
    verify(flashMessageEvent).fire(flashMessage);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) ArrayList(java.util.ArrayList) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 5 with FlashMessage

use of org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage in project kie-wb-common by kiegroup.

the class DataTypeConfirmationTest method testIfIsNotReferencedDataTypeWhenCallbackIsNotExecuted.

@Test
public void testIfIsNotReferencedDataTypeWhenCallbackIsNotExecuted() {
    final DataType dataType = mock(DataType.class);
    final DataType dataType1 = mock(DataType.class);
    final DataType dataType2 = mock(DataType.class);
    final List<DataType> allDataTypes = asList(dataType1, dataType2);
    final FlashMessage warningMessage = mock(FlashMessage.class);
    final Command onSuccess = mock(Command.class);
    final String tCity = "tCity";
    final String tPerson = "tPerson";
    when(dataType.getName()).thenReturn(tCity);
    when(dataType1.getType()).thenReturn(tCity);
    when(dataType2.getType()).thenReturn(tPerson);
    when(referencedDataTypeWarningMessage.getFlashMessage(eq(dataType), eq(onSuccess), any())).thenReturn(warningMessage);
    when(dataTypeStore.all()).thenReturn(allDataTypes);
    confirmation.ifIsNotReferencedDataType(dataType, onSuccess);
    verify(onSuccess, never()).execute();
    verify(flashMessageEvent).fire(warningMessage);
}
Also used : Command(org.uberfire.mvp.Command) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 FlashMessage (org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage)16 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)9 BaseIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)6 Command (org.uberfire.mvp.Command)5 ArrayList (java.util.ArrayList)4 Import (org.kie.workbench.common.dmn.api.definition.model.Import)4 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)4 Type (org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage.Type)2 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)1