Search in sources :

Example 51 with RepositoryId

use of com.enonic.xp.repository.RepositoryId in project xp by enonic.

the class SnapshotServiceImplTest method restore_all_no_orphan_indices_left.

@Test
public void restore_all_no_orphan_indices_left() {
    NodeHelper.runAsAdmin(() -> {
        this.snapshotService.snapshot(SnapshotParams.create().snapshotName("my-snapshot").build());
        final RepositoryId newRepoId = RepositoryId.from("new-repo");
        this.repositoryService.createRepository(CreateRepositoryParams.create().repositoryId(newRepoId).build());
        assertNotNull(this.repositoryService.get(newRepoId));
        this.snapshotService.restore(RestoreParams.create().snapshotName("my-snapshot").build());
        assertAll(() -> assertFalse(this.repositoryService.isInitialized(newRepoId)), () -> assertFalse(indexServiceInternal.indicesExists(IndexNameResolver.resolveStorageIndexName(newRepoId))), () -> assertFalse(indexServiceInternal.indicesExists(IndexNameResolver.resolveSearchIndexName(newRepoId))));
    });
}
Also used : RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 52 with RepositoryId

use of com.enonic.xp.repository.RepositoryId 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 53 with RepositoryId

use of com.enonic.xp.repository.RepositoryId 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 54 with RepositoryId

use of com.enonic.xp.repository.RepositoryId in project xp by enonic.

the class ProjectServiceImplTest method create_in_non_master_node.

@Test
void create_in_non_master_node() {
    IndexServiceInternal indexServiceInternalMock = Mockito.mock(IndexServiceInternal.class);
    when(indexServiceInternalMock.waitForYellowStatus()).thenReturn(true);
    indexService.setIndexServiceInternal(indexServiceInternalMock);
    final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
    final Project project = adminContext().callWith(() -> doCreateProject(ProjectName.from(projectRepoId), null, true, null));
    assertNotNull(project);
    assertEquals("test-project", project.getName().toString());
    final NodeBranchEntry nodeBranchEntry = this.branchService.get(Node.ROOT_UUID, InternalContext.create(adminContext()).repositoryId(projectRepoId).build());
    assertNotNull(nodeBranchEntry);
    adminContext().runWith(() -> {
        final Repository pro = repositoryService.get(projectRepoId);
        assertNotNull(pro);
    });
}
Also used : Project(com.enonic.xp.project.Project) Repository(com.enonic.xp.repository.Repository) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 55 with RepositoryId

use of com.enonic.xp.repository.RepositoryId in project xp by enonic.

the class ProjectServiceImplTest method create_with_role_members.

@Test
void create_with_role_members() {
    final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
    adminContext().runWith(() -> {
        final User user1 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("user1").login("user1").build());
        final User user2 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user2")).displayName("user2").login("user2").build());
        doCreateProjectAsAdmin(ProjectName.from(projectRepoId), ProjectPermissions.create().addOwner(user1.getKey()).addOwner(user2.getKey()).build());
        final Set<PrincipalKey> members = securityService.getRelationships(PrincipalKey.ofRole("cms.project.test-project.owner")).stream().map(PrincipalRelationship::getTo).collect(Collectors.toSet());
        assertTrue(members.contains(user1.getKey()));
        assertTrue(members.contains(user2.getKey()));
    });
}
Also used : User(com.enonic.xp.security.User) RepositoryId(com.enonic.xp.repository.RepositoryId) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

RepositoryId (com.enonic.xp.repository.RepositoryId)61 Test (org.junit.jupiter.api.Test)21 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)19 Branch (com.enonic.xp.branch.Branch)14 Repository (com.enonic.xp.repository.Repository)11 Node (com.enonic.xp.node.Node)9 ByteSource (com.google.common.io.ByteSource)8 IOException (java.io.IOException)7 PropertyTree (com.enonic.xp.data.PropertyTree)6 Segment (com.enonic.xp.blob.Segment)5 Context (com.enonic.xp.context.Context)5 ContextAccessor (com.enonic.xp.context.ContextAccessor)5 ContextBuilder (com.enonic.xp.context.ContextBuilder)5 BlobKey (com.enonic.xp.blob.BlobKey)4 EventPublisher (com.enonic.xp.event.EventPublisher)4 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)4 Project (com.enonic.xp.project.Project)4 DumpConstants (com.enonic.xp.repo.impl.dump.DumpConstants)4 DumpBlobRecord (com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord)4 RepositoryIds (com.enonic.xp.repository.RepositoryIds)4