Assistant extends BaseService { public ServiceCall<MessageResponse> message(MessageOptions messageOptions) { com.ibm.cloud.sdk.core.util.Validator.notNull(messageOptions, "messageOptions cannot be null"); String[] pathSegments = {"v1/workspaces", "message"}; String[] pathParameters = {messageOptions.workspaceId()}; RequestBuilder builder = RequestBuilder.post( RequestBuilder.constructHttpUrl(getServiceUrl(), pathSegments, pathParameters)); builder.query("version", versionDate); Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "message"); for (Entry<String, String> header : sdkHeaders.entrySet()) { builder.header(header.getKey(), header.getValue()); } builder.header("Accept", "application/json"); if (messageOptions.nodesVisitedDetails() != null) { builder.query("nodes_visited_details", String.valueOf(messageOptions.nodesVisitedDetails())); } final JsonObject contentJson = new JsonObject(); if (messageOptions.input() != null) { contentJson.add( "input", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.input())); } if (messageOptions.intents() != null) { contentJson.add( "intents", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.intents())); } if (messageOptions.entities() != null) { contentJson.add( "entities", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson() .toJsonTree(messageOptions.entities())); } if (messageOptions.alternateIntents() != null) { contentJson.addProperty("alternate_intents", messageOptions.alternateIntents()); } if (messageOptions.context() != null) { contentJson.add( "context", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.context())); } if (messageOptions.output() != null) { contentJson.add( "output", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.output())); } builder.bodyJson(contentJson); ResponseConverter<MessageResponse> responseConverter = ResponseConverterUtils.getValue( new com.google.gson.reflect.TypeToken<MessageResponse>() {}.getType()); return createServiceCall(builder.build(), responseConverter); } Assistant(String versionDate);  Assistant(String versionDate, Authenticator authenticator);  Assistant(String versionDate, String serviceName);  Assistant(String versionDate, String serviceName, Authenticator authenticator); ServiceCall<MessageResponse> message(MessageOptions messageOptions); ServiceCall<WorkspaceCollection> listWorkspaces(
      ListWorkspacesOptions listWorkspacesOptions); ServiceCall<WorkspaceCollection> listWorkspaces(); ServiceCall<Workspace> createWorkspace(CreateWorkspaceOptions createWorkspaceOptions); ServiceCall<Workspace> createWorkspace(); ServiceCall<Workspace> getWorkspace(GetWorkspaceOptions getWorkspaceOptions); ServiceCall<Workspace> updateWorkspace(UpdateWorkspaceOptions updateWorkspaceOptions); ServiceCall<Void> deleteWorkspace(DeleteWorkspaceOptions deleteWorkspaceOptions); ServiceCall<IntentCollection> listIntents(ListIntentsOptions listIntentsOptions); ServiceCall<Intent> createIntent(CreateIntentOptions createIntentOptions); ServiceCall<Intent> getIntent(GetIntentOptions getIntentOptions); ServiceCall<Intent> updateIntent(UpdateIntentOptions updateIntentOptions); ServiceCall<Void> deleteIntent(DeleteIntentOptions deleteIntentOptions); ServiceCall<ExampleCollection> listExamples(ListExamplesOptions listExamplesOptions); ServiceCall<Example> createExample(CreateExampleOptions createExampleOptions); ServiceCall<Example> getExample(GetExampleOptions getExampleOptions); ServiceCall<Example> updateExample(UpdateExampleOptions updateExampleOptions); ServiceCall<Void> deleteExample(DeleteExampleOptions deleteExampleOptions); ServiceCall<CounterexampleCollection> listCounterexamples(
      ListCounterexamplesOptions listCounterexamplesOptions); ServiceCall<Counterexample> createCounterexample(
      CreateCounterexampleOptions createCounterexampleOptions); ServiceCall<Counterexample> getCounterexample(
      GetCounterexampleOptions getCounterexampleOptions); ServiceCall<Counterexample> updateCounterexample(
      UpdateCounterexampleOptions updateCounterexampleOptions); ServiceCall<Void> deleteCounterexample(
      DeleteCounterexampleOptions deleteCounterexampleOptions); ServiceCall<EntityCollection> listEntities(ListEntitiesOptions listEntitiesOptions); ServiceCall<Entity> createEntity(CreateEntityOptions createEntityOptions); ServiceCall<Entity> getEntity(GetEntityOptions getEntityOptions); ServiceCall<Entity> updateEntity(UpdateEntityOptions updateEntityOptions); ServiceCall<Void> deleteEntity(DeleteEntityOptions deleteEntityOptions); ServiceCall<EntityMentionCollection> listMentions(
      ListMentionsOptions listMentionsOptions); ServiceCall<ValueCollection> listValues(ListValuesOptions listValuesOptions); ServiceCall<Value> createValue(CreateValueOptions createValueOptions); ServiceCall<Value> getValue(GetValueOptions getValueOptions); ServiceCall<Value> updateValue(UpdateValueOptions updateValueOptions); ServiceCall<Void> deleteValue(DeleteValueOptions deleteValueOptions); ServiceCall<SynonymCollection> listSynonyms(ListSynonymsOptions listSynonymsOptions); ServiceCall<Synonym> createSynonym(CreateSynonymOptions createSynonymOptions); ServiceCall<Synonym> getSynonym(GetSynonymOptions getSynonymOptions); ServiceCall<Synonym> updateSynonym(UpdateSynonymOptions updateSynonymOptions); ServiceCall<Void> deleteSynonym(DeleteSynonymOptions deleteSynonymOptions); ServiceCall<DialogNodeCollection> listDialogNodes(
      ListDialogNodesOptions listDialogNodesOptions); ServiceCall<DialogNode> createDialogNode(CreateDialogNodeOptions createDialogNodeOptions); ServiceCall<DialogNode> getDialogNode(GetDialogNodeOptions getDialogNodeOptions); ServiceCall<DialogNode> updateDialogNode(UpdateDialogNodeOptions updateDialogNodeOptions); ServiceCall<Void> deleteDialogNode(DeleteDialogNodeOptions deleteDialogNodeOptions); ServiceCall<LogCollection> listLogs(ListLogsOptions listLogsOptions); ServiceCall<LogCollection> listAllLogs(ListAllLogsOptions listAllLogsOptions); ServiceCall<Void> deleteUserData(DeleteUserDataOptions deleteUserDataOptions);  }
@Test(expected = IllegalArgumentException.class) public void testAssistantWithNullOptions() { service.message(null).execute().getResult(); }
@Test(expected = IllegalArgumentException.class) public void testAssistantWithNullWorkspaceId() { MessageOptions options = new MessageOptions.Builder().build(); service.message(options).execute().getResult(); }
@Test(expected = IllegalArgumentException.class) public void testAssistantWithEmptyWorkspaceId() { MessageOptions options = new MessageOptions.Builder("").build(); service.message(options).execute().getResult(); }
@Test public void testSendMessage() throws IOException, InterruptedException { String text = "I would love to hear some jazz music."; MessageResponse mockResponse = loadFixture(FIXTURE, MessageResponse.class); server.enqueue(jsonResponse(mockResponse)); MessageInput input = new MessageInput(); input.setText(text); RuntimeIntent intent = new RuntimeIntent.Builder().intent(INTENT).confidence(CONFIDENCE).build(); RuntimeEntity entity = new RuntimeEntity.Builder().entity(ENTITY).value(VALUE).location(LOCATION).build(); MessageOptions options = new MessageOptions.Builder(WORKSPACE_ID) .input(input) .addIntent(intent) .addEntity(entity) .alternateIntents(true) .build(); MessageResponse serviceResponse = service.message(options).execute().getResult(); RecordedRequest request = server.takeRequest(); String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=", VERSION_DATE); assertEquals(path, request.getPath()); assertArrayEquals( new String[] {"Great choice! Playing some jazz for you."}, serviceResponse.getOutput().getText().toArray(new String[0])); assertEquals(request.getMethod(), "POST"); assertNotNull(serviceResponse.getActions()); assertNotNull(serviceResponse.getActions().get(0).name()); assertNotNull(serviceResponse.getActions().get(0).credentials()); assertNotNull(serviceResponse.getActions().get(0).type()); assertNotNull(serviceResponse.getActions().get(0).parameters()); assertNotNull(serviceResponse.getActions().get(0).resultVariable()); assertNotNull(serviceResponse.getOutput().getLogMessages()); assertNotNull(serviceResponse.getOutput().getNodesVisited()); assertNotNull(serviceResponse.getOutput().getNodesVisitedDetails()); assertNotNull(serviceResponse.getOutput().getNodesVisitedDetails().get(0).dialogNode()); assertNotNull(serviceResponse.getOutput().getNodesVisitedDetails().get(0).title()); assertNotNull(serviceResponse.getOutput().getNodesVisitedDetails().get(0).conditions()); assertNotNull(serviceResponse.getOutput().getNodesVisitedDetails().get(0).conditions()); }
@Test public void testSendMessageWithAlternateIntents() throws IOException, InterruptedException { MessageResponse mockResponse = loadFixture(FIXTURE, MessageResponse.class); server.enqueue(jsonResponse(mockResponse)); MessageContextMetadata metadata = new MessageContextMetadata.Builder().build(); Context contextTemp = new Context(); contextTemp.put("name", "Myname"); contextTemp.setMetadata(metadata); MessageInput inputTemp = new MessageInput(); inputTemp.setText("My text"); assertEquals("Myname", contextTemp.get("name")); assertEquals(metadata, contextTemp.getMetadata()); MessageOptions options = new MessageOptions.Builder(WORKSPACE_ID) .input(inputTemp) .alternateIntents(false) .context(contextTemp) .entities(null) .intents(null) .build(); MessageResponse serviceResponse = service.message(options).execute().getResult(); RecordedRequest request = server.takeRequest(); String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=", VERSION_DATE); assertEquals(path, request.getPath()); assertArrayEquals( new String[] {"Great choice! Playing some jazz for you."}, serviceResponse.getOutput().getText().toArray(new String[0])); assertEquals(request.getMethod(), "POST"); }
@Test public void testSendMessageWithMessageRequest() throws FileNotFoundException, InterruptedException { String text = "I would love to hear some jazz music."; MessageResponse mockResponse = loadFixture(FIXTURE, MessageResponse.class); server.enqueue(jsonResponse(mockResponse)); MessageInput input = new MessageInput(); input.setText(text); RuntimeIntent intent = new RuntimeIntent.Builder().intent(INTENT).confidence(CONFIDENCE).build(); RuntimeEntity entity = new RuntimeEntity.Builder().entity(ENTITY).value(VALUE).location(LOCATION).build(); Context context = new Context(); OutputData outputData = new OutputData(); MessageRequest messageRequest = new MessageRequest.Builder() .input(input) .intents(Collections.singletonList(intent)) .entities(Collections.singletonList(entity)) .alternateIntents(true) .context(context) .output(outputData) .build(); assertEquals(input, messageRequest.input()); assertEquals(intent, messageRequest.intents().get(0)); assertEquals(entity, messageRequest.entities().get(0)); assertEquals(context, messageRequest.context()); assertEquals(outputData, messageRequest.output()); MessageOptions options = new MessageOptions.Builder() .workspaceId(WORKSPACE_ID) .messageRequest(messageRequest) .build(); MessageResponse serviceResponse = service.message(options).execute().getResult(); RecordedRequest request = server.takeRequest(); String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=", VERSION_DATE); assertEquals(path, request.getPath()); assertArrayEquals( new String[] {"Great choice! Playing some jazz for you."}, serviceResponse.getOutput().getText().toArray(new String[0])); assertEquals(request.getMethod(), "POST"); assertNotNull(serviceResponse.getActions()); assertNotNull(serviceResponse.getActions().get(0).name()); assertNotNull(serviceResponse.getActions().get(0).credentials()); assertNotNull(serviceResponse.getActions().get(0).type()); assertNotNull(serviceResponse.getActions().get(0).parameters()); assertNotNull(serviceResponse.getActions().get(0).resultVariable()); assertNotNull(serviceResponse.getOutput().getLogMessages()); assertNotNull(serviceResponse.getOutput().getNodesVisited()); assertNotNull(serviceResponse.getOutput().getNodesVisitedDetails()); assertNotNull(serviceResponse.getOutput().getNodesVisitedDetails().get(0).dialogNode()); assertNotNull(serviceResponse.getOutput().getNodesVisitedDetails().get(0).title()); assertNotNull(serviceResponse.getOutput().getNodesVisitedDetails().get(0).conditions()); assertNotNull(serviceResponse.getOutput().getNodesVisitedDetails().get(0).conditions()); }
@Test(expected = IllegalArgumentException.class) public void testSendMessageWithNullWorkspaceId() throws InterruptedException { String text = "I'd like to get insurance to for my home"; MessageInput input = new MessageInput(); input.setText(text); MessageOptions options = new MessageOptions.Builder().input(input).alternateIntents(true).build(); service.message(options).execute().getResult(); }