use of com.adobe.target.delivery.v1.model.Context in project target-java-sdk by adobe.
the class TelemetryServiceTest method testTelemetryForServerSideSendNotification.
/**
* Test case for server-side decisioning that calls getOffers() once and then sendNotifications()
* once. This is to verify (and document the use case) telemetry is being added to any request
* that goes to Delivery API, regardless of which method is being called on TargetClient by the
* user.
*
* @throws NoSuchFieldException
*/
@Test
void testTelemetryForServerSideSendNotification() throws NoSuchFieldException {
setup(true, DecisioningMethod.SERVER_SIDE, "testTelemetryForServerSideSendNotification");
Context context = getContext();
PrefetchRequest prefetchRequest = getPrefetchViewsRequest();
ExecuteRequest executeRequest = getMboxExecuteRequest();
String nonDefaultToken = "non-default-token";
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).property(new Property().token(nonDefaultToken)).decisioningMethod(DecisioningMethod.SERVER_SIDE).build();
TargetDeliveryResponse targetDeliveryResponse1 = targetJavaClient.getOffers(targetDeliveryRequest);
assertNull(targetDeliveryResponse1.getRequest().getTelemetry());
targetJavaClient.sendNotifications(targetDeliveryRequest);
verify(telemetryServiceSpy, atLeast(2)).getTelemetry();
verify(telemetryServiceSpy, times(2)).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class), any(Double.class), any(Long.class));
assertEquals(1, telemetryServiceSpy.getTelemetry().getEntries().size());
}
use of com.adobe.target.delivery.v1.model.Context in project target-java-sdk by adobe.
the class TelemetryServiceTest method testExecutionModeForHybridWithAllLocal.
/**
* Test to verify telemetryEntry has correct executionMode With partial content 206 status &
* hybrid our mode should be edge
*
* @throws NoSuchFieldException
*/
@Test
void testExecutionModeForHybridWithAllLocal() throws NoSuchFieldException {
setup(true, DecisioningMethod.HYBRID, "testExecutionModeHybridWithAllLocal");
TimingTool timer = new TimingTool();
timer.timeStart(TIMING_EXECUTE_REQUEST);
Context context = getContext();
ExecuteRequest executeRequest = getMboxExecuteRequest();
String nonDefaultToken = "non-default-token";
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).execute(executeRequest).property(new Property().token(nonDefaultToken)).decisioningMethod(DecisioningMethod.HYBRID).build();
DeliveryResponse deliveryResponse = new DeliveryResponse();
deliveryResponse.setClient("SUMMIT_TEST2021");
deliveryResponse.setEdgeHost(null);
TargetDeliveryResponse targetDeliveryResponse = new TargetDeliveryResponse(targetDeliveryRequest, deliveryResponse, 200, "test call");
targetDeliveryResponse.getResponse().setRequestId("testID");
telemetryServiceSpy.addTelemetry(targetDeliveryRequest, timer, targetDeliveryResponse);
TelemetryEntry telemetryEntry = telemetryServiceSpy.getTelemetry().getEntries().get(1);
assert telemetryEntry != null;
assertEquals(ExecutionMode.LOCAL, telemetryEntry.getMode());
}
use of com.adobe.target.delivery.v1.model.Context in project java-sdk by watson-developer-cloud.
the class ConversationTest method testSendMessageWithAlternateIntents.
/**
* Test send message. use some different MessageOptions options like context and other public methods
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
@Test
public void testSendMessageWithAlternateIntents() throws IOException, InterruptedException {
MessageResponse mockResponse = loadFixture(FIXTURE, MessageResponse.class);
server.enqueue(jsonResponse(mockResponse));
Context contextTemp = new Context();
contextTemp.put("name", "Myname");
InputData inputTemp = new InputData.Builder("My text").build();
MessageOptions options = new MessageOptions.Builder(WORKSPACE_ID).input(inputTemp).alternateIntents(false).context(contextTemp).entities(null).intents(null).build();
// execute first request
MessageResponse serviceResponse = service.message(options).execute();
// first request
RecordedRequest request = server.takeRequest();
String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=2018-02-16");
assertEquals(path, request.getPath());
assertArrayEquals(new String[] { "Do you want to get a quote?" }, serviceResponse.getOutput().getText().toArray(new String[0]));
assertEquals(request.getMethod(), "POST");
assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
assertEquals("{\"input\":{\"text\":\"My text\"},\"alternate_intents\":false," + "\"context\":{\"name\":\"Myname\"}}", request.getBody().readUtf8());
assertEquals(serviceResponse, mockResponse);
}
use of com.adobe.target.delivery.v1.model.Context in project java-sdk by watson-developer-cloud.
the class AssistantServiceIT method testSendMessages.
/**
* Test send messages.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void testSendMessages() throws InterruptedException {
final String[] messages = new String[] { "turn ac on", "turn right", "no", "yes" };
Context context = null;
for (final String message : messages) {
MessageOptions request = new MessageOptions.Builder(workspaceId).input(new InputData.Builder(message).build()).alternateIntents(true).context(context).nodesVisitedDetails(true).build();
if (message.equals("yes")) {
RuntimeIntent offTopic = new RuntimeIntent();
offTopic.setIntent("off_topic");
offTopic.setConfidence(1.0);
request = request.newBuilder().addIntent(offTopic).build();
}
MessageResponse response = service.message(request).execute();
assertMessageFromService(response);
assertNotNull(response.getOutput().getNodesVisitedDetails());
for (RuntimeEntity entity : response.getEntities()) {
assertNotNull(entity.getGroups());
}
context = new Context();
context.putAll(response.getContext());
Thread.sleep(500);
}
}
use of com.adobe.target.delivery.v1.model.Context in project java-sdk by watson-developer-cloud.
the class AssistantTest method testSendMessageWithAlternateIntents.
/**
* Test send message. use some different MessageOptions options like context and other public methods
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
@Test
public void testSendMessageWithAlternateIntents() throws IOException, InterruptedException {
MessageResponse mockResponse = loadFixture(FIXTURE, MessageResponse.class);
server.enqueue(jsonResponse(mockResponse));
Context contextTemp = new Context();
contextTemp.put("name", "Myname");
InputData inputTemp = new InputData.Builder("My text").build();
MessageOptions options = new MessageOptions.Builder(WORKSPACE_ID).input(inputTemp).alternateIntents(false).context(contextTemp).entities(null).intents(null).build();
// execute first request
MessageResponse serviceResponse = service.message(options).execute();
// first request
RecordedRequest request = server.takeRequest();
String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=2018-02-16");
assertEquals(path, request.getPath());
assertArrayEquals(new String[] { "Do you want to get a quote?" }, serviceResponse.getOutput().getText().toArray(new String[0]));
assertEquals(request.getMethod(), "POST");
assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
assertEquals("{\"input\":{\"text\":\"My text\"},\"alternate_intents\":false," + "\"context\":{\"name\":\"Myname\"}}", request.getBody().readUtf8());
assertEquals(serviceResponse, mockResponse);
}
Aggregations