Search in sources :

Example 1 with VersionedPerson

use of org.springframework.data.mongodb.repository.VersionedPerson in project spring-data-mongodb by spring-projects.

the class SimpleMongoRepositoryVersionedEntityTests method deleteNonExistingInTx.

// DATAMONGO-2195
@Test
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
public void deleteNonExistingInTx() {
    assumeThat(ReplicaSet.required().runsAsReplicaSet()).isTrue();
    initTxTemplate().execute(status -> {
        assertThatThrownBy(() -> repository.delete(new VersionedPerson("T-800"))).isInstanceOf(OptimisticLockingFailureException.class);
        return Void.TYPE;
    });
}
Also used : VersionedPerson(org.springframework.data.mongodb.repository.VersionedPerson) EnableIfMongoServerVersion(org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion) Test(org.junit.jupiter.api.Test)

Example 2 with VersionedPerson

use of org.springframework.data.mongodb.repository.VersionedPerson in project spring-data-mongodb by spring-projects.

the class SimpleReactiveMongoRepositoryVersionedEntityTests method setUp.

@Before
public void setUp() {
    MongoPersistentEntity entity = template.getConverter().getMappingContext().getRequiredPersistentEntity(VersionedPerson.class);
    personEntityInformation = new MappingMongoEntityInformation(entity);
    repository = new SimpleReactiveMongoRepository<>(personEntityInformation, template);
    repository.deleteAll().as(StepVerifier::create).verifyComplete();
    sarah = repository.save(new VersionedPerson("Sarah", "Connor")).block();
}
Also used : MongoPersistentEntity(org.springframework.data.mongodb.core.mapping.MongoPersistentEntity) VersionedPerson(org.springframework.data.mongodb.repository.VersionedPerson) Before(org.junit.Before)

Example 3 with VersionedPerson

use of org.springframework.data.mongodb.repository.VersionedPerson in project spring-data-mongodb by spring-projects.

the class SimpleMongoRepositoryVersionedEntityTests method setUp.

@BeforeEach
public void setUp() {
    MongoPersistentEntity entity = template.getConverter().getMappingContext().getRequiredPersistentEntity(VersionedPerson.class);
    personEntityInformation = new MappingMongoEntityInformation(entity);
    repository = new SimpleMongoRepository<>(personEntityInformation, template);
    repository.deleteAll();
    sarah = repository.save(new VersionedPerson("Sarah", "Connor"));
}
Also used : MongoPersistentEntity(org.springframework.data.mongodb.core.mapping.MongoPersistentEntity) VersionedPerson(org.springframework.data.mongodb.repository.VersionedPerson) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with VersionedPerson

use of org.springframework.data.mongodb.repository.VersionedPerson in project spring-data-mongodb by spring-projects.

the class SimpleMongoRepositoryVersionedEntityTests method deleteWithMatchingVersionInTx.

// DATAMONGO-2195
@Test
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
public void deleteWithMatchingVersionInTx() {
    assumeThat(ReplicaSet.required().runsAsReplicaSet()).isTrue();
    long countBefore = repository.count();
    initTxTemplate().execute(status -> {
        VersionedPerson t800 = repository.save(new VersionedPerson("T-800"));
        repository.delete(t800);
        return Void.TYPE;
    });
    assertThat(repository.count()).isEqualTo(countBefore);
}
Also used : VersionedPerson(org.springframework.data.mongodb.repository.VersionedPerson) EnableIfMongoServerVersion(org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion) Test(org.junit.jupiter.api.Test)

Aggregations

VersionedPerson (org.springframework.data.mongodb.repository.VersionedPerson)4 Test (org.junit.jupiter.api.Test)2 MongoPersistentEntity (org.springframework.data.mongodb.core.mapping.MongoPersistentEntity)2 EnableIfMongoServerVersion (org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion)2 Before (org.junit.Before)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1