Skip to content

Commit a7a6332

Browse files
test(discov2): update unit tests for new methods
1 parent a29cb73 commit a7a6332

File tree

56 files changed

+4024
-1010
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4024
-1010
lines changed

discovery/src/test/java/com/ibm/watson/discovery/v2/DiscoveryTest.java

Lines changed: 2034 additions & 877 deletions
Large diffs are not rendered by default.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2022.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package com.ibm.watson.discovery.v2.model;
15+
16+
import static org.testng.Assert.*;
17+
18+
import com.ibm.cloud.sdk.core.service.model.FileWithMetadata;
19+
import com.ibm.watson.discovery.v2.utils.TestUtilities;
20+
import java.io.InputStream;
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import org.testng.annotations.Test;
24+
25+
/** Unit test class for the ClassifierFederatedModel model. */
26+
public class ClassifierFederatedModelTest {
27+
final HashMap<String, InputStream> mockStreamMap = TestUtilities.createMockStreamMap();
28+
final List<FileWithMetadata> mockListFileWithMetadata =
29+
TestUtilities.creatMockListFileWithMetadata();
30+
31+
@Test
32+
public void testClassifierFederatedModel() throws Throwable {
33+
ClassifierFederatedModel classifierFederatedModelModel =
34+
new ClassifierFederatedModel.Builder().field("testString").build();
35+
assertEquals(classifierFederatedModelModel.field(), "testString");
36+
37+
String json = TestUtilities.serialize(classifierFederatedModelModel);
38+
39+
ClassifierFederatedModel classifierFederatedModelModelNew =
40+
TestUtilities.deserialize(json, ClassifierFederatedModel.class);
41+
assertTrue(classifierFederatedModelModelNew instanceof ClassifierFederatedModel);
42+
assertEquals(classifierFederatedModelModelNew.field(), "testString");
43+
}
44+
45+
@Test(expectedExceptions = IllegalArgumentException.class)
46+
public void testClassifierFederatedModelError() throws Throwable {
47+
new ClassifierFederatedModel.Builder().build();
48+
}
49+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2022.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package com.ibm.watson.discovery.v2.model;
15+
16+
import static org.testng.Assert.*;
17+
18+
import com.ibm.cloud.sdk.core.service.model.FileWithMetadata;
19+
import com.ibm.watson.discovery.v2.utils.TestUtilities;
20+
import java.io.InputStream;
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import org.testng.annotations.Test;
24+
25+
/** Unit test class for the ClassifierModelEvaluation model. */
26+
public class ClassifierModelEvaluationTest {
27+
final HashMap<String, InputStream> mockStreamMap = TestUtilities.createMockStreamMap();
28+
final List<FileWithMetadata> mockListFileWithMetadata =
29+
TestUtilities.creatMockListFileWithMetadata();
30+
31+
@Test
32+
public void testClassifierModelEvaluation() throws Throwable {
33+
ClassifierModelEvaluation classifierModelEvaluationModel = new ClassifierModelEvaluation();
34+
assertNull(classifierModelEvaluationModel.getMicroAverage());
35+
assertNull(classifierModelEvaluationModel.getMacroAverage());
36+
assertNull(classifierModelEvaluationModel.getPerClass());
37+
}
38+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2022.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package com.ibm.watson.discovery.v2.model;
15+
16+
import static org.testng.Assert.*;
17+
18+
import com.ibm.cloud.sdk.core.service.model.FileWithMetadata;
19+
import com.ibm.watson.discovery.v2.utils.TestUtilities;
20+
import java.io.InputStream;
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import org.testng.annotations.Test;
24+
25+
/** Unit test class for the CollectionDetailsSmartDocumentUnderstanding model. */
26+
public class CollectionDetailsSmartDocumentUnderstandingTest {
27+
final HashMap<String, InputStream> mockStreamMap = TestUtilities.createMockStreamMap();
28+
final List<FileWithMetadata> mockListFileWithMetadata =
29+
TestUtilities.creatMockListFileWithMetadata();
30+
31+
@Test
32+
public void testCollectionDetailsSmartDocumentUnderstanding() throws Throwable {
33+
CollectionDetailsSmartDocumentUnderstanding collectionDetailsSmartDocumentUnderstandingModel =
34+
new CollectionDetailsSmartDocumentUnderstanding.Builder()
35+
.enabled(true)
36+
.model("custom")
37+
.build();
38+
assertEquals(collectionDetailsSmartDocumentUnderstandingModel.enabled(), Boolean.valueOf(true));
39+
assertEquals(collectionDetailsSmartDocumentUnderstandingModel.model(), "custom");
40+
41+
String json = TestUtilities.serialize(collectionDetailsSmartDocumentUnderstandingModel);
42+
43+
CollectionDetailsSmartDocumentUnderstanding
44+
collectionDetailsSmartDocumentUnderstandingModelNew =
45+
TestUtilities.deserialize(json, CollectionDetailsSmartDocumentUnderstanding.class);
46+
assertTrue(
47+
collectionDetailsSmartDocumentUnderstandingModelNew
48+
instanceof CollectionDetailsSmartDocumentUnderstanding);
49+
assertEquals(
50+
collectionDetailsSmartDocumentUnderstandingModelNew.enabled(), Boolean.valueOf(true));
51+
assertEquals(collectionDetailsSmartDocumentUnderstandingModelNew.model(), "custom");
52+
}
53+
}

discovery/src/test/java/com/ibm/watson/discovery/v2/model/CollectionDetailsTest.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020, 2021.
2+
* (C) Copyright IBM Corp. 2022.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -33,29 +33,35 @@ public void testCollectionDetails() throws Throwable {
3333
CollectionEnrichment collectionEnrichmentModel =
3434
new CollectionEnrichment.Builder()
3535
.enrichmentId("testString")
36-
.fields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")))
36+
.fields(java.util.Arrays.asList("testString"))
3737
.build();
3838
assertEquals(collectionEnrichmentModel.enrichmentId(), "testString");
39-
assertEquals(
40-
collectionEnrichmentModel.fields(),
41-
new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
39+
assertEquals(collectionEnrichmentModel.fields(), java.util.Arrays.asList("testString"));
40+
41+
CollectionDetailsSmartDocumentUnderstanding collectionDetailsSmartDocumentUnderstandingModel =
42+
new CollectionDetailsSmartDocumentUnderstanding.Builder()
43+
.enabled(true)
44+
.model("custom")
45+
.build();
46+
assertEquals(collectionDetailsSmartDocumentUnderstandingModel.enabled(), Boolean.valueOf(true));
47+
assertEquals(collectionDetailsSmartDocumentUnderstandingModel.model(), "custom");
4248

4349
CollectionDetails collectionDetailsModel =
4450
new CollectionDetails.Builder()
4551
.name("testString")
4652
.description("testString")
4753
.language("en")
48-
.enrichments(
49-
new java.util.ArrayList<CollectionEnrichment>(
50-
java.util.Arrays.asList(collectionEnrichmentModel)))
54+
.enrichments(java.util.Arrays.asList(collectionEnrichmentModel))
55+
.smartDocumentUnderstanding(collectionDetailsSmartDocumentUnderstandingModel)
5156
.build();
5257
assertEquals(collectionDetailsModel.name(), "testString");
5358
assertEquals(collectionDetailsModel.description(), "testString");
5459
assertEquals(collectionDetailsModel.language(), "en");
5560
assertEquals(
56-
collectionDetailsModel.enrichments(),
57-
new java.util.ArrayList<CollectionEnrichment>(
58-
java.util.Arrays.asList(collectionEnrichmentModel)));
61+
collectionDetailsModel.enrichments(), java.util.Arrays.asList(collectionEnrichmentModel));
62+
assertEquals(
63+
collectionDetailsModel.smartDocumentUnderstanding(),
64+
collectionDetailsSmartDocumentUnderstandingModel);
5965

6066
String json = TestUtilities.serialize(collectionDetailsModel);
6167

@@ -65,6 +71,9 @@ public void testCollectionDetails() throws Throwable {
6571
assertEquals(collectionDetailsModelNew.name(), "testString");
6672
assertEquals(collectionDetailsModelNew.description(), "testString");
6773
assertEquals(collectionDetailsModelNew.language(), "en");
74+
assertEquals(
75+
collectionDetailsModelNew.smartDocumentUnderstanding().toString(),
76+
collectionDetailsSmartDocumentUnderstandingModel.toString());
6877
}
6978

7079
@Test(expectedExceptions = IllegalArgumentException.class)

discovery/src/test/java/com/ibm/watson/discovery/v2/model/CollectionEnrichmentTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020.
2+
* (C) Copyright IBM Corp. 2022.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -33,12 +33,10 @@ public void testCollectionEnrichment() throws Throwable {
3333
CollectionEnrichment collectionEnrichmentModel =
3434
new CollectionEnrichment.Builder()
3535
.enrichmentId("testString")
36-
.fields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")))
36+
.fields(java.util.Arrays.asList("testString"))
3737
.build();
3838
assertEquals(collectionEnrichmentModel.enrichmentId(), "testString");
39-
assertEquals(
40-
collectionEnrichmentModel.fields(),
41-
new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
39+
assertEquals(collectionEnrichmentModel.fields(), java.util.Arrays.asList("testString"));
4240

4341
String json = TestUtilities.serialize(collectionEnrichmentModel);
4442

discovery/src/test/java/com/ibm/watson/discovery/v2/model/CreateCollectionOptionsTest.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020, 2021.
2+
* (C) Copyright IBM Corp. 2022.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -33,31 +33,38 @@ public void testCreateCollectionOptions() throws Throwable {
3333
CollectionEnrichment collectionEnrichmentModel =
3434
new CollectionEnrichment.Builder()
3535
.enrichmentId("testString")
36-
.fields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")))
36+
.fields(java.util.Arrays.asList("testString"))
3737
.build();
3838
assertEquals(collectionEnrichmentModel.enrichmentId(), "testString");
39-
assertEquals(
40-
collectionEnrichmentModel.fields(),
41-
new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
39+
assertEquals(collectionEnrichmentModel.fields(), java.util.Arrays.asList("testString"));
40+
41+
CollectionDetailsSmartDocumentUnderstanding collectionDetailsSmartDocumentUnderstandingModel =
42+
new CollectionDetailsSmartDocumentUnderstanding.Builder()
43+
.enabled(true)
44+
.model("custom")
45+
.build();
46+
assertEquals(collectionDetailsSmartDocumentUnderstandingModel.enabled(), Boolean.valueOf(true));
47+
assertEquals(collectionDetailsSmartDocumentUnderstandingModel.model(), "custom");
4248

4349
CreateCollectionOptions createCollectionOptionsModel =
4450
new CreateCollectionOptions.Builder()
4551
.projectId("testString")
4652
.name("testString")
4753
.description("testString")
4854
.language("en")
49-
.enrichments(
50-
new java.util.ArrayList<CollectionEnrichment>(
51-
java.util.Arrays.asList(collectionEnrichmentModel)))
55+
.enrichments(java.util.Arrays.asList(collectionEnrichmentModel))
56+
.smartDocumentUnderstanding(collectionDetailsSmartDocumentUnderstandingModel)
5257
.build();
5358
assertEquals(createCollectionOptionsModel.projectId(), "testString");
5459
assertEquals(createCollectionOptionsModel.name(), "testString");
5560
assertEquals(createCollectionOptionsModel.description(), "testString");
5661
assertEquals(createCollectionOptionsModel.language(), "en");
5762
assertEquals(
5863
createCollectionOptionsModel.enrichments(),
59-
new java.util.ArrayList<CollectionEnrichment>(
60-
java.util.Arrays.asList(collectionEnrichmentModel)));
64+
java.util.Arrays.asList(collectionEnrichmentModel));
65+
assertEquals(
66+
createCollectionOptionsModel.smartDocumentUnderstanding(),
67+
collectionDetailsSmartDocumentUnderstandingModel);
6168
}
6269

6370
@Test(expectedExceptions = IllegalArgumentException.class)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2022.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package com.ibm.watson.discovery.v2.model;
15+
16+
import static org.testng.Assert.*;
17+
18+
import com.ibm.cloud.sdk.core.service.model.FileWithMetadata;
19+
import com.ibm.watson.discovery.v2.utils.TestUtilities;
20+
import java.io.InputStream;
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import org.testng.annotations.Test;
24+
25+
/** Unit test class for the CreateDocumentClassifierModelOptions model. */
26+
public class CreateDocumentClassifierModelOptionsTest {
27+
final HashMap<String, InputStream> mockStreamMap = TestUtilities.createMockStreamMap();
28+
final List<FileWithMetadata> mockListFileWithMetadata =
29+
TestUtilities.creatMockListFileWithMetadata();
30+
31+
@Test
32+
public void testCreateDocumentClassifierModelOptions() throws Throwable {
33+
CreateDocumentClassifierModelOptions createDocumentClassifierModelOptionsModel =
34+
new CreateDocumentClassifierModelOptions.Builder()
35+
.projectId("testString")
36+
.classifierId("testString")
37+
.name("testString")
38+
.description("testString")
39+
.learningRate(Double.valueOf("0"))
40+
.l1RegularizationStrengths(java.util.Arrays.asList(Double.valueOf("1.0E-6")))
41+
.l2RegularizationStrengths(java.util.Arrays.asList(Double.valueOf("1.0E-6")))
42+
.trainingMaxSteps(Long.valueOf("0"))
43+
.improvementRatio(Double.valueOf("0"))
44+
.build();
45+
assertEquals(createDocumentClassifierModelOptionsModel.projectId(), "testString");
46+
assertEquals(createDocumentClassifierModelOptionsModel.classifierId(), "testString");
47+
assertEquals(createDocumentClassifierModelOptionsModel.name(), "testString");
48+
assertEquals(createDocumentClassifierModelOptionsModel.description(), "testString");
49+
assertEquals(createDocumentClassifierModelOptionsModel.learningRate(), Double.valueOf("0"));
50+
assertEquals(
51+
createDocumentClassifierModelOptionsModel.l1RegularizationStrengths(),
52+
java.util.Arrays.asList(Double.valueOf("1.0E-6")));
53+
assertEquals(
54+
createDocumentClassifierModelOptionsModel.l2RegularizationStrengths(),
55+
java.util.Arrays.asList(Double.valueOf("1.0E-6")));
56+
assertEquals(createDocumentClassifierModelOptionsModel.trainingMaxSteps(), Long.valueOf("0"));
57+
assertEquals(createDocumentClassifierModelOptionsModel.improvementRatio(), Double.valueOf("0"));
58+
}
59+
60+
@Test(expectedExceptions = IllegalArgumentException.class)
61+
public void testCreateDocumentClassifierModelOptionsError() throws Throwable {
62+
new CreateDocumentClassifierModelOptions.Builder().build();
63+
}
64+
}

0 commit comments

Comments
 (0)