Search in sources :

Example 1 with AccountEntity

use of org.eclipse.sirius.web.persistence.entities.AccountEntity in project sirius-web by eclipse-sirius.

the class AccountRepositoryIntegrationTests method testInsertAndRetrieveAnAccount.

@Test
@Transactional
public void testInsertAndRetrieveAnAccount() {
    AccountEntity account = new AccountEntity();
    account.setUsername(FIRST_USERNAME);
    account.setPassword(FIRST_PASSWORD);
    account.setRole(USER);
    AccountEntity savedAccount = this.accountRepository.save(account);
    assertThat(savedAccount.getId()).isNotNull();
    var optionalAccountFound = this.accountRepository.findById(savedAccount.getId());
    assertThat(optionalAccountFound.isPresent()).isTrue();
    optionalAccountFound.ifPresent(accountFound -> {
        assertThat(accountFound.getId()).isNotNull();
        assertThat(accountFound.getUsername()).isEqualTo(FIRST_USERNAME);
        assertThat(accountFound.getPassword()).isEqualTo(FIRST_PASSWORD);
    });
}
Also used : AccountEntity(org.eclipse.sirius.web.persistence.entities.AccountEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with AccountEntity

use of org.eclipse.sirius.web.persistence.entities.AccountEntity in project sirius-web by eclipse-sirius.

the class ProjectRepositoryIntegrationTests method testDefaultProjectVisibilityIsPublic.

@Test
@Transactional
public void testDefaultProjectVisibilityIsPublic() {
    AccountEntity owner = this.createAndSaveUser(FIRST_OWNER_NAME);
    ProjectEntity project = new ProjectEntity();
    project.setName(FIRST_PROJECT_NAME);
    project.setOwner(owner);
    project.setVisibility(VisibilityEntity.PUBLIC);
    var savedProject = this.projectRepository.save(project);
    assertThat(savedProject.getId()).isNotNull();
    var optionalProjectFound = this.projectRepository.findById(savedProject.getId());
    assertThat(optionalProjectFound.isPresent()).isTrue();
    optionalProjectFound.ifPresent(projectFound -> {
        assertThat(projectFound.getId()).isNotNull();
        assertThat(projectFound.getName()).isEqualTo(FIRST_PROJECT_NAME);
        assertThat(projectFound.getVisibility()).isSameAs(VisibilityEntity.PUBLIC);
    });
}
Also used : ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) AccountEntity(org.eclipse.sirius.web.persistence.entities.AccountEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with AccountEntity

use of org.eclipse.sirius.web.persistence.entities.AccountEntity in project sirius-web by eclipse-sirius.

the class RepresentationRepositoryIntegrationTests method createAndSaveProjectEntity.

private ProjectEntity createAndSaveProjectEntity() {
    AccountEntity owner = new AccountEntity();
    owner.setUsername(OWNER_NAME);
    owner.setPassword(OWNER_NAME);
    owner.setRole(ROLE_USER);
    AccountEntity savedOwner = this.accountRepository.save(owner);
    ProjectEntity project = new ProjectEntity();
    project.setName(FIRST_PROJECT_NAME);
    project.setOwner(savedOwner);
    ProjectEntity savedProject = this.projectRepository.save(project);
    return savedProject;
}
Also used : ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) AccountEntity(org.eclipse.sirius.web.persistence.entities.AccountEntity)

Example 4 with AccountEntity

use of org.eclipse.sirius.web.persistence.entities.AccountEntity in project sirius-web by eclipse-sirius.

the class RepresentationRepositoryIntegrationTests method testFindByIdAndProjectId.

@Test
@Transactional
public void testFindByIdAndProjectId() {
    AccountEntity owner = new AccountEntity();
    owner.setUsername(OWNER_NAME);
    owner.setPassword(OWNER_NAME);
    owner.setRole(ROLE_USER);
    AccountEntity savedOwner = this.accountRepository.save(owner);
    ProjectEntity firstProject = new ProjectEntity();
    firstProject.setName(FIRST_PROJECT_NAME);
    firstProject.setOwner(savedOwner);
    ProjectEntity savedFirstProject = this.projectRepository.save(firstProject);
    ProjectEntity secondProject = new ProjectEntity();
    secondProject.setName(SECOND_PROJECT_NAME);
    secondProject.setOwner(savedOwner);
    ProjectEntity savedSecondProject = this.projectRepository.save(secondProject);
    RepresentationEntity firstRepresentationEntity = this.createRepresentationEntity(savedFirstProject, FIRST_DIAGRAM_LABEL, FIRST_TARGET_OBJECT_ID);
    this.representationRepository.save(firstRepresentationEntity);
    RepresentationEntity secondRepresentationEntity = this.createRepresentationEntity(savedSecondProject, SECOND_DIAGRAM_LABEL, FIRST_TARGET_OBJECT_ID);
    this.representationRepository.save(secondRepresentationEntity);
    var optionalFirstRepresentationEntity = this.representationRepository.findByIdAndProjectId(firstRepresentationEntity.getId(), firstProject.getId());
    var optionalNotFoundFirstRepresentationEntity = this.representationRepository.findByIdAndProjectId(firstRepresentationEntity.getId(), secondProject.getId());
    var optionalSecondRepresentationEntity = this.representationRepository.findByIdAndProjectId(secondRepresentationEntity.getId(), secondProject.getId());
    var optionalNotFoundSecondRepresentationEntity = this.representationRepository.findByIdAndProjectId(secondRepresentationEntity.getId(), firstProject.getId());
    assertThat(optionalFirstRepresentationEntity).isPresent();
    assertThat(optionalSecondRepresentationEntity).isPresent();
    assertThat(optionalNotFoundFirstRepresentationEntity).isEmpty();
    assertThat(optionalNotFoundSecondRepresentationEntity).isEmpty();
}
Also used : RepresentationEntity(org.eclipse.sirius.web.persistence.entities.RepresentationEntity) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) AccountEntity(org.eclipse.sirius.web.persistence.entities.AccountEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with AccountEntity

use of org.eclipse.sirius.web.persistence.entities.AccountEntity in project sirius-web by eclipse-sirius.

the class AccountRepositoryIntegrationTests method testFindByUsername.

@Test
@Transactional
public void testFindByUsername() {
    AccountEntity account = new AccountEntity();
    account.setUsername(SECOND_USERNAME);
    account.setPassword(SECOND_PASSWORD);
    account.setRole(USER);
    this.accountRepository.save(account);
    var optionalAccountFound = this.accountRepository.findByUsername(SECOND_USERNAME);
    assertThat(optionalAccountFound.isPresent()).isTrue();
    optionalAccountFound.ifPresent(accountFound -> {
        assertThat(accountFound.getId()).isNotNull();
        assertThat(accountFound.getUsername()).isEqualTo(SECOND_USERNAME);
        assertThat(accountFound.getPassword()).isEqualTo(SECOND_PASSWORD);
    });
}
Also used : AccountEntity(org.eclipse.sirius.web.persistence.entities.AccountEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AccountEntity (org.eclipse.sirius.web.persistence.entities.AccountEntity)11 ProjectEntity (org.eclipse.sirius.web.persistence.entities.ProjectEntity)8 Test (org.junit.jupiter.api.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 Transactional (org.springframework.transaction.annotation.Transactional)7 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 EClass (org.eclipse.emf.ecore.EClass)1 AdapterFactoryEditingDomain (org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1 IEditingContextPersistenceService (org.eclipse.sirius.components.core.api.IEditingContextPersistenceService)1 EditingContext (org.eclipse.sirius.components.emf.services.EditingContext)1 SiriusWebJSONResourceFactoryImpl (org.eclipse.sirius.components.emf.services.SiriusWebJSONResourceFactoryImpl)1 JsonResource (org.eclipse.sirius.emfjson.resource.JsonResource)1 DocumentEntity (org.eclipse.sirius.web.persistence.entities.DocumentEntity)1 RepresentationEntity (org.eclipse.sirius.web.persistence.entities.RepresentationEntity)1 IDocumentRepository (org.eclipse.sirius.web.persistence.repositories.IDocumentRepository)1 DocumentMetadataAdapter (org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter)1 EditingDomainFactory (org.eclipse.sirius.web.services.documents.EditingDomainFactory)1