@SuppressWarnings("unchecked") @Test public void testList() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { securityContextInjector.setEducatorContext(); RightAccessValidator mockAccessValidator = Mockito.mock(RightAccessValidator.class); Field rightAccessValidator = BasicService.class.getDeclaredField("rightAccessValidator"); rightAccessValidator.setAccessible(true); rightAccessValidator.set(service, mockAccessValidator); EntityBody entityBody1 = new EntityBody(); entityBody1.put("studentUniqueStateId", "student1"); EntityBody entityBody2 = new EntityBody(); entityBody2.put("studentUniqueStateId", "student2"); Entity entity1 = new MongoEntity("student", "student1", entityBody1, new HashMap<String,Object>()); Entity entity2 = new MongoEntity("student", "student2", entityBody2, new HashMap<String,Object>()); Iterable<Entity> entities = Arrays.asList(entity1, entity2); Mockito.when(mockRepo.findAll(Mockito.eq("student"), Mockito.any(NeutralQuery.class))).thenReturn(entities); Mockito.when(mockRepo.count(Mockito.eq("student"), Mockito.any(NeutralQuery.class))).thenReturn(2L); Mockito.when(mockRightsFilter.makeEntityBody(Mockito.eq(entity1), Mockito.any(List.class), Mockito.any(EntityDefinition.class), Mockito.any(Collection.class), Mockito.any(Collection.class))).thenReturn(entityBody1); Mockito.when(mockRightsFilter.makeEntityBody(Mockito.eq(entity2), Mockito.any(List.class), Mockito.any(EntityDefinition.class), Mockito.any(Collection.class), Mockito.any(Collection.class))).thenReturn(entityBody2); RequestUtil.setCurrentRequestId(); Iterable<EntityBody> listResult = service.list(new NeutralQuery()); List<EntityBody> bodies= new ArrayList<EntityBody>(); for (EntityBody body : listResult) { bodies.add(body); } Assert.assertEquals("EntityBody mismatch", entityBody1, bodies.toArray()[0]); Assert.assertEquals("EntityBody mismatch", entityBody2, bodies.toArray()[1]); long count = service.count(new NeutralQuery()); Assert.assertEquals(2, count); }
@Override public Iterable<EntityBody> list(NeutralQuery neutralQuery) { LOG.debug(">>>BasicService.list(neutralQuery)"); listSecurityCheck(neutralQuery); return listImplementationAfterSecurityChecks(neutralQuery); }
BasicService implements EntityService, AccessibilityCheck { @Override public Iterable<EntityBody> list(NeutralQuery neutralQuery) { LOG.debug(">>>BasicService.list(neutralQuery)"); listSecurityCheck(neutralQuery); return listImplementationAfterSecurityChecks(neutralQuery); } }
BasicService implements EntityService, AccessibilityCheck { @Override public Iterable<EntityBody> list(NeutralQuery neutralQuery) { LOG.debug(">>>BasicService.list(neutralQuery)"); listSecurityCheck(neutralQuery); return listImplementationAfterSecurityChecks(neutralQuery); } BasicService(String collectionName, List<Treatment> treatments, Repository<Entity> repo); }
BasicService implements EntityService, AccessibilityCheck { @Override public Iterable<EntityBody> list(NeutralQuery neutralQuery) { LOG.debug(">>>BasicService.list(neutralQuery)"); listSecurityCheck(neutralQuery); return listImplementationAfterSecurityChecks(neutralQuery); } BasicService(String collectionName, List<Treatment> treatments, Repository<Entity> repo); @Override long count(NeutralQuery neutralQuery); @Override long countBasedOnContextualRoles(NeutralQuery neutralQuery); @Override List<String> create(List<EntityBody> content); @Override List<String> createBasedOnContextualRoles(List<EntityBody> content); @Override Iterable<String> listIds(final NeutralQuery neutralQuery); @Override String create(EntityBody content); @Override String createBasedOnContextualRoles(EntityBody content); @Override boolean accessibilityCheck(String id); @Override void delete(String id); @Override void deleteBasedOnContextualRoles(String id); @Override boolean update(String id, EntityBody content, boolean applySecurityContext); @Override boolean patch(String id, EntityBody content, boolean applySecurityContext); @Override EntityBody get(String id); @Override EntityBody get(String id, NeutralQuery neutralQuery); @Override Iterable<EntityBody> get(Iterable<String> ids); @Override Iterable<EntityBody> get(Iterable<String> ids, final NeutralQuery neutralQuery); @Override Iterable<EntityBody> list(NeutralQuery neutralQuery); @Override Iterable<EntityBody> listBasedOnContextualRoles(NeutralQuery neutralQuery); @Override boolean exists(String id); @Override EntityBody getCustom(String id); @Override void deleteCustom(String id); @Override void createOrUpdateCustom(String id, EntityBody customEntity); void setDefn(EntityDefinition defn); @Override EntityDefinition getEntityDefinition(); long getCountLimit(); int getBatchSize(); @Override CalculatedData<String> getCalculatedValues(String id); @Override CalculatedData<Map<String, Integer>> getAggregates(String id); @Override boolean collectionExists(String collection); }
BasicService implements EntityService, AccessibilityCheck { @Override public Iterable<EntityBody> list(NeutralQuery neutralQuery) { LOG.debug(">>>BasicService.list(neutralQuery)"); listSecurityCheck(neutralQuery); return listImplementationAfterSecurityChecks(neutralQuery); } BasicService(String collectionName, List<Treatment> treatments, Repository<Entity> repo); @Override long count(NeutralQuery neutralQuery); @Override long countBasedOnContextualRoles(NeutralQuery neutralQuery); @Override List<String> create(List<EntityBody> content); @Override List<String> createBasedOnContextualRoles(List<EntityBody> content); @Override Iterable<String> listIds(final NeutralQuery neutralQuery); @Override String create(EntityBody content); @Override String createBasedOnContextualRoles(EntityBody content); @Override boolean accessibilityCheck(String id); @Override void delete(String id); @Override void deleteBasedOnContextualRoles(String id); @Override boolean update(String id, EntityBody content, boolean applySecurityContext); @Override boolean patch(String id, EntityBody content, boolean applySecurityContext); @Override EntityBody get(String id); @Override EntityBody get(String id, NeutralQuery neutralQuery); @Override Iterable<EntityBody> get(Iterable<String> ids); @Override Iterable<EntityBody> get(Iterable<String> ids, final NeutralQuery neutralQuery); @Override Iterable<EntityBody> list(NeutralQuery neutralQuery); @Override Iterable<EntityBody> listBasedOnContextualRoles(NeutralQuery neutralQuery); @Override boolean exists(String id); @Override EntityBody getCustom(String id); @Override void deleteCustom(String id); @Override void createOrUpdateCustom(String id, EntityBody customEntity); void setDefn(EntityDefinition defn); @Override EntityDefinition getEntityDefinition(); long getCountLimit(); int getBatchSize(); @Override CalculatedData<String> getCalculatedValues(String id); @Override CalculatedData<Map<String, Integer>> getAggregates(String id); @Override boolean collectionExists(String collection);  }