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());
}
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());
}
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);
}
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());
}
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());
}
Aggregations