Search in sources :

Example 61 with TargetDeliveryResponse

use of com.adobe.target.edge.client.model.TargetDeliveryResponse in project target-java-sdk by adobe.

the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryLocalRequestMboxMacros.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
void testTargetDeliveryLocalRequestMboxMacros() throws IOException, NoSuchFieldException {
    fileRuleLoader("DECISIONING_PAYLOAD_CAMPAIGN_MACROS.json", localService);
    TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874", DecisioningMethod.ON_DEVICE, null);
    targetDeliveryRequest.getDeliveryRequest().getContext().setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36");
    targetDeliveryRequest.getDeliveryRequest().getContext().setChannel(ChannelType.WEB);
    targetDeliveryRequest.getDeliveryRequest().getContext().setAddress(new Address().url("http://local-target-test/"));
    targetDeliveryRequest.getDeliveryRequest().getContext().setBrowser(new Browser().host("local-target-test"));
    PrefetchRequest prefetchRequest = new PrefetchRequest();
    List<MboxRequest> mboxRequests = new ArrayList() {

        {
            add(new MboxRequest().name("macros").index(1).parameters(new HashMap<String, String>() {

                {
                    put("user", "Mickey Mouse");
                    put("pgname", "blippi");
                    put("browserWidth", "1024");
                }
            }));
        }
    };
    prefetchRequest.setMboxes(mboxRequests);
    targetDeliveryRequest.getDeliveryRequest().setPrefetch(prefetchRequest);
    TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
    PrefetchMboxResponse mbox = targetDeliveryResponse.getResponse().getPrefetch().getMboxes().get(0);
    assertEquals("macros", mbox.getName());
    Option option = mbox.getOptions().get(0);
    assertEquals(OptionType.HTML, option.getType());
    assertEquals("<ol>\n" + "  <li>667870</li>\n" + "  <li>/campaign_macros/experiences/1/pages/0/zones/0/1599065324776</li>\n" + "  <li>362147</li>\n" + "  <li>campaign macros</li>\n" + "  <li>1</li>\n" + "  <li>Experience B</li>\n" + "  <li>362147</li>\n" + "  <li>campaign macros</li>\n" + "  <li>1</li>\n" + "  <li>Experience B</li>\n" + "  <li>macros</li>\n" + "  <li>Mickey Mouse</li>\n" + "  <li>blippi</li>\n" + "  <li>1024</li>\n" + "</ol>", option.getContent());
}
Also used : TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Test(org.junit.jupiter.api.Test)

Example 62 with TargetDeliveryResponse

use of com.adobe.target.edge.client.model.TargetDeliveryResponse in project target-java-sdk by adobe.

the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryAttributesHybridRemote.

@Test
@SuppressWarnings("unchecked")
void testTargetDeliveryAttributesHybridRemote() throws IOException, NoSuchFieldException {
    fileRuleLoader("DECISIONING_PAYLOAD_RECOMMENDATIONS.json", localService);
    TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874", DecisioningMethod.HYBRID, "daterange-mbox");
    targetDeliveryRequest.getDeliveryRequest().getPrefetch().addMboxesItem(new MboxRequest().index(2).name("recommendations"));
    TargetDeliveryResponse response = targetJavaClient.getOffers(targetDeliveryRequest);
    assertNotNull(response);
    assertEquals(200, response.getStatus());
    verify(defaultTargetHttpClient, atMostOnce()).execute(any(Map.class), any(String.class), eq(targetDeliveryRequest), any(Class.class));
}
Also used : TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Test(org.junit.jupiter.api.Test)

Example 63 with TargetDeliveryResponse

use of com.adobe.target.edge.client.model.TargetDeliveryResponse in project target-java-sdk by adobe.

the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryLocalRequestBrowserNoMatch.

@Test
void testTargetDeliveryLocalRequestBrowserNoMatch() throws IOException, NoSuchFieldException {
    fileRuleLoader("DECISIONING_PAYLOAD_BROWSER.json", localService);
    TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916873", DecisioningMethod.HYBRID, "browser-mbox");
    targetDeliveryRequest.getDeliveryRequest().getContext().setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134");
    TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
    List<Option> prefetchOptions = extractOptions(targetDeliveryRequest, targetDeliveryResponse, "browser-mbox");
    verifyHTMLContent(prefetchOptions, "<h1>not firefox, safari or chrome</h1>", "B8C2FP2IuBgmeJcDfXHjGmqipfsIHvVzTQxHolz2IpSCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==");
}
Also used : TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Test(org.junit.jupiter.api.Test)

Example 64 with TargetDeliveryResponse

use of com.adobe.target.edge.client.model.TargetDeliveryResponse in project target-java-sdk by adobe.

the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryLocalRequestPageload.

@Test
void testTargetDeliveryLocalRequestPageload() throws IOException, NoSuchFieldException {
    fileRuleLoader("DECISIONING_PAYLOAD_GLOBAL_MBOX.json", localService);
    TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874", DecisioningMethod.ON_DEVICE, null);
    targetDeliveryRequest.getDeliveryRequest().getContext().setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/71.0");
    PrefetchRequest prefetchRequest = new PrefetchRequest();
    prefetchRequest.setPageLoad(new RequestDetails());
    targetDeliveryRequest.getDeliveryRequest().setPrefetch(prefetchRequest);
    TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
    List<Option> prefetchOptions = targetDeliveryResponse.getResponse().getPrefetch().getPageLoad().getOptions();
    assertNotNull(prefetchOptions);
    assertEquals(2, prefetchOptions.size());
    int matches = 0;
    for (Option option : prefetchOptions) {
        assertEquals(OptionType.HTML, option.getType());
        String preContent = (String) option.getContent();
        switch(preContent) {
            case "<div>Firetime</div>":
                assertEquals("9FNM3ikASssS+sVoFXNulJNWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==", option.getEventToken());
                matches++;
                break;
            case "<div>lion</div>":
                assertEquals("5C2cbrGD+bQ5qOATNGy1AQreqXMfVUcUx0s/BHR5kCKCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==", option.getEventToken());
                matches++;
                break;
            case "<div>whale</div>":
                assertEquals("5C2cbrGD+bQ5qOATNGy1AWqipfsIHvVzTQxHolz2IpSCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==", option.getEventToken());
                matches++;
                break;
            default:
                throw new IllegalStateException("unexpected content");
        }
    }
    assertEquals(2, matches);
}
Also used : TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Test(org.junit.jupiter.api.Test)

Example 65 with TargetDeliveryResponse

use of com.adobe.target.edge.client.model.TargetDeliveryResponse in project target-java-sdk by adobe.

the class DefaultTargetService method executeRequest.

@Override
public TargetDeliveryResponse executeRequest(TargetDeliveryRequest deliveryRequest) {
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    TargetDeliveryResponse targetDeliveryResponse;
    Telemetry telemetry = telemetryService.getTelemetry();
    if (!telemetry.getEntries().isEmpty()) {
        deliveryRequest.getDeliveryRequest().setTelemetry(telemetry);
    }
    ResponseWrapper<DeliveryResponse> response = callDeliveryApi(deliveryRequest);
    targetDeliveryResponse = getTargetDeliveryResponse(deliveryRequest, response.getHttpResponse());
    /* capture Telemetry information once original request's response is received */
    telemetryService.addTelemetry(deliveryRequest, timer, targetDeliveryResponse, response.getParsingTime(), response.getResponseSize());
    return targetDeliveryResponse;
}
Also used : TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) Telemetry(com.adobe.target.delivery.v1.model.Telemetry) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse)

Aggregations

TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)66 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)58 Test (org.junit.jupiter.api.Test)53 TimingTool (com.adobe.target.edge.client.utils.TimingTool)13 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)10 Context (com.adobe.target.delivery.v1.model.Context)9 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)9 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)9 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)9 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)9 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)8 Property (com.adobe.target.delivery.v1.model.Property)7 TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse)6 Telemetry (com.adobe.target.delivery.v1.model.Telemetry)5 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)4 ParamsCollator (com.adobe.target.edge.client.ondevice.collator.ParamsCollator)4 CustomerState (com.adobe.experiencecloud.ecid.visitor.CustomerState)3 TargetRequestException (com.adobe.target.edge.client.exception.TargetRequestException)3 ResponseStatus (com.adobe.target.edge.client.http.ResponseStatus)3 ResponseWrapper (com.adobe.target.edge.client.http.ResponseWrapper)3