Search in sources :

Example 1 with BranchCopyRequest

use of net.nemerosa.ontrack.model.structure.BranchCopyRequest in project ontrack by nemerosa.

the class BuildFilterServiceIT method copyToBranch.

@Test
public void copyToBranch() throws Exception {
    // Source branch
    Branch sourceBranch = doCreateBranch();
    // Target branch
    Branch targetBranch = doCreateBranch();
    // Account for the tests
    Account account = doCreateAccount();
    // Creates a filter for this account
    Ack filterCreated = asAccount(account).call(() -> buildFilterService.saveFilter(sourceBranch.getId(), false, "MyFilter", StandardBuildFilterProvider.class.getName(), JsonUtils.object().with("count", 1).end()));
    assertTrue(filterCreated.isSuccess());
    // Checks the filter is created
    Collection<BuildFilterResource<?>> filters = asAccount(account).with(sourceBranch.projectId(), ProjectView.class).call(() -> buildFilterService.getBuildFilters(sourceBranch.getId()));
    assertEquals(1, filters.size());
    BuildFilterResource<?> filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertEquals(StandardBuildFilterProvider.class.getName(), filter.getType());
    // Copy of the branch
    asUser().with(sourceBranch.projectId(), ProjectView.class).with(targetBranch.projectId(), BranchEdit.class).call(() -> copyService.copy(targetBranch, new BranchCopyRequest(sourceBranch.getId(), Collections.emptyList())));
    // Gets the filter on the new branch
    filters = asAccount(account).withView(targetBranch).call(() -> buildFilterService.getBuildFilters(targetBranch.getId()));
    assertEquals(1, filters.size());
    filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertEquals(StandardBuildFilterProvider.class.getName(), filter.getType());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) Branch(net.nemerosa.ontrack.model.structure.Branch) BuildFilterResource(net.nemerosa.ontrack.model.buildfilter.BuildFilterResource) BranchCopyRequest(net.nemerosa.ontrack.model.structure.BranchCopyRequest) Ack(net.nemerosa.ontrack.model.Ack) ProjectView(net.nemerosa.ontrack.model.security.ProjectView) BranchEdit(net.nemerosa.ontrack.model.security.BranchEdit) Test(org.junit.Test)

Aggregations

Ack (net.nemerosa.ontrack.model.Ack)1 BuildFilterResource (net.nemerosa.ontrack.model.buildfilter.BuildFilterResource)1 Account (net.nemerosa.ontrack.model.security.Account)1 BranchEdit (net.nemerosa.ontrack.model.security.BranchEdit)1 ProjectView (net.nemerosa.ontrack.model.security.ProjectView)1 Branch (net.nemerosa.ontrack.model.structure.Branch)1 BranchCopyRequest (net.nemerosa.ontrack.model.structure.BranchCopyRequest)1 Test (org.junit.Test)1