Search in sources :

Example 1 with NewResourceHandler

use of org.kie.workbench.common.widgets.client.handlers.NewResourceHandler in project kie-wb-common by kiegroup.

the class ResourceUtilsTest method createNewResourceHandler.

private NewResourceHandler createNewResourceHandler(String description, int order) {
    NewResourceHandler newResourceHandler = mock(NewResourceHandler.class);
    doReturn(description).when(newResourceHandler).getDescription();
    doReturn(order).when(newResourceHandler).order();
    return newResourceHandler;
}
Also used : NewResourceHandler(org.kie.workbench.common.widgets.client.handlers.NewResourceHandler)

Example 2 with NewResourceHandler

use of org.kie.workbench.common.widgets.client.handlers.NewResourceHandler in project kie-wb-common by kiegroup.

the class AddAssetScreenTest method mockResourceHandler.

private NewResourceHandler mockResourceHandler(Profile... profiles) {
    NewResourceHandler nrh = mock(NewResourceHandler.class);
    when(nrh.getProfiles()).thenReturn(Arrays.asList(profiles));
    when(nrh.isProjectAsset()).thenReturn(true);
    return nrh;
}
Also used : NewResourceHandler(org.kie.workbench.common.widgets.client.handlers.NewResourceHandler)

Example 3 with NewResourceHandler

use of org.kie.workbench.common.widgets.client.handlers.NewResourceHandler in project kie-wb-common by kiegroup.

the class AddAssetScreenTest method testOnOpenProfileFilter.

@Test
public void testOnOpenProfileFilter() {
    NewResourceHandler rhFull = mockResourceHandler(Profile.FULL);
    NewResourceHandler rhDroolsPlanner = mockResourceHandler(Profile.PLANNER_AND_RULES);
    NewResourceHandler rhAll = mockResourceHandler(Profile.values());
    addAssetScreen.initialize();
    doReturn(Arrays.asList(rhFull, rhDroolsPlanner, rhAll)).when(resourceHandlerManager).getNewResourceHandlers();
    addAssetScreen.onOpen();
    assertEquals(2, addAssetScreen.newResourceHandlers.size());
    assertTrue(addAssetScreen.newResourceHandlers.contains(rhFull));
    assertTrue(addAssetScreen.newResourceHandlers.contains(rhAll));
    assertTrue(!addAssetScreen.newResourceHandlers.contains(rhDroolsPlanner));
    executeParametrizedCommandWith(0, new ProfilePreferences(Profile.PLANNER_AND_RULES)).when(profilePreferences).load(any(ParameterizedCommand.class), any(ParameterizedCommand.class));
    addAssetScreen.onOpen();
    assertEquals(2, addAssetScreen.newResourceHandlers.size());
    assertTrue(!addAssetScreen.newResourceHandlers.contains(rhFull));
    assertTrue(addAssetScreen.newResourceHandlers.contains(rhAll));
    assertTrue(addAssetScreen.newResourceHandlers.contains(rhDroolsPlanner));
}
Also used : NewResourceHandler(org.kie.workbench.common.widgets.client.handlers.NewResourceHandler) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) ProfilePreferences(org.kie.workbench.common.profile.api.preferences.ProfilePreferences) Test(org.junit.Test)

Example 4 with NewResourceHandler

use of org.kie.workbench.common.widgets.client.handlers.NewResourceHandler in project kie-wb-common by kiegroup.

the class AddAssetScreenTest method testFilterByCategory.

@Test
public void testFilterByCategory() {
    NewResourceHandler resourceHandler = mock(NewResourceHandler.class, Answers.RETURNS_DEEP_STUBS.get());
    when(resourceHandler.getDescription()).thenReturn("demo");
    when(resourceHandler.getResourceType().getCategory()).thenReturn(new Decision());
    {
        List<NewResourceHandler> filtered = this.addAssetScreen.filterAndSortHandlers(Arrays.asList(resourceHandler), "", new Decision());
        assertEquals(resourceHandler, filtered.get(0));
    }
    {
        List<NewResourceHandler> filtered = this.addAssetScreen.filterAndSortHandlers(Arrays.asList(resourceHandler), "", new Others());
        assertTrue(filtered.isEmpty());
    }
}
Also used : NewResourceHandler(org.kie.workbench.common.widgets.client.handlers.NewResourceHandler) Others(org.uberfire.workbench.category.Others) List(java.util.List) Decision(org.guvnor.common.services.project.categories.Decision) Test(org.junit.Test)

Example 5 with NewResourceHandler

use of org.kie.workbench.common.widgets.client.handlers.NewResourceHandler in project kie-wb-common by kiegroup.

the class AddAssetScreenTest method testProfileFilter.

@Test
public void testProfileFilter() {
    NewResourceHandler rhFull = mockResourceHandler(Profile.FULL);
    NewResourceHandler rhDroolsPlanner = mockResourceHandler(Profile.PLANNER_AND_RULES);
    NewResourceHandler rhAll = mockResourceHandler(Profile.values());
    addAssetScreen.initialize();
    doReturn(Arrays.asList(rhFull, rhDroolsPlanner, rhAll)).when(resourceHandlerManager).getNewResourceHandlers();
    List<NewResourceHandler> filteredResourceHandlers = this.addAssetScreen.filterNewResourceHandlers(new ProfilePreferences(Profile.FULL));
    assertEquals(2, filteredResourceHandlers.size());
    filteredResourceHandlers = this.addAssetScreen.filterNewResourceHandlers(new ProfilePreferences(Profile.PLANNER_AND_RULES));
    assertEquals(2, filteredResourceHandlers.size());
    doReturn(Arrays.asList(rhFull, rhDroolsPlanner)).when(resourceHandlerManager).getNewResourceHandlers();
    filteredResourceHandlers = this.addAssetScreen.filterNewResourceHandlers(new ProfilePreferences(Profile.PLANNER_AND_RULES));
    assertEquals(1, filteredResourceHandlers.size());
    assertEquals(Profile.PLANNER_AND_RULES, filteredResourceHandlers.get(0).getProfiles().get(0));
    filteredResourceHandlers = this.addAssetScreen.filterNewResourceHandlers(new ProfilePreferences(Profile.FULL));
    assertEquals(1, filteredResourceHandlers.size());
    assertEquals(Profile.FULL, filteredResourceHandlers.get(0).getProfiles().get(0));
}
Also used : NewResourceHandler(org.kie.workbench.common.widgets.client.handlers.NewResourceHandler) ProfilePreferences(org.kie.workbench.common.profile.api.preferences.ProfilePreferences) Test(org.junit.Test)

Aggregations

NewResourceHandler (org.kie.workbench.common.widgets.client.handlers.NewResourceHandler)10 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Decision (org.guvnor.common.services.project.categories.Decision)2 ProfilePreferences (org.kie.workbench.common.profile.api.preferences.ProfilePreferences)2 Others (org.uberfire.workbench.category.Others)2 Model (org.guvnor.common.services.project.categories.Model)1 NewJavaFileTextHandler (org.kie.workbench.common.screens.datamodeller.client.handlers.NewJavaFileTextHandler)1 NewFileUploader (org.kie.workbench.common.screens.defaulteditor.client.editor.NewFileUploader)1 JavaResourceTypeDefinition (org.kie.workbench.common.screens.javaeditor.type.JavaResourceTypeDefinition)1 ProjectImportsResourceTypeDefinition (org.kie.workbench.common.screens.projectimportsscreen.type.ProjectImportsResourceTypeDefinition)1 NewWorkspaceProjectHandler (org.kie.workbench.common.widgets.client.handlers.NewWorkspaceProjectHandler)1 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)1 Undefined (org.uberfire.workbench.category.Undefined)1