Search in sources :

Example 61 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class NewWorkspaceProjectHandlerTest method testGetCommandWithActiveRepository.

@Test
public void testGetCommandWithActiveRepository() {
    final LibraryOrganizationalUnitPreferences libraryOrganizationalUnitPreferences = mock(LibraryOrganizationalUnitPreferences.class);
    when(libraryOrganizationalUnitPreferences.getName()).thenReturn("myOU");
    when(libraryPreferences.getOrganizationalUnitPreferences()).thenReturn(libraryOrganizationalUnitPreferences);
    when(context.getActiveWorkspaceProject()).thenReturn(Optional.of(new WorkspaceProject(mock(OrganizationalUnit.class), repository, mock(Branch.class), mock(Module.class))));
    final OrganizationalUnit organizationalUnit = mock(OrganizationalUnit.class);
    when(organizationalUnit.getDefaultGroupId()).thenReturn("defaultGroupId");
    when(organizationalUnitService.getOrganizationalUnit("myOU")).thenReturn(organizationalUnit);
    doAnswer(new Answer() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            when(context.getActiveOrganizationalUnit()).thenReturn(Optional.of(organizationalUnit));
            return null;
        }
    }).when(projectContextChangeEvent).fire(any(WorkspaceProjectContextChangeEvent.class));
    final Command command = handler.getCommand(newResourcePresenter);
    assertNotNull(command);
    command.execute();
    ArgumentCaptor<POM> pomArgumentCaptor = ArgumentCaptor.forClass(POM.class);
    verify(wizard, times(1)).initialise(pomArgumentCaptor.capture());
    verify(wizard, times(1)).start(any(org.uberfire.client.callbacks.Callback.class), anyBoolean());
    assertEquals("defaultGroupId", pomArgumentCaptor.getValue().getGav().getGroupId());
    assertEquals("kjar", pomArgumentCaptor.getValue().getPackaging());
}
Also used : OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) POM(org.guvnor.common.services.project.model.POM) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) LibraryOrganizationalUnitPreferences(org.kie.workbench.common.screens.library.api.preferences.LibraryOrganizationalUnitPreferences) Callback(com.google.gwt.core.client.Callback) ValidatorWithReasonCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback) Command(org.uberfire.mvp.Command) Branch(org.guvnor.structure.repositories.Branch) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Module(org.guvnor.common.services.project.model.Module) Test(org.junit.Test)

Example 62 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class ExamplesServiceImplRepositoryNamesTest method setup.

@Before
public void setup() {
    service = spy(new ExamplesServiceImpl(ioService, configurationFactory, repositoryFactory, moduleService, repositoryService, repositoryCopier, ouService, projectService, metadataService, spaces, newProjectEvent, projectScreenService));
    when(ouService.getOrganizationalUnits()).thenReturn(new HashSet<OrganizationalUnit>() {

        {
            add(new OrganizationalUnitImpl("ou1Name", "ou1Owner", "ou1GroupId"));
        }
    });
    when(moduleService.resolveModule(any(Path.class))).thenAnswer(new Answer<KieModule>() {

        @Override
        public KieModule answer(final InvocationOnMock invocationOnMock) throws Throwable {
            final Path path = (Path) invocationOnMock.getArguments()[0];
            final KieModule module = new KieModule(path, path, path, path, path, path, mock(POM.class));
            return module;
        }
    });
    when(sessionInfo.getId()).thenReturn("sessionId");
    when(sessionInfo.getIdentity()).thenReturn(user);
    when(user.getIdentifier()).thenReturn("user");
    when(configurationFactory.newConfigGroup(any(ConfigType.class), anyString(), anyString())).thenReturn(mock(ConfigGroup.class));
    final ExampleProject exProject1 = mock(ExampleProject.class);
    exampleProjects = new ArrayList<ExampleProject>() {

        {
            add(exProject1);
        }
    };
    final OrganizationalUnit ou = mock(OrganizationalUnit.class);
    doReturn("ou").when(ou).getName();
    final GitRepository repository1 = mock(GitRepository.class);
    final Path repositoryRoot = mock(Path.class);
    final Path module1Root = mock(Path.class);
    when(exampleOrganizationalUnit.getName()).thenReturn("ou");
    when(exProject1.getName()).thenReturn("module1");
    when(exProject1.getRoot()).thenReturn(module1Root);
    when(repository1.getBranch("dev_branch")).thenReturn(Optional.of(new Branch("dev_branch", repositoryRoot)));
    final Optional<Branch> master = Optional.of(new Branch("master", PathFactory.newPath("testFile", "file:///")));
    when(repository1.getDefaultBranch()).thenReturn(master);
    when(repositoryRoot.toURI()).thenReturn("default:///");
    when(module1Root.toURI()).thenReturn("default:///module1");
    when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(ou);
    doReturn("module1").when(repository1).getAlias();
    doReturn(repository1).when(repositoryCopier).copy(eq(ou), anyString(), eq(module1Root));
    final WorkspaceProject project = spy(new WorkspaceProject());
    doReturn(repository1.getAlias()).when(project).getName();
    doReturn(mock(Module.class)).when(project).getMainModule();
    doReturn(mock(OrganizationalUnit.class)).when(project).getOrganizationalUnit();
    doReturn(project).when(projectService).resolveProject(repository1);
    doReturn(project).when(projectService).resolveProject(any(Path.class));
    final ProjectScreenModel model = new ProjectScreenModel();
    model.setPOM(new POM());
    doReturn(model).when(projectScreenService).load(any());
}
Also used : Path(org.uberfire.backend.vfs.Path) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) OrganizationalUnitImpl(org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) POM(org.guvnor.common.services.project.model.POM) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Branch(org.guvnor.structure.repositories.Branch) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) ConfigType(org.guvnor.structure.server.config.ConfigType) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Before(org.junit.Before)

Example 63 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class ExamplesServiceImplRepositoryNamesTest method evenTheSecundaryNameIsTaken.

@Test
public void evenTheSecundaryNameIsTaken() {
    String module = "module1";
    String module_1 = "module1 [1]";
    String module_2 = "module1 [2]";
    doReturn(mock(Repository.class)).when(repositoryService).getRepositoryFromSpace(any(Space.class), eq(module));
    doReturn(mock(Repository.class)).when(repositoryService).getRepositoryFromSpace(any(Space.class), eq(module_1));
    doReturn(module_2).when(projectService).createFreshProjectName(any(), eq(module));
    WorkspaceProject project1 = mock(WorkspaceProject.class);
    doReturn(module).when(project1).getName();
    List<WorkspaceProject> projects1 = new ArrayList<>();
    projects1.add(project1);
    projects1.add(project1);
    doReturn(projects1).when(projectService).getAllWorkspaceProjectsByName(any(), eq(module));
    WorkspaceProject project2 = mock(WorkspaceProject.class);
    doReturn(module_1).when(project2).getName();
    List<WorkspaceProject> projects2 = new ArrayList<>();
    projects2.add(project2);
    doReturn(projects2).when(projectService).getAllWorkspaceProjectsByName(any(), eq(module_1));
    service.setupExamples(exampleOrganizationalUnit, exampleProjects);
    verify(projectScreenService).save(any(), modelCapture.capture(), any());
    final ProjectScreenModel model = modelCapture.getValue();
    assertEquals(module_2, model.getPOM().getName());
}
Also used : Space(org.uberfire.spaces.Space) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 64 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class DefExplorerQueryServiceTest method setup.

@Before
public void setup() {
    createOrganizationalUnits();
    // setup current organizational units
    when(organizationalUnitService.getOrganizationalUnits()).thenReturn(organizationalUnits);
    when(organizationalUnitService.getOrganizationalUnit(o1.getName())).thenReturn(o1);
    when(organizationalUnitService.getOrganizationalUnit(o2.getName())).thenReturn(o2);
    when(organizationalUnitService.getOrganizationalUnit(o3.getName())).thenReturn(o3);
    // emulates the authorizations for current identity.
    // o1 is not authorized
    when(authorizationManager.authorize(o1, identity)).thenReturn(false);
    // o2 is authorized
    when(authorizationManager.authorize(o2, identity)).thenReturn(true);
    // repo_o2_1 is authorized
    when(authorizationManager.authorize(repo_o2_1, identity)).thenReturn(true);
    // repo_o2_2 is authorized
    when(authorizationManager.authorize(repo_o2_2, identity)).thenReturn(true);
    // o3 is authorized
    when(authorizationManager.authorize(o3, identity)).thenReturn(true);
    // repo_o3_1 is authorized
    when(authorizationManager.authorize(repo_o3_1, identity)).thenReturn(true);
    // repo_o3_2 is not authorized
    when(authorizationManager.authorize(repo_o3_2, identity)).thenReturn(false);
    // repo_o3_3 is authorized
    when(authorizationManager.authorize(repo_o3_3, identity)).thenReturn(true);
    // prepare the modules
    when(module1.getModuleName()).thenReturn("module1");
    when(module1.getRootPath()).thenReturn(rootPath1);
    when(module2.getModuleName()).thenReturn("module2");
    when(module2.getRootPath()).thenReturn(rootPath2);
    when(module3.getModuleName()).thenReturn("module3");
    when(module3.getRootPath()).thenReturn(rootPath3);
    doReturn(new WorkspaceProject(o3, repo_o3_1, new Branch("master", mock(Path.class)), module1)).when(projectService).resolveProject(repo_o3_1);
    doReturn(new WorkspaceProject(o3, repo_o3_2, new Branch("master", mock(Path.class)), module2)).when(projectService).resolveProject(repo_o3_2);
    doReturn(new WorkspaceProject(o3, repo_o3_3, new Branch("master", mock(Path.class)), module3)).when(projectService).resolveProject(repo_o3_3);
    // module1 has data sources ds1 and ds2, and drivers driver1, driver2 and driver3
    ArrayList<DataSourceDefInfo> module2DSs = new ArrayList<>();
    module2DSs.add(ds1);
    module2DSs.add(ds2);
    ArrayList<DriverDefInfo> module2Drivers = new ArrayList<>();
    module2Drivers.add(driver1);
    module2Drivers.add(driver2);
    module2Drivers.add(driver3);
    when(dataSourceDefQueryService.findModuleDataSources(module1)).thenReturn(module2DSs);
    when(dataSourceDefQueryService.findModuleDrivers(module1)).thenReturn(module2Drivers);
}
Also used : Path(org.uberfire.backend.vfs.Path) DriverDefInfo(org.kie.workbench.common.screens.datasource.management.model.DriverDefInfo) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Branch(org.guvnor.structure.repositories.Branch) ArrayList(java.util.ArrayList) DataSourceDefInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDefInfo) Before(org.junit.Before)

Example 65 with WorkspaceProject

use of org.guvnor.common.services.project.model.WorkspaceProject in project kie-wb-common by kiegroup.

the class SocialEventModuleConstraintTest method hasNoRestrictionsTest.

@Test
public void hasNoRestrictionsTest() throws Exception {
    final WorkspaceProject project = mock(WorkspaceProject.class);
    Repository repository = mock(Repository.class);
    doReturn(repository).when(project).getRepository();
    when(authorizationManager.authorize(repository, user)).thenReturn(true);
    eventProject = project;
    final SocialActivitiesEvent vfsEvent = new SocialActivitiesEvent(socialUser, "type", new Date());
    final SocialActivitiesEvent moduleEvent = new SocialActivitiesEvent(socialUser, OrganizationalUnitEventType.NEW_ORGANIZATIONAL_UNIT, new Date()).withLink("otherName", "otherName", SocialActivitiesEvent.LINK_TYPE.CUSTOM);
    socialEventModuleConstraint.init();
    assertFalse(socialEventModuleConstraint.hasRestrictions(vfsEvent));
    assertFalse(socialEventModuleConstraint.hasRestrictions(moduleEvent));
}
Also used : Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) SocialActivitiesEvent(org.ext.uberfire.social.activities.model.SocialActivitiesEvent) Date(java.util.Date) Test(org.junit.Test)

Aggregations

WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)67 Test (org.junit.Test)42 Branch (org.guvnor.structure.repositories.Branch)29 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)28 Repository (org.guvnor.structure.repositories.Repository)26 Path (org.uberfire.backend.vfs.Path)26 Module (org.guvnor.common.services.project.model.Module)21 ArrayList (java.util.ArrayList)12 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)12 WorkspaceProjectContextChangeEvent (org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent)10 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)9 Before (org.junit.Before)8 KieModule (org.kie.workbench.common.services.shared.project.KieModule)7 POM (org.guvnor.common.services.project.model.POM)6 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)5 ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)5 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)5 Date (java.util.Date)4 HashSet (java.util.HashSet)4 ExampleProject (org.kie.workbench.common.screens.examples.model.ExampleProject)4