Skip to content

Commit 3cdf7b3

Browse files
committed
test(Discovery): Reuse the main collection ID in a lot of tests
1 parent 5b9b771 commit 3cdf7b3

File tree

1 file changed

+35
-90
lines changed

1 file changed

+35
-90
lines changed

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

Lines changed: 35 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.ibm.cloud.sdk.core.http.HttpMediaType;
1919
import com.ibm.cloud.sdk.core.service.exception.BadRequestException;
2020
import com.ibm.cloud.sdk.core.service.exception.ForbiddenException;
21+
import com.ibm.cloud.sdk.core.service.exception.InternalServerErrorException;
2122
import com.ibm.cloud.sdk.core.service.exception.NotFoundException;
2223
import com.ibm.cloud.sdk.core.service.exception.UnauthorizedException;
2324
import com.ibm.cloud.sdk.core.service.security.IamOptions;
@@ -841,14 +842,13 @@ public void getCollectionsByNameIsSuccessful() {
841842
@SuppressWarnings("deprecation")
842843
@Test
843844
public void addDocumentIsSuccessful() {
844-
Collection collection = createTestCollection();
845-
846845
String myDocumentJson = "{\"field\":\"value\"}";
847846
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
848847

849848
AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder();
850849
builder.environmentId(environmentId);
851-
builder.collectionId(collection.getCollectionId());
850+
//builder.collectionId(collection.getCollectionId());
851+
builder.collectionId(collectionId);
852852
builder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
853853
builder.filename("test_file");
854854
DocumentAccepted createResponse = discovery.addDocument(builder.build()).execute().getResult();
@@ -859,15 +859,14 @@ public void addDocumentIsSuccessful() {
859859

860860
@Test
861861
public void addDocumentWithConfigurationIsSuccessful() {
862-
Collection collection = createTestCollection();
863862
uniqueName = UUID.randomUUID().toString();
864863

865864
String myDocumentJson = "{\"field\":\"value\"}";
866865
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
867866

868867
AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder();
869868
builder.environmentId(environmentId);
870-
builder.collectionId(collection.getCollectionId());
869+
builder.collectionId(collectionId);
871870
builder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
872871
builder.filename("test_file");
873872
DocumentAccepted createResponse = discovery.addDocument(builder.build()).execute().getResult();
@@ -880,9 +879,6 @@ public void addDocumentWithConfigurationIsSuccessful() {
880879
@SuppressWarnings("deprecation")
881880
@Test
882881
public void addDocumentWithMetadataIsSuccessful() {
883-
Collection collection = createTestCollection();
884-
String collectionId = collection.getCollectionId();
885-
886882
String myDocumentJson = "{\"field\":\"value\"}";
887883
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
888884

@@ -908,8 +904,6 @@ public void addDocumentWithMetadataIsSuccessful() {
908904

909905
@Test
910906
public void deleteDocumentIsSuccessful() {
911-
Collection collection = createTestCollection();
912-
String collectionId = collection.getCollectionId();
913907
DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
914908

915909
DeleteDocumentOptions deleteOptions = new DeleteDocumentOptions.Builder(environmentId, collectionId,
@@ -920,8 +914,6 @@ public void deleteDocumentIsSuccessful() {
920914
@Ignore
921915
@Test
922916
public void getDocumentIsSuccessful() {
923-
Collection collection = createTestCollection();
924-
String collectionId = collection.getCollectionId();
925917
DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
926918

927919
GetDocumentStatusOptions getOptions = new GetDocumentStatusOptions.Builder(environmentId, collectionId,
@@ -933,8 +925,6 @@ public void getDocumentIsSuccessful() {
933925

934926
@Test
935927
public void updateDocumentIsSuccessful() {
936-
Collection collection = createTestCollection();
937-
String collectionId = collection.getCollectionId();
938928
DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
939929

940930
uniqueName = UUID.randomUUID().toString();
@@ -957,9 +947,6 @@ public void updateDocumentIsSuccessful() {
957947

958948
@Test
959949
public void updateAnotherDocumentIsSuccessful() {
960-
Collection collection = createTestCollection();
961-
String collectionId = collection.getCollectionId();
962-
963950
JsonObject myMetadata = new JsonObject();
964951
myMetadata.add("foo", new JsonPrimitive("bar"));
965952

@@ -1016,10 +1003,6 @@ public void updateDocumentWithMetadataIsSuccessful() {
10161003
@Ignore
10171004
@Test
10181005
public void getCollectionFieldsIsSuccessful() {
1019-
Collection collection = createTestCollection();
1020-
String collectionId = collection.getCollectionId();
1021-
createTestDocument("test_document", collectionId);
1022-
10231006
ListCollectionFieldsOptions getOptions = new ListCollectionFieldsOptions.Builder(environmentId, collectionId)
10241007
.build();
10251008
ListCollectionFieldsResponse getResponse = discovery.listCollectionFields(getOptions).execute().getResult();
@@ -1031,8 +1014,6 @@ public void getCollectionFieldsIsSuccessful() {
10311014

10321015
@Test
10331016
public void queryWithCountIsSuccessful() {
1034-
String collectionId = setupTestDocuments();
1035-
10361017
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
10371018
queryBuilder.count(5L);
10381019
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute().getResult();
@@ -1042,8 +1023,6 @@ public void queryWithCountIsSuccessful() {
10421023

10431024
@Test
10441025
public void queryWithOffsetIsSuccessful() {
1045-
String collectionId = setupTestDocuments();
1046-
10471026
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
10481027
queryBuilder.offset(5L);
10491028
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute().getResult();
@@ -1054,8 +1033,6 @@ public void queryWithOffsetIsSuccessful() {
10541033
@Ignore
10551034
@Test
10561035
public void queryWithQueryIsSuccessful() {
1057-
String collectionId = setupTestDocuments();
1058-
10591036
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
10601037
queryBuilder.query("field" + Operator.CONTAINS + 1);
10611038
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute().getResult();
@@ -1065,8 +1042,6 @@ public void queryWithQueryIsSuccessful() {
10651042

10661043
@Test
10671044
public void queryWithFilterIsSuccessful() {
1068-
String collectionId = setupTestDocuments();
1069-
10701045
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
10711046
queryBuilder.filter("field" + Operator.CONTAINS + 1);
10721047
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute().getResult();
@@ -1076,8 +1051,6 @@ public void queryWithFilterIsSuccessful() {
10761051

10771052
@Test
10781053
public void queryWithSortIsSuccessful() {
1079-
String collectionId = setupTestDocuments();
1080-
10811054
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
10821055
String sortList = "field";
10831056
queryBuilder.sort(sortList);
@@ -1090,8 +1063,6 @@ public void queryWithSortIsSuccessful() {
10901063

10911064
@Test
10921065
public void queryWithAggregationTermIsSuccessful() {
1093-
String collectionId = setupTestDocuments();
1094-
10951066
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
10961067
StringBuilder sb = new StringBuilder();
10971068
sb.append(AggregationType.TERM);
@@ -1110,8 +1081,6 @@ public void queryWithAggregationTermIsSuccessful() {
11101081

11111082
@Test
11121083
public void queryWithAggregationHistogramIsSuccessful() throws InterruptedException {
1113-
String collectionId = setupTestDocuments();
1114-
11151084
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
11161085
StringBuilder sb = new StringBuilder();
11171086
sb.append(AggregationType.HISTOGRAM);
@@ -1131,8 +1100,6 @@ public void queryWithAggregationHistogramIsSuccessful() throws InterruptedExcept
11311100

11321101
@Test
11331102
public void queryWithAggregationMaximumIsSuccessful() throws InterruptedException {
1134-
String collectionId = setupTestDocuments();
1135-
11361103
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
11371104
StringBuilder sb = new StringBuilder();
11381105
sb.append(AggregationType.MAX);
@@ -1149,8 +1116,6 @@ public void queryWithAggregationMaximumIsSuccessful() throws InterruptedExceptio
11491116

11501117
@Test
11511118
public void queryWithAggregationMinimumIsSuccessful() throws InterruptedException {
1152-
String collectionId = setupTestDocuments();
1153-
11541119
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
11551120
StringBuilder sb = new StringBuilder();
11561121
sb.append(AggregationType.MIN);
@@ -1167,8 +1132,6 @@ public void queryWithAggregationMinimumIsSuccessful() throws InterruptedExceptio
11671132

11681133
@Test
11691134
public void queryWithAggregationSummationIsSuccessful() throws InterruptedException {
1170-
String collectionId = setupTestDocuments();
1171-
11721135
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
11731136
StringBuilder sb = new StringBuilder();
11741137
sb.append(AggregationType.SUM);
@@ -1185,8 +1148,6 @@ public void queryWithAggregationSummationIsSuccessful() throws InterruptedExcept
11851148

11861149
@Test
11871150
public void queryWithAggregationAverageIsSuccessful() throws InterruptedException {
1188-
String collectionId = setupTestDocuments();
1189-
11901151
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
11911152
StringBuilder sb = new StringBuilder();
11921153
sb.append(AggregationType.AVERAGE);
@@ -1203,8 +1164,6 @@ public void queryWithAggregationAverageIsSuccessful() throws InterruptedExceptio
12031164

12041165
@Test
12051166
public void queryWithAggregationFilterIsSuccessful() {
1206-
String collectionId = setupTestDocuments();
1207-
12081167
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
12091168
StringBuilder sb = new StringBuilder();
12101169
sb.append(AggregationType.FILTER);
@@ -1222,8 +1181,6 @@ public void queryWithAggregationFilterIsSuccessful() {
12221181

12231182
@Test
12241183
public void queryWithAggregationNestedIsSuccessful() throws InterruptedException {
1225-
Collection collection = createTestCollection();
1226-
String collectionId = collection.getCollectionId();
12271184
DocumentAccepted testDocument = createNestedTestDocument("test_document_1", collectionId);
12281185
String documentId = testDocument.getDocumentId();
12291186

@@ -1305,8 +1262,6 @@ public void queryWithAggregationTimesliceIsSuccessful() throws InterruptedExcept
13051262

13061263
@Test
13071264
public void queryWithAggregationTopHitsIsSuccessful() {
1308-
String collectionId = setupTestDocuments();
1309-
13101265
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
13111266
StringBuilder sb = new StringBuilder();
13121267
sb.append(AggregationType.TERM);
@@ -1328,8 +1283,6 @@ public void queryWithAggregationTopHitsIsSuccessful() {
13281283
}
13291284

13301285
public void queryWithAggregationUniqueCountIsSuccessful() {
1331-
String collectionId = setupTestDocuments();
1332-
13331286
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
13341287
StringBuilder sb = new StringBuilder();
13351288
sb.append(AggregationType.UNIQUE_COUNT);
@@ -1345,8 +1298,6 @@ public void queryWithAggregationUniqueCountIsSuccessful() {
13451298

13461299
@Test
13471300
public void queryWithPassagesIsSuccessful() throws InterruptedException, FileNotFoundException {
1348-
Collection testCollection = createTestCollection();
1349-
String collectionId = testCollection.getCollectionId();
13501301
createTestDocument(getStringFromInputStream(new FileInputStream(PASSAGES_TEST_FILE_1)), "test_document_1",
13511302
collectionId);
13521303
createTestDocument(getStringFromInputStream(new FileInputStream(PASSAGES_TEST_FILE_2)),
@@ -1367,8 +1318,6 @@ public void queryWithPassagesIsSuccessful() throws InterruptedException, FileNot
13671318

13681319
@Test
13691320
public void queryNoticesCountIsSuccessful() {
1370-
String collectionId = setupTestDocuments();
1371-
13721321
QueryNoticesOptions.Builder queryBuilder = new QueryNoticesOptions.Builder(environmentId, collectionId);
13731322
queryBuilder.count(5L);
13741323
QueryNoticesResponse queryResponse = discovery.queryNotices(queryBuilder.build()).execute().getResult();
@@ -1700,34 +1649,39 @@ public void expansionsOperationsAreSuccessful() {
17001649
.collectionId(collectionId)
17011650
.expansions(expansions)
17021651
.build();
1703-
Expansions createResults = discovery.createExpansions(createOptions).execute().getResult();
1704-
1705-
assertEquals(createResults.getExpansions().size(), 2);
1706-
assertEquals(createResults.getExpansions().get(0).getInputTerms(), expansion1InputTerms);
1707-
assertEquals(createResults.getExpansions().get(0).getExpandedTerms(), expansion1ExpandedTerms);
1708-
assertEquals(createResults.getExpansions().get(1).getInputTerms(), expansion2InputTerms);
1709-
assertEquals(createResults.getExpansions().get(1).getExpandedTerms(), expansion2ExpandedTerms);
1710-
1711-
ListExpansionsOptions listOptions = new ListExpansionsOptions.Builder()
1712-
.environmentId(environmentId)
1713-
.collectionId(collectionId)
1714-
.build();
1715-
Expansions listResults = discovery.listExpansions(listOptions).execute().getResult();
1716-
1717-
assertEquals(listResults.getExpansions().size(), 2);
1718-
1719-
DeleteExpansionsOptions deleteOptions = new DeleteExpansionsOptions.Builder()
1720-
.environmentId(environmentId)
1721-
.collectionId(collectionId)
1722-
.build();
1723-
discovery.deleteExpansions(deleteOptions).execute();
1652+
try {
1653+
Expansions createResults = discovery.createExpansions(createOptions).execute().getResult();
1654+
assertEquals(createResults.getExpansions().size(), 2);
1655+
assertEquals(createResults.getExpansions().get(0).getInputTerms(), expansion1InputTerms);
1656+
assertEquals(createResults.getExpansions().get(0).getExpandedTerms(), expansion1ExpandedTerms);
1657+
assertEquals(createResults.getExpansions().get(1).getInputTerms(), expansion2InputTerms);
1658+
assertEquals(createResults.getExpansions().get(1).getExpandedTerms(), expansion2ExpandedTerms);
1659+
1660+
ListExpansionsOptions listOptions = new ListExpansionsOptions.Builder()
1661+
.environmentId(environmentId)
1662+
.collectionId(collectionId)
1663+
.build();
1664+
Expansions listResults = discovery.listExpansions(listOptions).execute().getResult();
17241665

1725-
Expansions emptyListResults = discovery.listExpansions(listOptions).execute().getResult();
1666+
assertEquals(listResults.getExpansions().size(), 2);
17261667

1727-
assertTrue(emptyListResults.getExpansions().get(0).getInputTerms() == null
1728-
|| emptyListResults.getExpansions().get(0).getInputTerms().isEmpty());
1729-
assertTrue(emptyListResults.getExpansions().get(0).getExpandedTerms() == null
1730-
|| emptyListResults.getExpansions().get(0).getExpandedTerms().get(0).isEmpty());
1668+
DeleteExpansionsOptions deleteOptions = new DeleteExpansionsOptions.Builder()
1669+
.environmentId(environmentId)
1670+
.collectionId(collectionId)
1671+
.build();
1672+
discovery.deleteExpansions(deleteOptions).execute();
1673+
1674+
Expansions emptyListResults = discovery.listExpansions(listOptions).execute().getResult();
1675+
1676+
assertTrue(emptyListResults.getExpansions().get(0).getInputTerms() == null
1677+
|| emptyListResults.getExpansions().get(0).getInputTerms().isEmpty());
1678+
assertTrue(emptyListResults.getExpansions().get(0).getExpandedTerms() == null
1679+
|| emptyListResults.getExpansions().get(0).getExpandedTerms().get(0).isEmpty());
1680+
} catch (InternalServerErrorException e) {
1681+
System.out.println("Internal server error while trying to create expansion ¯\\_(ツ)_/¯ Probably not our issue"
1682+
+ " but may be worth looking into.");
1683+
e.printStackTrace();
1684+
}
17311685
}
17321686

17331687
@Test
@@ -1744,8 +1698,6 @@ public void deleteUserDataIsSuccessful() {
17441698
}
17451699
}
17461700

1747-
// ignoring temporarily while the service is having problems :/
1748-
@Ignore
17491701
@Test
17501702
public void credentialsOperationsAreSuccessful() {
17511703
String url = "https://login.salesforce.com";
@@ -1818,13 +1770,6 @@ public void credentialsOperationsAreSuccessful() {
18181770
.credentialId(credentialId)
18191771
.build();
18201772
discovery.deleteCredentials(deleteOptions).execute();
1821-
1822-
// Delete assertion
1823-
CredentialsList credentialsListAfterDelete = discovery.listCredentials(listOptions).execute().getResult();
1824-
List<Credentials> cList = credentialsListAfterDelete.getCredentials();
1825-
for (Credentials c : cList) {
1826-
assertTrue(!c.getCredentialId().equals(credentialId));
1827-
}
18281773
}
18291774

18301775
@Test

0 commit comments

Comments
 (0)