Search in sources :

Example 6 with ProjectService

use of org.hudsonci.service.ProjectService in project hudson-2.x by hudson.

the class ProjectServiceImplTest method createProjectFromXMLToProjectAlreadyExists.

@Test(expected = SystemIntegrityViolationException.class)
public void createProjectFromXMLToProjectAlreadyExists() throws IOException {
    ProjectService inst = spy(getInst());
    doReturn(true).when(inst).projectExists("toProject");
    inst.createProjectFromXML("toProject", input);
}
Also used : ProjectService(org.hudsonci.service.ProjectService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with ProjectService

use of org.hudsonci.service.ProjectService in project hudson-2.x by hudson.

the class ProjectServiceImplTest method getProjectByUUIDNotFound.

@Test(expected = ProjectNotFoundException.class)
public void getProjectByUUIDNotFound() {
    ProjectService inst = spy(getInst());
    UUID id = UUID.randomUUID();
    doReturn(null).when(inst).findProject(id);
    inst.getProject(id);
}
Also used : ProjectService(org.hudsonci.service.ProjectService) UUID(java.util.UUID) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with ProjectService

use of org.hudsonci.service.ProjectService in project hudson-2.x by hudson.

the class ProjectServiceImplTest method copyProjectSecurity.

@Test
public void copyProjectSecurity() throws IOException {
    // mocks
    AbstractProject<?, ?> toProject = Mockito.mock(AbstractProject.class);
    ProjectService inst = spy(getInst());
    // make method succeed
    doReturn(false).when(inst).projectExists("toProject");
    when(hudson.copy(project, "toProject")).thenReturn(toProject);
    // test
    inst.copyProject(project, "toProject");
    // verify
    Mockito.verify(securityService).checkPermission(Item.CREATE);
    Mockito.verify(securityService).checkPermission(project, Item.EXTENDED_READ);
}
Also used : ProjectService(org.hudsonci.service.ProjectService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with ProjectService

use of org.hudsonci.service.ProjectService in project hudson-2.x by hudson.

the class ProjectServiceImplTest method findProjectByProjectNameSecurity.

@Test
public void findProjectByProjectNameSecurity() {
    ProjectService inst = spy(getInst());
    doReturn(project).when(hudson).getItemByFullName("projectName", AbstractProject.class);
    @SuppressWarnings("unchecked") Collection<String> names = Mockito.mock(Collection.class);
    when(names.contains("projectName")).thenReturn(true);
    when(inst.getProjectNames()).thenReturn(names);
    AbstractProject<?, ?> result = getInst().findProject("projectName");
    assertThat(result, equalTo(project));
    Mockito.verify(securityService).checkPermission(project, Item.READ);
}
Also used : ProjectService(org.hudsonci.service.ProjectService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with ProjectService

use of org.hudsonci.service.ProjectService in project hudson-2.x by hudson.

the class ProjectServiceImplTest method createProjectFromXMLIOException.

@Test(expected = ServiceRuntimeException.class)
public void createProjectFromXMLIOException() throws IOException {
    // mocks
    ProjectService inst = spy(getInst());
    // make method succeed
    doReturn(false).when(inst).projectExists("toProject");
    when(hudson.createProjectFromXML("toProject", input)).thenThrow(new IOException());
    // test
    inst.createProjectFromXML("toProject", input);
}
Also used : ProjectService(org.hudsonci.service.ProjectService) IOException(java.io.IOException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ProjectService (org.hudsonci.service.ProjectService)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 IOException (java.io.IOException)2 TopLevelItem (hudson.model.TopLevelItem)1 UUID (java.util.UUID)1