-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Whisper calls for integration tests
- Loading branch information
1 parent
ede6d35
commit d700a81
Showing
8 changed files
with
57 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# CSE 110 Project Team 39 Culinary Companion Crew | ||
PantryPals - the application that provides you with recipes that YOU have currently in your possession! | ||
PantryPals - the application that provides you with recipes that YOU have currently in your possession! | ||
|
||
## How to run the app | ||
1. Clone the repository | ||
2. Change or create a `.vscode/launch.json`, and change the `vmArgs` to point to your JavaFX lib. | ||
3. Run from `Main.java`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...code/client/Model/MockHttpConnection.java → ...rc/test/java/code/MockHttpConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,56 @@ | ||
package code; | ||
|
||
import javafx.scene.control.Label; | ||
|
||
import java.io.*; | ||
import org.junit.jupiter.api.Test; | ||
import java.net.URISyntaxException; | ||
|
||
import code.client.Controllers.AudioRecorder; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import javafx.application.Platform; | ||
import code.client.Model.CustomHttpConnection; | ||
import code.client.Model.WhisperHandler; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
/** | ||
* Work In Progress Voice Retrieval Unit Test | ||
*/ | ||
public class VoiceRetrievalTest { | ||
private AudioRecorder audioRecorder; | ||
private Label recordingLabel; | ||
|
||
@BeforeAll | ||
static void initJfxRuntime() { | ||
Platform.startup(() -> { | ||
}); | ||
} | ||
/* | ||
* Integration Tests | ||
*/ | ||
@Test | ||
void testSuccessfulProcessAudio() throws IOException, URISyntaxException { | ||
CustomHttpConnection connection = new MockHttpConnection(200, | ||
new ByteArrayInputStream("{\"text\":\"Breakfast.\"}".getBytes()), new ByteArrayOutputStream()); | ||
WhisperHandler audioProcessor = new WhisperHandler("API_ENDPOINT", "TOKEN", "MODEL", connection); | ||
String response = audioProcessor.processAudio(); | ||
assertEquals("Breakfast.", response); | ||
|
||
audioProcessor.setHttpConnection(new MockHttpConnection(200, | ||
new ByteArrayInputStream("{\"text\":\"Chicken, cheese.\"}".getBytes()), null)); | ||
response = audioProcessor.processAudio(); | ||
assertEquals("Chicken, cheese.", response); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
recordingLabel = new Label("Recording"); | ||
audioRecorder = new AudioRecorder(recordingLabel); | ||
} | ||
|
||
void testAudioSave() throws InterruptedException { | ||
audioRecorder.startRecording(); | ||
Thread.sleep(1000); | ||
audioRecorder.stopRecording(); | ||
File file = new File("recording.wav"); | ||
assertTrue(file.exists()); | ||
@Test | ||
void testFailedProcessAudio() throws IOException, URISyntaxException { | ||
CustomHttpConnection connection = new MockHttpConnection(404, | ||
new ByteArrayInputStream("Error text".getBytes()), | ||
null); | ||
WhisperHandler audioProcessor = new WhisperHandler("API_ENDPOINT", "TOKEN", "MODEL", connection); | ||
String response = audioProcessor.processAudio(); | ||
assertEquals("Error text", response); | ||
} | ||
|
||
void testLabelChanges() throws InterruptedException { | ||
audioRecorder.startRecording(); | ||
assertTrue(recordingLabel.isVisible()); | ||
Thread.sleep(1000); | ||
/* | ||
* Unit tests | ||
*/ | ||
@Test | ||
void testMockHttpCreation() throws IOException { | ||
CustomHttpConnection connection = new MockHttpConnection(200, new ByteArrayInputStream("hello".getBytes()), | ||
null); | ||
int responseCode = connection.getResponseCode(); | ||
assertEquals(responseCode, 200); | ||
assertEquals(connection.getInputStream(), connection.getErrorStream()); | ||
|
||
audioRecorder.stopRecording(); | ||
assertFalse(recordingLabel.isVisible()); | ||
} | ||
|
||
} |