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