Skip to content

Commit e1229cd

Browse files
committed
Update to docs
1 parent b04a390 commit e1229cd

File tree

1 file changed

+80
-19
lines changed

1 file changed

+80
-19
lines changed

src/test/java/com/uid2/client/DocSampleCodeTest.java

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ public void testPublisherAdvancedTokenRefreshResponse() {
545545

546546
@Test
547547
public void testImportStatements() {
548-
// Documentation sdk-ref-java.md Line 419-422: Import statements verification for migration guide
548+
// Documentation sdk-ref-java.md Line 437-442: Import statements verification for migration guide
549549
// Verify that all documented import classes are accessible and can be instantiated
550550

551551
// import com.uid2.client.IdentityMapV3Client;
@@ -584,19 +584,80 @@ public void testImportStatements() {
584584
assertTrue(hasUnknown);
585585
}
586586

587+
@Test
588+
public void testRecommendedChangesExamples() {
589+
// Documentation sdk-ref-java.md Line 446-488: Recommended changes examples for v3 optional features
590+
591+
// Documentation sdk-ref-java.md Line 449-460: 1. Mix identity types in a single request
592+
// Before - single identity type only
593+
IdentityMapInput inputV2 = IdentityMapInput.fromEmails(Arrays.asList("[email protected]"));
594+
595+
// After - can mix identity types (new v3 capability)
596+
IdentityMapV3Input mixedInput = new IdentityMapV3Input()
597+
.withEmail("[email protected]")
598+
.withPhone("+12345678901")
599+
.withHashedEmail("preHashedEmail")
600+
.withHashedPhone("preHashedPhone");
601+
602+
IdentityMapV3Response mixedResponse = identityMapV3Client.generateIdentityMap(mixedInput);
603+
assertNotNull(mixedResponse);
604+
605+
// Documentation sdk-ref-java.md Line 463-475: 2. Access previous UID2s
606+
// Before - only current UID2 available
607+
IdentityMapClient clientV2 = new IdentityMapClient(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY);
608+
IdentityMapResponse responseV2 = clientV2.generateIdentityMap(inputV2);
609+
IdentityMapResponse.MappedIdentity mappedV2 = responseV2.getMappedIdentities().get("[email protected]");
610+
if (mappedV2 != null) {
611+
String uid = mappedV2.getRawUid();
612+
assertNotNull(uid);
613+
}
614+
615+
// After - access to both current and previous UID2s
616+
IdentityMapV3Response responseV3 = identityMapV3Client.generateIdentityMap(IdentityMapV3Input.fromEmails(Arrays.asList("[email protected]")));
617+
IdentityMapV3Response.MappedIdentity mappedV3 = responseV3.getMappedIdentities().get("[email protected]");
618+
if (mappedV3 != null) {
619+
String currentUid = mappedV3.getCurrentRawUid();
620+
String previousUid = mappedV3.getPreviousRawUid(); // Available for 90 days after rotation
621+
Instant refreshFrom = mappedV3.getRefreshFrom();
622+
623+
assertNotNull(currentUid);
624+
assertNotNull(refreshFrom);
625+
// previousUid may be null if no rotation occurred
626+
}
627+
628+
// Documentation sdk-ref-java.md Line 478-488: 3. Use structured error reasons
629+
// Before - string-based error reasons
630+
IdentityMapResponse.UnmappedIdentity unmappedV2 = responseV2.getUnmappedIdentities().get("[email protected]");
631+
if (unmappedV2 != null) {
632+
String reason = unmappedV2.getReason();
633+
assertNotNull(reason);
634+
}
635+
636+
// After - structured enum-based error reasons
637+
IdentityMapV3Response.UnmappedIdentity unmappedV3 = responseV3.getUnmappedIdentities().get("[email protected]");
638+
if (unmappedV3 != null) {
639+
UnmappedIdentityReason reason = unmappedV3.getReason(); // Enum: OPTOUT, INVALID_IDENTIFIER, UNKNOWN
640+
assertNotNull(reason);
641+
642+
// Or continue using string reasons if preferred
643+
String rawReason = unmappedV3.getRawReason();
644+
assertNotNull(rawReason);
645+
}
646+
}
647+
587648
// ========================================
588649
// DSP USAGE TESTS
589650
// ========================================
590651

591652
@Test
592653
public void testDspUsageExample() {
593-
// Documentation sdk-ref-java.md Line 514: DSP Usage - BidstreamClient creation
654+
// Documentation sdk-ref-java.md Line 528: DSP Usage - BidstreamClient creation
594655
BidstreamClient client = new BidstreamClient(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY);
595656

596-
// Documentation sdk-ref-java.md Line 520: Refresh at startup and periodically
657+
// Documentation sdk-ref-java.md Line 534: Refresh at startup and periodically
597658
client.refresh();
598659

599-
// Documentation sdk-ref-java.md Line 529: Decrypt token into raw UID2 with domain/app name
660+
// Documentation sdk-ref-java.md Line 543: Decrypt token into raw UID2 with domain/app name
600661
String mockUidToken = "mock-uid-token"; // In real usage, this would be from bid request
601662
String domainOrAppName = "example.com"; // or app name, or null
602663

@@ -624,13 +685,13 @@ public void testDspUsageExample() {
624685

625686
@Test
626687
public void testSharingClientUsageExample() {
627-
// Documentation sdk-ref-java.md Line 557: UID2 Sharers Usage - SharingClient creation
688+
// Documentation sdk-ref-java.md Line 571: UID2 Sharers Usage - SharingClient creation
628689
SharingClient client = new SharingClient(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY);
629690

630-
// Documentation sdk-ref-java.md Line 562: Refresh at startup and periodically
691+
// Documentation sdk-ref-java.md Line 576: Refresh at startup and periodically
631692
client.refresh();
632693

633-
// Documentation sdk-ref-java.md Line 567: Encrypt raw UID as sender
694+
// Documentation sdk-ref-java.md Line 581: Encrypt raw UID as sender
634695
String mockRawUid = "mock-raw-uid"; // In real usage, this would be actual raw UID2
635696

636697
try {
@@ -650,7 +711,7 @@ public void testSharingClientUsageExample() {
650711
assertTrue(true);
651712
}
652713

653-
// Documentation sdk-ref-java.md Line 581: Decrypt token as receiver
714+
// Documentation sdk-ref-java.md Line 595: Decrypt token as receiver
654715
String mockUidToken = "mock-uid-token"; // In real usage, this would be from sender
655716

656717
try {
@@ -677,23 +738,23 @@ public void testSharingClientUsageExample() {
677738

678739
@Test
679740
public void testV2LegacyUsageExample() {
680-
// Documentation sdk-ref-java.md Line 480: V2 Implementation - Legacy IdentityMapClient creation
741+
// Documentation sdk-ref-java.md Line 494: V2 Implementation - Legacy IdentityMapClient creation
681742
IdentityMapClient identityMapClient = new IdentityMapClient(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY);
682743

683-
// Documentation sdk-ref-java.md Line 485: V2 Input construction (single identity type only)
744+
// Documentation sdk-ref-java.md Line 499: V2 Input construction (single identity type only)
684745
IdentityMapInput input = IdentityMapInput.fromEmails(Arrays.asList("[email protected]"));
685746

686-
// Documentation sdk-ref-java.md Line 485: V2 API call
747+
// Documentation sdk-ref-java.md Line 499: V2 API call
687748
IdentityMapResponse identityMapResponse = identityMapClient.generateIdentityMap(input);
688749

689-
// Documentation sdk-ref-java.md Line 492-493: V2 Response handling with proper types
750+
// Documentation sdk-ref-java.md Line 506-507: V2 Response handling with proper types
690751
HashMap<String, IdentityMapResponse.MappedIdentity> mappedIdentities = identityMapResponse.getMappedIdentities();
691752
HashMap<String, IdentityMapResponse.UnmappedIdentity> unmappedIdentities = identityMapResponse.getUnmappedIdentities();
692753

693754
assertNotNull(mappedIdentities);
694755
assertNotNull(unmappedIdentities);
695756

696-
// Documentation sdk-ref-java.md Line 498-501: V2 Result processing with bucket ID
757+
// Documentation sdk-ref-java.md Line 512-515: V2 Result processing with bucket ID
697758
IdentityMapResponse.MappedIdentity mappedIdentity = mappedIdentities.get("[email protected]");
698759
if (mappedIdentity != null) {
699760
String rawUID = mappedIdentity.getRawUid();
@@ -706,9 +767,9 @@ public void testV2LegacyUsageExample() {
706767

707768
@Test
708769
public void testV2ToV3MigrationExamples() {
709-
// Documentation sdk-ref-java.md Line 410-415: Basic email mapping migration example
770+
// Documentation sdk-ref-java.md Line 427-432: Basic client class migration example
710771

711-
// Documentation sdk-ref-java.md Line 411: V2 approach (before migration)
772+
// Documentation sdk-ref-java.md Line 430: V2 approach (before migration)
712773
IdentityMapClient clientV2 = new IdentityMapClient(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY);
713774
IdentityMapInput inputV2 = IdentityMapInput.fromEmails(Arrays.asList("[email protected]"));
714775
IdentityMapResponse responseV2 = clientV2.generateIdentityMap(inputV2);
@@ -717,7 +778,7 @@ public void testV2ToV3MigrationExamples() {
717778
uidV2 = responseV2.getMappedIdentities().values().iterator().next().getRawUid();
718779
}
719780

720-
// Documentation sdk-ref-java.md Line 414: V3 approach (after migration)
781+
// Documentation sdk-ref-java.md Line 433: V3 approach (after migration)
721782
IdentityMapV3Client clientV3 = new IdentityMapV3Client(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY);
722783
IdentityMapV3Input inputV3 = IdentityMapV3Input.fromEmails(Arrays.asList("[email protected]"));
723784
IdentityMapV3Response responseV3 = clientV3.generateIdentityMap(inputV3);
@@ -730,7 +791,7 @@ public void testV2ToV3MigrationExamples() {
730791
assertNotNull(responseV2);
731792
assertNotNull(responseV3);
732793

733-
// Documentation sdk-ref-java.md Line 517-527: Enhanced response processing with UID rotation support
794+
// Enhanced response processing with UID rotation support from recommended changes section
734795
IdentityMapV3Response.MappedIdentity mapped = responseV3.getMappedIdentities().get("[email protected]");
735796
if (mapped != null) {
736797
String currentUid = mapped.getCurrentRawUid();
@@ -740,14 +801,14 @@ public void testV2ToV3MigrationExamples() {
740801
assertNotNull(currentUid);
741802
assertNotNull(refreshFrom);
742803

743-
// Documentation sdk-ref-java.md Line 524-526: Check if refresh is needed
804+
// Check if refresh is needed
744805
if (Instant.now().isAfter(refreshFrom)) {
745806
// Refresh this identity
746807
assertTrue(true); // Placeholder for refresh logic
747808
}
748809
}
749810

750-
// Documentation sdk-ref-java.md Line 535-549: Error handling migration with structured switch statement
811+
// Error handling migration with structured switch statement from recommended changes section
751812
IdentityMapV3Response.UnmappedIdentity unmapped = responseV3.getUnmappedIdentities().get("[email protected]");
752813
if (unmapped != null) {
753814
switch (unmapped.getReason()) {

0 commit comments

Comments
 (0)