Search in sources :

Example 1 with ProjectService

use of com.cloud.projects.ProjectService in project cloudstack by apache.

the class ActivateProjectCmdTest method testGetEntityOwnerIdForProject.

@Test
public void testGetEntityOwnerIdForProject() {
    Project project = Mockito.mock(Project.class);
    Mockito.when(project.getId()).thenReturn(2L);
    ProjectService projectService = Mockito.mock(ProjectService.class);
    Account account = Mockito.mock(Account.class);
    Mockito.when(account.getId()).thenReturn(2L);
    Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(project);
    Mockito.when(projectService.getProjectOwner(Matchers.anyLong())).thenReturn(account);
    activateProjectCmd._projectService = projectService;
    Assert.assertEquals(2L, activateProjectCmd.getEntityOwnerId());
}
Also used : Project(com.cloud.projects.Project) Account(com.cloud.user.Account) ProjectService(com.cloud.projects.ProjectService) Test(org.junit.Test)

Example 2 with ProjectService

use of com.cloud.projects.ProjectService in project cloudstack by apache.

the class ActivateProjectCmdTest method testGetEntityOwnerIdForNullProject.

@Test
public void testGetEntityOwnerIdForNullProject() {
    ProjectService projectService = Mockito.mock(ProjectService.class);
    Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(null);
    activateProjectCmd._projectService = projectService;
    try {
        activateProjectCmd.getEntityOwnerId();
    } catch (InvalidParameterValueException exception) {
        Assert.assertEquals("Unable to find project by id 2", exception.getLocalizedMessage());
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ProjectService(com.cloud.projects.ProjectService) Test(org.junit.Test)

Example 3 with ProjectService

use of com.cloud.projects.ProjectService in project cloudstack by apache.

the class AddAccountToProjectCmdTest method testGetEntityOwnerIdForProject.

/****
     * Condition not handled in the code
     *
     *****/
/*
     * @Test public void testGetEntityOwnerIdForNullProject() {
     *
     * ProjectService projectService = Mockito.mock(ProjectService.class);
     * Mockito
     * .when(projectService.getProject(Mockito.anyLong())).thenReturn(null);
     * addAccountToProjectCmd._projectService = projectService;
     *
     * try { addAccountToProjectCmd.getEntityOwnerId(); }
     * catch(InvalidParameterValueException exception) {
     * Assert.assertEquals("Unable to find project by id 2",
     * exception.getLocalizedMessage()); }
     *
     * }
     */
@Test
public void testGetEntityOwnerIdForProject() {
    Project project = Mockito.mock(Project.class);
    Mockito.when(project.getId()).thenReturn(2L);
    ProjectService projectService = Mockito.mock(ProjectService.class);
    Account account = Mockito.mock(Account.class);
    Mockito.when(account.getId()).thenReturn(2L);
    Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(project);
    Mockito.when(projectService.getProjectOwner(Matchers.anyLong())).thenReturn(account);
    addAccountToProjectCmd._projectService = projectService;
    Assert.assertEquals(2L, addAccountToProjectCmd.getEntityOwnerId());
}
Also used : Project(com.cloud.projects.Project) Account(com.cloud.user.Account) ProjectService(com.cloud.projects.ProjectService) Test(org.junit.Test)

Aggregations

ProjectService (com.cloud.projects.ProjectService)3 Test (org.junit.Test)3 Project (com.cloud.projects.Project)2 Account (com.cloud.user.Account)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1