Skip to content

Commit

Permalink
Adding test for partner config
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-constine-ttd committed Oct 22, 2024
1 parent f503a4b commit f109230
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/test/java/com/uid2/optout/vertx/OptOutSenderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

import com.uid2.shared.optout.OptOutEntry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.vertx.core.Future;
Expand Down Expand Up @@ -110,7 +112,7 @@ void testScanLocalForUnprocessedWithNewFile(Vertx vertx, VertxTestContext testCo

// If this test hangs delete the /tmp/uid2/optout folder and run again.
@Test
void testRecieveMessage(Vertx vertx, VertxTestContext testContext) throws InterruptedException {
void testRecieveMessageAndSendsIDs(Vertx vertx, VertxTestContext testContext) throws InterruptedException {
deployVerticle(vertx, testContext);
Path newFile = getDeltaPath();
TestUtils.newDeltaFile(newFile, 1, 2, 3);
Expand All @@ -120,5 +122,6 @@ void testRecieveMessage(Vertx vertx, VertxTestContext testContext) throws Interr
Thread.sleep(100);
}
verify(optOutPartnerEndpoint, times(3)).send(any());
testContext.completeNow();
}
}
114 changes: 114 additions & 0 deletions src/test/java/com/uid2/optout/vertx/PartnerConfigMonitorV2Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.uid2.optout.vertx;

import com.uid2.optout.Const;
import com.uid2.shared.cloud.CloudStorageException;
import com.uid2.shared.cloud.DownloadCloudStorage;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.junit.jupiter.api.Assertions.*;

import java.io.ByteArrayInputStream;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@ExtendWith(VertxExtension.class)
public class PartnerConfigMonitorV2Test {
private AutoCloseable mocks;
private final String filePath = "/tmp/uid2/optout";
private final JsonObject config = new JsonObject();
private final String eventBusName = "testEventBus";

@Mock
private DownloadCloudStorage metadataStorage;
@Mock
private DownloadCloudStorage contentStorage;

private PartnerConfigMonitorV2 partnerConfigMonitorV2;

@BeforeEach
public void deployVerticle(Vertx vertx, VertxTestContext testContext) {
mocks = MockitoAnnotations.openMocks(this);

setupConfig();

partnerConfigMonitorV2 = new PartnerConfigMonitorV2(vertx, config, metadataStorage, contentStorage, eventBusName);
testContext.completeNow();
}

private void setupConfig() {
config.put(Const.Config.OptOutDataDirProp, filePath);
config.put(Const.Config.OptOutProducerReplicaIdProp, 1);

config.put(Const.Config.OptOutSenderReplicaIdProp, 1);
config.put(Const.Config.OptOutProducerMaxReplicasProp, 1);

config.put(Const.Config.OptOutDeltaRotateIntervalProp, 300);

config.put(Const.Config.PartnersMetadataPathProp, "testPath");
}

@Test
void testConstructor(Vertx vertx, VertxTestContext testContext) {
testContext.completeNow();
}

@Test
void testLoadContent(Vertx vertx, VertxTestContext testContext) throws Exception {
JsonObject metadata = new JsonObject();
JsonObject partner = new JsonObject();
partner.put("location", "testLocation");
metadata.put("partners", partner);

String testString = """
[
{
"name": "test1",
"url": "https:/test.com/uid2/optout",
"method": "GET",
"query_params": [
"action=dooptout",
"uid2=${ADVERTISING_ID}",
"timestamp=${OPTOUT_EPOCH}"
],
"additional_headers": [
"Authorization: Bearer some_bearer"
],
"retry_count": 600,
"retry_backoff_ms": 6000
},
{
"name": "test2",
"url": "https:/example.com/optout",
"method": "POST",
"query_params": [
"token=${ADVERTISING_ID}",
"timestamp=${OPTOUT_EPOCH}"
],
"additional_headers": [
"Authorization: Bearer bearer2"
],
"retry_count": 60,
"retry_backoff_ms": 1000
}
]
""";

when(contentStorage.download(any())).thenReturn(new ByteArrayInputStream(testString.getBytes()));

long endpoints = partnerConfigMonitorV2.loadContent(metadata);

//Two endpoints senders should be deployed
assertEquals(2, endpoints);


testContext.completeNow();
}
}

0 comments on commit f109230

Please sign in to comment.