Search in sources :

Example 1 with Ack

use of net.nemerosa.ontrack.model.Ack in project ontrack by nemerosa.

the class BuildFilterJdbcRepositoryIT method save_account_build_filter.

@Test
public void save_account_build_filter() {
    Ack ack = repository.save(OptionalInt.of(account.id()), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end());
    assertTrue(ack.isSuccess());
    // Gets the list for this branch AND account
    Collection<TBuildFilter> list = repository.findForBranch(OptionalInt.of(account.id()), branch.id());
    assertEquals(Arrays.asList(new TBuildFilter(OptionalInt.of(account.id()), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end())), list);
    // Gets the list for this branch
    list = repository.findForBranch(branch.id());
    assertEquals(Arrays.asList(new TBuildFilter(OptionalInt.of(account.id()), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end())), list);
    // Gets this filter
    Optional<TBuildFilter> filter = repository.findByBranchAndName(account.id(), branch.id(), "Test");
    assertTrue(filter.isPresent());
    assertEquals(new TBuildFilter(OptionalInt.of(account.id()), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end()), filter.get());
}
Also used : Ack(net.nemerosa.ontrack.model.Ack) Test(org.junit.Test)

Example 2 with Ack

use of net.nemerosa.ontrack.model.Ack in project ontrack by nemerosa.

the class BuildFilterServiceIT method delete_shared_filter.

@Test
public void delete_shared_filter() throws Exception {
    // Branch
    Branch branch = doCreateBranch();
    // Account for the tests
    Account account = doCreateAccount();
    // Creates a shared filter for this account
    Ack ack = asAccount(account).with(branch, BranchFilterMgt.class).call(() -> buildFilterService.saveFilter(branch.getId(), // Shared
    true, "MyFilter", NamedBuildFilterProvider.class.getName(), objectMapper.valueToTree(NamedBuildFilterData.of("1"))));
    assertTrue("Account filter saved", ack.isSuccess());
    // The filter is present for this account
    Collection<BuildFilterResource<?>> filters = asAccount(account).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals(1, filters.size());
    BuildFilterResource<?> filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertTrue(filter.isShared());
    // ... and that it is available also for not logged users
    filters = asUser().withId(10).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals("Account filter available for everybody else", 1, filters.size());
    filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertTrue(filter.isShared());
    // Deletes the filter
    asAccount(account).call(() -> buildFilterService.deleteFilter(branch.getId(), "MyFilter"));
    // The filter is no longer there for the account
    filters = asAccount(account).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals(0, filters.size());
    // ... not for unlogged users
    filters = asUser().withId(10).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals("Account filter not available for everybody else", 0, filters.size());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) Branch(net.nemerosa.ontrack.model.structure.Branch) BuildFilterResource(net.nemerosa.ontrack.model.buildfilter.BuildFilterResource) Ack(net.nemerosa.ontrack.model.Ack) BranchFilterMgt(net.nemerosa.ontrack.model.security.BranchFilterMgt) Test(org.junit.Test)

Example 3 with Ack

use of net.nemerosa.ontrack.model.Ack in project ontrack by nemerosa.

the class BuildFilterServiceIT method saveFilter_shared_after_account_one.

/**
 * Checks that sharing a saved filter overrides the account specific one.
 */
@Test
public void saveFilter_shared_after_account_one() throws Exception {
    // Branch
    Branch branch = doCreateBranch();
    // Account for the tests
    Account account = doCreateAccount();
    Account otherAccount = doCreateAccount();
    // Creates a filter for this account
    Ack ack = asAccount(account).call(() -> buildFilterService.saveFilter(branch.getId(), false, "MyFilter", NamedBuildFilterProvider.class.getName(), objectMapper.valueToTree(NamedBuildFilterData.of("1"))));
    assertTrue("Account filter saved", ack.isSuccess());
    // Makes sure we find this filter back when logged
    Collection<BuildFilterResource<?>> filters = asAccount(account).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals(1, filters.size());
    BuildFilterResource<?> filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertFalse(filter.isShared());
    // ... but it is not available for anybody else
    assertTrue("Account filter not available for everybody else", asAccount(otherAccount).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()).isEmpty()));
    // Now, shares a filter with the same name
    ack = asAccount(account).with(branch.projectId(), ProjectView.class).with(branch.projectId(), BranchFilterMgt.class).call(() -> buildFilterService.saveFilter(branch.getId(), // Sharing
    true, "MyFilter", NamedBuildFilterProvider.class.getName(), objectMapper.valueToTree(NamedBuildFilterData.of("1"))));
    assertTrue("Account filter shared", ack.isSuccess());
    // Makes sure we find this filter back when logged
    filters = asAccount(account).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals(1, filters.size());
    filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertTrue(filter.isShared());
    // ... and that it is available also for not logged users
    filters = asUser().withId(10).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals("Account filter available for everybody else", 1, filters.size());
    filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertTrue(filter.isShared());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) Branch(net.nemerosa.ontrack.model.structure.Branch) BuildFilterResource(net.nemerosa.ontrack.model.buildfilter.BuildFilterResource) Ack(net.nemerosa.ontrack.model.Ack) ProjectView(net.nemerosa.ontrack.model.security.ProjectView) Test(org.junit.Test)

Example 4 with Ack

use of net.nemerosa.ontrack.model.Ack in project ontrack by nemerosa.

the class BuildFilterJdbcRepositoryIT method save_shared_build_filter.

@Test
public void save_shared_build_filter() {
    Ack ack = repository.save(OptionalInt.empty(), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end());
    assertTrue(ack.isSuccess());
    // Gets the list for this branch AND account
    Collection<TBuildFilter> list = repository.findForBranch(OptionalInt.of(account.id()), branch.id());
    assertEquals(Arrays.asList(new TBuildFilter(OptionalInt.empty(), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end())), list);
    // Gets the list for this branch
    list = repository.findForBranch(branch.id());
    assertEquals(Arrays.asList(new TBuildFilter(OptionalInt.empty(), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end())), list);
    // Gets this filter
    Optional<TBuildFilter> filter = repository.findByBranchAndName(account.id(), branch.id(), "Test");
    assertTrue(filter.isPresent());
    assertEquals(new TBuildFilter(OptionalInt.empty(), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end()), filter.get());
}
Also used : Ack(net.nemerosa.ontrack.model.Ack) Test(org.junit.Test)

Example 5 with Ack

use of net.nemerosa.ontrack.model.Ack in project ontrack by nemerosa.

the class BuildFilterJdbcRepositoryIT method save_shared_build_filter_same_name.

@Test
public void save_shared_build_filter_same_name() {
    Ack ack = repository.save(OptionalInt.empty(), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end());
    assertTrue(ack.isSuccess());
    ack = repository.save(OptionalInt.of(account.id()), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end());
    assertTrue(ack.isSuccess());
    // Gets the list for this branch AND account
    Collection<TBuildFilter> list = repository.findForBranch(OptionalInt.of(account.id()), branch.id());
    assertEquals(Arrays.asList(new TBuildFilter(OptionalInt.empty(), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end()), new TBuildFilter(OptionalInt.of(account.id()), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end())), list);
    // Gets the list for this branch
    list = repository.findForBranch(branch.id());
    assertEquals(Arrays.asList(new TBuildFilter(OptionalInt.empty(), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end()), new TBuildFilter(OptionalInt.of(account.id()), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end())), list);
    // Gets this filter
    Optional<TBuildFilter> filter = repository.findByBranchAndName(account.id(), branch.id(), "Test");
    assertTrue(filter.isPresent());
    assertEquals(new TBuildFilter(OptionalInt.empty(), branch.id(), "Test", "TestFilterType", JsonUtils.object().with("test", 1).end()), filter.get());
}
Also used : Ack(net.nemerosa.ontrack.model.Ack) Test(org.junit.Test)

Aggregations

Ack (net.nemerosa.ontrack.model.Ack)10 Test (org.junit.Test)8 Account (net.nemerosa.ontrack.model.security.Account)5 Branch (net.nemerosa.ontrack.model.structure.Branch)5 BuildFilterResource (net.nemerosa.ontrack.model.buildfilter.BuildFilterResource)4 ProjectView (net.nemerosa.ontrack.model.security.ProjectView)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ObjectMapperFactory (net.nemerosa.ontrack.json.ObjectMapperFactory)1 DescribedForm (net.nemerosa.ontrack.model.form.DescribedForm)1 BranchEdit (net.nemerosa.ontrack.model.security.BranchEdit)1 BranchFilterMgt (net.nemerosa.ontrack.model.security.BranchFilterMgt)1 GlobalSettings (net.nemerosa.ontrack.model.security.GlobalSettings)1 SecurityService (net.nemerosa.ontrack.model.security.SecurityService)1 SettingsManager (net.nemerosa.ontrack.model.settings.SettingsManager)1 SettingsManagerNotFoundException (net.nemerosa.ontrack.model.settings.SettingsManagerNotFoundException)1