Skip to content

Commit

Permalink
extract SDK > fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DC2-DanielKrueger committed Apr 29, 2024
1 parent aa136f0 commit d01bcfa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.google.common.base.Preconditions;
import com.hivemq.edge.modules.adapters.annotations.ModuleConfigField;
import com.hivemq.edge.modules.config.AdapterSubscription;
import com.hivemq.edge.modules.config.impl.AbstractPollingProtocolAdapterConfig;
import com.hivemq.edge.modules.config.CustomConfig;
import com.hivemq.edge.modules.config.impl.AdapterSubscriptionImpl;
import com.hivemq.edge.modules.config.impl.UserPropertyImpl;
import com.hivemq.extension.sdk.api.annotations.NotNull;
Expand Down Expand Up @@ -89,12 +89,17 @@ private static boolean hasImmediateChild(final @NotNull JsonNode parent, final @
return parent.get(nodeName) != null;
}

static class AdapterConfiguration extends AbstractPollingProtocolAdapterConfig {
static class AdapterConfiguration implements CustomConfig {

@JsonProperty("subscriptions")
@ModuleConfigField(title = "Subscriptions",
description = "List of subscriptions for the simulation",
required = true)
private @NotNull List<AdapterSubscription> subscriptions = new ArrayList<>();

@Override
public @NotNull String getId() {
return "id";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.hivemq.api.json.CustomConfigSchemaGenerator;
import com.hivemq.edge.modules.adapters.annotations.ModuleConfigField;
import com.hivemq.edge.modules.config.AdapterSubscription;
import com.hivemq.edge.modules.config.impl.AbstractProtocolAdapterConfig;
import com.hivemq.edge.modules.config.CustomConfig;
import com.hivemq.extension.sdk.api.annotations.NotNull;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -36,6 +36,8 @@
import java.util.Iterator;
import java.util.List;

import static com.hivemq.edge.HiveMQEdgeConstants.ID_REGEX;


/**
* @author Simon L Johnson
Expand Down Expand Up @@ -110,7 +112,17 @@ private static boolean hasImmediateChild(final @NotNull JsonNode parent, final @
}

@JsonPropertyOrder({"startIdx", "endIdx"})
static class TestOrderingConfig extends AbstractProtocolAdapterConfig {
static class TestOrderingConfig implements CustomConfig {

@JsonProperty(value = "id", required = true)
@ModuleConfigField(title = "Identifier",
description = "Unique identifier for this protocol adapter",
format = ModuleConfigField.FieldType.IDENTIFIER,
required = true,
stringPattern = ID_REGEX,
stringMinLength = 1,
stringMaxLength = 1024)
protected @NotNull String id;

@JsonProperty(value = "startIdx")
@ModuleConfigField(title = "Start Index")
Expand All @@ -119,9 +131,14 @@ static class TestOrderingConfig extends AbstractProtocolAdapterConfig {
@JsonProperty(value = "endIdx")
@ModuleConfigField(title = "End Index")
int endIdx;

@Override
public @NotNull String getId() {
return id;
}
}

static class TestNestedEntity extends AbstractProtocolAdapterConfig {
static class TestNestedEntity implements CustomConfig {

@JsonProperty("subscriptions")
@ModuleConfigField(title = "Subscriptions",
Expand All @@ -130,5 +147,20 @@ static class TestNestedEntity extends AbstractProtocolAdapterConfig {
})
private @NotNull List<AdapterSubscription> subscriptions = new ArrayList<>();


@JsonProperty(value = "id", required = true)
@ModuleConfigField(title = "Identifier",
description = "Unique identifier for this protocol adapter",
format = ModuleConfigField.FieldType.IDENTIFIER,
required = true,
stringPattern = ID_REGEX,
stringMinLength = 1,
stringMaxLength = 1024)
protected @NotNull String id;

@Override
public @NotNull String getId() {
return id;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void setUp() {
@Test
void test_captureDataSample_expectedPayloadPresent() throws ExecutionException, InterruptedException {
final AdapterSubscription subscription = new AdapterSubscriptionImpl("topic", 2, null);
final HttpData httpData = new HttpData("http://localhost:8080", 200, "text/plain", new TestDataPointFactory());
final HttpData httpData = new HttpData(new AdapterSubscriptionImpl(), "http://localhost:8080", 200, "text/plain", new TestDataPointFactory());
httpData.addDataPoint(RESPONSE_DATA, "hello world");

httpProtocolAdapter.poll().get();
Expand All @@ -82,8 +82,8 @@ void test_captureDataSample_expectedPayloadPresent() throws ExecutionException,
@Test
void test_captureDataSample_errorPayloadFormat() throws ExecutionException, InterruptedException {
final AdapterSubscription subscription = new AdapterSubscriptionImpl("topic", 2, null);
final HttpData httpData = new HttpData("http://localhost:8080", 200, "text/plain", new TestDataPointFactory());
final HttpData payload = new HttpData("http://localhost:8080", 404, "text/plain", new TestDataPointFactory());
final HttpData httpData = new HttpData(new AdapterSubscriptionImpl(),"http://localhost:8080", 200, "text/plain", new TestDataPointFactory());
final HttpData payload = new HttpData(new AdapterSubscriptionImpl(),"http://localhost:8080", 404, "text/plain", new TestDataPointFactory());
httpData.addDataPoint(RESPONSE_DATA, payload);

httpProtocolAdapter.poll().get();
Expand Down

0 comments on commit d01bcfa

Please sign in to comment.