use of org.edx.mobile.model.Filter in project edx-app-android by edx.
the class CourseComponentTest method testFindWithFilter.
@Test
public void testFindWithFilter() throws Exception {
CourseComponent found = course.find(new Filter<CourseComponent>() {
@Override
public boolean apply(CourseComponent component) {
return false;
}
});
assertTrue("find with filter failed", found == null);
found = course.find(new Filter<CourseComponent>() {
@Override
public boolean apply(CourseComponent component) {
return component == unit1;
}
});
assertTrue("find with filter failed", found == unit1);
found = course.find(new Filter<CourseComponent>() {
@Override
public boolean apply(CourseComponent component) {
return component.getType() == BlockType.VIDEO;
}
});
assertTrue("find with filter failed", found == unit1);
}
use of org.edx.mobile.model.Filter in project edx-app-android by edx.
the class ApiTests method testGetCourseStructure.
@Test
public void testGetCourseStructure() throws Exception {
login();
// General overall testing of CourseComponent API without recursion
EnrolledCoursesResponse e = executeStrict(courseAPI.getEnrolledCourses()).get(0);
final String courseId = e.getCourse().getId();
final CourseStructureV1Model model = executeStrict(courseAPI.getCourseStructure(courseId));
final CourseComponent courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
assertNotNull(courseComponent);
assertNotNull(courseComponent.getRoot());
assertEquals(courseId, courseComponent.getCourseId());
List<IBlock> children = courseComponent.getChildren();
assertNotNull(children);
List<CourseComponent> childContainers = new ArrayList<>();
List<CourseComponent> childLeafs = new ArrayList<>();
for (IBlock c : children) {
assertTrue(c instanceof CourseComponent);
final CourseComponent child = (CourseComponent) c;
assertEquals(child, courseComponent.find(new Filter<CourseComponent>() {
@Override
public boolean apply(CourseComponent component) {
return child.getId().equals(component.getId());
}
}));
List<IBlock> grandchildren = child.getChildren();
for (IBlock gc : grandchildren) {
assertTrue(gc instanceof CourseComponent);
final CourseComponent grandchild = (CourseComponent) c;
assertEquals(grandchild, courseComponent.find(new Filter<CourseComponent>() {
@Override
public boolean apply(CourseComponent component) {
return grandchild.getId().equals(component.getId());
}
}));
}
assertNull(child.find(new Filter<CourseComponent>() {
@Override
public boolean apply(CourseComponent component) {
return courseComponent.getId().equals(component.getId());
}
}));
if (child.isContainer()) {
childContainers.add(child);
} else {
childLeafs.add(child);
}
}
assertEquals(childContainers, courseComponent.getChildContainers());
assertEquals(childLeafs, courseComponent.getChildLeafs());
assertTrue(courseComponent.isLastChild());
int childrenSize = children.size();
assertTrue(childrenSize > 0);
assertTrue(((CourseComponent) children.get(childrenSize - 1)).isLastChild());
BlockType blockType = courseComponent.getType();
assertSame(courseComponent, courseComponent.getAncestor(Integer.MAX_VALUE));
assertSame(courseComponent, courseComponent.getAncestor(EnumSet.of(blockType)));
List<VideoBlockModel> videos = courseComponent.getVideos();
assertNotNull(videos);
for (HasDownloadEntry video : videos) {
assertNotNull(video);
assertTrue(video instanceof CourseComponent);
CourseComponent videoComponent = (CourseComponent) video;
assertFalse(videoComponent.isContainer());
assertEquals(BlockType.VIDEO, videoComponent.getType());
}
for (BlockType type : BlockType.values()) {
EnumSet<BlockType> typeSet = EnumSet.of(type);
List<CourseComponent> typeComponents = new ArrayList<>();
courseComponent.fetchAllLeafComponents(typeComponents, typeSet);
for (CourseComponent typeComponent : typeComponents) {
assertEquals(type, typeComponent.getType());
verifyModelParsing(typeComponent);
}
if (type != blockType) {
assertNotSame(courseComponent, courseComponent.getAncestor(EnumSet.of(type)));
}
}
BlockPath path = courseComponent.getPath();
assertNotNull(path);
assertEquals(1, path.getPath().size());
assertSame(courseComponent, path.get(0));
List<CourseComponent> leafComponents = new ArrayList<>();
courseComponent.fetchAllLeafComponents(leafComponents, EnumSet.allOf(BlockType.class));
for (CourseComponent leafComponent : leafComponents) {
BlockPath leafPath = leafComponent.getPath();
assertNotNull(leafPath);
int pathSize = leafPath.getPath().size();
assertTrue(pathSize > 1);
CourseComponent component = leafComponent;
for (int i = pathSize - 1; i >= 0; i--) {
assertSame(component, leafPath.get(i));
component = component.getParent();
}
}
}
Aggregations