Search in sources :

Example 1 with UserAssignmentFilter

use of ch.aaap.harvestclient.api.filter.UserAssignmentFilter in project harvest-client by 3AP-AG.

the class UserAssignmentsApiListTest method listByUpdatedSince.

@Test
void listByUpdatedSince() {
    Instant creationTime = Instant.now().minusSeconds(1);
    UserAssignment creationInfo = ImmutableUserAssignment.builder().user(userReference).build();
    userAssignment = userAssignmentApi.create(projectReference, creationInfo);
    log.debug("time now: {}", Instant.now());
    log.debug("Creation time for userAssignment: {}", userAssignment.getCreatedAt());
    log.debug("Update time for userAssignment: {}", userAssignment.getUpdatedAt());
    UserAssignmentFilter filter = new UserAssignmentFilter();
    filter.setUpdatedSince(creationTime);
    List<UserAssignment> userAssignments = userAssignmentApi.list(projectReference, filter);
    assertThat(userAssignments).usingFieldByFieldElementComparator().containsExactly(userAssignment);
}
Also used : ImmutableUserAssignment(ch.aaap.harvestclient.domain.ImmutableUserAssignment) UserAssignment(ch.aaap.harvestclient.domain.UserAssignment) Instant(java.time.Instant) UserAssignmentFilter(ch.aaap.harvestclient.api.filter.UserAssignmentFilter) HarvestTest(ch.aaap.harvestclient.HarvestTest) Test(org.junit.jupiter.api.Test)

Example 2 with UserAssignmentFilter

use of ch.aaap.harvestclient.api.filter.UserAssignmentFilter in project harvest-client by 3AP-AG.

the class UserAssignmentsApiListTest method list.

@Test
void list() {
    UserAssignmentFilter filter = new UserAssignmentFilter();
    List<UserAssignment> userAssignments = userAssignmentApi.list(projectReference, filter);
    assertThat(userAssignments).isNotEmpty();
}
Also used : ImmutableUserAssignment(ch.aaap.harvestclient.domain.ImmutableUserAssignment) UserAssignment(ch.aaap.harvestclient.domain.UserAssignment) UserAssignmentFilter(ch.aaap.harvestclient.api.filter.UserAssignmentFilter) HarvestTest(ch.aaap.harvestclient.HarvestTest) Test(org.junit.jupiter.api.Test)

Example 3 with UserAssignmentFilter

use of ch.aaap.harvestclient.api.filter.UserAssignmentFilter in project harvest-client by 3AP-AG.

the class ProjectAssignmentsApiImplTest method listSelf.

@Test
void listSelf(TestInfo testInfo) {
    Project project = null;
    try {
        final Project tempProject = harvest.projects().create(ImmutableProject.builder().name("Project for " + testInfo.getDisplayName()).billBy(Project.BillingMethod.PROJECT).budgetBy(Project.BudgetMethod.HOURS_PER_PROJECT).billable(false).client(ExistingData.getInstance().getClientReference()).build());
        project = tempProject;
        User self = harvest.users().getSelf();
        // remove self from tempProject
        harvest.userAssignments().list(project, new UserAssignmentFilter()).stream().filter(ua -> ua.getUser().getId().equals(self.getId())).forEach(ua -> harvest.userAssignments().delete(tempProject, ua));
        List<ProjectAssignment> projectAssignments = projectAssignmentsApi.listSelf();
        assertThat(projectAssignments).isNotEmpty();
        assertThat(projectAssignments).extracting("project").extracting("id").doesNotContain(tempProject.getId());
    } finally {
        if (project != null) {
            harvest.projects().delete(project);
        }
    }
}
Also used : HarvestTest(ch.aaap.harvestclient.HarvestTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Instant(java.time.Instant) TestInfo(org.junit.jupiter.api.TestInfo) TestSetupUtil(util.TestSetupUtil) Test(org.junit.jupiter.api.Test) Harvest(ch.aaap.harvestclient.core.Harvest) List(java.util.List) Reference(ch.aaap.harvestclient.domain.reference.Reference) ProjectAssignmentsApi(ch.aaap.harvestclient.api.ProjectAssignmentsApi) Project(ch.aaap.harvestclient.domain.Project) ImmutableProject(ch.aaap.harvestclient.domain.ImmutableProject) User(ch.aaap.harvestclient.domain.User) UserAssignmentFilter(ch.aaap.harvestclient.api.filter.UserAssignmentFilter) ProjectAssignment(ch.aaap.harvestclient.domain.ProjectAssignment) ExistingData(util.ExistingData) Project(ch.aaap.harvestclient.domain.Project) ImmutableProject(ch.aaap.harvestclient.domain.ImmutableProject) User(ch.aaap.harvestclient.domain.User) ProjectAssignment(ch.aaap.harvestclient.domain.ProjectAssignment) UserAssignmentFilter(ch.aaap.harvestclient.api.filter.UserAssignmentFilter) HarvestTest(ch.aaap.harvestclient.HarvestTest) Test(org.junit.jupiter.api.Test)

Example 4 with UserAssignmentFilter

use of ch.aaap.harvestclient.api.filter.UserAssignmentFilter in project harvest-client by 3AP-AG.

the class UserAssignmentsApiListTest method listByActive.

@Test
void listByActive() {
    UserAssignment creationInfo = ImmutableUserAssignment.builder().user(userReference).active(true).build();
    userAssignment = userAssignmentApi.create(projectReference, creationInfo);
    UserAssignmentFilter filter = new UserAssignmentFilter();
    filter.setActive(true);
    List<UserAssignment> userAssignments = userAssignmentApi.list(projectReference, filter);
    assertThat(userAssignments).usingFieldByFieldElementComparator().contains(userAssignment);
}
Also used : ImmutableUserAssignment(ch.aaap.harvestclient.domain.ImmutableUserAssignment) UserAssignment(ch.aaap.harvestclient.domain.UserAssignment) UserAssignmentFilter(ch.aaap.harvestclient.api.filter.UserAssignmentFilter) HarvestTest(ch.aaap.harvestclient.HarvestTest) Test(org.junit.jupiter.api.Test)

Example 5 with UserAssignmentFilter

use of ch.aaap.harvestclient.api.filter.UserAssignmentFilter in project harvest-client by 3AP-AG.

the class UserAssignmentsApiListTest method listPaginated.

@Test
void listPaginated() {
    // create a second one to check the pagination
    UserAssignment creationInfo = ImmutableUserAssignment.builder().user(userReference).active(true).build();
    userAssignment = userAssignmentApi.create(projectReference, creationInfo);
    Pagination<UserAssignment> pagination = userAssignmentApi.list(projectReference, new UserAssignmentFilter(), 1, 1);
    List<UserAssignment> result = pagination.getList();
    assertThat(result).hasSize(1);
    assertThat(pagination.getTotalPages()).isGreaterThanOrEqualTo(2);
    assertThat(pagination.getNextPage()).isEqualTo(2);
    assertThat(pagination.getPreviousPage()).isNull();
    assertThat(pagination.getPerPage()).isEqualTo(1);
    assertThat(pagination.getTotalPages()).isGreaterThanOrEqualTo(2);
}
Also used : ImmutableUserAssignment(ch.aaap.harvestclient.domain.ImmutableUserAssignment) UserAssignment(ch.aaap.harvestclient.domain.UserAssignment) UserAssignmentFilter(ch.aaap.harvestclient.api.filter.UserAssignmentFilter) HarvestTest(ch.aaap.harvestclient.HarvestTest) Test(org.junit.jupiter.api.Test)

Aggregations

HarvestTest (ch.aaap.harvestclient.HarvestTest)5 UserAssignmentFilter (ch.aaap.harvestclient.api.filter.UserAssignmentFilter)5 Test (org.junit.jupiter.api.Test)5 ImmutableUserAssignment (ch.aaap.harvestclient.domain.ImmutableUserAssignment)4 UserAssignment (ch.aaap.harvestclient.domain.UserAssignment)4 Instant (java.time.Instant)2 ProjectAssignmentsApi (ch.aaap.harvestclient.api.ProjectAssignmentsApi)1 Harvest (ch.aaap.harvestclient.core.Harvest)1 ImmutableProject (ch.aaap.harvestclient.domain.ImmutableProject)1 Project (ch.aaap.harvestclient.domain.Project)1 ProjectAssignment (ch.aaap.harvestclient.domain.ProjectAssignment)1 User (ch.aaap.harvestclient.domain.User)1 Reference (ch.aaap.harvestclient.domain.reference.Reference)1 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 TestInfo (org.junit.jupiter.api.TestInfo)1 ExistingData (util.ExistingData)1 TestSetupUtil (util.TestSetupUtil)1