Skip to content

Commit 32c9c44

Browse files
committed
don't execute test when OPENAI_TOKEN isn't set
1 parent 28c95c5 commit 32c9c44

16 files changed

+170
-33
lines changed

service/src/test/java/com/launchableinc/openai/service/AssistantFunctionTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,32 @@
2626
import com.launchableinc.openai.threads.Thread;
2727
import com.launchableinc.openai.threads.ThreadRequest;
2828
import com.launchableinc.openai.utils.TikTokensUtil;
29+
import org.junit.jupiter.api.Assumptions;
30+
import org.junit.jupiter.api.BeforeAll;
2931
import org.junit.jupiter.api.Test;
3032

3133
import java.time.Duration;
3234
import java.util.ArrayList;
3335
import java.util.List;
3436
import java.util.Map;
3537

36-
import static org.junit.jupiter.api.Assertions.assertEquals;
3738
import static org.junit.jupiter.api.Assertions.assertNotNull;
3839

3940
class AssistantFunctionTest {
4041

41-
String token = System.getenv("OPENAI_TOKEN");
42-
OpenAiService service = new OpenAiService(token, Duration.ofMinutes(1));
42+
static final private String token = System.getenv("OPENAI_TOKEN");
43+
44+
static OpenAiService service;
45+
46+
@BeforeAll
47+
static void setup() {
48+
Assumptions.assumeTrue(token != null && !token.isEmpty());
49+
service = new OpenAiService(token, Duration.ofMinutes(1));
50+
}
51+
4352

4453
@Test
4554
void createRetrieveRun() throws JsonProcessingException {
46-
4755
ObjectMapper mapper = new ObjectMapper();
4856
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
4957
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

service/src/test/java/com/launchableinc/openai/service/AssistantTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,23 @@
1717
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
1818
public class AssistantTest {
1919

20-
static OpenAiService service = new OpenAiService(System.getenv("OPENAI_TOKEN"));
20+
static final private String token = System.getenv("OPENAI_TOKEN");
21+
2122
static String assistantId;
2223
static String fileId;
2324

25+
static OpenAiService service;
26+
27+
@BeforeAll
28+
static void setup() {
29+
Assumptions.assumeTrue(token != null && !token.isEmpty());
30+
service = new OpenAiService(token);
31+
}
2432

2533
@AfterAll
2634
static void teardown() {
35+
Assumptions.assumeTrue(token != null && !token.isEmpty());
36+
OpenAiService service = new OpenAiService(token);
2737
try {
2838
service.deleteAssistantFile(assistantId, fileId);
2939
} catch (Exception e) {

service/src/test/java/com/launchableinc/openai/service/AudioTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.launchableinc.openai.audio.CreateTranslationRequest;
66
import com.launchableinc.openai.audio.TranscriptionResult;
77
import com.launchableinc.openai.audio.TranslationResult;
8+
import org.junit.jupiter.api.Assumptions;
9+
import org.junit.jupiter.api.BeforeAll;
810
import org.junit.jupiter.api.Test;
911

1012
import java.io.IOException;
@@ -22,8 +24,14 @@ public class AudioTest {
2224

2325
static String koreanAudioFilePath = "src/test/resources/korean-hello.mp3";
2426

25-
String token = System.getenv("OPENAI_TOKEN");
26-
OpenAiService service = new OpenAiService(token, Duration.ofSeconds(30));
27+
static final private String token = System.getenv("OPENAI_TOKEN");
28+
static OpenAiService service;
29+
30+
@BeforeAll
31+
static void setup() {
32+
Assumptions.assumeTrue(token != null && !token.isEmpty());
33+
service = new OpenAiService(token, Duration.ofSeconds(30));
34+
}
2735

2836
@Test
2937
void createTranscription() {

service/src/test/java/com/launchableinc/openai/service/ChatCompletionTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.fasterxml.jackson.databind.JsonNode;
66
import com.fasterxml.jackson.databind.node.ObjectNode;
77
import com.launchableinc.openai.completion.chat.*;
8+
import org.junit.jupiter.api.Assumptions;
9+
import org.junit.jupiter.api.BeforeAll;
810
import org.junit.jupiter.api.Test;
911

1012
import java.util.*;
@@ -13,6 +15,17 @@
1315

1416
class ChatCompletionTest {
1517

18+
static final private String token = System.getenv("OPENAI_TOKEN");
19+
20+
static OpenAiService service;
21+
22+
@BeforeAll
23+
static void setup() {
24+
Assumptions.assumeTrue(token != null && !token.isEmpty());
25+
service = new OpenAiService(token);
26+
}
27+
28+
1629
static class Weather {
1730

1831
@JsonPropertyDescription("City and state, for example: León, Guanajuato")
@@ -42,8 +55,6 @@ public WeatherResponse(String location, WeatherUnit unit, int temperature, Strin
4255
}
4356
}
4457

45-
String token = System.getenv("OPENAI_TOKEN");
46-
OpenAiService service = new OpenAiService(token);
4758

4859
@Test
4960
void createChatCompletion() {

service/src/test/java/com/launchableinc/openai/service/CompletionTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.launchableinc.openai.completion.CompletionChoice;
44
import com.launchableinc.openai.completion.CompletionChunk;
55
import com.launchableinc.openai.completion.CompletionRequest;
6+
import org.junit.jupiter.api.Assumptions;
7+
import org.junit.jupiter.api.BeforeAll;
68
import org.junit.jupiter.api.Test;
79

810
import java.util.ArrayList;
@@ -14,8 +16,16 @@
1416

1517
public class CompletionTest {
1618

17-
String token = System.getenv("OPENAI_TOKEN");
18-
OpenAiService service = new OpenAiService(token);
19+
static final private String token = System.getenv("OPENAI_TOKEN");
20+
21+
static OpenAiService service;
22+
23+
@BeforeAll
24+
static void setup() {
25+
Assumptions.assumeTrue(token != null && !token.isEmpty());
26+
service = new OpenAiService(token);
27+
}
28+
1929

2030
@Test
2131
void createCompletion() {

service/src/test/java/com/launchableinc/openai/service/EditTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
import com.launchableinc.openai.OpenAiHttpException;
44
import com.launchableinc.openai.edit.EditRequest;
55
import com.launchableinc.openai.edit.EditResult;
6+
import org.junit.jupiter.api.Assumptions;
7+
import org.junit.jupiter.api.BeforeAll;
68
import org.junit.jupiter.api.Test;
79

810
import static org.junit.jupiter.api.Assertions.assertNotNull;
911

1012
public class EditTest {
1113

12-
String token = System.getenv("OPENAI_TOKEN");
13-
com.launchableinc.openai.service.OpenAiService service = new OpenAiService(token);
14+
static final private String token = System.getenv("OPENAI_TOKEN");
15+
16+
static OpenAiService service;
17+
18+
@BeforeAll
19+
static void setup() {
20+
Assumptions.assumeTrue(token != null && !token.isEmpty());
21+
service = new OpenAiService(token);
22+
}
1423

1524
@Test
1625
void edit() throws OpenAiHttpException {

service/src/test/java/com/launchableinc/openai/service/EmbeddingTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.launchableinc.openai.embedding.Embedding;
44
import com.launchableinc.openai.embedding.EmbeddingRequest;
5+
import org.junit.jupiter.api.Assumptions;
6+
import org.junit.jupiter.api.BeforeAll;
57
import org.junit.jupiter.api.Test;
68

79
import java.util.Collections;
@@ -12,8 +14,15 @@
1214

1315
public class EmbeddingTest {
1416

15-
String token = System.getenv("OPENAI_TOKEN");
16-
com.launchableinc.openai.service.OpenAiService service = new OpenAiService(token);
17+
static final private String token = System.getenv("OPENAI_TOKEN");
18+
19+
static OpenAiService service;
20+
21+
@BeforeAll
22+
static void setup() {
23+
Assumptions.assumeTrue(token != null && !token.isEmpty());
24+
service = new OpenAiService(token);
25+
}
1726

1827
@Test
1928
void createEmbeddings() {

service/src/test/java/com/launchableinc/openai/service/FileTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.launchableinc.openai.DeleteResult;
44
import com.launchableinc.openai.file.File;
5+
import java.time.Duration;
6+
import org.junit.jupiter.api.Assumptions;
7+
import org.junit.jupiter.api.BeforeAll;
58
import org.junit.jupiter.api.MethodOrderer;
69
import org.junit.jupiter.api.Order;
710
import org.junit.jupiter.api.Test;
@@ -22,9 +25,17 @@ public class FileTest {
2225

2326
static String filePath = "src/test/resources/fine-tuning-data.jsonl";
2427

25-
String token = System.getenv("OPENAI_TOKEN");
26-
OpenAiService service = new OpenAiService(token);
2728
static String fileId;
29+
static final private String token = System.getenv("OPENAI_TOKEN");
30+
31+
static OpenAiService service;
32+
33+
@BeforeAll
34+
static void setup() {
35+
Assumptions.assumeTrue(token != null && !token.isEmpty());
36+
service = new OpenAiService(token);
37+
}
38+
2839

2940
@Test
3041
@Order(1)

service/src/test/java/com/launchableinc/openai/service/FineTuneTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
1515
public class FineTuneTest {
1616

17-
static com.launchableinc.openai.service.OpenAiService service;
17+
18+
static final private String token = System.getenv("OPENAI_TOKEN");
19+
20+
static OpenAiService service;
21+
1822
static String fileId;
1923
static String fineTuneId;
2024

21-
2225
@BeforeAll
2326
static void setup() throws Exception {
24-
String token = System.getenv("OPENAI_TOKEN");
27+
Assumptions.assumeTrue(token != null && !token.isEmpty());
28+
2529
service = new OpenAiService(token);
2630
fileId = service.uploadFile("fine-tune", "src/test/resources/fine-tuning-data.jsonl").getId();
2731

@@ -31,6 +35,7 @@ static void setup() throws Exception {
3135

3236
@AfterAll
3337
static void teardown() {
38+
Assumptions.assumeTrue(token != null && !token.isEmpty());
3439
service.deleteFile(fileId);
3540
}
3641

service/src/test/java/com/launchableinc/openai/service/FineTuningTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
1515
public class FineTuningTest {
1616

17+
static final private String token = System.getenv("OPENAI_TOKEN");
18+
1719
static OpenAiService service;
20+
1821
static String fileId;
1922
static String fineTuningJobId;
2023

2124

2225
@BeforeAll
2326
static void setup() throws Exception {
24-
String token = System.getenv("OPENAI_TOKEN");
27+
Assumptions.assumeTrue(token != null && !token.isEmpty());
28+
2529
service = new OpenAiService(token);
2630
fileId = service.uploadFile("fine-tune", "src/test/resources/chat-fine-tuning-data.jsonl")
2731
.getId();
@@ -32,6 +36,8 @@ static void setup() throws Exception {
3236

3337
@AfterAll
3438
static void teardown() {
39+
Assumptions.assumeTrue(token != null && !token.isEmpty());
40+
3541
try {
3642
service.deleteFile(fileId);
3743
} catch (Exception e) {

0 commit comments

Comments
 (0)