use of com.ibm.watson.speech_to_text.v1.model.AddCorpusOptions in project java-sdk by watson-developer-cloud.
the class SpeechToTextTest method testAddCorpus.
/**
* Test add corpus.
*
* @throws InterruptedException the interrupted exception
* @throws IOException the IO exception
*/
@Test
public void testAddCorpus() throws InterruptedException, IOException {
String id = "foo";
String corpusName = "cName";
File corpusFile = new File("src/test/resources/speech_to_text/corpus-text.txt");
String corpusFileText = new String(Files.readAllBytes(Paths.get(corpusFile.toURI())));
server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{}"));
AddCorpusOptions addOptions = new AddCorpusOptions.Builder().customizationId(id).corpusName(corpusName).corpusFile(corpusFile).corpusFileContentType(HttpMediaType.TEXT_PLAIN).allowOverwrite(true).build();
service.addCorpus(addOptions).execute();
final RecordedRequest request = server.takeRequest();
assertEquals("POST", request.getMethod());
assertEquals(String.format(PATH_CORPUS, id, corpusName) + "?allow_overwrite=true", request.getPath());
assertTrue(request.getBody().readUtf8().contains(corpusFileText));
}
use of com.ibm.watson.speech_to_text.v1.model.AddCorpusOptions in project java-sdk by watson-developer-cloud.
the class SpeechToTextIT method testAddCorpusFail.
/**
* Test add corpus with expected failure.
*/
@Test(expected = IllegalArgumentException.class)
public void testAddCorpusFail() {
AddCorpusOptions addOptions = new AddCorpusOptions.Builder().corpusName("foo3").customizationId(customizationId).build();
service.addCorpus(addOptions).execute().getResult();
}
use of com.ibm.watson.speech_to_text.v1.model.AddCorpusOptions in project java-sdk by watson-developer-cloud.
the class SpeechToTextTest method testAddCorpusWOptions.
// Test the addCorpus operation with a valid options model parameter
@Test
public void testAddCorpusWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "";
String addCorpusPath = "/v1/customizations/testString/corpora/testString";
server.enqueue(new MockResponse().setResponseCode(201).setBody(mockResponseBody));
// Construct an instance of the AddCorpusOptions model
AddCorpusOptions addCorpusOptionsModel = new AddCorpusOptions.Builder().customizationId("testString").corpusName("testString").corpusFile(TestUtilities.createMockStream("This is a mock file.")).allowOverwrite(false).build();
// Invoke addCorpus() with a valid options model and verify the result
Response<Void> response = speechToTextService.addCorpus(addCorpusOptionsModel).execute();
assertNotNull(response);
Void responseObj = response.getResult();
assertNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, addCorpusPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(Boolean.valueOf(query.get("allow_overwrite")), Boolean.valueOf(false));
}
Aggregations