Skip to content

Commit 3cfbfeb

Browse files
committed
NO-JIRA: Add a few unit tests.
1 parent 9a039e6 commit 3cfbfeb

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

examples/src/main/java/com/basistech/rosette/examples/ExampleBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
/**
2626
* Provides examples on how to use the {@link com.basistech.rosette.api.HttpRosetteAPI HttpRosetteAPI}
2727
*/
28+
@SuppressWarnings("java:S106")
2829
public abstract class ExampleBase {
2930
private static final String KEY_PROP_NAME = "rosette.api.key";
3031
private static final String URL_PROP_NAME = "rosette.api.altUrl";
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2022 Basis Technology Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.basistech.rosette.apimodel;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import java.io.ByteArrayInputStream;
22+
import java.io.InputStream;
23+
import java.nio.charset.StandardCharsets;
24+
25+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertNull;
28+
29+
class DocumentRequestTest {
30+
31+
@Test
32+
void getContentString() {
33+
String content = "expected";
34+
DocumentRequest<EntitiesOptions> request = DocumentRequest.<EntitiesOptions>builder()
35+
.content(content)
36+
.build();
37+
assertEquals(content, request.getContent());
38+
assertEquals(content, request.getRawContent());
39+
assertNull(request.getContentBytes());
40+
}
41+
42+
@Test
43+
void getContentBytes() {
44+
String json = "{\"content\": \"My JSON content.\", \"language\": \"eng\"}";
45+
byte[] content = json.getBytes(StandardCharsets.UTF_8);
46+
DocumentRequest<EntitiesOptions> request = DocumentRequest.<EntitiesOptions>builder()
47+
.content(content, "application/json")
48+
.build();
49+
50+
var actualRawContentInputStream = (ByteArrayInputStream) request.getRawContent();
51+
var actualRawContent = actualRawContentInputStream.readAllBytes();
52+
53+
assertArrayEquals(content, actualRawContent);
54+
assertNull(request.getContent());
55+
}
56+
57+
@Test
58+
void getContentInputStream() {
59+
InputStream content = new ByteArrayInputStream("expected".getBytes(StandardCharsets.UTF_8));
60+
DocumentRequest<EntitiesOptions> request = DocumentRequest.<EntitiesOptions>builder()
61+
.content(content, "text/plain")
62+
.build();
63+
assertEquals(content, request.getContentBytes());
64+
assertNull(request.getContent());
65+
assertEquals(content, request.getRawContent());
66+
}
67+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2022 Basis Technology Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.basistech.rosette.apimodel;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import static com.basistech.rosette.apimodel.EntitiesOptions.DEFAULT;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertNotNull;
25+
import static org.junit.jupiter.api.Assertions.assertTrue;
26+
27+
class EntitiesOptionsTest {
28+
29+
@Test
30+
void builderDefaults() {
31+
var entitiesOptions = DEFAULT;
32+
assertNotNull(entitiesOptions);
33+
34+
assertFalse(entitiesOptions.getCalculateConfidence());
35+
assertFalse(entitiesOptions.getCalculateSalience());
36+
assertTrue(entitiesOptions.getLinkEntities());
37+
assertEquals("statistical", entitiesOptions.getModelType());
38+
assertFalse(entitiesOptions.getEnableStructuredRegion());
39+
}
40+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2022 Basis Technology Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.basistech.rosette.apimodel;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import static com.basistech.rosette.apimodel.SentimentOptions.DEFAULT;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
25+
class SentimentOptionsTest {
26+
27+
@Test
28+
void builderDefaults() {
29+
var sentimentOptions = DEFAULT;
30+
assertNotNull(sentimentOptions);
31+
32+
assertFalse(sentimentOptions.getCalculateEntityConfidence());
33+
assertFalse(sentimentOptions.getCalculateEntitySalience());
34+
}
35+
}

0 commit comments

Comments
 (0)