GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Tests for logs and other test improvements to boost coverage · semtle/java-sdk@e79c4c0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • conversation/src/test/java/com/ibm/watson/developer_cloud/conversation/v1
    • ConversationServiceIT.java
    • ConversationTest.java
    • ValuesIT.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎conversation/src/test/java/com/ibm/watson/developer_cloud/conversation/v1/ConversationServiceIT.java‎

Copy file name to clipboardExpand all lines: conversation/src/test/java/com/ibm/watson/developer_cloud/conversation/v1/ConversationServiceIT.java
+252-4Lines changed: 252 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
import static org.junit.Assert.assertEquals;
1616
import static org.junit.Assert.assertNotEquals;
1717
import static org.junit.Assert.assertNotNull;
18+
import static org.junit.Assert.assertNull;
1819
import static org.junit.Assert.assertTrue;
1920
import static org.junit.Assert.fail;
2021

22+
import java.text.DateFormat;
23+
import java.text.SimpleDateFormat;
2124
import java.util.ArrayList;
2225
import java.util.Date;
2326
import java.util.HashMap;
@@ -36,6 +39,9 @@
3639
import com.ibm.watson.developer_cloud.conversation.v1.model.IntentCollectionResponse;
3740
import com.ibm.watson.developer_cloud.conversation.v1.model.IntentExportResponse;
3841
import com.ibm.watson.developer_cloud.conversation.v1.model.IntentResponse;
42+
import com.ibm.watson.developer_cloud.conversation.v1.model.ListLogsOptions;
43+
import com.ibm.watson.developer_cloud.conversation.v1.model.LogCollectionResponse;
44+
import com.ibm.watson.developer_cloud.conversation.v1.model.LogExportResponse;
3945
import com.ibm.watson.developer_cloud.conversation.v1.model.UpdateWorkspace;
4046
import com.ibm.watson.developer_cloud.conversation.v1.model.WorkspaceCollectionResponse;
4147
import com.ibm.watson.developer_cloud.conversation.v1.model.WorkspaceExportResponse;
@@ -63,6 +69,8 @@ public class ConversationServiceIT extends WatsonServiceTest {
6369
protected String workspaceId;
6470
private String exampleIntent;
6571

72+
DateFormat isoDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
73+
6674
/*
6775
* (non-Javadoc)
6876
*
@@ -301,6 +309,52 @@ public void testListCounterexamples() {
301309
}
302310
}
303311

312+
/**
313+
* Test listCounterexamples with paging.
314+
*/
315+
@Test
316+
public void testListCounterexamplesWithPaging() {
317+
318+
String counterExampleText1 = "alpha" + UUID.randomUUID().toString(); // gotta be unique
319+
String counterExampleText2 = "zeta" + UUID.randomUUID().toString(); // gotta be unique
320+
321+
// Add two counterexamples
322+
service.createCounterexample(workspaceId, counterExampleText1).execute();
323+
service.createCounterexample(workspaceId, counterExampleText2).execute();
324+
325+
try {
326+
CounterexampleCollectionResponse response =
327+
service.listCounterexamples(workspaceId, 1L, null, "text", null).execute();
328+
assertNotNull(response);
329+
assertNotNull(response.getPagination());
330+
assertNotNull(response.getPagination().getRefreshUrl());
331+
assertNotNull(response.getPagination().getNextUrl());
332+
assertNotNull(response.getPagination().getCursor());
333+
334+
boolean found1 = false, found2 = false;
335+
while (true) {
336+
assertNotNull(response.getCounterexamples());
337+
assertTrue(response.getCounterexamples().size() == 1);
338+
found1 |= response.getCounterexamples().get(0).getText().equals(counterExampleText1);
339+
found2 |= response.getCounterexamples().get(0).getText().equals(counterExampleText2);
340+
assertTrue(found1 || !found2); // verify sort
341+
if (response.getPagination().getCursor() == null) {
342+
break;
343+
}
344+
String cursor = response.getPagination().getCursor();
345+
response = service.listCounterexamples(workspaceId, 1L, null, "text", cursor).execute();
346+
}
347+
348+
assertTrue(found1 && found2);
349+
} catch (Exception ex) {
350+
fail(ex.getMessage());
351+
} finally {
352+
// Clean up
353+
service.deleteCounterexample(workspaceId, counterExampleText1).execute();
354+
service.deleteCounterexample(workspaceId, counterExampleText2).execute();
355+
}
356+
}
357+
304358
/**
305359
* Test updateCounterexample.
306360
*/
@@ -491,6 +545,54 @@ public void testListExamples() {
491545

492546
}
493547

548+
/**
549+
* Test listExamples with paging.
550+
*/
551+
@Test
552+
public void testListExamplesWithPaging() {
553+
554+
createExampleIntent();
555+
556+
String exampleText1 = "Alpha " + UUID.randomUUID().toString(); // gotta be unique
557+
String exampleText2 = "Zeta " + UUID.randomUUID().toString(); // gotta be unique
558+
service.createExample(workspaceId, exampleIntent, exampleText1).execute();
559+
service.createExample(workspaceId, exampleIntent, exampleText2).execute();
560+
561+
try {
562+
ExampleCollectionResponse response =
563+
service.listExamples(workspaceId, exampleIntent, 1L, null, "-text", null).execute();
564+
assertNotNull(response);
565+
assertNotNull(response.getExamples());
566+
assertNotNull(response.getPagination());
567+
assertNotNull(response.getPagination().getRefreshUrl());
568+
assertNotNull(response.getPagination().getNextUrl());
569+
assertNotNull(response.getPagination().getCursor());
570+
571+
boolean found1 = false, found2 = false;
572+
while (true) {
573+
assertNotNull(response.getExamples());
574+
assertTrue(response.getExamples().size() == 1);
575+
found1 |= response.getExamples().get(0).getText().equals(exampleText1);
576+
found2 |= response.getExamples().get(0).getText().equals(exampleText2);
577+
assertTrue(found2 || !found1); // verify sort
578+
if (response.getPagination().getCursor() == null) {
579+
break;
580+
}
581+
String cursor = response.getPagination().getCursor();
582+
response = service.listExamples(workspaceId, exampleIntent, 1L, null, "-text", cursor).execute();
583+
}
584+
assertTrue(found1 && found2);
585+
586+
} catch (Exception ex) {
587+
fail(ex.getMessage());
588+
} finally {
589+
// Clean up
590+
service.deleteExample(workspaceId, exampleIntent, exampleText1).execute();
591+
service.deleteExample(workspaceId, exampleIntent, exampleText2).execute();
592+
}
593+
594+
}
595+
494596
/**
495597
* Test updateExample.
496598
*/
@@ -585,14 +687,13 @@ public void testCreateIntent() {
585687
public void testDeleteIntent() {
586688

587689
String intentName = "Hello" + UUID.randomUUID().toString(); // gotta be unique
588-
String intentDescription = "Description of " + intentName;
589690

590-
service.createIntent(workspaceId, intentName, intentDescription, null).execute();
691+
service.createIntent(workspaceId, intentName, null, null).execute();
591692

592693
service.deleteIntent(workspaceId, intentName).execute();
593694

594695
try {
595-
service.getIntent(workspaceId, intentName, false).execute();
696+
service.getIntent(workspaceId, intentName, null).execute();
596697
fail("deleteIntent failed");
597698
} catch (Exception ex) {
598699
// Expected result
@@ -658,7 +759,7 @@ public void testListIntents() {
658759
String intentName = "Hello" + UUID.randomUUID().toString(); // gotta be unique
659760

660761
try {
661-
IntentCollectionResponse response = service.listIntents(workspaceId, false, null, null, null, null).execute();
762+
IntentCollectionResponse response = service.listIntents(workspaceId, null, null, null, null, null).execute();
662763
assertNotNull(response);
663764
assertNotNull(response.getIntents());
664765
assertNotNull(response.getPagination());
@@ -713,6 +814,54 @@ public void testListIntents() {
713814
}
714815
}
715816

817+
/**
818+
* Test listIntents with paging.
819+
*/
820+
@Test
821+
public void testListIntentsWithPaging() {
822+
823+
String intentName1 = "First" + UUID.randomUUID().toString(); // gotta be unique
824+
String intentName2 = "Second" + UUID.randomUUID().toString(); // gotta be unique
825+
826+
service.createIntent(workspaceId, intentName1, null, null).execute();
827+
service.createIntent(workspaceId, intentName2, null, null).execute();
828+
829+
try {
830+
IntentCollectionResponse response =
831+
service.listIntents(workspaceId, true, 1L, null, "modified", null).execute();
832+
assertNotNull(response);
833+
assertNotNull(response.getIntents());
834+
assertNotNull(response.getPagination());
835+
assertNotNull(response.getPagination().getRefreshUrl());
836+
assertNotNull(response.getPagination().getNextUrl());
837+
assertNotNull(response.getPagination().getCursor());
838+
839+
boolean found1 = false, found2 = false;
840+
while (true) {
841+
assertNotNull(response.getIntents());
842+
assertTrue(response.getIntents().size() == 1);
843+
found1 |= response.getIntents().get(0).getIntent().equals(intentName1);
844+
found2 |= response.getIntents().get(0).getIntent().equals(intentName2);
845+
assertTrue(found1 || !found2); // verify sort
846+
if (response.getPagination().getCursor() == null) {
847+
break;
848+
}
849+
String cursor = response.getPagination().getCursor();
850+
response = service.listIntents(workspaceId, true, 1L, null, "modified", cursor).execute();
851+
852+
}
853+
assertTrue(found1 && found2);
854+
855+
856+
} catch (Exception ex) {
857+
fail(ex.getMessage());
858+
} finally {
859+
// Clean up
860+
service.deleteIntent(workspaceId, intentName1).execute();
861+
service.deleteIntent(workspaceId, intentName2).execute();
862+
}
863+
}
864+
716865
/**
717866
* Test updateIntent.
718867
*/
@@ -1003,6 +1152,36 @@ public void testListWorkspaces() {
10031152
assertNotNull(wResponse.getDescription());
10041153
}
10051154

1155+
/**
1156+
* Test listWorkspaces with paging.
1157+
*/
1158+
@Test
1159+
public void testListWorkspacesWithPaging() {
1160+
1161+
WorkspaceCollectionResponse response =
1162+
service.listWorkspaces(1L, null, "-modified", null).execute();
1163+
1164+
assertNotNull(response);
1165+
assertNotNull(response.getPagination());
1166+
assertNotNull(response.getPagination().getRefreshUrl());
1167+
assertNotNull(response.getPagination().getNextUrl());
1168+
assertNotNull(response.getPagination().getCursor());
1169+
1170+
boolean found = false;
1171+
while (true) {
1172+
assertNotNull(response.getWorkspaces());
1173+
assertTrue(response.getWorkspaces().size() == 1);
1174+
found |= response.getWorkspaces().get(0).getWorkspaceId().equals(workspaceId);
1175+
if (response.getPagination().getCursor() == null) {
1176+
break;
1177+
}
1178+
String cursor = response.getPagination().getCursor();
1179+
response = service.listWorkspaces(1L, null, "-modified", cursor).execute();
1180+
}
1181+
1182+
assertTrue(found);
1183+
}
1184+
10061185
/**
10071186
* Test updateWorkspace.
10081187
*/
@@ -1039,4 +1218,73 @@ public void testUpdateWorkspace() {
10391218
service.deleteCounterexample(workspaceId, counterExampleText).execute();
10401219
}
10411220
}
1221+
1222+
/**
1223+
* Test listLogs.
1224+
*/
1225+
@Test
1226+
public void testListLogs() {
1227+
1228+
try {
1229+
ListLogsOptions listOptions = new ListLogsOptions.Builder()
1230+
.workspaceId(workspaceId)
1231+
.build();
1232+
LogCollectionResponse response = service.listLogs(listOptions).execute();
1233+
assertNotNull(response);
1234+
assertNotNull(response.getLogs());
1235+
assertNotNull(response.getPagination());
1236+
// Empirically -- no refresh_url in pagination of listLogs
1237+
// assertNotNull(response.getPagination().getRefreshUrl());
1238+
// nextUrl may be null
1239+
if (response.getPagination().getNextUrl() == null) {
1240+
assertNull(response.getPagination().getCursor());
1241+
} else {
1242+
assertNotNull(response.getPagination().getCursor());
1243+
}
1244+
} catch (Exception ex) {
1245+
fail(ex.getMessage());
1246+
}
1247+
}
1248+
1249+
/**
1250+
* Test listLogs with pagination.
1251+
*/
1252+
@Test
1253+
public void testListLogsWithPaging() {
1254+
1255+
try {
1256+
ListLogsOptions.Builder listOptionsBuilder = new ListLogsOptions.Builder(workspaceId);
1257+
listOptionsBuilder.sort("-request_timestamp");
1258+
listOptionsBuilder.filter("request.input.text:wipers");
1259+
listOptionsBuilder.pageLimit(1L);
1260+
1261+
LogCollectionResponse response = service.listLogs(listOptionsBuilder.build()).execute();
1262+
assertNotNull(response);
1263+
assertNotNull(response.getLogs());
1264+
assertNotNull(response.getPagination());
1265+
// Empirically -- no refresh_url in pagination of listLogs
1266+
// assertNotNull(response.getPagination().getRefreshUrl());
1267+
assertNotNull(response.getPagination().getNextUrl());
1268+
assertNotNull(response.getPagination().getCursor());
1269+
1270+
assertTrue(response.getLogs().size() == 1);
1271+
LogExportResponse logEntry1 = response.getLogs().get(0);
1272+
1273+
String cursor = response.getPagination().getCursor();
1274+
response = service.listLogs(listOptionsBuilder.cursor(cursor).build()).execute();
1275+
1276+
assertNotNull(response.getLogs());
1277+
assertTrue(response.getLogs().size() == 1);
1278+
1279+
LogExportResponse logEntry2 = response.getLogs().get(0);
1280+
1281+
Date requestDate1 = isoDateFormat.parse(logEntry1.getRequestTimestamp());
1282+
Date requestDate2 = isoDateFormat.parse(logEntry2.getRequestTimestamp());
1283+
1284+
assertTrue(requestDate2.before(requestDate1));
1285+
1286+
} catch (Exception ex) {
1287+
fail(ex.getMessage());
1288+
}
1289+
}
10421290
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.