Search in sources :

Example 1 with SpaceConfigStorageRegistry

use of org.guvnor.structure.organizationalunit.config.SpaceConfigStorageRegistry in project kie-wb-common by kiegroup.

the class ProjectImportServiceImplRepositoryNamesTest method setup.

@Before
public void setup() {
    service = spy(new ProjectImportServiceImpl(ioService, metadataService, repositoryFactory, moduleService, validators, pathUtil, projectService, projectScreenService, newProjectEvent, repoService, spaceConfigStorageRegistry));
    when(spaceConfigStorageRegistry.get(anyString())).thenReturn(spaceConfigStorage);
    when(spaceConfigStorageRegistry.getBatch(anyString())).thenReturn(new SpaceConfigStorageRegistryImpl.SpaceStorageBatchImpl(spaceConfigStorage));
    when(spaceConfigStorageRegistry.exist(anyString())).thenReturn(true);
    when(validators.getValidators()).thenReturn(new ArrayList<>());
    when(ouService.getOrganizationalUnits()).thenReturn(new HashSet<OrganizationalUnit>() {

        {
            add(new OrganizationalUnitImpl("ou1Name", "ou1GroupId"));
        }
    });
    when(moduleService.resolveModule(any(Path.class))).thenAnswer((Answer<KieModule>) invocationOnMock -> {
        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");
    exProject1 = mock(ImportProject.class);
    importProjects = Collections.singletonList(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(organizationalUnit.getName()).thenReturn("ou");
    when(organizationalUnit.getSpace()).thenReturn(space);
    when(space.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> main = Optional.of(new Branch("main", PathFactory.newPath("testFile", "file:///")));
    when(repository1.getDefaultBranch()).thenReturn(main);
    when(repositoryRoot.toURI()).thenReturn("default:///");
    when(module1Root.toURI()).thenReturn("default:///module1");
    when(ouService.getOrganizationalUnit(eq("ou"))).thenReturn(ou);
    doReturn("module1").when(repository1).getAlias();
    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) RepositoryFactory(org.guvnor.structure.server.repositories.RepositoryFactory) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) OrganizationalUnitService(org.guvnor.structure.organizationalunit.OrganizationalUnitService) POM(org.guvnor.common.services.project.model.POM) PathFactory(org.uberfire.backend.vfs.PathFactory) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) SessionInfo(org.uberfire.rpc.SessionInfo) Module(org.guvnor.common.services.project.model.Module) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Assert.fail(org.junit.Assert.fail) SpaceConfigStorage(org.guvnor.structure.organizationalunit.config.SpaceConfigStorage) ProjectScreenService(org.kie.workbench.common.screens.projecteditor.service.ProjectScreenService) Mockito.doReturn(org.mockito.Mockito.doReturn) NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) MetadataService(org.guvnor.common.services.shared.metadata.MetadataService) SpaceConfigStorageRegistry(org.guvnor.structure.organizationalunit.config.SpaceConfigStorageRegistry) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) KieModule(org.kie.workbench.common.services.shared.project.KieModule) List(java.util.List) ImportProjectValidators(org.kie.workbench.common.screens.examples.validation.ImportProjectValidators) PathUtil(org.guvnor.common.services.project.backend.server.utils.PathUtil) Optional(java.util.Optional) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SpaceConfigStorageRegistryImpl(org.guvnor.structure.backend.organizationalunit.config.SpaceConfigStorageRegistryImpl) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mockito.doCallRealMethod(org.mockito.Mockito.doCallRealMethod) Space(org.uberfire.spaces.Space) Mock(org.mockito.Mock) OrganizationalUnitImpl(org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) Captor(org.mockito.Captor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) ProjectAlreadyExistException(org.kie.workbench.common.screens.examples.exception.ProjectAlreadyExistException) Path(org.uberfire.backend.vfs.Path) Before(org.junit.Before) Event(javax.enterprise.event.Event) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) Answers(org.mockito.Answers) Assert.assertNotNull(org.junit.Assert.assertNotNull) RepositoryService(org.guvnor.structure.repositories.RepositoryService) Test(org.junit.Test) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) Mockito.when(org.mockito.Mockito.when) WorkspaceProjectService(org.guvnor.common.services.project.service.WorkspaceProjectService) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) User(org.jboss.errai.security.shared.api.identity.User) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) IOService(org.uberfire.io.IOService) Collections(java.util.Collections) Branch(org.guvnor.structure.repositories.Branch) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SpaceConfigStorageRegistryImpl(org.guvnor.structure.backend.organizationalunit.config.SpaceConfigStorageRegistryImpl) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) OrganizationalUnitImpl(org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl) POM(org.guvnor.common.services.project.model.POM) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) Branch(org.guvnor.structure.repositories.Branch) 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) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Before(org.junit.Before)

Example 2 with SpaceConfigStorageRegistry

use of org.guvnor.structure.organizationalunit.config.SpaceConfigStorageRegistry in project kie-wb-common by kiegroup.

the class ExamplesServiceImplTest method setup.

@Before
public void setup() throws Exception {
    when(spaceConfigStorageRegistry.get(Mockito.<String>any())).thenReturn(spaceConfigStorage);
    when(spaceConfigStorageRegistry.getBatch(Mockito.<String>any())).thenReturn(new SpaceConfigStorageRegistryImpl.SpaceStorageBatchImpl(spaceConfigStorage));
    when(spaceConfigStorageRegistry.exist(Mockito.<String>any())).thenReturn(true);
    when(ou.getSpace()).thenReturn(space);
    when(space.getName()).thenReturn("ou");
    service = spy(new ExamplesServiceImpl(ioService, repositoryFactory, moduleService, ouService, projectService, metadataService, newProjectEvent, projectScreenService, validators, spaceConfigStorageRegistry, systemFS, pathUtil, repositoryService));
    FileUtils.deleteDirectory(new File(".kie-wb-playground"));
    when(this.validators.getValidators()).thenReturn(new ArrayList<>());
    doAnswer(invocationOnMock -> {
        String spaceName = (String) invocationOnMock.getArguments()[0];
        String defaultGroupId = (String) invocationOnMock.getArguments()[1];
        OrganizationalUnitImpl o = new OrganizationalUnitImpl(spaceName, defaultGroupId);
        organizationalUnits.put(spaceName, o);
        return o;
    }).when(ouService).createOrganizationalUnit(Mockito.<String>any(), Mockito.<String>any());
    doAnswer(invocationOnMock -> organizationalUnits.get(invocationOnMock.getArguments()[0])).when(ouService).getOrganizationalUnit(Mockito.<String>any());
    when(ouService.getOrganizationalUnits()).thenReturn(new HashSet<OrganizationalUnit>() {

        {
            add(new OrganizationalUnitImpl("ou1Name", "ou1GroupId"));
            add(new OrganizationalUnitImpl("ou2Name", "ou2GroupId"));
        }
    });
    when(moduleService.resolveModule(Mockito.<Path>any())).thenAnswer((Answer<KieModule>) invocationOnMock -> {
        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");
    doAnswer(invocationOnMock -> organizationalUnits.containsKey(invocationOnMock.getArguments()[0])).when(service).existSpace(any());
}
Also used : Arrays(java.util.Arrays) RepositoryInfo(org.guvnor.structure.organizationalunit.config.RepositoryInfo) RepositoryFactory(org.guvnor.structure.server.repositories.RepositoryFactory) URL(java.net.URL) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) OrganizationalUnitService(org.guvnor.structure.organizationalunit.OrganizationalUnitService) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) POM(org.guvnor.common.services.project.model.POM) PathFactory(org.uberfire.backend.vfs.PathFactory) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Map(java.util.Map) After(org.junit.After) Spy(org.mockito.Spy) Mockito.doAnswer(org.mockito.Mockito.doAnswer) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) SessionInfo(org.uberfire.rpc.SessionInfo) Module(org.guvnor.common.services.project.model.Module) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) SpaceConfigStorage(org.guvnor.structure.organizationalunit.config.SpaceConfigStorage) ProjectScreenService(org.kie.workbench.common.screens.projecteditor.service.ProjectScreenService) Mockito.doReturn(org.mockito.Mockito.doReturn) NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) MetadataService(org.guvnor.common.services.shared.metadata.MetadataService) SpaceConfigStorageRegistry(org.guvnor.structure.organizationalunit.config.SpaceConfigStorageRegistry) Set(java.util.Set) KieModule(org.kie.workbench.common.services.shared.project.KieModule) List(java.util.List) ImportProjectValidators(org.kie.workbench.common.screens.examples.validation.ImportProjectValidators) Assert.assertFalse(org.junit.Assert.assertFalse) PathUtil(org.guvnor.common.services.project.backend.server.utils.PathUtil) Optional(java.util.Optional) EventSourceMock(org.uberfire.mocks.EventSourceMock) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SpaceConfigStorageRegistryImpl(org.guvnor.structure.backend.organizationalunit.config.SpaceConfigStorageRegistryImpl) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Space(org.uberfire.spaces.Space) Mock(org.mockito.Mock) OrganizationalUnitImpl(org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Captor(org.mockito.Captor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) ExamplesMetaData(org.kie.workbench.common.screens.examples.model.ExamplesMetaData) ArgumentCaptor(org.mockito.ArgumentCaptor) Path(org.uberfire.backend.vfs.Path) Before(org.junit.Before) Event(javax.enterprise.event.Event) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) Assert.assertNotNull(org.junit.Assert.assertNotNull) RepositoryService(org.guvnor.structure.repositories.RepositoryService) Assert.assertTrue(org.junit.Assert.assertTrue) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) Mockito.when(org.mockito.Mockito.when) WorkspaceProjectService(org.guvnor.common.services.project.service.WorkspaceProjectService) File(java.io.File) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) Mockito.verify(org.mockito.Mockito.verify) ImportUtils.makeGitRepository(org.kie.workbench.common.screens.examples.backend.server.ImportUtils.makeGitRepository) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) Assert.assertNull(org.junit.Assert.assertNull) Paths(java.nio.file.Paths) User(org.jboss.errai.security.shared.api.identity.User) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) IOService(org.uberfire.io.IOService) Collections(java.util.Collections) FileSystem(org.uberfire.java.nio.file.FileSystem) Assert.assertEquals(org.junit.Assert.assertEquals) Branch(org.guvnor.structure.repositories.Branch) Path(org.uberfire.backend.vfs.Path) SpaceConfigStorageRegistryImpl(org.guvnor.structure.backend.organizationalunit.config.SpaceConfigStorageRegistryImpl) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) File(java.io.File) OrganizationalUnitImpl(org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Before(org.junit.Before)

Aggregations

ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Optional (java.util.Optional)2 Event (javax.enterprise.event.Event)2 PathUtil (org.guvnor.common.services.project.backend.server.utils.PathUtil)2 NewProjectEvent (org.guvnor.common.services.project.events.NewProjectEvent)2 Module (org.guvnor.common.services.project.model.Module)2 POM (org.guvnor.common.services.project.model.POM)2 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)2 WorkspaceProjectService (org.guvnor.common.services.project.service.WorkspaceProjectService)2 MetadataService (org.guvnor.common.services.shared.metadata.MetadataService)2 SpaceConfigStorageRegistryImpl (org.guvnor.structure.backend.organizationalunit.config.SpaceConfigStorageRegistryImpl)2 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)2 OrganizationalUnitService (org.guvnor.structure.organizationalunit.OrganizationalUnitService)2 SpaceConfigStorage (org.guvnor.structure.organizationalunit.config.SpaceConfigStorage)2 SpaceConfigStorageRegistry (org.guvnor.structure.organizationalunit.config.SpaceConfigStorageRegistry)2 OrganizationalUnitImpl (org.guvnor.structure.organizationalunit.impl.OrganizationalUnitImpl)2 Branch (org.guvnor.structure.repositories.Branch)2