Search in sources :

Example 1 with ViewMetamodel

use of com.blazebit.persistence.view.metamodel.ViewMetamodel in project blaze-persistence by Blazebit.

the class ViewMetamodelTest method testMappingConstructor.

@Test
public void testMappingConstructor() throws Exception {
    ViewMetamodel viewMetamodel = getViewMetamodel();
    ViewType<DocumentViewAbstractClass> viewType = viewMetamodel.view(DocumentViewAbstractClass.class);
    Set<MappingConstructor<DocumentViewAbstractClass>> constructors = viewType.getConstructors();
    MappingConstructor<DocumentViewAbstractClass> constructor = constructors.iterator().next();
    assertNotNull(constructor);
    assertEquals(3, constructor.getParameterAttributes().size());
    assertEquals(Long.class, constructor.getParameterAttributes().get(0).getJavaType());
    assertEquals(constructor, constructor.getParameterAttributes().get(0).getDeclaringConstructor());
    assertEquals(viewType, constructor.getParameterAttributes().get(0).getDeclaringType());
    assertEquals(0, constructor.getParameterAttributes().get(0).getIndex());
    assertFalse(constructor.getParameterAttributes().get(0).isSubquery());
    assertEquals("age + 1", ((MappingAttribute<?, ?>) constructor.getParameterAttributes().get(0)).getMapping());
    assertFalse(constructor.getParameterAttributes().get(0).isCollection());
    assertFalse(((SingularAttribute<?, ?>) constructor.getParameterAttributes().get(0)).isQueryParameter());
    assertEquals(Integer.class, constructor.getParameterAttributes().get(1).getJavaType());
    assertEquals(constructor, constructor.getParameterAttributes().get(1).getDeclaringConstructor());
    assertEquals(viewType, constructor.getParameterAttributes().get(1).getDeclaringType());
    assertEquals(1, constructor.getParameterAttributes().get(1).getIndex());
    assertFalse(constructor.getParameterAttributes().get(1).isSubquery());
    assertEquals("contactPersonNumber", ((MappingAttribute<?, ?>) constructor.getParameterAttributes().get(1)).getMapping());
    assertFalse(constructor.getParameterAttributes().get(1).isCollection());
    assertTrue(((SingularAttribute<?, ?>) constructor.getParameterAttributes().get(1)).isQueryParameter());
    assertEquals(String.class, constructor.getParameterAttributes().get(2).getJavaType());
    assertEquals(constructor, constructor.getParameterAttributes().get(2).getDeclaringConstructor());
    assertEquals(viewType, constructor.getParameterAttributes().get(2).getDeclaringType());
    assertEquals(2, constructor.getParameterAttributes().get(2).getIndex());
    assertFalse(constructor.getParameterAttributes().get(2).isSubquery());
    assertEquals("optionalParameter", ((MappingAttribute<?, ?>) constructor.getParameterAttributes().get(2)).getMapping());
    assertFalse(constructor.getParameterAttributes().get(2).isCollection());
    assertTrue(((SingularAttribute<?, ?>) constructor.getParameterAttributes().get(2)).isQueryParameter());
    assertEquals(DocumentViewAbstractClass.class.getConstructor(Long.class, Integer.class, String.class), constructor.getJavaConstructor());
    assertEquals(viewType, constructor.getDeclaringType());
}
Also used : MappingConstructor(com.blazebit.persistence.view.metamodel.MappingConstructor) ViewMetamodel(com.blazebit.persistence.view.metamodel.ViewMetamodel) DocumentViewAbstractClass(com.blazebit.persistence.view.testsuite.basic.model.DocumentViewAbstractClass) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 2 with ViewMetamodel

use of com.blazebit.persistence.view.metamodel.ViewMetamodel in project blaze-persistence by Blazebit.

the class ViewMetamodelTest method testSetterOnSubtype.

@Test
public void testSetterOnSubtype() {
    ViewMetamodel metamodel = build(SetterOnSubtypeDocument.class).getMetamodel();
    MethodAttribute<? super SetterOnSubtypeDocument, ?> idAttribute = metamodel.view(SetterOnSubtypeDocument.class).getAttribute("id");
    assertFalse(idAttribute.isMutable());
    assertFalse(idAttribute.isUpdatable());
}
Also used : ViewMetamodel(com.blazebit.persistence.view.metamodel.ViewMetamodel) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 3 with ViewMetamodel

use of com.blazebit.persistence.view.metamodel.ViewMetamodel in project blaze-persistence by Blazebit.

the class ViewMetamodelTest method testMappingSingularView.

@Test
public void testMappingSingularView() {
    ViewMetamodel viewMetamodel = build(PersonViewWithSingularMapping.class).getMetamodel();
    ViewType<?> viewType = viewMetamodel.view(PersonViewWithSingularMapping.class);
    assertNotNull(viewType);
    MethodAttribute<?, ?> attribute = viewType.getAttribute("ownedDocuments");
    assertNotNull(attribute);
    assertFalse(attribute.isCollection());
    assertTrue(attribute instanceof SingularAttribute);
}
Also used : SingularAttribute(com.blazebit.persistence.view.metamodel.SingularAttribute) ViewMetamodel(com.blazebit.persistence.view.metamodel.ViewMetamodel) PersonViewWithSingularMapping(com.blazebit.persistence.view.testsuite.basic.model.PersonViewWithSingularMapping) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 4 with ViewMetamodel

use of com.blazebit.persistence.view.metamodel.ViewMetamodel in project blaze-persistence by Blazebit.

the class ViewMetamodelTest method testExplicitAbstractClassMethodPreferredOverInterfaceMethod.

@Test
public void testExplicitAbstractClassMethodPreferredOverInterfaceMethod() {
    ViewMetamodel metamodel = build(ExplicitAbstractClassMethodPreferredOverInterfaceMethod.class).getMetamodel();
    MethodAttribute<?, ?> methodAttribute = metamodel.view(ExplicitAbstractClassMethodPreferredOverInterfaceMethod.class).getAttribute("name");
    assertEquals(ExplicitAbstractClassMethodPreferredOverInterfaceMethodAbstractClass.class, methodAttribute.getJavaMethod().getDeclaringClass());
    assertEquals("COALESCE(name, '')", ((MappingAttribute<?, ?>) methodAttribute).getMapping());
}
Also used : ViewMetamodel(com.blazebit.persistence.view.metamodel.ViewMetamodel) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Example 5 with ViewMetamodel

use of com.blazebit.persistence.view.metamodel.ViewMetamodel in project blaze-persistence by Blazebit.

the class ViewMetamodelTest method testViewTypeDefaults.

@Test
public void testViewTypeDefaults() {
    ViewMetamodel viewMetamodel = getViewMetamodel();
    Class<?> expectedViewClass = DocumentViewInterface.class;
    Class<?> expectedEntityClass = Document.class;
    ViewType<?> docView = viewMetamodel.view(expectedViewClass);
    assertEquals(expectedViewClass, docView.getJavaType());
    assertEquals(expectedEntityClass, docView.getEntityClass());
}
Also used : DocumentViewInterface(com.blazebit.persistence.view.testsuite.basic.model.DocumentViewInterface) ViewMetamodel(com.blazebit.persistence.view.metamodel.ViewMetamodel) Document(com.blazebit.persistence.testsuite.entity.Document) CircularDocument(com.blazebit.persistence.view.testsuite.basic.model.CircularDocument) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Aggregations

ViewMetamodel (com.blazebit.persistence.view.metamodel.ViewMetamodel)44 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)44 Test (org.junit.Test)44 DocumentViewInterface (com.blazebit.persistence.view.testsuite.basic.model.DocumentViewInterface)15 EntityViewConfiguration (com.blazebit.persistence.view.spi.EntityViewConfiguration)5 DocumentViewAbstractClass (com.blazebit.persistence.view.testsuite.basic.model.DocumentViewAbstractClass)5 MappingAttribute (com.blazebit.persistence.view.metamodel.MappingAttribute)3 MappingConstructor (com.blazebit.persistence.view.metamodel.MappingConstructor)3 IdHolderView (com.blazebit.persistence.view.testsuite.basic.model.IdHolderView)3 PersonView (com.blazebit.persistence.view.testsuite.basic.model.PersonView)3 MethodAttribute (com.blazebit.persistence.view.metamodel.MethodAttribute)2 Document (com.blazebit.persistence.testsuite.entity.Document)1 Person (com.blazebit.persistence.testsuite.entity.Person)1 FlatViewType (com.blazebit.persistence.view.metamodel.FlatViewType)1 SingularAttribute (com.blazebit.persistence.view.metamodel.SingularAttribute)1 CircularDocument (com.blazebit.persistence.view.testsuite.basic.model.CircularDocument)1 CircularPerson (com.blazebit.persistence.view.testsuite.basic.model.CircularPerson)1 PersonViewWithSingularMapping (com.blazebit.persistence.view.testsuite.basic.model.PersonViewWithSingularMapping)1