Search in sources :

Example 6 with DownloadEntry

use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.

the class DbTests method testgetAllVideos.

@Test
public void testgetAllVideos() throws Exception {
    db.clearDataByUser(username);
    db.getAllVideos(username, new DataCallback<List<VideoModel>>() {

        @Override
        public void onResult(List<VideoModel> result) {
            assertNotNull(result);
            assertTrue("there should not be any video present in cleared database", result.size() == 0);
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
    DownloadEntry de = getDummyVideoModel();
    db.addVideoData(de, null);
    db.getAllVideos(username, new DataCallback<List<VideoModel>>() {

        @Override
        public void onResult(List<VideoModel> result) {
            assertNotNull(result);
            assertTrue(result.size() == 1);
            // assertFalse("something is downloading", result);
            print("result for getAllVideos :" + result.toString());
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
}
Also used : List(java.util.List) VideoModel(org.edx.mobile.model.VideoModel) DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Example 7 with DownloadEntry

use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.

the class DbTests method testgetVideosCountByChapter.

@Test
public void testgetVideosCountByChapter() throws Exception {
    db.clearDataByUser(username);
    String enrollmentId = "enrollmentId";
    String chapter = "chapter";
    db.getVideosCountByChapter(enrollmentId, chapter, new DataCallback<Integer>() {

        @Override
        public void onResult(Integer result) {
            assertTrue(result == 0);
            print("Videos Count By Chapter is: " + result.toString());
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
    DownloadEntry de = getDummyVideoModel();
    de.chapter = "chapter";
    de.eid = "enrollmentId";
    db.addVideoData(de, null);
    db.getVideosCountByChapter(enrollmentId, chapter, new DataCallback<Integer>() {

        @Override
        public void onResult(Integer result) {
            assertTrue(result == 1);
            print("Videos Count By Chapter is: " + result.toString());
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
}
Also used : DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Example 8 with DownloadEntry

use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.

the class DbTests method testDeleteVideo.

@Test
public void testDeleteVideo() throws Exception {
    String videoId = "testVideoId";
    db.clearDataByUser(username);
    DownloadEntry de = getDummyVideoModel();
    de.videoId = videoId;
    Long rowId = db.addVideoData(de, null);
    assertNotNull(rowId);
    assertTrue("Row Id must be non zero positive number", rowId > 0);
    VideoModel video = db.getVideoEntryByVideoId(videoId, null);
    assertNotNull("Should have got one video object", video);
    Integer count = db.deleteVideoByVideoId(video, null);
    assertNotNull(count);
    assertTrue("Should have deleted ONE video only", count == 1);
}
Also used : VideoModel(org.edx.mobile.model.VideoModel) DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Example 9 with DownloadEntry

use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.

the class DbTests method testisVideoDownloadingInSection.

@Test
public void testisVideoDownloadingInSection() throws Exception {
    db.clearDataByUser(username);
    String enrollmentId = "enrollmentId";
    String chapter = "chapter";
    final String section = "section";
    db.isVideoDownloadingInSection(enrollmentId, chapter, section, new DataCallback<Boolean>() {

        @Override
        public void onResult(Boolean result) {
            assertNotNull(result);
            assertFalse("Video should not be downloading in section " + section, result);
            print("got result for Video Downloading In assertfalse " + result.toString());
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
    DownloadEntry de = getDummyVideoModel();
    de.chapter = "chapter";
    de.section = "section";
    de.eid = "enrollmentId";
    db.addVideoData(de, null);
    db.isVideoDownloadingInSection(enrollmentId, chapter, section, new DataCallback<Boolean>() {

        @Override
        public void onResult(Boolean result) {
            assertNotNull(result);
            assertTrue(result);
            // assertFalse("Video should not be downloading in section "+ section, result);
            print("got result for Video Downloading In assertTrue " + result.toString());
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
}
Also used : DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Example 10 with DownloadEntry

use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.

the class DbTests method testgetVideoCountByVideoUrl.

@Test
public void testgetVideoCountByVideoUrl() throws Exception {
    db.clearDataByUser(username);
    String videoUrl = "url";
    db.getVideoCountByVideoUrl(videoUrl, new DataCallback<Integer>() {

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            // assertNull("result should be null", result);
            assertTrue(result == 0);
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
    DownloadEntry de = getDummyVideoModel();
    de.url = "http://fake/url";
    db.addVideoData(de, null);
    db.getVideoCountByVideoUrl(de.url, new DataCallback<Integer>() {

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            assertTrue(result == 1);
            print("Result for testgetVideoCountByVideoUrl is in 1:" + result);
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
}
Also used : DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Aggregations

DownloadEntry (org.edx.mobile.model.db.DownloadEntry)50 Test (org.junit.Test)36 VideoModel (org.edx.mobile.model.VideoModel)10 List (java.util.List)6 HasDownloadEntry (org.edx.mobile.model.course.HasDownloadEntry)4 CourseComponent (org.edx.mobile.model.course.CourseComponent)2 DiscussionBlockModel (org.edx.mobile.model.course.DiscussionBlockModel)2 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)2 WatchedState (org.edx.mobile.model.db.DownloadEntry.WatchedState)2 BulkVideosDownloadCancelledEvent (org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent)2 MenuItem (android.view.MenuItem)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BaseFragmentActivity (org.edx.mobile.base.BaseFragmentActivity)1 BaseVideosDownloadStateActivity (org.edx.mobile.base.BaseVideosDownloadStateActivity)1 BlockPath (org.edx.mobile.model.course.BlockPath)1 IBlock (org.edx.mobile.model.course.IBlock)1 VideoInfo (org.edx.mobile.model.course.VideoInfo)1 DownloadedState (org.edx.mobile.model.db.DownloadEntry.DownloadedState)1