use of com.ibm.watson.assistant.v2.model.CreateSessionOptions in project java-sdk by watson-developer-cloud.
the class AssistantTest method testCreateSessionWOptions.
// Test the createSession operation with a valid options model parameter
@Test
public void testCreateSessionWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"session_id\": \"sessionId\"}";
String createSessionPath = "/v2/assistants/testString/sessions";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
// Construct an instance of the CreateSessionOptions model
CreateSessionOptions createSessionOptionsModel = new CreateSessionOptions.Builder().assistantId("testString").build();
// Invoke createSession() with a valid options model and verify the result
Response<SessionResponse> response = assistantService.createSession(createSessionOptionsModel).execute();
assertNotNull(response);
SessionResponse 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(), "POST");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, createSessionPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
}
use of com.ibm.watson.assistant.v2.model.CreateSessionOptions in project java-sdk by watson-developer-cloud.
the class Assistant method createSession.
/**
* Create a session.
*
* <p>Create a new session. A session is used to send user input to a skill and receive responses.
* It also maintains the state of the conversation. A session persists until it is deleted, or
* until it times out because of inactivity. (For more information, see the
* [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-assistant-settings).
*
* @param createSessionOptions the {@link CreateSessionOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link SessionResponse}
*/
public ServiceCall<SessionResponse> createSession(CreateSessionOptions createSessionOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createSessionOptions, "createSessionOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("assistant_id", createSessionOptions.assistantId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/assistants/{assistant_id}/sessions", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v2", "createSession");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
ResponseConverter<SessionResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SessionResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations