Search in sources :

Example 11 with Corpora

use of com.ibm.watson.speech_to_text.v1.model.Corpora in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testGetCorpusWOptions.

// Test the getCorpus operation with a valid options model parameter
@Test
public void testGetCorpusWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"name\": \"name\", \"total_words\": 10, \"out_of_vocabulary_words\": 20, \"status\": \"analyzed\", \"error\": \"error\"}";
    String getCorpusPath = "/v1/customizations/testString/corpora/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetCorpusOptions model
    GetCorpusOptions getCorpusOptionsModel = new GetCorpusOptions.Builder().customizationId("testString").corpusName("testString").build();
    // Invoke getCorpus() with a valid options model and verify the result
    Response<Corpus> response = speechToTextService.getCorpus(getCorpusOptionsModel).execute();
    assertNotNull(response);
    Corpus responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getCorpusPath);
    // Verify that there is no query string
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetCorpusOptions(com.ibm.watson.speech_to_text.v1.model.GetCorpusOptions) Corpus(com.ibm.watson.speech_to_text.v1.model.Corpus) Test(org.testng.annotations.Test)

Example 12 with Corpora

use of com.ibm.watson.speech_to_text.v1.model.Corpora in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testDeleteCorpusWOptions.

// Test the deleteCorpus operation with a valid options model parameter
@Test
public void testDeleteCorpusWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "";
    String deleteCorpusPath = "/v1/customizations/testString/corpora/testString";
    server.enqueue(new MockResponse().setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the DeleteCorpusOptions model
    DeleteCorpusOptions deleteCorpusOptionsModel = new DeleteCorpusOptions.Builder().customizationId("testString").corpusName("testString").build();
    // Invoke deleteCorpus() with a valid options model and verify the result
    Response<Void> response = speechToTextService.deleteCorpus(deleteCorpusOptionsModel).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(), "DELETE");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, deleteCorpusPath);
    // Verify that there is no query string
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteCorpusOptions(com.ibm.watson.speech_to_text.v1.model.DeleteCorpusOptions) Test(org.testng.annotations.Test)

Example 13 with Corpora

use of com.ibm.watson.speech_to_text.v1.model.Corpora in project java-sdk by watson-developer-cloud.

the class SpeechToTextIT method testListCorpora.

/**
 * Test list corpora.
 */
@Test
@Ignore
public void testListCorpora() {
    ListCorporaOptions listOptions = new ListCorporaOptions.Builder().customizationId(customizationId).build();
    Corpora result = service.listCorpora(listOptions).execute();
    assertNotNull(result);
}
Also used : Corpora(com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpora) ListCorporaOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListCorporaOptions) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 14 with Corpora

use of com.ibm.watson.speech_to_text.v1.model.Corpora in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testListCorporaWOptions.

// Test the listCorpora operation with a valid options model parameter
@Test
public void testListCorporaWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"corpora\": [{\"name\": \"name\", \"total_words\": 10, \"out_of_vocabulary_words\": 20, \"status\": \"analyzed\", \"error\": \"error\"}]}";
    String listCorporaPath = "/v1/customizations/testString/corpora";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListCorporaOptions model
    ListCorporaOptions listCorporaOptionsModel = new ListCorporaOptions.Builder().customizationId("testString").build();
    // Invoke listCorpora() with a valid options model and verify the result
    Response<Corpora> response = speechToTextService.listCorpora(listCorporaOptionsModel).execute();
    assertNotNull(response);
    Corpora responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, listCorporaPath);
    // Verify that there is no query string
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Corpora(com.ibm.watson.speech_to_text.v1.model.Corpora) ListCorporaOptions(com.ibm.watson.speech_to_text.v1.model.ListCorporaOptions) Test(org.testng.annotations.Test)

Example 15 with Corpora

use of com.ibm.watson.speech_to_text.v1.model.Corpora 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));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) AddCorpusOptions(com.ibm.watson.speech_to_text.v1.model.AddCorpusOptions) Test(org.testng.annotations.Test)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)5 Corpora (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpora)5 Corpora (com.ibm.watson.speech_to_text.v1.model.Corpora)5 HashMap (java.util.HashMap)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 Test (org.junit.Test)5 ListCorporaOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListCorporaOptions)4 ListCorporaOptions (com.ibm.watson.speech_to_text.v1.model.ListCorporaOptions)4 File (java.io.File)4 Test (org.testng.annotations.Test)4 AddCorpusOptions (com.ibm.watson.speech_to_text.v1.model.AddCorpusOptions)3 Corpus (com.ibm.watson.speech_to_text.v1.model.Corpus)3 GetCorpusOptions (com.ibm.watson.speech_to_text.v1.model.GetCorpusOptions)3 Words (com.ibm.watson.speech_to_text.v1.model.Words)3 Ignore (org.junit.Ignore)3 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 AddCorpusOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddCorpusOptions)2 AddWordOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddWordOptions)2