Search in sources :

Example 1 with EntityInstantiators

use of org.springframework.data.mapping.model.EntityInstantiators in project spring-data-ldap by spring-projects.

the class PartTreeLdapRepositoryQueryTests method assertFilterAndBaseForMethod.

private void assertFilterAndBaseForMethod(Method targetMethod, String expectedFilter, String expectedBase, Object... expectedParams) {
    LdapQueryMethod queryMethod = new LdapQueryMethod(targetMethod, repositoryMetadata, factory);
    PartTreeLdapRepositoryQuery tested = new PartTreeLdapRepositoryQuery(queryMethod, entityClass, ldapTemplate, new LdapMappingContext(), new EntityInstantiators());
    LdapQuery query = tested.createQuery(new LdapParametersParameterAccessor(queryMethod, expectedParams));
    String base = query.base().toString();
    assertThat(base).isEqualTo(expectedBase);
    assertThat(query.filter().encode()).isEqualTo(expectedFilter);
}
Also used : LdapMappingContext(org.springframework.data.ldap.core.mapping.LdapMappingContext) EntityInstantiators(org.springframework.data.mapping.model.EntityInstantiators) LdapQuery(org.springframework.ldap.query.LdapQuery)

Example 2 with EntityInstantiators

use of org.springframework.data.mapping.model.EntityInstantiators in project spring-data-geode by spring-projects.

the class MappingPdxSerializerUnitTests method setEntityInstantiatorsWithNonNullEntityInstantiators.

@Test
public void setEntityInstantiatorsWithNonNullEntityInstantiators() {
    EntityInstantiators mockEntityInstantiators = mock(EntityInstantiators.class);
    this.pdxSerializer.setEntityInstantiators(mockEntityInstantiators);
    assertThat(this.pdxSerializer.getEntityInstantiators()).isSameAs(mockEntityInstantiators);
}
Also used : EntityInstantiators(org.springframework.data.mapping.model.EntityInstantiators) Test(org.junit.Test)

Example 3 with EntityInstantiators

use of org.springframework.data.mapping.model.EntityInstantiators in project spring-data-geode by spring-projects.

the class MappingPdxSerializerUnitTests method resolveEntityInstantiatorForNonManagedPersistentEntityWithNoEntityInstantiator.

@Test
@SuppressWarnings("rawtypes")
public void resolveEntityInstantiatorForNonManagedPersistentEntityWithNoEntityInstantiator() {
    EntityInstantiator mockEntityInstantiator = mock(EntityInstantiator.class);
    EntityInstantiators mockEntityInstantiators = mock(EntityInstantiators.class);
    PersistentEntity mockEntity = mock(PersistentEntity.class);
    doReturn(mockEntityInstantiators).when(this.pdxSerializer).getEntityInstantiators();
    assertThat(this.pdxSerializer.resolveEntityInstantiator(mockEntity)).isNotEqualTo(mockEntityInstantiator);
    verify(this.pdxSerializer, times(1)).getEntityInstantiators();
    verify(mockEntityInstantiators, times(1)).getInstantiatorFor(eq(mockEntity));
    verifyNoInteractions(mockEntityInstantiator);
    verifyNoInteractions(mockEntity);
}
Also used : PersistentEntity(org.springframework.data.mapping.PersistentEntity) EntityInstantiators(org.springframework.data.mapping.model.EntityInstantiators) EntityInstantiator(org.springframework.data.mapping.model.EntityInstantiator) Test(org.junit.Test)

Example 4 with EntityInstantiators

use of org.springframework.data.mapping.model.EntityInstantiators in project spring-data-geode by spring-projects.

the class MappingPdxSerializerUnitTests method resolveEntityInstantiatorForManagedPersistentEntityWithEntityInstantiator.

@Test
@SuppressWarnings("rawtypes")
public void resolveEntityInstantiatorForManagedPersistentEntityWithEntityInstantiator() {
    EntityInstantiator mockEntityInstantiator = mock(EntityInstantiator.class);
    EntityInstantiators mockEntityInstantiators = mock(EntityInstantiators.class);
    PersistentEntity mockEntity = mock(PersistentEntity.class);
    doReturn(mockEntityInstantiators).when(this.pdxSerializer).getEntityInstantiators();
    doReturn(mockEntityInstantiator).when(mockEntityInstantiators).getInstantiatorFor(eq(mockEntity));
    assertThat(this.pdxSerializer.resolveEntityInstantiator(mockEntity)).isEqualTo(mockEntityInstantiator);
    verify(this.pdxSerializer, times(1)).getEntityInstantiators();
    verify(mockEntityInstantiators, times(1)).getInstantiatorFor(eq(mockEntity));
    verifyNoInteractions(mockEntityInstantiator);
    verifyNoInteractions(mockEntity);
}
Also used : PersistentEntity(org.springframework.data.mapping.PersistentEntity) EntityInstantiators(org.springframework.data.mapping.model.EntityInstantiators) EntityInstantiator(org.springframework.data.mapping.model.EntityInstantiator) Test(org.junit.Test)

Example 5 with EntityInstantiators

use of org.springframework.data.mapping.model.EntityInstantiators in project spring-data-commons by spring-projects.

the class InstantiationAwarePersistentPropertyAccessorUnitTests method shouldSetMultipleProperties.

// DATACMNS-1768
@Test
void shouldSetMultipleProperties() {
    EntityInstantiators instantiators = new EntityInstantiators();
    SampleMappingContext context = new SampleMappingContext();
    PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Sample.class);
    Sample bean = new Sample("Dave", "Matthews", 42);
    PersistentPropertyAccessor<Sample> wrapper = new InstantiationAwarePropertyAccessor<>(bean, entity::getPropertyAccessor, instantiators);
    wrapper.setProperty(entity.getRequiredPersistentProperty("firstname"), "Oliver August");
    wrapper.setProperty(entity.getRequiredPersistentProperty("lastname"), "Heisenberg");
    assertThat(wrapper.getBean()).isEqualTo(new Sample("Oliver August", "Heisenberg", 42));
}
Also used : EntityInstantiators(org.springframework.data.mapping.model.EntityInstantiators) SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) SampleMappingContext(org.springframework.data.mapping.context.SampleMappingContext) InstantiationAwarePropertyAccessor(org.springframework.data.mapping.model.InstantiationAwarePropertyAccessor) Test(org.junit.jupiter.api.Test)

Aggregations

EntityInstantiators (org.springframework.data.mapping.model.EntityInstantiators)6 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)2 PersistentEntity (org.springframework.data.mapping.PersistentEntity)2 SampleMappingContext (org.springframework.data.mapping.context.SampleMappingContext)2 SamplePersistentProperty (org.springframework.data.mapping.context.SamplePersistentProperty)2 EntityInstantiator (org.springframework.data.mapping.model.EntityInstantiator)2 InstantiationAwarePropertyAccessor (org.springframework.data.mapping.model.InstantiationAwarePropertyAccessor)2 LdapMappingContext (org.springframework.data.ldap.core.mapping.LdapMappingContext)1 LdapQuery (org.springframework.ldap.query.LdapQuery)1