Skip to content

Commit 944f644

Browse files
author
chris-hoefgen
committed
tweaked how fixtures work
1 parent cfd52fd commit 944f644

File tree

4 files changed

+92
-44
lines changed

4 files changed

+92
-44
lines changed

src/test/java/com/devcycle/sdk/server/helpers/LocalConfigServer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.*;
77
import java.net.InetSocketAddress;
8+
import java.nio.charset.StandardCharsets;
89

910
public class LocalConfigServer {
1011
private HttpServer server;
@@ -19,9 +20,10 @@ public LocalConfigServer(String configData) throws IOException{
1920
}
2021

2122
public void handleConfigRequest(HttpExchange exchange) throws IOException {
22-
exchange.sendResponseHeaders(200, configData.length());
23+
byte[] responseData = configData.getBytes(StandardCharsets.UTF_8);
24+
exchange.sendResponseHeaders(200, responseData.length);
2325
OutputStream outputStream = exchange.getResponseBody();
24-
outputStream.write(configData.getBytes());
26+
outputStream.write(responseData);
2527
outputStream.flush();
2628
outputStream.close();
2729
}

src/test/java/com/devcycle/sdk/server/helpers/TestDataFixtures.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
import java.nio.charset.StandardCharsets;
77

88
public class TestDataFixtures {
9-
public static final String SMALL_CONFIG = loadConfigData("fixture_small_config.json");
10-
public static final String LARGE_CONFIG = loadConfigData("fixture_large_config.json");
11-
public static final String SPECIAL_CHARACTERS_CONFIG = loadConfigData("fixture_small_config_special_characters.json");
12-
139
/**
1410
* Loads the config data from the file in the resources folder
1511
* @param fileName name of the file to load
@@ -31,4 +27,17 @@ private static String loadConfigData(String fileName) {
3127
}
3228
return configData;
3329
}
30+
31+
32+
public static String SmallConfig() {
33+
return loadConfigData("fixture_small_config.json");
34+
}
35+
36+
public static String LargeConfig() {
37+
return loadConfigData("fixture_large_config.json");
38+
}
39+
40+
public static String SmallConfigWithSpecialCharacters() {
41+
return loadConfigData("fixture_small_config_special_characters.json");
42+
}
3443
}

src/test/java/com/devcycle/sdk/server/local/DVCLocalClientTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class DVCLocalClientTest {
2323

2424
@BeforeClass
2525
public static void setup() throws Exception {
26-
localConfigServer = new LocalConfigServer(TestDataFixtures.SMALL_CONFIG);
26+
localConfigServer = new LocalConfigServer(TestDataFixtures.SmallConfig());
2727
localConfigServer.start();
2828

2929
DVCLocalOptions options = DVCLocalOptions.builder().configCdnBaseUrl("http://localhost:8000/").configPollingIntervalMS(60000).build();
@@ -38,6 +38,7 @@ public static void setup() throws Exception {
3838

3939
@AfterClass
4040
public static void cleanup() throws Exception {
41+
client.close();
4142
localConfigServer.stop();
4243
}
4344

Lines changed: 73 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,115 @@
11
{
22
"project": {
3+
"_id": "61f97628ff4afcb6d057dbf0",
4+
"key": "emma-project",
5+
"a0_organization": "org_tPyJN5dvNNirKar7",
36
"settings": {
47
"edgeDB": {
58
"enabled": false
69
},
710
"optIn": {
811
"enabled": true,
9-
"title": "Beta Feature Access",
10-
"description": "Get early access to new features below",
11-
"imageURL": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR68cgQT_BTgnhWTdfjUXSN8zM9Vpxgq82dhw&usqp=CAU",
12+
"title": "EarlyAccess",
13+
"description": "Getearlyaccesstobetafeaturesbelow!",
14+
"imageURL": "",
1215
"colors": {
13-
"primary": "#0042f9",
14-
"secondary": "#facc15"
16+
"primary": "#531cd9",
17+
"secondary": "#16dec0"
1518
}
1619
}
17-
},
18-
"a0_organization": "org_NszUFyWBFy7cr95J",
19-
"_id": "6216420c2ea68943c8833c09",
20-
"key": "default"
20+
}
2121
},
2222
"environment": {
23-
"_id": "6216420c2ea68943c8833c0b",
23+
"_id": "61f97628ff4afcb6d057dbf2",
2424
"key": "development"
2525
},
2626
"features": [
2727
{
28-
"_id": "6216422850294da359385e8b",
29-
"key": "test",
28+
"_id": "62fbf6566f1ba302829f9e32",
29+
"key": "a-cool-new-feature",
3030
"type": "release",
3131
"variations": [
3232
{
33+
"key": "variation-on",
34+
"name": "VariationOn",
3335
"variables": [
3436
{
35-
"_var": "6216422850294da359385e8d",
36-
"value": "öé \uD83D\uDC0D \u00A5"
37+
"_var": "62fbf6566f1ba302829f9e34",
38+
"value": true
39+
},
40+
{
41+
"_var": "63125320a4719939fd57cb2b",
42+
"value": "ä variationOff"
3743
}
3844
],
39-
"name": "Variation On",
40-
"key": "variation-on",
41-
"_id": "6216422850294da359385e8f"
45+
"_id": "62fbf6566f1ba302829f9e38"
4246
},
4347
{
48+
"key": "variation-off",
49+
"name": "VariationOff",
4450
"variables": [
4551
{
46-
"_var": "6216422850294da359385e8d",
47-
"value": "ä"
52+
"_var": "62fbf6566f1ba302829f9e34",
53+
"value": false
54+
},
55+
{
56+
"_var": "63125320a4719939fd57cb2b",
57+
"value": "ß variationOn"
4858
}
4959
],
50-
"name": "Variation Off",
51-
"key": "variation-off",
52-
"_id": "6216422850294da359385e90"
60+
"_id": "62fbf6566f1ba302829f9e39"
5361
}
5462
],
5563
"configuration": {
56-
"_id": "621642332ea68943c8833c4a",
64+
"_id": "62fbf6576f1ba302829f9e4d",
5765
"targets": [
5866
{
67+
"_audience": {
68+
"_id": "63125321d31c601f992288b6",
69+
"filters": {
70+
"filters": [
71+
{
72+
"type": "user",
73+
"subType": "email",
74+
"comparator": "=",
75+
"values": [
76+
"giveMeVariationOff@email.com"
77+
],
78+
"filters": []
79+
}
80+
],
81+
"operator": "and"
82+
}
83+
},
5984
"distribution": [
6085
{
61-
"percentage": 0.5,
62-
"_variation": "6216422850294da359385e8f"
63-
},
64-
{
65-
"percentage": 0.5,
66-
"_variation": "6216422850294da359385e90"
86+
"_variation": "62fbf6566f1ba302829f9e38",
87+
"percentage": 1
6788
}
6889
],
90+
"_id": "63125321d31c601f992288bb"
91+
},
92+
{
6993
"_audience": {
70-
"_id": "621642332ea68943c8833c4b",
94+
"_id": "63125321d31c601f992288b7",
7195
"filters": {
72-
"operator": "and",
7396
"filters": [
7497
{
75-
"values": [],
7698
"type": "all",
99+
"values": [],
77100
"filters": []
78101
}
79-
]
102+
],
103+
"operator": "and"
80104
}
81105
},
82-
"_id": "621642332ea68943c8833c4d"
106+
"distribution": [
107+
{
108+
"_variation": "62fbf6566f1ba302829f9e39",
109+
"percentage": 1
110+
}
111+
],
112+
"_id": "63125321d31c601f992288bc"
83113
}
84114
],
85115
"forcedUsers": {}
@@ -88,12 +118,18 @@
88118
],
89119
"variables": [
90120
{
91-
"_id": "6216422850294da359385e8d",
92-
"key": "test",
121+
"_id": "62fbf6566f1ba302829f9e34",
122+
"key": "a-cool-new-feature",
123+
"type": "Boolean"
124+
},
125+
{
126+
"_id": "63125320a4719939fd57cb2b",
127+
"key": "string-var",
93128
"type": "String"
94129
}
95130
],
96131
"variableHashes": {
97-
"test": 2447239932
132+
"a-cool-new-feature": 1868656757,
133+
"string-var": 2413071944
98134
}
99135
}

0 commit comments

Comments
 (0)