Skip to content

Commit fca3304

Browse files
authored
Merge pull request #26 from SlicingDice/bugfix/change-api-key
replace api key by new one
2 parents 4801af0 + 34e3d60 commit fca3304

File tree

6 files changed

+533
-1371
lines changed

6 files changed

+533
-1371
lines changed

src/main/java/com/slicingdice/jslicer/utils/URLResources.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public enum URLResources {
3535
QUERY_DATA_EXTRACTION_RESULT("/data_extraction/result/"),
3636
QUERY_DATA_EXTRACTION_SCORE("/data_extraction/score/"),
3737
DATABASE("/database/"),
38-
QUERY_SQL("/query/sql/");
38+
QUERY_SQL("/sql/");
3939

4040
public final String url;
4141

src/test/java/com/slicingdice/jslicer/RunQueryTests.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
public class RunQueryTests {
77
// Your demo api key, to get a valid demo API key you can use:
88
// http://panel.slicingdice.com/docs/#api-details-api-connection-api-keys-demo-key
9-
private static final String DEMO_API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfX3NhbHQiOiIxN" +
10-
"TE4NjA3ODQ0NDAzIiwicGVybWlzc2lvbl9sZXZlbCI6MywicHJvamVjdF9pZCI6NDY5NjYsImNsaWVudF9pZ" +
11-
"CI6OTUxfQ.S6LCWQDcLS1DEFy3lsqk2jTGIe5rJ5fsQIvWuuFBdkw";
9+
private static final String DEMO_API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfX3NhbHQiOiJkZW1vNzAzM20iLCJwZXJtaXNzaW9uX2xldmVsIjozLCJwcm9qZWN0X2lkIjoyNzAzMywiY2xpZW50X2lkIjoxMH0.8lLB7vDAj8SecpHUsgCyZm4yRoizqggKPRm4Q9BfEu8";
10+
11+
private static String getDemoKey() {
12+
String demoApiKey = System.getenv("SD_API_KEY");
13+
14+
if (demoApiKey == null) {
15+
demoApiKey = DEMO_API_KEY;
16+
}
17+
18+
return demoApiKey;
19+
}
1220

1321
public static void main(final String[] args) throws ExecutionException, InterruptedException {
1422
// the query types to use on tests
1523
final ArrayList<String> queryTypes = new ArrayList<String>() {{
24+
add("sql");
1625
add("count_entity");
1726
add("count_event");
1827
add("top_values");
@@ -22,7 +31,7 @@ public static void main(final String[] args) throws ExecutionException, Interrup
2231
}};
2332

2433
// Testing class with demo API key
25-
final SlicingDiceTester sdTester = new SlicingDiceTester(DEMO_API_KEY, true);
34+
final SlicingDiceTester sdTester = new SlicingDiceTester(getDemoKey(), true);
2635

2736
Runtime.getRuntime().addShutdownHook(new Thread()
2837
{

src/test/java/com/slicingdice/jslicer/SlicingDiceTester.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class SlicingDiceTester {
4141

4242
private boolean perTestInsertion;
4343

44+
private boolean insertSqlData;
45+
4446
public SlicingDiceTester(final String apiKey) {
4547
this.client = new SlicingDice(apiKey);
4648
this.loadConfigTest();
@@ -53,7 +55,7 @@ public SlicingDiceTester(final String apiKey, final boolean verbose) {
5355
}
5456

5557
private void loadConfigTest() {
56-
this.sleepTime = 5;
58+
this.sleepTime = 10;
5759
this.path = "src/test/java/com/slicingdice/jslicer/examples/";
5860
this.fileExtension = ".json";
5961
this.numberOfSuccesses = 0;
@@ -71,7 +73,7 @@ public void runTests(final String queryType) throws ExecutionException, Interrup
7173
final int numberOfTests = testData.length();
7274

7375
this.perTestInsertion = testData.getJSONObject(0).has("insert");
74-
if (!this.perTestInsertion) {
76+
if (!this.perTestInsertion && this.insertSqlData) {
7577
final JSONArray insertionData = this.loadInsertionData(queryType);
7678
for (final Object insertCommand : insertionData) {
7779
this.client.insert((JSONObject) insertCommand).get();
@@ -190,13 +192,13 @@ private void createColumns(final JSONObject columnObject) {
190192
* @param column the column to put timestamp
191193
*/
192194
private void addTimestampToColumnName(final JSONObject column) {
193-
final String oldName = "\"" + column.getString("api-name");
195+
final String oldName = "\"" + column.getString("api-name") + "\"";
194196

195197
final String timestamp = this.getTimestamp();
196198
column.put("name", column.get("name") + timestamp);
197199
column.put("api-name", column.get("api-name") + timestamp);
198200

199-
final String newName = "\"" + column.getString("api-name");
201+
final String newName = "\"" + column.getString("api-name") + "\"";
200202
this.columnTranslation.put(oldName, newName);
201203
}
202204

@@ -365,8 +367,13 @@ private void compareResult(final JSONObject expectedObject, final String queryTy
365367

366368
System.out.println(String.format("\tExpected: \"%1$s\": %2$s", keyStr,
367369
expected.getJSONObject(keyStr).toString()));
368-
System.out.println(String.format("\tResult: \"%1$s\": %2$s", keyStr,
369-
result.getJSONObject(keyStr).toString()));
370+
try {
371+
System.out.println(String.format("\tResult: \"%1$s\": %2$s", keyStr,
372+
result.getJSONObject(keyStr).toString()));
373+
} catch (final Exception e) {
374+
System.out.println(String.format("\tResult: \"%1$s\": %2$s", keyStr,
375+
e.getMessage()));
376+
}
370377
System.out.println("\tStatus: Failed\n");
371378
return;
372379
} else {
@@ -403,7 +410,7 @@ private boolean testSecondTime(final JSONObject expectedObject, final String que
403410
System.out.println("\tStatus: Passed\n");
404411
return true;
405412
}
406-
} catch (ExecutionException | InterruptedException e) {
413+
} catch (final Exception e) {
407414
e.printStackTrace();
408415
}
409416

@@ -497,7 +504,7 @@ private boolean compareJsonValue(final Object valueExpected, final Object valueG
497504
}
498505
return true;
499506
}
500-
} catch (final ClassCastException e) {
507+
} catch (final Exception e) {
501508
return false;
502509
}
503510

0 commit comments

Comments
 (0)