@@ -51,6 +51,10 @@ public class NaturalLanguageUnderstandingTest extends WatsonServiceUnitTest {
5151 private static final String ANALYZE_PATH = "/v1/analyze?version=2018-11-16" ;
5252 private static final String RESOURCE = "src/test/resources/natural_language_understanding/" ;
5353
54+ private static final String TEXT = "text" ;
55+ private static final Long LOCATION = 0L ;
56+ private static final Double CONFIDENCE = 0.5 ;
57+
5458 private ListModelsResults models ;
5559 private AnalysisResults analyzeResults ;
5660 private String modelId ;
@@ -76,69 +80,7 @@ public void setUp() throws Exception {
7680 analyzeResults = loadFixture (RESOURCE + "analyze.json" , AnalysisResults .class );
7781 }
7882
79- /**
80- * Test analyze.
81- *
82- * @throws InterruptedException the interrupted exception
83- * @throws FileNotFoundException
84- */
85- @ Test
86- public void testAnalyze () throws InterruptedException , FileNotFoundException {
87- String testHtmlFileName = RESOURCE + "testArticle.html" ;
88- String html = getStringFromInputStream (new FileInputStream (testHtmlFileName ));
89-
90- ConceptsOptions concepts = new ConceptsOptions .Builder ()
91- .limit (5 )
92- .build ();
93- assertEquals (concepts .limit (), 5 , 0 );
94- concepts .newBuilder ();
95-
96- Features features = new Features .Builder ().concepts (concepts ).build ();
97- AnalyzeOptions parameters = new AnalyzeOptions .Builder ().html (html ).features (features ).build ();
98-
99- server .enqueue (jsonResponse (analyzeResults ));
100- final AnalysisResults response = service .analyze (parameters ).execute ().getResult ();
101- final RecordedRequest request = server .takeRequest ();
102-
103- assertEquals (ANALYZE_PATH , request .getPath ());
104- assertEquals ("POST" , request .getMethod ());
105- assertEquals (analyzeResults , response );
106- assertNotNull (analyzeResults .getAnalyzedText ());
107- assertNotNull (analyzeResults .getSentiment ());
108- assertNotNull (analyzeResults .getLanguage ());
109- assertNotNull (analyzeResults .getEntities ());
110- assertNotNull (analyzeResults .getEmotion ());
111- assertNotNull (analyzeResults .getConcepts ());
112- assertNotNull (analyzeResults .getCategories ());
113- assertEquals (analyzeResults .getCategories ().get (0 ).getExplanation ().getRelevantText ().get (0 ).getText (),
114- response .getCategories ().get (0 ).getExplanation ().getRelevantText ().get (0 ).getText ());
115- assertNotNull (analyzeResults .getKeywords ());
116- assertNotNull (analyzeResults .getMetadata ());
117- assertNotNull (analyzeResults .getSemanticRoles ());
118- assertNotNull (analyzeResults .getRetrievedUrl ());
119- assertNotNull (analyzeResults .getRelations ());
120- assertNotNull (analyzeResults .getSyntax ());
121- assertNotNull (analyzeResults .getUsage ());
122- }
123-
124- /**
125- * Test analyze with null parameters. Test different constructor
126- *
127- * @throws InterruptedException the interrupted exception
128- */
129- @ Test
130- public void testAnalyzeNullParams () throws InterruptedException {
131- server .enqueue (jsonResponse (analyzeResults ));
132- Features features = new Features .Builder ().concepts (null ).categories (null ).emotion (null )
133- .entities (null ).keywords (null ).metadata (null ).relations (null ).semanticRoles (null ).sentiment (null ).build ();
134- AnalyzeOptions .Builder builder = new AnalyzeOptions .Builder ().features (features );
135- final AnalysisResults response = service .analyze (builder .build ()).execute ().getResult ();
136- final RecordedRequest request = server .takeRequest ();
137-
138- assertEquals (ANALYZE_PATH , request .getPath ());
139- assertEquals ("POST" , request .getMethod ());
140- assertEquals (analyzeResults , response );
141- }
83+ // --- MODELS ---
14284
14385 /**
14486 * Test some of the model constructors. pump up the code coverage numbers
@@ -239,6 +181,76 @@ public void testModelOptions() throws InterruptedException {
239181 sentimentOptions .newBuilder ();
240182 }
241183
184+ // --- METHODS ---
185+
186+ /**
187+ * Test analyze.
188+ *
189+ * @throws InterruptedException the interrupted exception
190+ * @throws FileNotFoundException
191+ */
192+ @ Test
193+ public void testAnalyze () throws InterruptedException , FileNotFoundException {
194+ String testHtmlFileName = RESOURCE + "testArticle.html" ;
195+ String html = getStringFromInputStream (new FileInputStream (testHtmlFileName ));
196+
197+ ConceptsOptions concepts = new ConceptsOptions .Builder ()
198+ .limit (5 )
199+ .build ();
200+ assertEquals (concepts .limit (), 5 , 0 );
201+ concepts .newBuilder ();
202+
203+ Features features = new Features .Builder ().concepts (concepts ).build ();
204+ AnalyzeOptions parameters = new AnalyzeOptions .Builder ().html (html ).features (features ).build ();
205+
206+ server .enqueue (jsonResponse (analyzeResults ));
207+ final AnalysisResults response = service .analyze (parameters ).execute ().getResult ();
208+ final RecordedRequest request = server .takeRequest ();
209+
210+ assertEquals (ANALYZE_PATH , request .getPath ());
211+ assertEquals ("POST" , request .getMethod ());
212+ assertEquals (analyzeResults , response );
213+ assertNotNull (analyzeResults .getAnalyzedText ());
214+ assertNotNull (analyzeResults .getSentiment ());
215+ assertNotNull (analyzeResults .getLanguage ());
216+ assertNotNull (analyzeResults .getEntities ());
217+ assertNotNull (analyzeResults .getEmotion ());
218+ assertNotNull (analyzeResults .getConcepts ());
219+ assertNotNull (analyzeResults .getCategories ());
220+ assertEquals (analyzeResults .getCategories ().get (0 ).getExplanation ().getRelevantText ().get (0 ).getText (),
221+ response .getCategories ().get (0 ).getExplanation ().getRelevantText ().get (0 ).getText ());
222+ assertNotNull (analyzeResults .getKeywords ());
223+ assertNotNull (analyzeResults .getMetadata ());
224+ assertNotNull (analyzeResults .getSemanticRoles ());
225+ assertNotNull (analyzeResults .getRetrievedUrl ());
226+ assertNotNull (analyzeResults .getRelations ());
227+ assertNotNull (analyzeResults .getSyntax ());
228+ assertNotNull (analyzeResults .getUsage ());
229+ assertEquals (CONFIDENCE , analyzeResults .getEntities ().get (0 ).getConfidence ());
230+ assertEquals (TEXT , analyzeResults .getEntities ().get (0 ).getMentions ().get (0 ).getText ());
231+ assertEquals (LOCATION , analyzeResults .getEntities ().get (0 ).getMentions ().get (0 ).getLocation ().get (0 ));
232+ assertEquals (CONFIDENCE , analyzeResults .getEntities ().get (0 ).getMentions ().get (0 ).getConfidence ());
233+ }
234+
235+ /**
236+ * Test analyze with null parameters. Test different constructor
237+ *
238+ * @throws InterruptedException the interrupted exception
239+ */
240+ @ Test
241+ public void testAnalyzeNullParams () throws InterruptedException {
242+ server .enqueue (jsonResponse (analyzeResults ));
243+ Features features = new Features .Builder ().concepts (null ).categories (null ).emotion (null )
244+ .entities (null ).keywords (null ).metadata (null ).relations (null ).semanticRoles (null ).sentiment (null ).build ();
245+ AnalyzeOptions .Builder builder = new AnalyzeOptions .Builder ().features (features );
246+ final AnalysisResults response = service .analyze (builder .build ()).execute ().getResult ();
247+ final RecordedRequest request = server .takeRequest ();
248+
249+ assertEquals (ANALYZE_PATH , request .getPath ());
250+ assertEquals ("POST" , request .getMethod ());
251+ assertEquals (analyzeResults , response );
252+ }
253+
242254 /**
243255 * Test get models.
244256 *
0 commit comments