@Before
public void initialize() throws ParseException, NoSuchMethodException {
Metamodel metamodel = mock(Metamodel.class);
SecurePersistenceUnitUtil persistenceUnitUtil = mock(SecurePersistenceUnitUtil.class);
accessManager = mock(DefaultAccessManager.class);
SecurityContext securityContext = mock(SecurityContext.class);
EntityType entityType = mock(EntityType.class);
SingularAttribute idAttribute = mock(SingularAttribute.class);
SingularAttribute nameAttribute = mock(SingularAttribute.class);
SingularAttribute parentAttribute = mock(SingularAttribute.class);
PluralAttribute childrenAttribute = mock(PluralAttribute.class);
MapAttribute relatedAttribute = mock(MapAttribute.class);
Type integerType = mock(Type.class);
when(metamodel.getEntities()).thenReturn(Collections.<EntityType<?>>singleton(entityType));
when(metamodel.managedType(MethodAccessTestBean.class)).thenReturn(entityType);
when(metamodel.entity(MethodAccessTestBean.class)).thenReturn(entityType);
when(accessManager.getContext()).thenReturn(securityContext);
when(securityContext.getAliases()).thenReturn(Collections.singleton(CURRENT_PRINCIPAL));
when(securityContext.getAliasValue(CURRENT_PRINCIPAL)).thenReturn(NAME);
when(entityType.getName()).thenReturn(MethodAccessTestBean.class.getSimpleName());
when(entityType.getJavaType()).thenReturn((Class)MethodAccessTestBean.class);
when(entityType.getAttributes()).thenReturn(new HashSet(Arrays.asList(
idAttribute, nameAttribute, parentAttribute, childrenAttribute, relatedAttribute)));
when(entityType.getAttribute("id")).thenReturn(idAttribute);
when(entityType.getAttribute("name")).thenReturn(nameAttribute);
when(entityType.getAttribute("parent")).thenReturn(parentAttribute);
when(entityType.getAttribute("children")).thenReturn(childrenAttribute);
when(entityType.getAttribute("related")).thenReturn(relatedAttribute);
when(idAttribute.getName()).thenReturn("id");
when(idAttribute.isCollection()).thenReturn(false);
when(idAttribute.getType()).thenReturn(integerType);
when(idAttribute.getPersistentAttributeType()).thenReturn(PersistentAttributeType.BASIC);
when(idAttribute.getJavaType()).thenReturn(Integer.TYPE);
when(idAttribute.getJavaMember()).thenReturn(MethodAccessTestBean.class.getDeclaredMethod("getId"));
when(nameAttribute.getName()).thenReturn("name");
when(nameAttribute.isCollection()).thenReturn(false);
when(nameAttribute.getType()).thenReturn(integerType);
when(nameAttribute.getPersistentAttributeType()).thenReturn(PersistentAttributeType.BASIC);
when(nameAttribute.getJavaType()).thenReturn(String.class);
when(nameAttribute.getJavaMember()).thenReturn(MethodAccessTestBean.class.getDeclaredMethod("getName"));
when(parentAttribute.getName()).thenReturn("parent");
when(parentAttribute.isCollection()).thenReturn(false);
when(parentAttribute.getType()).thenReturn(entityType);
when(parentAttribute.getPersistentAttributeType()).thenReturn(PersistentAttributeType.MANY_TO_ONE);
when(parentAttribute.getJavaType()).thenReturn(MethodAccessTestBean.class);
when(parentAttribute.getJavaMember()).thenReturn(MethodAccessTestBean.class.getDeclaredMethod("getParent"));
when(childrenAttribute.getName()).thenReturn("children");
when(childrenAttribute.isCollection()).thenReturn(true);
when(childrenAttribute.getElementType()).thenReturn(entityType);
when(childrenAttribute.getJavaMember())
.thenReturn(MethodAccessTestBean.class.getDeclaredMethod("getChildren"));
when(relatedAttribute.getName()).thenReturn("related");
when(relatedAttribute.isCollection()).thenReturn(true);
when(relatedAttribute.getKeyJavaType()).thenReturn(MethodAccessTestBean.class);
when(relatedAttribute.getBindableJavaType()).thenReturn(MethodAccessTestBean.class);
when(relatedAttribute.getElementType()).thenReturn(entityType);
when(relatedAttribute.getJavaMember())
.thenReturn(MethodAccessTestBean.class.getDeclaredMethod("getRelated"));
entityFilter = new EntityFilter(metamodel, persistenceUnitUtil, initializeAccessRules(metamodel));
DefaultAccessManager.Instance.register(accessManager);
}
EntityFilterTest.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:jpasecurity
作者:
评论列表
文章目录