Search in sources :

Example 21 with ProfileOptions

use of com.ibm.watson.personality_insights.v3.model.ProfileOptions in project java-sdk by watson-developer-cloud.

the class PersonalityInsightsIT method testReadme.

/**
 * Test example in Readme.
 */
@Test
public void testReadme() {
    // Demo content from Moby Dick by Hermann Melville (Chapter 1)
    String text = "Call me Ishmael. Some years ago-never mind how long precisely-having " + "little or no money in my purse, and nothing particular to interest me on shore, " + "I thought I would sail about a little and see the watery part of the world. " + "It is a way I have of driving off the spleen and regulating the circulation. " + "Whenever I find myself growing grim about the mouth; whenever it is a damp, " + "drizzly November in my soul; whenever I find myself involuntarily pausing before " + "coffin warehouses, and bringing up the rear of every funeral I meet; and especially " + "whenever my hypos get such an upper hand of me, that it requires a strong moral " + "principle to prevent me from deliberately stepping into the street, and methodically " + "knocking people's hats off-then, I account it high time to get to sea as soon as I can. " + "This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself " + "upon his sword; I quietly take to the ship. There is nothing surprising in this. " + "If they but knew it, almost all men in their degree, some time or other, cherish " + "very nearly the same feelings towards the ocean with me. There now is your insular " + "city of the Manhattoes, belted round by wharves as Indian isles by coral reefs-commerce surrounds " + "it with her surf. Right and left, the streets take you waterward.";
    ProfileOptions options = new ProfileOptions.Builder().text(text).build();
    Profile profile = service.profile(options).execute().getResult();
    Assert.assertNotNull(profile);
// System.out.println(profile);
}
Also used : ProfileOptions(com.ibm.watson.personality_insights.v3.model.ProfileOptions) Profile(com.ibm.watson.personality_insights.v3.model.Profile) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 22 with ProfileOptions

use of com.ibm.watson.personality_insights.v3.model.ProfileOptions in project java-sdk by watson-developer-cloud.

the class PersonalityInsightsTest method testProfileAsCsvWOptions.

@Test
public void testProfileAsCsvWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "\"operationResponse\"";
    String profileAsCsvPath = "/v3/profile";
    server.enqueue(new MockResponse().setHeader("Content-type", "text/csv").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ContentItem model
    ContentItem contentItemModel = new ContentItem.Builder().content("testString").id("testString").created(Long.valueOf("26")).updated(Long.valueOf("26")).contenttype("text/plain").language("en").parentid("testString").reply(false).forward(false).build();
    // Construct an instance of the Content model
    Content contentModel = new Content.Builder().contentItems(new java.util.ArrayList<ContentItem>(java.util.Arrays.asList(contentItemModel))).build();
    // Construct an instance of the ProfileOptions model
    ProfileOptions profileOptionsModel = new ProfileOptions.Builder().content(contentModel).contentLanguage("en").acceptLanguage("en").rawScores(false).csvHeaders(false).consumptionPreferences(false).build();
    // Invoke operation with valid options model (positive test)
    Response<InputStream> response = personalityInsightsService.profileAsCsv(profileOptionsModel).execute();
    assertNotNull(response);
    InputStream responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("raw_scores")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("csv_headers")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("consumption_preferences")), Boolean.valueOf(false));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, profileAsCsvPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) InputStream(java.io.InputStream) ProfileOptions(com.ibm.watson.personality_insights.v3.model.ProfileOptions) Content(com.ibm.watson.personality_insights.v3.model.Content) ContentItem(com.ibm.watson.personality_insights.v3.model.ContentItem) Test(org.testng.annotations.Test)

Aggregations

Test (org.junit.Test)18 ProfileOptions (com.ibm.watson.developer_cloud.personality_insights.v3.model.ProfileOptions)12 File (java.io.File)10 FileInputStream (java.io.FileInputStream)10 Profile (com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile)9 ProfileOptions (com.ibm.watson.personality_insights.v3.model.ProfileOptions)9 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)7 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)7 Profile (com.ibm.watson.personality_insights.v3.model.Profile)7 Content (com.ibm.watson.personality_insights.v3.model.Content)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 Content (com.ibm.watson.developer_cloud.personality_insights.v3.model.Content)4 ContentItem (com.ibm.watson.personality_insights.v3.model.ContentItem)4 InputStream (java.io.InputStream)3 ContentItem (com.ibm.watson.developer_cloud.personality_insights.v3.model.ContentItem)2 InputStreamReader (java.io.InputStreamReader)2 Date (java.util.Date)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 Test (org.testng.annotations.Test)2