use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class CourseDetailFragment method openCourseDashboard.
/**
* Open course dashboard for given course from the enrollments list cache.
*/
private void openCourseDashboard() {
try {
List<EnrolledCoursesResponse> enrolledCoursesResponse = executeStrict(courseApi.getEnrolledCoursesFromCache());
for (EnrolledCoursesResponse course : enrolledCoursesResponse) {
if (course.getCourse().getId().equals(courseDetail.course_id)) {
environment.getRouter().showMyCourses(getActivity());
environment.getRouter().showCourseDashboardTabs(getActivity(), environment.getConfig(), course, false);
}
}
} catch (Exception exception) {
logger.debug(exception.toString());
Toast.makeText(getContext(), R.string.cannot_show_dashboard, Toast.LENGTH_SHORT).show();
}
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse 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();
}
}
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class ApiTests method testEnrollInACourse.
// TODO: Debug and fix test failure
@Ignore
@Test
public void testEnrollInACourse() throws Exception {
login();
print("test: Enroll in a course");
EnrolledCoursesResponse e = executeStrict(courseAPI.getEnrolledCourses()).get(0);
String courseId = e.getCourse().getId();
executeStrict(courseService.enrollInACourse(new CourseService.EnrollBody(courseId, true)));
print("success");
print("test: finished: reset password");
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class CourseUnitNavigationActivityTest method getIntent.
/**
* {@inheritDoc}
*/
@Override
protected Intent getIntent() {
EnrolledCoursesResponse courseData;
try {
courseData = executeStrict(courseAPI.getEnrolledCourses()).get(0);
} catch (Exception e) {
throw new RuntimeException(e);
}
String courseId = courseData.getCourse().getId();
CourseStructureV1Model model;
CourseComponent courseComponent;
try {
model = executeStrict(courseAPI.getCourseStructure(courseId));
courseComponent = (CourseComponent) CourseAPI.normalizeCourseStructure(model, courseId);
} catch (Exception e) {
throw new RuntimeException(e);
}
List<CourseComponent> leafComponents = new ArrayList<>();
courseComponent.fetchAllLeafComponents(leafComponents, EnumSet.allOf(BlockType.class));
CourseComponent courseUnit = leafComponents.get(0);
Intent intent = super.getIntent();
Bundle extras = new Bundle();
extras.putSerializable(Router.EXTRA_COURSE_DATA, courseData);
extras.putString(Router.EXTRA_COURSE_COMPONENT_ID, courseUnit.getId());
intent.putExtra(Router.EXTRA_BUNDLE, extras);
return intent;
}
use of org.edx.mobile.model.api.EnrolledCoursesResponse in project edx-app-android by edx.
the class CourseUnitNavigationActivityTest method testUnitFragmentCreation.
/**
* Testing creation of various fragments in the {@link CourseUnitNavigationActivity}'s
* ViewPager, by supplying its {@link CourseUnitPagerAdapter} with all possible
* {@link CourseComponent} models.
*/
@Test
public void testUnitFragmentCreation() {
FragmentManager fragmentManager = Mockito.mock(FragmentManager.class);
EnrolledCoursesResponse courseData = Mockito.mock(EnrolledCoursesResponse.class);
CourseUnitFragment.HasComponent hasComponent = Mockito.mock(CourseUnitFragment.HasComponent.class);
List<CourseComponent> unitList = new ArrayList<>();
List<Class<? extends CourseUnitFragment>> classesList = new ArrayList<>();
VideoBlockModel encodeVideosModel = Mockito.mock(VideoBlockModel.class);
VideoData videoData = Mockito.mock(VideoData.class);
videoData.encodedVideos = Mockito.mock(EncodedVideos.class);
when(videoData.encodedVideos.getPreferredVideoInfo()).thenReturn(Mockito.mock(VideoInfo.class));
when(encodeVideosModel.getData()).thenReturn(videoData);
unitList.add(encodeVideosModel);
classesList.add(CourseUnitVideoFragment.class);
VideoBlockModel youtubeVideosModel = Mockito.mock(VideoBlockModel.class);
VideoData videoData2 = Mockito.mock(VideoData.class);
videoData2.encodedVideos = Mockito.mock(EncodedVideos.class);
when(videoData2.encodedVideos.getYoutubeVideoInfo()).thenReturn(Mockito.mock(VideoInfo.class));
when(youtubeVideosModel.getData()).thenReturn(videoData2);
unitList.add(youtubeVideosModel);
classesList.add(CourseUnitOnlyOnYoutubeFragment.class);
DiscussionBlockModel discussionModel = Mockito.mock(DiscussionBlockModel.class);
unitList.add(discussionModel);
if (config.isDiscussionsEnabled()) {
classesList.add(CourseUnitDiscussionFragment.class);
} else {
classesList.add(CourseUnitMobileNotSupportedFragment.class);
}
CourseComponent nonMultiDeviceModel = Mockito.mock(CourseComponent.class);
when(nonMultiDeviceModel.isMultiDevice()).thenReturn(false);
unitList.add(nonMultiDeviceModel);
classesList.add(CourseUnitMobileNotSupportedFragment.class);
HtmlBlockModel htmlModel = Mockito.mock(HtmlBlockModel.class);
when(htmlModel.isMultiDevice()).thenReturn(true);
when(htmlModel.getType()).thenReturn(BlockType.HTML);
unitList.add(htmlModel);
classesList.add(CourseUnitWebViewFragment.class);
CourseComponent unknownModel = Mockito.mock(CourseComponent.class);
when(unknownModel.isMultiDevice()).thenReturn(true);
when(unknownModel.getType()).thenReturn(BlockType.COURSE);
unitList.add(unknownModel);
classesList.add(CourseUnitEmptyFragment.class);
CourseComponent problemModel = Mockito.mock(CourseComponent.class);
when(problemModel.isMultiDevice()).thenReturn(true);
when(problemModel.getType()).thenReturn(BlockType.PROBLEM);
unitList.add(problemModel);
classesList.add(CourseUnitMobileNotSupportedFragment.class);
CourseComponent othersModel = Mockito.mock(CourseComponent.class);
when(othersModel.isMultiDevice()).thenReturn(true);
when(othersModel.getType()).thenReturn(BlockType.OTHERS);
unitList.add(othersModel);
classesList.add(CourseUnitMobileNotSupportedFragment.class);
CourseUnitPagerAdapter adapter = new CourseUnitPagerAdapter(fragmentManager, config, unitList, courseData, hasComponent);
for (int size = unitList.size(), i = 0; i < size; i++) {
assertThat(adapter.getItem(i)).isInstanceOf(classesList.get(i));
}
}
Aggregations