forked from kiegroup/jbpm-wb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38dfc79
commit b325769
Showing
20 changed files
with
1,096 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
.../test/java/org/jbpm/workbench/common/client/filters/active/ActiveFiltersViewImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jbpm.workbench.common.client.filters.active; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Spy; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.uberfire.client.views.pfly.widgets.Popover; | ||
import org.uberfire.mvp.Command; | ||
import org.uberfire.mvp.ParameterizedCommand; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ActiveFiltersViewImplTest { | ||
|
||
@Mock | ||
Popover saveFilterPopover; | ||
|
||
@Mock | ||
SaveFilterPopoverView saveFilterPopoverView; | ||
|
||
@InjectMocks | ||
@Spy | ||
ActiveFiltersViewImpl view; | ||
|
||
@Test | ||
public void testSaveFilterCallback() { | ||
final String name = "filterName"; | ||
doAnswer(invocation -> { | ||
ParameterizedCommand<String> callback = (ParameterizedCommand<String>) invocation.getArguments()[0]; | ||
callback.execute(name); | ||
return null; | ||
}).when(saveFilterPopoverView).setSaveCallback(any()); | ||
|
||
view.setSaveFilterPopoverCallback(); | ||
|
||
verify(view).saveFilter(name); | ||
} | ||
|
||
@Test | ||
public void testCancelFilterCallback() { | ||
doAnswer(invocation -> { | ||
Command callback = (Command) invocation.getArguments()[0]; | ||
callback.execute(); | ||
return null; | ||
}).when(saveFilterPopoverView).setCancelCallback(any()); | ||
|
||
view.setSaveFilterPopoverCallback(); | ||
|
||
verify(saveFilterPopover).hide(); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
.../test/java/org/jbpm/workbench/common/client/filters/active/SaveFilterPopoverViewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jbpm.workbench.common.client.filters.active; | ||
|
||
import com.google.gwt.event.dom.client.KeyCodes; | ||
import com.google.gwt.event.dom.client.KeyDownEvent; | ||
import elemental2.dom.HTMLInputElement; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.uberfire.mvp.Command; | ||
import org.uberfire.mvp.ParameterizedCommand; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class SaveFilterPopoverViewTest { | ||
|
||
@Mock | ||
HTMLInputElement filterName; | ||
|
||
@InjectMocks | ||
SaveFilterPopoverView popoverView; | ||
|
||
@Test | ||
public void testOnSaveCallback() { | ||
final String value = "value"; | ||
filterName.value = value; | ||
|
||
final ParameterizedCommand<String> callback = mock(ParameterizedCommand.class); | ||
|
||
popoverView.setSaveCallback(callback); | ||
|
||
popoverView.onSave(null); | ||
|
||
verify(callback).execute(value); | ||
} | ||
|
||
@Test | ||
public void testOnKeyPressEvent() { | ||
final String value = "value"; | ||
filterName.value = value; | ||
|
||
final ParameterizedCommand<String> callback = mock(ParameterizedCommand.class); | ||
|
||
popoverView.setSaveCallback(callback); | ||
|
||
final KeyDownEvent event = mock(KeyDownEvent.class); | ||
when(event.getNativeKeyCode()).thenReturn(KeyCodes.KEY_ENTER, | ||
KeyCodes.KEY_A); | ||
popoverView.onKeyPressEvent(event); | ||
popoverView.onKeyPressEvent(event); | ||
|
||
verify(callback).execute(value); | ||
} | ||
|
||
@Test | ||
public void testCancelCallback() { | ||
final Command callback = mock(Command.class); | ||
|
||
popoverView.setCancelCallback(callback); | ||
|
||
popoverView.onCancel(null); | ||
|
||
verify(callback).execute(); | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
...ava/org/jbpm/workbench/common/client/filters/basic/AbstractBasicFiltersPresenterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jbpm.workbench.common.client.filters.basic; | ||
|
||
import java.util.function.Consumer; | ||
import javax.enterprise.event.Event; | ||
|
||
import org.jbpm.workbench.common.client.filters.saved.SavedFilterSelectedEvent; | ||
import org.jbpm.workbench.df.client.filter.FilterEditorPopup; | ||
import org.jbpm.workbench.df.client.filter.FilterSettings; | ||
import org.jbpm.workbench.df.client.filter.FilterSettingsManager; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mock; | ||
import org.mockito.Spy; | ||
import org.uberfire.mocks.EventSourceMock; | ||
import org.uberfire.mvp.Command; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.*; | ||
|
||
public abstract class AbstractBasicFiltersPresenterTest { | ||
|
||
@Mock | ||
BasicFiltersView view; | ||
|
||
@Mock | ||
FilterEditorPopup filterEditorPopup; | ||
|
||
@Mock | ||
FilterSettingsManager filterSettingsManager; | ||
|
||
@Spy | ||
Event<BasicFilterAddEvent> activeFilters = new EventSourceMock<>(); | ||
|
||
@Spy | ||
Event<SavedFilterSelectedEvent> savedFilterSelectedEvent = new EventSourceMock<>(); | ||
|
||
public abstract BasicFiltersPresenter getPresenter(); | ||
|
||
public BasicFiltersView getView() { | ||
return view; | ||
} | ||
|
||
@Before | ||
public void init() { | ||
doNothing().when(savedFilterSelectedEvent).fire(any(SavedFilterSelectedEvent.class)); | ||
doNothing().when(activeFilters).fire(any(BasicFilterAddEvent.class)); | ||
} | ||
|
||
@Test | ||
public void testSaveAdvancedFiltersCallback() { | ||
doAnswer(invocation -> { | ||
Command callback = (Command) invocation.getArguments()[0]; | ||
callback.execute(); | ||
return null; | ||
}).when(view).setAdvancedFiltersCallback(any()); | ||
|
||
getPresenter().init(); | ||
|
||
verify(filterEditorPopup).setTitle(any()); | ||
ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); | ||
verify(filterEditorPopup).show(any(), | ||
captor.capture()); | ||
final FilterSettings filterSettings = new FilterSettings(); | ||
captor.getValue().accept(filterSettings); | ||
|
||
verify(filterSettingsManager).saveFilterIntoPreferences(eq(filterSettings), | ||
captor.capture()); | ||
captor.getValue().accept(true); | ||
|
||
verify(filterEditorPopup).hide(); | ||
verify(savedFilterSelectedEvent).fire(any()); | ||
} | ||
|
||
@Test | ||
public void testSaveInvalidAdvancedFiltersCallback() { | ||
doAnswer(invocation -> { | ||
Command callback = (Command) invocation.getArguments()[0]; | ||
callback.execute(); | ||
return null; | ||
}).when(view).setAdvancedFiltersCallback(any()); | ||
|
||
getPresenter().init(); | ||
|
||
verify(filterEditorPopup).setTitle(any()); | ||
ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer.class); | ||
verify(filterEditorPopup).show(any(), | ||
captor.capture()); | ||
final FilterSettings filterSettings = new FilterSettings(); | ||
captor.getValue().accept(filterSettings); | ||
|
||
verify(filterSettingsManager).saveFilterIntoPreferences(eq(filterSettings), | ||
captor.capture()); | ||
captor.getValue().accept(false); | ||
|
||
verify(filterEditorPopup).setTableNameError(any()); | ||
} | ||
|
||
public abstract void testLoadFilters(); | ||
} |
90 changes: 90 additions & 0 deletions
90
...t/src/test/java/org/jbpm/workbench/common/client/filters/basic/ActiveFiltersImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jbpm.workbench.common.client.filters.basic; | ||
|
||
import org.jbpm.workbench.common.client.filters.active.ActiveFilterItem; | ||
import org.jbpm.workbench.common.client.filters.active.ActiveFiltersImpl; | ||
import org.jbpm.workbench.common.client.filters.active.ActiveFiltersView; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.uberfire.mvp.ParameterizedCommand; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ActiveFiltersImplTest { | ||
|
||
@Mock | ||
ActiveFiltersView view; | ||
|
||
@InjectMocks | ||
ActiveFiltersImpl activeFilters; | ||
|
||
@Test | ||
public void testRemoveAllActiveFilters() { | ||
activeFilters.removeAllActiveFilters(); | ||
|
||
verify(view).removeAllActiveFilters(); | ||
} | ||
|
||
@Test | ||
public void testAddActiveFilter() { | ||
final ActiveFilterItem<Object> filter = new ActiveFilterItem<>(); | ||
activeFilters.addActiveFilter(filter); | ||
|
||
verify(view).addActiveFilter(filter); | ||
} | ||
|
||
@Test | ||
public void testSaveFilterCallbackNull() { | ||
doAnswer(invocation -> { | ||
ParameterizedCommand<String> callback = (ParameterizedCommand<String>) invocation.getArguments()[0]; | ||
callback.execute(null); | ||
return null; | ||
}).when(view).setSaveFilterCallback(any()); | ||
|
||
activeFilters.setSaveFilterCallback((name, callback) -> callback.accept(null)); | ||
activeFilters.init(); | ||
|
||
verify(view).setSaveFilterCallback(any()); | ||
verify(view).closeSaveFilter(); | ||
verify(view, | ||
never()).setSaveFilterErrorMessage(any()); | ||
} | ||
|
||
@Test | ||
public void testSaveFilterCallbackError() { | ||
final String message = "error"; | ||
doAnswer(invocation -> { | ||
ParameterizedCommand<String> callback = (ParameterizedCommand<String>) invocation.getArguments()[0]; | ||
callback.execute(null); | ||
return null; | ||
}).when(view).setSaveFilterCallback(any()); | ||
|
||
activeFilters.setSaveFilterCallback((name, callback) -> callback.accept(message)); | ||
activeFilters.init(); | ||
|
||
verify(view).setSaveFilterCallback(any()); | ||
verify(view, | ||
never()).closeSaveFilter(); | ||
verify(view).setSaveFilterErrorMessage(message); | ||
} | ||
} |
Oops, something went wrong.