|
| 1 | +package cloudinary.android.ui; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | + |
| 5 | +import java.util.HashMap; |
| 6 | +import java.util.Map; |
| 7 | + |
| 8 | +import static org.junit.Assert.assertEquals; |
| 9 | + |
| 10 | +import com.cloudinary.android.cldvideoplayer.analytics.models.EventNames; |
| 11 | +import com.cloudinary.android.cldvideoplayer.analytics.models.TrackingType; |
| 12 | +import com.cloudinary.android.cldvideoplayer.analytics.models.VideoEventJSONKeys; |
| 13 | +import com.cloudinary.android.cldvideoplayer.analytics.models.events.VideoLoadMetadata; |
| 14 | +import com.cloudinary.android.cldvideoplayer.analytics.models.events.VideoPauseEvent; |
| 15 | +import com.cloudinary.android.cldvideoplayer.analytics.models.events.VideoPlayEvent; |
| 16 | +import com.cloudinary.android.cldvideoplayer.analytics.models.events.VideoViewEnd; |
| 17 | +import com.cloudinary.android.cldvideoplayer.analytics.models.events.VideoViewStartEvent; |
| 18 | + |
| 19 | +public class VideoEventTests { |
| 20 | + |
| 21 | + @Test |
| 22 | + public void testVideoViewStartEventInitialization() { |
| 23 | + String videoUrl = "https://www.example.com/video.mp4"; |
| 24 | + Map<String, String> trackingData = new HashMap<>(); |
| 25 | + trackingData.put("cloudName", "exampleCloud"); |
| 26 | + trackingData.put("publicId", "abc123"); |
| 27 | + Map<String, Object> providedData = new HashMap<>(); |
| 28 | + providedData.put("key", "value"); |
| 29 | + |
| 30 | + VideoViewStartEvent event = new VideoViewStartEvent(TrackingType.AUTO, videoUrl, trackingData, providedData); |
| 31 | + |
| 32 | + assertEquals(event.eventName, EventNames.VIEW_START.getValue()); |
| 33 | + assertEquals(event.eventDetails.get(VideoEventJSONKeys.TRACKING_TYPE.getValue()), TrackingType.AUTO.getValue()); |
| 34 | + assertEquals(event.eventDetails.get(VideoEventJSONKeys.VIDEO_URL.getValue()), videoUrl); |
| 35 | + |
| 36 | + Map<String, Object> customerData = (Map<String, Object>) event.eventDetails.get(VideoEventJSONKeys.CUSTOMER_DATA.getValue()); |
| 37 | + Map<String, Object> videoData = (Map<String, Object>) customerData.get(VideoEventJSONKeys.VIDEO_DATA.getValue()); |
| 38 | + assertEquals(videoData.get(VideoEventJSONKeys.CLOUD_NAME.getValue()), trackingData.get("cloudName")); |
| 39 | + assertEquals(videoData.get(VideoEventJSONKeys.PUBLIC_ID.getValue()), trackingData.get("publicId")); |
| 40 | + |
| 41 | + Map<String, Object> providedDataObject = (Map<String, Object>) customerData.get(VideoEventJSONKeys.PROVIDED_DATA.getValue()); |
| 42 | + assertEquals(providedDataObject.get("key"), providedData.get("key")); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testVideoLoadMetadataEventInitialization() { |
| 47 | + int duration = 120; |
| 48 | + |
| 49 | + VideoLoadMetadata event = new VideoLoadMetadata(TrackingType.AUTO, duration, null); |
| 50 | + |
| 51 | + assertEquals(event.eventName, EventNames.LOAD_METADATA.getValue()); |
| 52 | + assertEquals(event.eventDetails.get(VideoEventJSONKeys.TRACKING_TYPE.getValue()), TrackingType.AUTO.getValue()); |
| 53 | + assertEquals(event.eventDetails.get(VideoEventJSONKeys.VIDEO_DURATION.getValue()), duration); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testVideoViewEndEventInitialization() { |
| 58 | + Map<String, Object> providedData = new HashMap<>(); |
| 59 | + providedData.put("key", "value"); |
| 60 | + |
| 61 | + VideoViewEnd event = new VideoViewEnd(TrackingType.AUTO, providedData); |
| 62 | + |
| 63 | + assertEquals(event.eventName, EventNames.VIEW_END.getValue()); |
| 64 | + assertEquals(event.eventDetails.get(VideoEventJSONKeys.TRACKING_TYPE.getValue()), TrackingType.AUTO.getValue()); |
| 65 | + Map<String, Object> customerData = (Map<String, Object>) event.eventDetails.get(VideoEventJSONKeys.CUSTOMER_DATA.getValue()); |
| 66 | + assertEquals(customerData.get(VideoEventJSONKeys.PROVIDED_DATA.getValue()), providedData); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void testVideoPlayEventInitialization() { |
| 71 | + Map<String, Object> providedData = new HashMap<>(); |
| 72 | + providedData.put("key", "value"); |
| 73 | + |
| 74 | + VideoPlayEvent event = new VideoPlayEvent(TrackingType.AUTO, providedData); |
| 75 | + |
| 76 | + assertEquals(event.eventName, EventNames.PLAY.getValue()); |
| 77 | + Map<String, Object> customerData = (Map<String, Object>) event.eventDetails.get(VideoEventJSONKeys.CUSTOMER_DATA.getValue()); |
| 78 | + assertEquals(customerData.get(VideoEventJSONKeys.PROVIDED_DATA.getValue()), providedData); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + public void testVideoPauseEventInitialization() { |
| 83 | + Map<String, Object> providedData = new HashMap<>(); |
| 84 | + providedData.put("key", "value"); |
| 85 | + |
| 86 | + VideoPauseEvent event = new VideoPauseEvent(TrackingType.AUTO, providedData); |
| 87 | + |
| 88 | + assertEquals(event.eventName, EventNames.PAUSE.getValue()); |
| 89 | + Map<String, Object> customerData = (Map<String, Object>) event.eventDetails.get(VideoEventJSONKeys.CUSTOMER_DATA.getValue()); |
| 90 | + assertEquals(customerData.get(VideoEventJSONKeys.PROVIDED_DATA.getValue()), providedData); |
| 91 | + } |
| 92 | +} |
0 commit comments