Search in sources :

Example 6 with TargetDeliveryRequest

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

the class DefaultTargetClient method addMBoxesToRequest.

private static TargetDeliveryRequest addMBoxesToRequest(TargetDeliveryRequest targetRequest, String... mboxes) {
    if (targetRequest == null || targetRequest.getDeliveryRequest() == null) {
        targetRequest = TargetDeliveryRequest.builder().decisioningMethod(DecisioningMethod.HYBRID).build();
    }
    int idx = 0;
    Set<String> existingMBoxNames = new HashSet<>();
    DeliveryRequest deliveryRequest = targetRequest.getDeliveryRequest();
    PrefetchRequest prefetchRequest = deliveryRequest.getPrefetch();
    if (prefetchRequest != null && prefetchRequest.getMboxes() != null) {
        for (MboxRequest mb : prefetchRequest.getMboxes()) {
            existingMBoxNames.add(mb.getName());
        }
    }
    ExecuteRequest executeRequest = deliveryRequest.getExecute();
    if (executeRequest != null) {
        List<MboxRequest> executeMboxes = executeRequest.getMboxes();
        if (executeMboxes != null) {
            for (MboxRequest mb : executeMboxes) {
                if (mb.getIndex() >= idx) {
                    idx = mb.getIndex() + 1;
                }
                existingMBoxNames.add(mb.getName());
            }
        }
    }
    for (String mbox : mboxes) {
        if (!existingMBoxNames.contains(mbox)) {
            if (executeRequest == null) {
                executeRequest = new ExecuteRequest();
                targetRequest.getDeliveryRequest().setExecute(executeRequest);
            }
            executeRequest.addMboxesItem(new MboxRequest().index(idx++).name(mbox));
        }
    }
    return targetRequest;
}
Also used : PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) HashSet(java.util.HashSet)

Example 7 with TargetDeliveryRequest

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

the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryAttributesLocalOnlyPartial.

@Test
@SuppressWarnings("unchecked")
void testTargetDeliveryAttributesLocalOnlyPartial() throws IOException, NoSuchFieldException {
    fileRuleLoader("DECISIONING_PAYLOAD_RECOMMENDATIONS.json", localService);
    TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874", DecisioningMethod.ON_DEVICE, "daterange-mbox");
    targetDeliveryRequest.getDeliveryRequest().getPrefetch().addMboxesItem(new MboxRequest().index(2).name("recommendations"));
    TargetDeliveryResponse response = targetJavaClient.getOffers(targetDeliveryRequest);
    assertNotNull(response);
    assertEquals(206, response.getStatus());
    verify(defaultTargetHttpClient, never()).execute(any(Map.class), any(String.class), eq(targetDeliveryRequest), any(Class.class));
    verify(defaultTargetHttpClient, atMostOnce()).execute(any(Map.class), any(String.class), any(TargetDeliveryRequest.class), 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 8 with TargetDeliveryRequest

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

the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryLocalRequestTimeRange.

@Test
void testTargetDeliveryLocalRequestTimeRange() throws IOException, NoSuchFieldException {
    fileRuleLoader("DECISIONING_PAYLOAD_TIMEFRAME.json", localService);
    TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916873", DecisioningMethod.HYBRID, "daterange-mbox");
    ParamsCollator specificTimeCollator = TargetTestDeliveryRequestUtils.getSpecificTimeCollator(1582830000000L);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("timeParamsCollator"), specificTimeCollator);
    TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
    List<Option> prefetchOptions = extractOptions(targetDeliveryRequest, targetDeliveryResponse, "daterange-mbox");
    verifyHTMLContent(prefetchOptions, "<strong>date range 1 (feb 27-29)</strong>", "wQY/V1IOYec8T4fAT5ww7unJlneZxJu5VqGhXCosHhWCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==");
}
Also used : ParamsCollator(com.adobe.target.edge.client.ondevice.collator.ParamsCollator) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Test(org.junit.jupiter.api.Test)

Example 9 with TargetDeliveryRequest

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

the class TargetDeliveryRequestLocalMboxTest method testTargetDeliveryLocalRequestAllMatchesNotOverriden.

@Test
@SuppressWarnings("unchecked")
void testTargetDeliveryLocalRequestAllMatchesNotOverriden() throws IOException, NoSuchFieldException {
    fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
    TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874", DecisioningMethod.ON_DEVICE, "allmatches");
    PrefetchRequest prefetchRequest = targetDeliveryRequest.getDeliveryRequest().getPrefetch();
    MboxRequest mboxRequest = prefetchRequest.getMboxes().get(0);
    mboxRequest.setParameters(new HashMap<String, String>() {

        {
            put("foo", "bar");
        }
    });
    TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
    List<Option> prefetchOptions = extractOptions(targetDeliveryRequest, targetDeliveryResponse, "allmatches");
    assertEquals(1, prefetchOptions.size());
    Option option1 = prefetchOptions.get(0);
    assertEquals(OptionType.JSON, option1.getType());
    Map<String, Object> preContent1 = (Map<String, Object>) option1.getContent();
    assertEquals(2, preContent1.get("allmatches"));
    assertEquals("b", preContent1.get("allmatches2_exp"));
    assertEquals("aNT5qgpj/qd5U7cLpV7p05NWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==", option1.getEventToken());
}
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 10 with TargetDeliveryRequest

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

the class TargetDeliveryRequestLocalMboxTest method extractOptions.

@SuppressWarnings("unchecked")
private List<Option> extractOptions(TargetDeliveryRequest targetDeliveryRequest, TargetDeliveryResponse targetDeliveryResponse, String prefetchMbox) {
    DeliveryResponse response = targetDeliveryResponse.getResponse();
    assertNotNull(response);
    PrefetchResponse preResponse = response.getPrefetch();
    assertNotNull(preResponse);
    List<PrefetchMboxResponse> preMboxes = preResponse.getMboxes();
    assertNotNull(preMboxes);
    List<Option> prefetchOptions = null;
    if (prefetchMbox != null) {
        assertEquals(1, preMboxes.size());
        PrefetchMboxResponse preMboxResponse = preMboxes.get(0);
        assertEquals(prefetchMbox, preMboxResponse.getName());
        assertEquals(1, preMboxResponse.getIndex());
        prefetchOptions = preMboxResponse.getOptions();
    } else {
        assertEquals(0, preMboxes.size());
    }
    ExecuteResponse execResponse = response.getExecute();
    assertNotNull(execResponse);
    List<MboxResponse> mboxes = execResponse.getMboxes();
    assertNotNull(mboxes);
    verify(defaultTargetHttpClient, never()).execute(any(Map.class), any(String.class), eq(targetDeliveryRequest), any(Class.class));
    verify(defaultTargetHttpClient, atMostOnce()).execute(any(Map.class), any(String.class), any(TargetDeliveryRequest.class), any(Class.class));
    return prefetchOptions;
}
Also used : TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest)

Aggregations

TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)104 Test (org.junit.jupiter.api.Test)89 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)62 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)24 Context (com.adobe.target.delivery.v1.model.Context)21 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)20 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)17 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)15 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)13 TimingTool (com.adobe.target.edge.client.utils.TimingTool)13 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)11 DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)10 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Property (com.adobe.target.delivery.v1.model.Property)9 OnDeviceDecisioningEvaluation (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningEvaluation)9 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)9 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)6 TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse)6