Search in sources :

Example 1 with ProjectService

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

the class ProjectServiceImplTest method getProjectByProjectNameSecurity.

@Test
public void getProjectByProjectNameSecurity() {
    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().getProject("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 2 with ProjectService

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

the class ProjectServiceImplTest method createProjectFromXMLSecurity.

@Test
public void createProjectFromXMLSecurity() throws IOException {
    // mocks
    TopLevelItem toProject = Mockito.mock(TopLevelItem.class);
    ProjectService inst = spy(getInst());
    // make method succeed
    doReturn(false).when(inst).projectExists("toProject");
    when(hudson.createProjectFromXML("toProject", input)).thenReturn(toProject);
    assertThat(inst.createProjectFromXML("toProject", input), equalTo(toProject));
    Mockito.verify(securityService).checkPermission(Item.CREATE);
}
Also used : TopLevelItem(hudson.model.TopLevelItem) ProjectService(org.hudsonci.service.ProjectService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with ProjectService

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

the class ProjectServiceImplTest method copyProjectToProjectAlreadyExists.

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

Example 4 with ProjectService

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

the class ProjectServiceImplTest method copyProjectIOException.

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

Example 5 with ProjectService

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

the class ProjectServiceImplTest method projectExistsTrue.

@Test
public void projectExistsTrue() {
    ProjectService inst = spy(getInst());
    @SuppressWarnings("unchecked") Collection<String> names = Mockito.mock(Collection.class);
    when(names.contains("projectName")).thenReturn(true);
    when(inst.getProjectNames()).thenReturn(names);
    assertThat(inst.projectExists("projectName"), is(true));
}
Also used : ProjectService(org.hudsonci.service.ProjectService) 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