Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node xy docker builds image jposecurity unittests #281

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ public class FileDecoderPublisher {
private static final Logger logger = LoggerFactory.getLogger(FileDecoderPublisher.class);

private JsonDecoderPublisher jsonDecPub;

@Autowired
public FileDecoderPublisher(OdeProperties odeProperties) {

OdeStringPublisher bsmStringMsgPub = new OdeStringPublisher(odeProperties);
this.jsonDecPub = new JsonDecoderPublisher(bsmStringMsgPub);
}

public void decodeAndPublishFile(
Path filePath,
BufferedInputStream fileInputStream,
ImporterFileType fileType) {
public void decodeAndPublishFile(Path filePath, BufferedInputStream fileInputStream, ImporterFileType fileType) {

String fileName = filePath.toFile().getName();

logger.info("Decoding and publishing file {}", fileName);

try {
logger.info("Decoding {} as json file.", filePath);
jsonDecPub.decodeAndPublish(fileInputStream, fileName, fileType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,33 @@
public class ToJsonServiceController {

private static final Logger logger = LoggerFactory.getLogger(ToJsonServiceController.class);

private OdeProperties odeProperties;

@Autowired
public ToJsonServiceController(OdeProperties odeProps) {
super();

this.odeProperties = odeProps;

logger.info("Starting {}", this.getClass().getSimpleName());
this.odeProperties = odeProps;

// BSM POJO --> JSON converter
launchConverter(odeProps.getKafkaTopicOdeBsmPojo(), OdeBsmDeserializer.class.getName(),
new ToJsonConverter<>(odeProps, false, odeProps.getKafkaTopicOdeBsmJson()));
new ToJsonConverter<>(odeProps, false, odeProps.getKafkaTopicOdeBsmJson()));

// TIM POJO --> JSON converter
launchConverter(odeProps.getKafkaTopicOdeTimPojo(), OdeTimDeserializer.class.getName(),
new ToJsonConverter<>(odeProps, false, odeProps.getKafkaTopicOdeTimJson()));
new ToJsonConverter<>(odeProps, false, odeProps.getKafkaTopicOdeTimJson()));

// ODE-787 Now POJO to JSon publishing will be done in us.dot.its.jpo.ode.traveler.TimController.depositTim(String, RequestVerb)
// // Broadcast TIM POJO --> Broadcast TIM JSON converter
// launchConverter(odeProps.getKafkaTopicOdeTimBroadcastPojo(), OdeTimDeserializer.class.getName(),
// new ToJsonConverter<>(odeProps, false, odeProps.getKafkaTopicOdeTimBroadcastJson()));
}

private <V> void launchConverter(String fromTopic, String serializerFQN,
ToJsonConverter<V> jsonConverter) {
logger.info("Converting records from topic {} and publishing to topic {} ",
fromTopic, jsonConverter.getOutputTopic());
private <V> void launchConverter(String fromTopic, String serializerFQN, ToJsonConverter<V> jsonConverter) {
logger.info("Starting JSON converter, converting records from topic {} and publishing to topic {} ", fromTopic,
jsonConverter.getOutputTopic());

MessageConsumer<String, V> consumer = new MessageConsumer<String, V>(
odeProperties.getKafkaBrokers(), this.getClass().getSimpleName(),
jsonConverter, serializerFQN);
MessageConsumer<String, V> consumer = new MessageConsumer<String, V>(odeProperties.getKafkaBrokers(),
this.getClass().getSimpleName(), jsonConverter, serializerFQN);

consumer.setName(this.getClass().getName() + fromTopic + "Consumer");
consumer.setName(this.getClass().getName().toString() + fromTopic + "Consumer");
jsonConverter.start(consumer, fromTopic);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void sendDataReceipt(byte[] encodedIsd) {
throw new IOException("Received invalid packet.");
}

} catch (IOException | InterruptedException | ExecutionException e) {
} catch (IOException | InterruptedException | ExecutionException e) { // NOSONAR
logger.error("Error sending ISD Acceptance message to SDC", e);
} catch (TimeoutException e) {
logger.error("Did not receive ISD data receipt within alotted "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public boolean establishTrust(TemporaryID requestId, SemiDialogID dialogId) {
logger.error("Did not receive Service Response within alotted "
+ +odeProperties.getServiceRespExpirationSeconds() + " seconds.", e);

} catch (InterruptedException | ExecutionException | UdpUtilException e) {
} catch (InterruptedException | ExecutionException | UdpUtilException e) { // NOSONAR
endTrustSession(requestId);
logger.error("Trust establishment interrupted.", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package us.dot.its.jpo.ode.coder;

import static org.junit.Assert.fail;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.Ignore;
import org.junit.Test;

import mockit.Capturing;
Expand All @@ -18,7 +16,6 @@
import us.dot.its.jpo.ode.coder.stream.JsonDecoderPublisher;
import us.dot.its.jpo.ode.importer.ImporterDirectoryWatcher.ImporterFileType;

@Ignore
public class FileDecoderPublisherTest {

@Injectable
Expand All @@ -28,78 +25,38 @@ public class FileDecoderPublisherTest {
@Capturing
JsonDecoderPublisher capturingJsonDecoderPublisher;
@Capturing
OdeDataPublisher capturedMessagePublisher;

OdeStringPublisher capturingOdeStringPublisher;

@Test
public void hexDecoderShouldDecodeHex() {
try {
public void testNoException() {

new Expectations() {
{
capturingJsonDecoderPublisher.decodeAndPublish((BufferedInputStream) any, anyString, ImporterFileType.OBU_LOG_FILE);
times = 0;
times = 1;
}
};

Path testPath = Paths.get("testFile.hex");
BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1 }));
testedFileDecoderPublisher.decodeAndPublishFile(testPath, bis, ImporterFileType.OBU_LOG_FILE);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}

}

@Test
public void hexDecoderShouldDecodeText() {
try {
new Expectations() {
{
capturingJsonDecoderPublisher.decodeAndPublish((BufferedInputStream) any, anyString, ImporterFileType.OBU_LOG_FILE);
times = 0;
}
};

Path testPath = Paths.get("testFile.txt");
BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1 }));
testedFileDecoderPublisher.decodeAndPublishFile(testPath, bis, ImporterFileType.OBU_LOG_FILE);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
}
public void testException() {

@Test
public void jsonDecoderShouldDecodeJson() {
try {
new Expectations() {
{
capturingJsonDecoderPublisher.decodeAndPublish((BufferedInputStream) any, anyString, ImporterFileType.OBU_LOG_FILE);
result = new IOException("testException123");
times = 1;
}
};

Path testPath = Paths.get("testFile.json");
Path testPath = Paths.get("testFile.hex");
BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1 }));
testedFileDecoderPublisher.decodeAndPublishFile(testPath, bis, ImporterFileType.OBU_LOG_FILE);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
}

@Test
public void binaryDecoderShouldDecodeOther() {
try {
new Expectations() {
{
capturingJsonDecoderPublisher.decodeAndPublish((BufferedInputStream) any, anyString, ImporterFileType.OBU_LOG_FILE);
times = 0;
}
};

Path testPath = Paths.get("testFile.uper");
BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 1 }));
testedFileDecoderPublisher.decodeAndPublishFile(testPath, bis, ImporterFileType.OBU_LOG_FILE);
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
package us.dot.its.jpo.ode.services.json;
//TODO
//Redo this test the class being tested had changed
//
//
import org.junit.Ignore;
import org.junit.Test;

import mockit.Capturing;
Expand All @@ -23,22 +18,16 @@ public class ToJsonServiceControllerTest {
@Capturing
MessageConsumer<?, ?> capturingMessageConsumer;

@Ignore
@Test
public void test() {
new Expectations() {
{
new ToJsonConverter<>((OdeProperties) any, anyBoolean, anyString);
times = 3;
times = 2;

new MessageConsumer<>(anyString, anyString, (MessageProcessor<?, ?>) any, anyString);
times = 3;
times = 2;

capturingMessageConsumer.setName(anyString);
times = 3;

capturingToJsonConverter.start((MessageConsumer) any, anyString);
times = 3;
}
};
new ToJsonServiceController(injectableOdeProperties);
Expand Down