Skip to content

Commit

Permalink
Merge pull request #23 from CDOT-CV/develop
Browse files Browse the repository at this point in the history
Fixes for Default SDX URL, Unit Test Failures, and Key Reference in KafkaConsumerRestDepositor.java
  • Loading branch information
dan-du-car authored Oct 30, 2023
2 parents f867c4b + 9fb5651 commit 2c82ef3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
5 changes: 3 additions & 2 deletions src/main/java/jpo/sdw/depositor/DepositorProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DepositorProperties implements EnvironmentAware {

private static final String DEFAULT_GROUP_ID = "usdot.jpo.sdw";
private static final String DEFAULT_KAFKA_PORT = "9092";
private static final String DEFAULT_DESTINATION_URL = "https://sdx-service.trihydro.com/api/deposit";
private static final String DEFAULT_DESTINATION_URL = "https://sdx-service.trihydro.com/api/deposit-multi";
private static final String[] DEFAULT_SUBSCRIPTION_TOPICS = { "topic.SDWDepositorInput" };
private static final String DEFAULT_ENCODE_TYPE = "hex";

Expand Down Expand Up @@ -61,8 +61,9 @@ void initialize() {
if (getEncodeType() == null)
setEncodeType(DEFAULT_ENCODE_TYPE);

if (getDestinationUrl() == null)
if (getDestinationUrl() == null || getDestinationUrl().isEmpty()) {
setDestinationUrl(DEFAULT_DESTINATION_URL);
}

if (getSubscriptionTopics() == null || getSubscriptionTopics().length == 0) {
String topics = String.join(",", DEFAULT_SUBSCRIPTION_TOPICS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public KafkaConsumerRestDepositor(KafkaConsumer<String, String> kafkaConsumer, R
this.setRestDepositor(restDepositor);
this.jsonMsgList = new JSONObject();
this.jsonMsg = new JSONObject();
this.jsonMsg.put("EncodeType", encodeType);
this.jsonMsg.put("encodeType", encodeType);
}

@Override
Expand All @@ -49,8 +49,8 @@ public void run(String... topics) {
JSONArray jsonRequests = new JSONArray();
for (ConsumerRecord<String, String> record : records) {
logger.info("Depositing message {}", record);
this.jsonMsg.put("EncodedMsg", record.value());
jsonRequests.put(jsonMsg);
this.jsonMsg.put("encodedMsg", record.value());
jsonRequests.put(new JSONObject(jsonMsg.toString()));
}
if (records.count() != 0) {
this.jsonMsgList.put("depositRequests", jsonRequests);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import jpo.sdw.depositor.DepositorProperties;
import jpo.sdw.depositor.consumerdepositors.KafkaConsumerRestDepositor;
import mockit.Capturing;
import mockit.Expectations;
import mockit.Injectable;
import mockit.Tested;
import mockit.Mocked;


public class DepositControllerTest {

Expand All @@ -24,20 +25,22 @@ public class DepositControllerTest {
@Injectable
JavaMailSender sender;

@Capturing
@Mocked
KafkaConsumerFactory capturingKafkaConsumerFactory;

@Capturing
@Mocked
KafkaConsumerRestDepositor capturingKafkaConsumerRestDepositor;

@Capturing
@Mocked
URI capturingURI;

// currently not running, seems to be in endless loop somewhere
// @Test
@Test
public void shouldRun() throws URISyntaxException {

new Expectations() {
{
injectableDepositorProperties.getDestinationUrl(); result = "127.0.0.1";

capturingKafkaConsumerRestDepositor.run((String[]) any);
times = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ public class KafkaConsumerFactoryTest {
@Mocked
DepositorProperties mockedDepositorProperties;

// currently failing due to attempt to connect to Kafka broker on creation of consumer
// attempted to mock kafka consumer constructor without luck
// @Test
// public void createConsumerShouldCreateConsumer() {
// new Expectations() {
// {
// // These are required because Properties throws NPE when values are null
// mockedDepositorProperties.getKafkaBrokers();
// result = "kafkaBrokers";

// mockedDepositorProperties.getGroupId();
// result = "groupId";

// }
// };
// assertNotNull(KafkaConsumerFactory.createConsumer(mockedDepositorProperties));
// }

@Test
public void createConsumerShouldCreateConsumer() {

new Expectations() {
{
// These are required because Properties throws NPE when values are null
mockedDepositorProperties.getKafkaBrokers();
result = "kafkaBrokers";

mockedDepositorProperties.getGroupId();
result = "groupId";

}
};
assertNotNull(KafkaConsumerFactory.createConsumer(mockedDepositorProperties));
}

@Test
public void testConstructorIsPrivate()
Expand Down

0 comments on commit 2c82ef3

Please sign in to comment.