Skip to content

Commit aafed08

Browse files
committed
test(Discovery): Add unit tests for new delete response models
1 parent f25c12d commit aafed08

3 files changed

Lines changed: 47 additions & 18 deletions

File tree

discovery/src/test/java/com/ibm/watson/discovery/v1/DiscoveryServiceTest.java

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@
4242
import com.ibm.watson.discovery.v1.model.CredentialsList;
4343
import com.ibm.watson.discovery.v1.model.DeleteAllTrainingDataOptions;
4444
import com.ibm.watson.discovery.v1.model.DeleteCollectionOptions;
45+
import com.ibm.watson.discovery.v1.model.DeleteCollectionResponse;
4546
import com.ibm.watson.discovery.v1.model.DeleteConfigurationOptions;
47+
import com.ibm.watson.discovery.v1.model.DeleteConfigurationResponse;
48+
import com.ibm.watson.discovery.v1.model.DeleteCredentials;
4649
import com.ibm.watson.discovery.v1.model.DeleteCredentialsOptions;
4750
import com.ibm.watson.discovery.v1.model.DeleteDocumentOptions;
51+
import com.ibm.watson.discovery.v1.model.DeleteDocumentResponse;
4852
import com.ibm.watson.discovery.v1.model.DeleteEnvironmentOptions;
53+
import com.ibm.watson.discovery.v1.model.DeleteEnvironmentResponse;
4954
import com.ibm.watson.discovery.v1.model.DeleteExpansionsOptions;
5055
import com.ibm.watson.discovery.v1.model.DeleteGatewayOptions;
5156
import com.ibm.watson.discovery.v1.model.DeleteStopwordListOptions;
@@ -63,6 +68,7 @@
6368
import com.ibm.watson.discovery.v1.model.FederatedQueryNoticesOptions;
6469
import com.ibm.watson.discovery.v1.model.FederatedQueryOptions;
6570
import com.ibm.watson.discovery.v1.model.Gateway;
71+
import com.ibm.watson.discovery.v1.model.GatewayDelete;
6672
import com.ibm.watson.discovery.v1.model.GatewayList;
6773
import com.ibm.watson.discovery.v1.model.GetCollectionOptions;
6874
import com.ibm.watson.discovery.v1.model.GetConfigurationOptions;
@@ -245,22 +251,22 @@ public class DiscoveryServiceTest extends WatsonServiceUnitTest {
245251
private Environment envResp;
246252
private ListEnvironmentsResponse envsResp;
247253
private Environment createEnvResp;
248-
private Map<String, Object> deleteEnvResp;
254+
private DeleteEnvironmentResponse deleteEnvResp;
249255
private Environment updateEnvResp;
250256
private Configuration createConfResp;
251257
private ListConfigurationsResponse getConfsResp;
252258
private Configuration getConfResp;
253-
private Map<String, Object> deleteConfResp;
259+
private DeleteConfigurationResponse deleteConfResp;
254260
private Configuration updateConfResp;
255261
private Collection createCollResp;
256262
private ListCollectionsResponse getCollsResp;
257263
private Collection getCollResp;
258-
private Map<String, Object> deleteCollResp;
264+
private DeleteCollectionResponse deleteCollResp;
259265
private ListCollectionFieldsResponse listfieldsCollResp;
260266
private DocumentAccepted createDocResp;
261267
private DocumentAccepted updateDocResp;
262268
private DocumentStatus getDocResp;
263-
private Map<String, Object> deleteDocResp;
269+
private DeleteDocumentResponse deleteDocResp;
264270
private QueryResponse queryResp;
265271
private QueryNoticesResponse queryNoticesResp;
266272
private TrainingQuery addTrainingQueryResp;
@@ -274,6 +280,7 @@ public class DiscoveryServiceTest extends WatsonServiceUnitTest {
274280
private Expansions expansionsResp;
275281
private Credentials credentialsResp;
276282
private CredentialsList listCredentialsResp;
283+
private DeleteCredentials deleteCredentialsResp;
277284
private CreateEventResponse createEventResp;
278285
private MetricResponse metricResp;
279286
private MetricTokenResponse metricTokenResp;
@@ -282,6 +289,7 @@ public class DiscoveryServiceTest extends WatsonServiceUnitTest {
282289
private TokenDictStatusResponse tokenDictStatusResponseStopwords;
283290
private Gateway gatewayResponse;
284291
private GatewayList listGatewaysResponse;
292+
private GatewayDelete deleteGatewayResponse;
285293

286294
@BeforeClass
287295
public static void setupClass() {
@@ -312,23 +320,23 @@ public void setup() throws Exception {
312320
envResp = loadFixture(RESOURCE + "get_env_resp.json", Environment.class);
313321
envsResp = loadFixture(RESOURCE + "get_envs_resp.json", ListEnvironmentsResponse.class);
314322
createEnvResp = loadFixture(RESOURCE + "create_env_resp.json", Environment.class);
315-
deleteEnvResp = loadFixture(RESOURCE + "delete_env_resp.json", Map.class);
323+
deleteEnvResp = loadFixture(RESOURCE + "delete_env_resp.json", DeleteEnvironmentResponse.class);
316324
updateEnvResp = loadFixture(RESOURCE + "update_env_resp.json", Environment.class);
317325
createConfResp = loadFixture(RESOURCE + "create_conf_resp.json", Configuration.class);
318326
getConfsResp = loadFixture(RESOURCE + "get_confs_resp.json", ListConfigurationsResponse.class);
319327
getConfResp = loadFixture(RESOURCE + "get_conf_resp.json", Configuration.class);
320-
deleteConfResp = loadFixture(RESOURCE + "delete_conf_resp.json", Map.class);
328+
deleteConfResp = loadFixture(RESOURCE + "delete_conf_resp.json", DeleteConfigurationResponse.class);
321329
updateConfResp = loadFixture(RESOURCE + "update_conf_resp.json", Configuration.class);
322330
createCollResp = loadFixture(RESOURCE + "create_coll_resp.json", Collection.class);
323331
getCollsResp = loadFixture(RESOURCE + "get_coll_resp.json", ListCollectionsResponse.class);
324332
getCollResp = loadFixture(RESOURCE + "get_coll1_resp.json", Collection.class);
325-
deleteCollResp = loadFixture(RESOURCE + "delete_coll_resp.json", Map.class);
333+
deleteCollResp = loadFixture(RESOURCE + "delete_coll_resp.json", DeleteCollectionResponse.class);
326334
listfieldsCollResp
327335
= loadFixture(RESOURCE + "listfields_coll_resp.json", ListCollectionFieldsResponse.class);
328336
createDocResp = loadFixture(RESOURCE + "create_doc_resp.json", DocumentAccepted.class);
329337
updateDocResp = loadFixture(RESOURCE + "update_doc_resp.json", DocumentAccepted.class);
330338
getDocResp = loadFixture(RESOURCE + "get_doc_resp.json", DocumentStatus.class);
331-
deleteDocResp = loadFixture(RESOURCE + "delete_doc_resp.json", Map.class);
339+
deleteDocResp = loadFixture(RESOURCE + "delete_doc_resp.json", DeleteDocumentResponse.class);
332340
queryResp = loadFixture(RESOURCE + "query1_resp.json", QueryResponse.class);
333341
queryNoticesResp = loadFixture(RESOURCE + "query1_resp.json", QueryNoticesResponse.class);
334342
addTrainingQueryResp = loadFixture(RESOURCE + "add_training_query_resp.json", TrainingQuery.class);
@@ -345,6 +353,7 @@ public void setup() throws Exception {
345353
expansionsResp = loadFixture(RESOURCE + "expansions_resp.json", Expansions.class);
346354
credentialsResp = loadFixture(RESOURCE + "credentials_resp.json", Credentials.class);
347355
listCredentialsResp = loadFixture(RESOURCE + "list_credentials_resp.json", CredentialsList.class);
356+
deleteCredentialsResp = loadFixture(RESOURCE + "delete_credentials_resp.json", DeleteCredentials.class);
348357
createEventResp = loadFixture(RESOURCE + "create_event_resp.json", CreateEventResponse.class);
349358
metricResp = loadFixture(RESOURCE + "metric_resp.json", MetricResponse.class);
350359
metricTokenResp = loadFixture(RESOURCE + "metric_token_resp.json", MetricTokenResponse.class);
@@ -355,6 +364,7 @@ public void setup() throws Exception {
355364
TokenDictStatusResponse.class);
356365
gatewayResponse = loadFixture(RESOURCE + "gateway_resp.json", Gateway.class);
357366
listGatewaysResponse = loadFixture(RESOURCE + "list_gateways_resp.json", GatewayList.class);
367+
deleteGatewayResponse = loadFixture(RESOURCE + "delete_gateway_resp.json", GatewayDelete.class);
358368
}
359369

360370
@After
@@ -436,11 +446,13 @@ public void createEnvironmentIsSuccessful() throws InterruptedException {
436446
public void deleteEnvironmentIsSuccessful() throws InterruptedException {
437447
server.enqueue(jsonResponse(deleteEnvResp));
438448
DeleteEnvironmentOptions deleteRequest = new DeleteEnvironmentOptions.Builder(environmentId).build();
439-
discoveryService.deleteEnvironment(deleteRequest).execute().getResult();
449+
DeleteEnvironmentResponse response = discoveryService.deleteEnvironment(deleteRequest).execute().getResult();
440450
RecordedRequest request = server.takeRequest();
441451

442452
assertEquals(ENV1_PATH, request.getPath());
443453
assertEquals(DELETE, request.getMethod());
454+
assertEquals(deleteEnvResp.getEnvironmentId(), response.getEnvironmentId());
455+
assertEquals(deleteEnvResp.getStatus(), response.getStatus());
444456
}
445457

446458
@Test(expected = IllegalArgumentException.class)
@@ -625,11 +637,14 @@ public void deleteConfigurationIsSuccessful() throws InterruptedException {
625637
server.enqueue(jsonResponse(deleteConfResp));
626638
DeleteConfigurationOptions deleteRequest = new DeleteConfigurationOptions.Builder(environmentId, configurationId)
627639
.build();
628-
discoveryService.deleteConfiguration(deleteRequest).execute().getResult();
640+
DeleteConfigurationResponse response = discoveryService.deleteConfiguration(deleteRequest).execute().getResult();
629641
RecordedRequest request = server.takeRequest();
630642

631643
assertEquals(CONF2_PATH, request.getPath());
632644
assertEquals(DELETE, request.getMethod());
645+
assertEquals(deleteConfResp.getConfigurationId(), response.getConfigurationId());
646+
assertEquals(DeleteConfigurationResponse.Status.DELETED, response.getStatus());
647+
assertNotNull(response.getNotices());
633648
}
634649

635650
@Test
@@ -707,11 +722,13 @@ public void listfieldsCollectionIsSuccessful() throws InterruptedException {
707722
public void deleteCollectionIsSuccessful() throws InterruptedException {
708723
server.enqueue(jsonResponse(deleteCollResp));
709724
DeleteCollectionOptions deleteRequest = new DeleteCollectionOptions.Builder(environmentId, collectionId).build();
710-
discoveryService.deleteCollection(deleteRequest).execute().getResult();
725+
DeleteCollectionResponse response = discoveryService.deleteCollection(deleteRequest).execute().getResult();
711726
RecordedRequest request = server.takeRequest();
712727

713728
assertEquals(COLL2_PATH, request.getPath());
714729
assertEquals(DELETE, request.getMethod());
730+
assertEquals(DeleteCollectionResponse.Status.DELETED, response.getStatus());
731+
assertEquals(deleteCollResp.getCollectionId(), response.getCollectionId());
715732
}
716733

717734
// Document tests
@@ -848,11 +865,13 @@ public void deleteDocumentIsSuccessful() throws InterruptedException {
848865
server.enqueue(jsonResponse(deleteDocResp));
849866
DeleteDocumentOptions deleteRequest = new DeleteDocumentOptions.Builder(environmentId, collectionId, documentId)
850867
.build();
851-
discoveryService.deleteDocument(deleteRequest).execute().getResult();
868+
DeleteDocumentResponse response = discoveryService.deleteDocument(deleteRequest).execute().getResult();
852869
RecordedRequest request = server.takeRequest();
853870

854871
assertEquals(DOCS2_PATH, request.getPath());
855872
assertEquals(DELETE, request.getMethod());
873+
assertEquals(deleteDocResp.getDocumentId(), response.getDocumentId());
874+
assertEquals(deleteDocResp.getStatus(), response.getStatus());
856875
}
857876

858877
// Query tests
@@ -1270,18 +1289,19 @@ public void createCredentialsIsSuccessful() throws InterruptedException {
12701289

12711290
@Test
12721291
public void deleteCredentialsIsSuccessful() throws InterruptedException {
1273-
MockResponse desiredResponse = new MockResponse().setResponseCode(200);
1274-
server.enqueue(desiredResponse);
1292+
server.enqueue(jsonResponse(deleteCredentialsResp));
12751293

12761294
DeleteCredentialsOptions options = new DeleteCredentialsOptions.Builder()
12771295
.environmentId(environmentId)
12781296
.credentialId("credential_id")
12791297
.build();
1280-
discoveryService.deleteCredentials(options).execute().getResult();
1298+
DeleteCredentials response = discoveryService.deleteCredentials(options).execute().getResult();
12811299
RecordedRequest request = server.takeRequest();
12821300

12831301
assertEquals(DELETE_CREDENTIALS_PATH, request.getPath());
12841302
assertEquals(DELETE, request.getMethod());
1303+
assertEquals(deleteCredentialsResp.getCredentialId(), response.getCredentialId());
1304+
assertEquals(deleteCredentialsResp.getStatus(), response.getStatus());
12851305
}
12861306

12871307
@Test
@@ -1947,19 +1967,20 @@ public void testDeleteGatewayOptions() {
19471967

19481968
@Test
19491969
public void testDeleteGateway() throws InterruptedException {
1950-
MockResponse desiredResponse = new MockResponse().setResponseCode(200);
1951-
server.enqueue(desiredResponse);
1970+
server.enqueue(jsonResponse(deleteGatewayResponse));
19521971

19531972
String gatewayId = "gateway_id";
19541973

19551974
DeleteGatewayOptions deleteGatewayOptions = new DeleteGatewayOptions.Builder()
19561975
.environmentId(environmentId)
19571976
.gatewayId(gatewayId)
19581977
.build();
1959-
discoveryService.deleteGateway(deleteGatewayOptions).execute().getResult();
1978+
GatewayDelete response = discoveryService.deleteGateway(deleteGatewayOptions).execute().getResult();
19601979
RecordedRequest request = server.takeRequest();
19611980

19621981
assertEquals(DELETE, request.getMethod());
1982+
assertEquals(deleteGatewayResponse.getGatewayId(), response.getGatewayId());
1983+
assertEquals(deleteGatewayResponse.getStatus(), response.getStatus());
19631984
}
19641985

19651986
@Test
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"credential_id": "448e3545-51ca-4530-a03b-6ff282ceac2e",
3+
"status": "deleted"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"gateway_id": "8691f0dd-7181-45b7-81de-5cb16206b3a1",
3+
"status": "deleted"
4+
}

0 commit comments

Comments
 (0)