Search in sources :

Example 1 with Attributes

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

the class TargetDeliveryAttributesTest method testTargetDeliveryAttributesAllMatches.

@Test
@SuppressWarnings("unchecked")
void testTargetDeliveryAttributesAllMatches() throws IOException, NoSuchFieldException {
    String mbox = "allmatches";
    ArrayList<String> mboxes = new ArrayList<String>() {

        {
            add(mbox);
        }
    };
    ClientConfig clientConfig = ClientConfig.builder().client("targettesting").organizationId(TEST_ORG_ID).onDeviceEnvironment("test").defaultDecisioningMethod(DecisioningMethod.ON_DEVICE).onDeviceAllMatchingRulesMboxes(mboxes).build();
    TelemetryService telemetryService = new TelemetryService(clientConfig);
    DefaultTargetService targetService = new DefaultTargetService(clientConfig, telemetryService);
    localService = new OnDeviceDecisioningService(clientConfig, targetService, telemetryService);
    fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
    FieldSetter.setField(targetJavaClient, targetJavaClient.getClass().getDeclaredField("localService"), localService);
    FieldSetter.setField(targetService, targetService.getClass().getDeclaredField("targetHttpClient"), defaultTargetHttpClient);
    FieldSetter.setField(targetJavaClient, targetJavaClient.getClass().getDeclaredField("targetService"), targetService);
    Context context = getLocalContext();
    PrefetchRequest prefetchRequest = getMboxPrefetchLocalRequest(mbox);
    VisitorId visitorId = new VisitorId().tntId("38734fba-262c-4722-b4a3-ac0a93916873");
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).id(visitorId).decisioningMethod(DecisioningMethod.ON_DEVICE).build();
    Attributes attrs = targetJavaClient.getAttributes(targetDeliveryRequest, mbox);
    assertNotNull(attrs);
    assertNotNull(attrs.getResponse());
    assertEquals(200, attrs.getResponse().getStatus());
    verify(defaultTargetHttpClient, atMostOnce()).execute(any(Map.class), any(String.class), any(TargetDeliveryRequest.class), any(Class.class));
    assertEquals(2, attrs.getInteger(mbox, "allmatches", 0));
    assertEquals("a", attrs.getString(mbox, "allmatches1_exp"));
    assertEquals("a", attrs.getString(mbox, "allmatches2_exp"));
}
Also used : DefaultTargetService(com.adobe.target.edge.client.service.DefaultTargetService) TelemetryService(com.adobe.target.edge.client.service.TelemetryService) ArrayList(java.util.ArrayList) Attributes(com.adobe.target.edge.client.Attributes) OnDeviceDecisioningService(com.adobe.target.edge.client.ondevice.OnDeviceDecisioningService) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) ClientConfig(com.adobe.target.edge.client.ClientConfig) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with Attributes

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

the class TargetDeliveryAttributesTest method testTargetDeliveryAttributesNoRequest.

@Test
@SuppressWarnings("unchecked")
void testTargetDeliveryAttributesNoRequest() {
    Attributes attrs = targetJavaClient.getAttributes(null, "testoffer", "testoffer2");
    assertNotNull(attrs);
    assertNotNull(attrs.getResponse());
    assertEquals(200, attrs.getResponse().getStatus());
    verify(defaultTargetHttpClient, atMostOnce()).execute(any(Map.class), any(String.class), any(TargetDeliveryRequest.class), any(Class.class));
    assertTrue(attrs.getBoolean("testoffer", "test", false));
    assertTrue(attrs.toMboxMap("testoffer").containsKey("experience"));
    assertTrue(attrs.toMboxMap("testoffer").containsKey("price"));
    assertTrue(attrs.toMboxMap("testoffer2").containsKey("offer"));
}
Also used : Attributes(com.adobe.target.edge.client.Attributes) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with Attributes

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

the class TargetDeliveryAttributesTest method testTargetDeliveryAttributesPageload.

@Test
void testTargetDeliveryAttributesPageload() {
    TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874");
    DeliveryRequest deliveryRequest = targetDeliveryRequest.getDeliveryRequest();
    deliveryRequest.getPrefetch().setPageLoad(new RequestDetails());
    deliveryRequest.getPrefetch().setMboxes(Collections.emptyList());
    deliveryRequest.setExecute(null);
    Attributes attrs = targetJavaClient.getAttributes(targetDeliveryRequest);
    validateInitialResponse(targetDeliveryRequest, attrs);
    assertTrue(attrs.getBoolean("target-global-mbox", "test", false));
    assertEquals("a", attrs.getString("target-global-mbox", "experience"));
    assertEquals(12.99, attrs.getDouble("target-global-mbox", "price", 0d), 0.0001);
    assertEquals("a", attrs.toMboxMap("target-global-mbox").get("experience"));
    assertEquals("a", attrs.toMap().get("target-global-mbox").get("experience"));
}
Also used : TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Attributes(com.adobe.target.edge.client.Attributes) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Test(org.junit.jupiter.api.Test)

Example 4 with Attributes

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

the class TargetDeliveryAttributesTest method testTargetDeliveryAttributesVisitor1.

@Test
void testTargetDeliveryAttributesVisitor1() {
    TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916874");
    Attributes attrs = targetJavaClient.getAttributes(targetDeliveryRequest, "testoffer", "testoffer2");
    validateInitialResponse(targetDeliveryRequest, attrs);
    validateResultA(attrs);
}
Also used : Attributes(com.adobe.target.edge.client.Attributes) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Test(org.junit.jupiter.api.Test)

Example 5 with Attributes

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

the class TargetDeliveryAttributesTest method testTargetDeliveryAttributesVisitor2.

@Test
void testTargetDeliveryAttributesVisitor2() {
    TargetDeliveryRequest targetDeliveryRequest = localDeliveryRequest("38734fba-262c-4722-b4a3-ac0a93916873");
    Attributes attrs = targetJavaClient.getAttributes(targetDeliveryRequest, "testoffer", "testoffer2");
    validateInitialResponse(targetDeliveryRequest, attrs);
    assertTrue(attrs.getBoolean("testoffer", "test", false));
    assertEquals("b", attrs.getString("testoffer", "experience"));
    assertEquals(9.99, attrs.getDouble("testoffer", "price", 0d), 0.0001);
    assertEquals("b", attrs.toMboxMap("testoffer").get("experience"));
    assertEquals("b", attrs.toMap().get("testoffer").get("experience"));
    assertEquals(2, attrs.getInteger("testoffer2", "offer", 0));
}
Also used : Attributes(com.adobe.target.edge.client.Attributes) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Test(org.junit.jupiter.api.Test)

Aggregations

Attributes (com.adobe.target.edge.client.Attributes)5 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)5 Test (org.junit.jupiter.api.Test)5 Map (java.util.Map)2 ClientConfig (com.adobe.target.edge.client.ClientConfig)1 OnDeviceDecisioningService (com.adobe.target.edge.client.ondevice.OnDeviceDecisioningService)1 DefaultTargetService (com.adobe.target.edge.client.service.DefaultTargetService)1 TelemetryService (com.adobe.target.edge.client.service.TelemetryService)1 ArrayList (java.util.ArrayList)1