Search in sources :

Example 36 with Branch

use of com.enonic.xp.branch.Branch in project xp by enonic.

the class RepositoryServiceImplTest method delete_branch_deletes_from_repo.

@Test
void delete_branch_deletes_from_repo() {
    doCreateRepo("fisk");
    Branch branch = Branch.from("myBranch");
    NodeHelper.runAsAdmin(() -> repositoryService.createBranch(CreateBranchParams.from(branch)));
    NodeHelper.runAsAdmin(() -> repositoryService.deleteBranch(DeleteBranchParams.from(branch)));
    final Repository persistedRepo = getPersistedRepoWithoutCache("fisk");
    assertFalse(persistedRepo.getBranches().contains(branch));
}
Also used : Repository(com.enonic.xp.repository.Repository) Branch(com.enonic.xp.branch.Branch) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 37 with Branch

use of com.enonic.xp.branch.Branch in project xp by enonic.

the class RepositoryServiceImplTest method update_attachment.

@Test
void update_attachment() throws Exception {
    final String repoId = "repo-with-attachment";
    doCreateRepo(repoId);
    final BinaryReference binaryRef = BinaryReference.from("image1.jpg");
    ByteSource binarySource = ByteSource.wrap("this-is-the-binary-data-for-image1".getBytes());
    Context mockCurrentContext = ContextBuilder.create().branch("master").repositoryId(repoId).authInfo(REPO_TEST_DEFAULT_USER_AUTHINFO).build();
    PropertyTree data = new PropertyTree();
    data.setBinaryReference("someIcon", binaryRef);
    mockCurrentContext.runWith(() -> repositoryService.updateRepository(UpdateRepositoryParams.create().repositoryId(RepositoryId.from(repoId)).editor(edit -> {
        edit.data = data;
        edit.binaryAttachments = ImmutableList.of(new BinaryAttachment(binaryRef, binarySource));
    }).build()));
    createAdminContext().runWith(() -> {
        repositoryService.invalidateAll();
    });
    ByteSource persistedAttachment = mockCurrentContext.callWith(() -> repositoryService.getBinary(RepositoryId.from(repoId), BinaryReference.from("image1.jpg")));
    assertTrue(binarySource.contentEquals(persistedAttachment));
}
Also used : Context(com.enonic.xp.context.Context) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) IdProviderKey(com.enonic.xp.security.IdProviderKey) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) DeleteRepositoryParams(com.enonic.xp.repository.DeleteRepositoryParams) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Branch(com.enonic.xp.branch.Branch) NodeHelper(com.enonic.xp.repo.impl.node.NodeHelper) RepositoryId(com.enonic.xp.repository.RepositoryId) ImmutableList(com.google.common.collect.ImmutableList) CreateBranchParams(com.enonic.xp.repository.CreateBranchParams) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ContextAccessor(com.enonic.xp.context.ContextAccessor) ContextBuilder(com.enonic.xp.context.ContextBuilder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) SystemConstants(com.enonic.xp.security.SystemConstants) PropertyTree(com.enonic.xp.data.PropertyTree) BinaryReference(com.enonic.xp.util.BinaryReference) DeleteBranchParams(com.enonic.xp.repository.DeleteBranchParams) User(com.enonic.xp.security.User) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) NodePath(com.enonic.xp.node.NodePath) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) AccessControlList(com.enonic.xp.security.acl.AccessControlList) CreateRepositoryParams(com.enonic.xp.repository.CreateRepositoryParams) UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) Test(org.junit.jupiter.api.Test) PrincipalKey(com.enonic.xp.security.PrincipalKey) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) Repository(com.enonic.xp.repository.Repository) PropertyTree(com.enonic.xp.data.PropertyTree) ByteSource(com.google.common.io.ByteSource) BinaryReference(com.enonic.xp.util.BinaryReference) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 38 with Branch

use of com.enonic.xp.branch.Branch in project xp by enonic.

the class RepositoryServiceImplTest method create_branch_creates_in_repo.

@Test
void create_branch_creates_in_repo() {
    doCreateRepo("fisk");
    Branch branch = Branch.from("myBranch");
    Context mockCurrentContext = ContextBuilder.create().branch("master").repositoryId("fisk").authInfo(REPO_TEST_DEFAULT_USER_AUTHINFO).build();
    mockCurrentContext.callWith(() -> repositoryService.createBranch(CreateBranchParams.from(branch)));
    final Repository persistedRepo = getPersistedRepoWithoutCache("fisk");
    assertTrue(persistedRepo.getBranches().contains(branch));
}
Also used : Context(com.enonic.xp.context.Context) Repository(com.enonic.xp.repository.Repository) Branch(com.enonic.xp.branch.Branch) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 39 with Branch

use of com.enonic.xp.branch.Branch in project xp by enonic.

the class AbstractNodeTest method createTestRepository.

private void createTestRepository() {
    final AccessControlList rootPermissions = AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().build());
    ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().principals(RoleKeys.ADMIN).user(User.ANONYMOUS).build()).build().callWith(() -> {
        this.repositoryService.createRepository(CreateRepositoryParams.create().repositoryId(TEST_REPO_ID).rootPermissions(rootPermissions).build());
        TEST_REPO_BRANCHES.stream().filter(branch -> !RepositoryConstants.MASTER_BRANCH.equals(branch)).forEach(branch -> {
            final CreateBranchParams createBranchParams = CreateBranchParams.from(branch.toString());
            this.repositoryService.createBranch(createBranchParams);
        });
        refresh();
        return null;
    });
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) BeforeEach(org.junit.jupiter.api.BeforeEach) Nodes(com.enonic.xp.node.Nodes) Arrays(java.util.Arrays) IdProviderKey(com.enonic.xp.security.IdProviderKey) QueryParser(com.enonic.xp.query.parser.QueryParser) IndexServiceInternalImpl(com.enonic.xp.repo.impl.elasticsearch.IndexServiceInternalImpl) SystemRepoInitializer(com.enonic.xp.repo.impl.repository.SystemRepoInitializer) Segment(com.enonic.xp.blob.Segment) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) NodeRepositoryServiceImpl(com.enonic.xp.repo.impl.repository.NodeRepositoryServiceImpl) SchedulerConstants(com.enonic.xp.scheduler.SchedulerConstants) Branch(com.enonic.xp.branch.Branch) IndexDataServiceImpl(com.enonic.xp.repo.impl.storage.IndexDataServiceImpl) CommitServiceImpl(com.enonic.xp.repo.impl.commit.CommitServiceImpl) RepositoryId(com.enonic.xp.repository.RepositoryId) ContextAccessor(com.enonic.xp.context.ContextAccessor) IndexServiceImpl(com.enonic.xp.repo.impl.index.IndexServiceImpl) ContextBuilder(com.enonic.xp.context.ContextBuilder) StorageDaoImpl(com.enonic.xp.repo.impl.elasticsearch.storage.StorageDaoImpl) Path(java.nio.file.Path) PushNodesResult(com.enonic.xp.node.PushNodesResult) IndexNameResolver(com.enonic.xp.repo.impl.repository.IndexNameResolver) User(com.enonic.xp.security.User) CreateRootNodeParams(com.enonic.xp.node.CreateRootNodeParams) AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) CreateRepositoryParams(com.enonic.xp.repository.CreateRepositoryParams) IndexType(com.enonic.xp.index.IndexType) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) SearchDaoImpl(com.enonic.xp.repo.impl.elasticsearch.search.SearchDaoImpl) VersionServiceImpl(com.enonic.xp.repo.impl.version.VersionServiceImpl) TempDir(org.junit.jupiter.api.io.TempDir) NodeStorageServiceImpl(com.enonic.xp.repo.impl.storage.NodeStorageServiceImpl) BinaryServiceImpl(com.enonic.xp.repo.impl.binary.BinaryServiceImpl) NodeSearchServiceImpl(com.enonic.xp.repo.impl.search.NodeSearchServiceImpl) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) ContentConstants(com.enonic.xp.content.ContentConstants) EventPublisher(com.enonic.xp.event.EventPublisher) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) RepositoryServiceImpl(com.enonic.xp.repo.impl.repository.RepositoryServiceImpl) SchedulerRepoInitializer(com.enonic.xp.impl.scheduler.SchedulerRepoInitializer) SegmentLevel(com.enonic.xp.blob.SegmentLevel) CreateBranchParams(com.enonic.xp.repository.CreateBranchParams) AuditLogRepoInitializer(com.enonic.xp.core.impl.audit.AuditLogRepoInitializer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeQuery(com.enonic.xp.node.NodeQuery) RepositoryEntryServiceImpl(com.enonic.xp.repo.impl.repository.RepositoryEntryServiceImpl) PropertyTree(com.enonic.xp.data.PropertyTree) RepoConfiguration(com.enonic.xp.repo.impl.config.RepoConfiguration) RepositorySegmentUtils(com.enonic.xp.repository.RepositorySegmentUtils) Iterator(java.util.Iterator) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodePath(com.enonic.xp.node.NodePath) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Branches(com.enonic.xp.branch.Branches) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Mockito(org.mockito.Mockito) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeVersionServiceImpl(com.enonic.xp.repo.impl.node.dao.NodeVersionServiceImpl) PrincipalKey(com.enonic.xp.security.PrincipalKey) Reference(com.enonic.xp.util.Reference) AuditLogConstants(com.enonic.xp.core.impl.audit.AuditLogConstants) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) MemoryBlobStore(com.enonic.xp.internal.blobstore.MemoryBlobStore) NodeIds(com.enonic.xp.node.NodeIds) BranchServiceImpl(com.enonic.xp.repo.impl.branch.storage.BranchServiceImpl) CreateBranchParams(com.enonic.xp.repository.CreateBranchParams)

Example 40 with Branch

use of com.enonic.xp.branch.Branch in project xp by enonic.

the class AbstractContentServiceTest method doPrintContentTree.

private void doPrintContentTree(final ContentId rootId) {
    final Content root = this.contentService.getById(rootId);
    final Branch branch = ContextAccessor.current().getBranch();
    System.out.println("** Content-tree in branch [" + branch.getValue() + "], starting with path [" + root.getPath() + "]");
    doPrintChildren(0, root);
}
Also used : Content(com.enonic.xp.content.Content) Branch(com.enonic.xp.branch.Branch)

Aggregations

Branch (com.enonic.xp.branch.Branch)52 Test (org.junit.jupiter.api.Test)19 Node (com.enonic.xp.node.Node)13 RepositoryId (com.enonic.xp.repository.RepositoryId)12 Context (com.enonic.xp.context.Context)10 NodeId (com.enonic.xp.node.NodeId)8 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)8 Repository (com.enonic.xp.repository.Repository)7 ContextAccessor (com.enonic.xp.context.ContextAccessor)5 ContextBuilder (com.enonic.xp.context.ContextBuilder)5 ContentId (com.enonic.xp.content.ContentId)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 CreateBranchParams (com.enonic.xp.repository.CreateBranchParams)4 ContentConstants (com.enonic.xp.content.ContentConstants)3 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)3 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)3 GetActiveNodeVersionsResult (com.enonic.xp.node.GetActiveNodeVersionsResult)3 NodeIds (com.enonic.xp.node.NodeIds)3 NodePath (com.enonic.xp.node.NodePath)3 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)3