diff --git a/src/test/java/AudioRecorderTest.java b/src/test/java/AudioRecorderTest.java index b5f76f9..e565ee8 100644 --- a/src/test/java/AudioRecorderTest.java +++ b/src/test/java/AudioRecorderTest.java @@ -56,4 +56,5 @@ public void setUp() { // Mockito.verify(targetDataLine).stop(); // Mockito.verify(targetDataLine).close(); // } + } diff --git a/src/test/java/AutoLoginTest.java b/src/test/java/AutoLoginTest.java new file mode 100644 index 0000000..3f07965 --- /dev/null +++ b/src/test/java/AutoLoginTest.java @@ -0,0 +1,48 @@ +import server.MongoDB; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; + +import org.bson.Document; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static com.mongodb.client.model.Filters.eq; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class AutoLoginTest { + private static MongoClient mongoClient; + private static MongoDatabase PantryPalDB; + + @BeforeAll + public static void setUp() { + String testUri = "mongodb+srv://sraswan:pandapanda777@cluster0.fefhkg8.mongodb.net/?retryWrites=true&w=majority"; + mongoClient = MongoClients.create(testUri); + PantryPalDB = mongoClient.getDatabase("PantryPal"); + } + + @Test + public void testAutoLoginSuccess() { + String username = "test"; + String password = "password"; + String userID = server.Account.loginAccount(username, password, false); + assertNotNull((userID)); + } + + @Test + public void testAutoLoginUnsuccessful() { + String username = "testuser"; + String password = "testpasswordd"; + String userID = server.Account.loginAccount(username, password, false); + assertEquals(userID, null); + } + + @Test + public void testLoginE2E() { + testAutoLoginSuccess(); + testAutoLoginUnsuccessful(); + } +} + diff --git a/src/test/java/ChatGPTTest.java b/src/test/java/ChatGPTTest.java index c7af3ac..f076577 100644 --- a/src/test/java/ChatGPTTest.java +++ b/src/test/java/ChatGPTTest.java @@ -41,21 +41,26 @@ public void testGenerateSuccess() throws IOException, InterruptedException, URIS assertEquals(expectedResponse, response); } - // @Test - // public void testHandle() throws IOException, InterruptedException, URISyntaxException { - // String requestText = "Test Prompt"; - // String responseText = "Generated Response"; - // ByteArrayInputStream bis = new ByteArrayInputStream(requestText.getBytes()); - // ByteArrayOutputStream bos = new ByteArrayOutputStream(); - - // when(exchange.getRequestBody()).thenReturn(bis); - // when(exchange.getResponseBody()).thenReturn(bos); - // doReturn(responseText).when(chatGPT).generate(anyString()); - - // chatGPT.handle(exchange); - - // verify(chatGPT, times(1)).generate(requestText); - // String responseBody = bos.toString(); - // assertEquals(responseText, responseBody.trim()); - // } + // @Test + // public void testHandle() throws IOException, InterruptedException, URISyntaxException { + // String requestText = "Test Prompt"; + // String responseText = "Generated Response"; + // ByteArrayInputStream bis = new ByteArrayInputStream(requestText.getBytes()); + // ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + // when(exchange.getRequestBody()).thenReturn(bis); + // when(exchange.getResponseBody()).thenReturn(bos); + // doReturn(responseText).when(chatGPT).generate(anyString()); + + // chatGPT.handle(exchange); + + // verify(chatGPT, times(1)).generate(requestText); + // String responseBody = bos.toString(); + // assertEquals(responseText, responseBody.trim()); + // } + + @Test + public void testChatGPTE2E() throws IOException, InterruptedException, URISyntaxException { + testGenerateSuccess(); + } } diff --git a/src/test/java/CreateAccountTest.java b/src/test/java/CreateAccountTest.java index d94ea74..1cec079 100644 --- a/src/test/java/CreateAccountTest.java +++ b/src/test/java/CreateAccountTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import static com.mongodb.client.model.Filters.and; import static com.mongodb.client.model.Filters.eq; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -24,7 +25,7 @@ public static void setUp() { } @Test - public void testCreateAccount() { + public void testCreateAccountSuccessful() { String username = "testuser"; String password = "testpassword"; server.Account.createAccount(username, password); @@ -34,4 +35,21 @@ public void testCreateAccount() { assertEquals(username, queryDocument.getString("username"), "Username should match"); assertEquals(password, queryDocument.getString("password"), "Password should match"); } + + @Test + public void testCreateAccountUnsuccessful() { + String username = "test"; + String password = "password"; + String output = server.Account.createAccount(username, password); + MongoCollection accountsCollection = PantryPalDB.getCollection("accounts"); + Document queryDocument = accountsCollection.find(and(eq("username", username), eq("password", password))).first(); + assertEquals(queryDocument.toString(), "Document{{_id=65714a6024ebf878f9f2b35e, username=test, password=password}}"); + assertEquals(output, null); + } + + @Test + public void testCreateAccountE2E() { + testCreateAccountSuccessful(); + testCreateAccountUnsuccessful(); + } } \ No newline at end of file diff --git a/src/test/java/FilterTest.java b/src/test/java/FilterByMealTest.java similarity index 94% rename from src/test/java/FilterTest.java rename to src/test/java/FilterByMealTest.java index 8c11a4a..9d014b0 100644 --- a/src/test/java/FilterTest.java +++ b/src/test/java/FilterByMealTest.java @@ -25,7 +25,7 @@ import org.mockito.Mockito; import static org.junit.jupiter.api.Assertions.*; -public class FilterTest extends ApplicationTest { +public class FilterByMealTest extends ApplicationTest { @BeforeAll public static void initJFX() { @@ -44,7 +44,7 @@ public void stop() throws Exception { } @Test - public void filterByOneMealType() { + public void testFilterByOneMealType() { AppFrame mockAppFrame = Mockito.mock(AppFrame.class); RecipeList list = new RecipeList(mockAppFrame); Mockito.when(mockAppFrame.getRecipeList()).thenReturn(list); @@ -90,7 +90,7 @@ public void filterByOneMealType() { } @Test - public void filterByMultiMealType() { + public void testFilterByMultiMealType() { AppFrame mockAppFrame = Mockito.mock(AppFrame.class); RecipeList list = new RecipeList(mockAppFrame); Mockito.when(mockAppFrame.getRecipeList()).thenReturn(list); @@ -138,7 +138,7 @@ public void filterByMultiMealType() { } @Test - public void deselectFilter() { + public void testDeselectFilter() { AppFrame mockAppFrame = Mockito.mock(AppFrame.class); RecipeList list = new RecipeList(mockAppFrame); Mockito.when(mockAppFrame.getRecipeList()).thenReturn(list); @@ -175,4 +175,11 @@ public void deselectFilter() { list.mealOptions.getCheckModel().clearCheck("Breakfast"); assertEquals(0, list.mealOptions.getCheckModel().getCheckedItems().size()); } + + @Test + public void testFilterByMealE2E() { + testFilterByOneMealType(); + testFilterByMultiMealType(); + testDeselectFilter(); + } } diff --git a/src/test/java/ImagePreviewTest.java b/src/test/java/ImagePreviewTest.java index 08adcfc..1ca674b 100644 --- a/src/test/java/ImagePreviewTest.java +++ b/src/test/java/ImagePreviewTest.java @@ -59,7 +59,9 @@ public void testGenerateImage() { assertTrue(recipe.isComplete()); } - - - + @Test + public void testImagePreviewE2E() { + testGenerateImage(); + } + } diff --git a/src/test/java/LoginTest.java b/src/test/java/LoginTest.java index cb13c99..8f29859 100644 --- a/src/test/java/LoginTest.java +++ b/src/test/java/LoginTest.java @@ -25,9 +25,23 @@ public static void setUp() { @Test public void testLoginAccount() { - String username = "testuser"; - String password = "testpassword"; + String username = "test"; + String password = "password"; String userID = server.Account.loginAccount(username, password, false); assertNotNull((userID)); } + + @Test + public void testLoginAccountUnsuccessful() { + String username = "testuser"; + String password = "testpasswordd"; + String userID = server.Account.loginAccount(username, password, false); + assertEquals(userID, null); + } + + @Test + public void testLoginE2E() { + testLoginAccount(); + testLoginAccountUnsuccessful(); + } } \ No newline at end of file diff --git a/src/test/java/RecipeTest.java b/src/test/java/RecipeTest.java index 9cabaac..346fe4a 100644 --- a/src/test/java/RecipeTest.java +++ b/src/test/java/RecipeTest.java @@ -50,15 +50,9 @@ public void testRecipeCompletion() { // assertTrue(recipe.isComplete()); } - /* - * this test case doesn't pass - */ - - // @Test - // public void testRecipeIncomplete() { - // Recipe rec1 = new Recipe(); - // rec1.getName().setText("Chicken Stir-Fry"); - - // assertFalse(rec1.isComplete()); - // } + @Test + public void testRecipeTestE2E() { + testRecipeInitialization(); + testRecipeCompletion(); + } } diff --git a/src/test/java/ShareURLTest.java b/src/test/java/ShareURLTest.java index 9ad9f33..8bb8044 100644 --- a/src/test/java/ShareURLTest.java +++ b/src/test/java/ShareURLTest.java @@ -105,4 +105,10 @@ public void testHandleGet() throws Exception { assertEquals(expectedHtml, capturedOutput); } + @Test + public void testShareURLE2E() throws Exception { + testbuildRecipeUrl(); + testfetchRecipeDetails(); + testHandleGet(); + } } diff --git a/src/test/java/WhisperTest.java b/src/test/java/WhisperTest.java index 391ceb9..fb51541 100644 --- a/src/test/java/WhisperTest.java +++ b/src/test/java/WhisperTest.java @@ -28,4 +28,9 @@ public void testGenerate() { assertNotNull(generatedText); assertEquals(location, generatedText); } + + @Test + public void testWhisperE2E() { + testGenerate(); + } }