Open SaptarshiSarkar12 opened 2 months ago
Meanwhile you can also discuss about the project in our Discord Server 😀
hey im currently working on this issue. Is anybody already working on that?
@JjJjJose Hi José 👋! No one is currently working on this issue. Feel free to work on this issue. I am assigning this task to you. Thank you for your interest 😁.
@SaptarshiSarkar12 hey! Right now im working on the unit tests and the youtube link is done i think, heres a example
it was really a pain in the head ahahaha i will do eventually the instagram and spotify links and make a note for future contributors for the file
@JjJjJose Great 😃. Are you testing the link type? Are you using the LinkType
class?
The outcome looks good and informative which is useful for debugging purposes.
i was using indirectly, actually i was using DownloadConfiguration class. i will use the LinkType class for tests!
and thank you !!! :D Junit is really simple to understand but never got my hands on big projects like that
Yeah, you can use Link type class for that purpose.
Junit is really simple to understand
That's true 😁
...but never got my hands on big projects like that
I hope you would enjoy working in this project on this issue gaining enough experience to work on more such big projects 😃.
really appreciate it 😄
if you have any extra info about the link Type class feel free to comment!
@JjJjJose The class is self explanatory, I suppose. Nothing more to tell 😄. If you don't understand any usage/method, you can comment.
when i try to implement the class the test keeps on a infinite loop, any idea how to fix it?
Show me the code
hello, sorry for the delay i was busy
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import support.DownloadConfiguration;
import support.Job;
import utils.MessageBroker;
import utils.Utility;
import init.Environment;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DownloadConfigurationTest {
private DownloadConfiguration downloadConfiguration;
private Job testJob;
private MessageBroker testMessageBroker;
@BeforeEach
public void setUp() {
testMessageBroker = new MessageBroker()
{
@Override
public void msgLinkInfo(String message)
{
System.out.println("Info: " + message);
}
@Override
public void msgLinkError(String message)
{
System.out.println("Error :" + message);
}
};
//need these things below idk why
Environment.setMessageBroker(testMessageBroker);
Utility.initializeUtility();
/* downloadConfiguration = new DownloadConfiguration("https://example.com", "/downloads", "exampleFile"); */
/**testJob = new Job("https://example.com", "/downloads", "examplefile", null);
testMessageBroker = new MessageBroker() {
// Implement necessary methods if any
};
downloadConfiguration = new DownloadConfiguration("https://example.com", "/downloads", "exampleFile");**/
}
@Test
public void testYoutubeDownload() {
// Simulate the behavior of Utility.getYtDlpMetadata
//String sampleJsonResponse = "{ \"entries\": [{ \"url\": \"https://youtube.com/video1\", \"title\": \"Video 1\" }] }";
downloadConfiguration = new DownloadConfiguration("https://www.youtube.com/video1", "/downloads", "exampleFile");
// Inject the utility instance into the DownloadConfiguration if necessary
// Assuming DownloadConfiguration uses Utility.getYtDlpMetadata internally
int statusCode = downloadConfiguration.fetchFileData();
// Verify the expected behavior
assertEquals(0, statusCode, "The status code should be 0 for successful processing.");
assertEquals(1, downloadConfiguration.getFileCount(), "The file count should be 1.");
assertEquals(1, downloadConfiguration.getFilesProcessed(), "The files processed should be 1.");
assertEquals(1, downloadConfiguration.getFileData().size(), "There should be one file data entry.");
assertEquals("https://youtube.com/video1", downloadConfiguration.getFileData().get(0).get("link"), "The link should match.");
assertEquals("Video 1.mp4", downloadConfiguration.getFileData().get(0).get("filename"), "The filename should match the expected value.");
}
@Test
public void testInstagramDownload()
{
downloadConfiguration = new DownloadConfiguration("https://instagram.com/p/abc123", "/downloads", "exampleFileITG");
int statusCode = downloadConfiguration.fetchFileData();
assertEquals(0, statusCode, "The status code should be 0 for successful processing.");
assertEquals(1, downloadConfiguration.getFileCount(), "The file count should be 1.");
assertEquals(1, downloadConfiguration.getFilesProcessed(), "The files processed should be 1.");
assertEquals(1, downloadConfiguration.getFileData().size(), "There should be one file data entry.");
assertEquals("https://instagram.com/p/abc123", downloadConfiguration.getFileData().get(0).get("link"), "The link should match.");
}
@Test
public void testSpotifyDownload()
{
downloadConfiguration = new DownloadConfiguration("https://open.spotify.com/track/abc123", "/downloads", "examplefileSPTF");
int statusCode = downloadConfiguration.fetchFileData();
assertEquals(0, statusCode, "The status code should be 0 for successful processing.");
assertEquals(1, downloadConfiguration.getFileCount(), "The file count should be 1.");
assertEquals(1, downloadConfiguration.getFilesProcessed(), "The files processed should be 1.");
assertEquals(1, downloadConfiguration.getFileData().size(), "There should be one file data entry.");
assertEquals("https://open.spotify.com/track/abc123", downloadConfiguration.getFileData().get(0).get("link"), "The link should match.");
}
@Test
public void testOtherLinkDownload()
{
downloadConfiguration = new DownloadConfiguration("https://sillynessCode.com", "/downloads", "sillyExample");
int statusCode = downloadConfiguration.fetchFileData();
assertEquals(0, statusCode, "The status code should be 0 for successful processing.");
assertEquals(1, downloadConfiguration.getFileCount(), "The file count should be 1.");
assertEquals(1, downloadConfiguration.getFilesProcessed(), "The files processed should be 1.");
assertEquals(1, downloadConfiguration.getFileData().size(), "There should be one file data entry.");
assertEquals("https://sillynessCode.com", downloadConfiguration.getFileData().get(0).get("link"), "The link should match.");
}
}
hello, sorry for the delay i was busy
@JjJjJose it's fine 😃.
From your code, it is clear that you're mixing things up. You are testing DownloadConfiguration
class and the download process in the same test class.
I suggest you to break down the test classes with the minimum work. For example, you can create test classes in Core
module to test the Environment
class, LinkType
class, UnitConverter
class, DownloadConfiguration
class, etc. Then, creating the test classes in CLI
module, for any specific class like you can check if theMessageBroker
passed to CLI isinstanceOf
CLI.MessageBroker
.
You can check this branch to get more idea about the point I'm emphasising. The branch hasn't been updated for a long time and is just a trial of how tests can be integrated in this project. I hope it helps you in understanding the procedure I mentioned. Please let me know if you have understood this or have any question.
oh that helps a lot thanks man! sorry for the trouble ahahaha, i will be looking in the next few days, if i got any questions i post here!
oh that helps a lot thanks man!
Happy to see that my trials are of some help to you 😁.
sorry for the trouble ahahaha
@JjJjJose It's fine 🙂. I should have told earlier 😅.
i will be looking in the next few days, if i got any questions i post here!
Alright 👍.
@JjJjJose How far did you progress? Have you faced any problem? Please let me know :smiley:.
@SaptarshiSarkar12 im studyng for some exams and didnt have time progress it properly, i will look it eventually. sorry
@JjJjJose It's okay. You can take your time. All the best for your exam :smile:.
@JjJjJose Did your exam finish? If yes, how was your exam?
Is your feature request related to a problem? Please describe.
It is a tedious task to check if Drifty can still download all the supported types of files like YouTube, and Instagram videos and Spotify songs along with general files like
https://download.oracle.com/java/22/latest/jdk-22_linux-x64_bin.deb
.Describe the solution you'd like.
Adding multiple separate JUnit tests (I suppose this would suffice; If you think integration testing would be better in some scenario, please let me know) for each download category, batch processing, etc. would be better. Moreover, these tests can then be run on schedule via GitHub Actions allowing automated testing.
Additional information
If anyone wants to work on this issue, please comment below. I would assign this task to you.