diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce80177..19d8615 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: sonar.java.binaries=home/runner/work/jpo-sdw-depositor/jpo-sdw-depositor/target sonar.projectName=jpo-sdw-depositor sonar.projectKey=usdot-jpo-ode_jpo-sdw-depositor - sonar.organization=usdot-jpo-ode-1 + sonar.organization=usdot-jpo-ode jpo-sdw-depositor.sonar.projectBaseDir=home/runner/work/jpo-sdw-depositor/jpo-sdw-depositor jpo-sdw-depositor.sonar.sources=src jpo-sdw-depositor.sonar.tests=src/test diff --git a/docs/Release_notes.md b/docs/Release_notes.md index 43af072..1a011be 100644 --- a/docs/Release_notes.md +++ b/docs/Release_notes.md @@ -1,6 +1,20 @@ Jpo-sdw-depositor Release Notes ---------------------------- +Version 1.5.0, released November 2023 +---------------------------------------- + +### **Summary** +The updates for the jpo-sdw-depositor 1.5.0 involve correcting the default SDX URL, fixing failing unit tests, and addressing a key reference issue in KafkaConsumerRestDepositor.java. +- The default SDX URL has been corrected. +- Resolved failing unit tests. +- Addressed a key reference issue in KafkaConsumerRestDepositor.java. +- Renamed mocked variables in DepositControllerTest.java + +Known Issues: +- No known issues at this time. + + Version 1.4.0, released July 5th 2023 ---------------------------------------- diff --git a/pom.xml b/pom.xml index 3239620..aae027c 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ 1.49 -javaagent:${user.home}/.m2/repository/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar - usdot-jpo-ode-1 + usdot-jpo-ode https://sonarcloud.io 0.8.8 diff --git a/src/main/java/jpo/sdw/depositor/DepositorProperties.java b/src/main/java/jpo/sdw/depositor/DepositorProperties.java index 07a9fc0..e376661 100644 --- a/src/main/java/jpo/sdw/depositor/DepositorProperties.java +++ b/src/main/java/jpo/sdw/depositor/DepositorProperties.java @@ -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"; @@ -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); diff --git a/src/main/java/jpo/sdw/depositor/consumerdepositors/KafkaConsumerRestDepositor.java b/src/main/java/jpo/sdw/depositor/consumerdepositors/KafkaConsumerRestDepositor.java index 41b3923..9995592 100644 --- a/src/main/java/jpo/sdw/depositor/consumerdepositors/KafkaConsumerRestDepositor.java +++ b/src/main/java/jpo/sdw/depositor/consumerdepositors/KafkaConsumerRestDepositor.java @@ -38,7 +38,7 @@ public KafkaConsumerRestDepositor(KafkaConsumer kafkaConsumer, R this.setRestDepositor(restDepositor); this.jsonMsgList = new JSONObject(); this.jsonMsg = new JSONObject(); - this.jsonMsg.put("EncodeType", encodeType); + this.jsonMsg.put("encodeType", encodeType); } @Override @@ -49,8 +49,8 @@ public void run(String... topics) { JSONArray jsonRequests = new JSONArray(); for (ConsumerRecord 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); diff --git a/src/test/java/jpo/sdw/depositor/controller/DepositControllerTest.java b/src/test/java/jpo/sdw/depositor/controller/DepositControllerTest.java index bcc0e7f..539cbd6 100644 --- a/src/test/java/jpo/sdw/depositor/controller/DepositControllerTest.java +++ b/src/test/java/jpo/sdw/depositor/controller/DepositControllerTest.java @@ -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 { @@ -24,21 +25,23 @@ public class DepositControllerTest { @Injectable JavaMailSender sender; - @Capturing - KafkaConsumerFactory capturingKafkaConsumerFactory; + @Mocked + KafkaConsumerFactory mockedCapturingKafkaConsumerFactory; - @Capturing - KafkaConsumerRestDepositor capturingKafkaConsumerRestDepositor; + @Mocked + KafkaConsumerRestDepositor mockedCapturingKafkaConsumerRestDepositor; - @Capturing - URI capturingURI; + @Mocked + URI mockedCapturingURI; - // currently not running, seems to be in endless loop somewhere - // @Test + @Test public void shouldRun() throws URISyntaxException { + new Expectations() { { - capturingKafkaConsumerRestDepositor.run((String[]) any); + injectableDepositorProperties.getDestinationUrl(); result = "127.0.0.1"; + + mockedCapturingKafkaConsumerRestDepositor.run((String[]) any); times = 1; } }; diff --git a/src/test/java/jpo/sdw/depositor/controller/KafkaConsumerFactoryTest.java b/src/test/java/jpo/sdw/depositor/controller/KafkaConsumerFactoryTest.java index 1b81f82..bc91ca4 100644 --- a/src/test/java/jpo/sdw/depositor/controller/KafkaConsumerFactoryTest.java +++ b/src/test/java/jpo/sdw/depositor/controller/KafkaConsumerFactoryTest.java @@ -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()