Skip to content

Commit

Permalink
Miscellaneous minor code cleanups (frankframework#5306)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnleeuw authored Aug 30, 2023
1 parent 99e8389 commit d06ee3c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ public class ExceptionHandlingPipeProcessor extends PipeProcessorBase {

@Override
protected PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, Message message, PipeLineSession pipeLineSession, ThrowingFunction<Message, PipeRunResult,PipeRunException> chain) throws PipeRunException {
PipeRunResult prr = null;
try {
prr = chain.apply(message);
return chain.apply(message);
} catch (Exception e) {
Map<String, PipeForward> forwards = pipe.getForwards();
if (forwards!=null && forwards.containsKey(PipeForward.EXCEPTION_FORWARD_NAME) && !(pipe instanceof ExceptionPipe)) {
Expand All @@ -52,7 +51,5 @@ protected PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, Message messa
}
throw e;
}
return prr;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public class InputOutputPipeProcessor extends PipeProcessorBase {
@Override
protected PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, Message message, PipeLineSession pipeLineSession, ThrowingFunction<Message, PipeRunResult,PipeRunException> chain) throws PipeRunException {
Object preservedObject = message;
PipeRunResult pipeRunResult = null;
INamedObject owner = pipeLine.getOwner();

IExtendedPipe pe=null;
Expand All @@ -93,26 +92,28 @@ protected PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, Message messa
if (StringUtils.isNotEmpty(pe.getGetInputFromFixedValue())) {
if (log.isDebugEnabled()) log.debug("Pipeline of adapter ["+owner.getName()+"] replacing input for pipe ["+pe.getName()+"] with fixed value ["+pe.getGetInputFromFixedValue()+"]");
message.closeOnCloseOf(pipeLineSession, owner);
message=new Message(pe.getGetInputFromFixedValue());
message = Message.asMessage(pe.getGetInputFromFixedValue());
}

if (Message.isEmpty(message) && StringUtils.isNotEmpty(pe.getEmptyInputReplacement())) {
if (log.isDebugEnabled()) log.debug("Pipeline of adapter ["+owner.getName()+"] replacing empty input for pipe ["+pe.getName()+"] with fixed value ["+pe.getEmptyInputReplacement()+"]");
message = new Message(pe.getEmptyInputReplacement());
message = Message.asMessage(pe.getEmptyInputReplacement());
}
}

PipeRunResult pipeRunResult = null;
if (pipe instanceof FixedForwardPipe) {
FixedForwardPipe ffPipe = (FixedForwardPipe) pipe;
if (ffPipe.skipPipe(message, pipeLineSession)) {
pipeRunResult = new PipeRunResult(ffPipe.getSuccessForward(), message);
}
}

if (pipeRunResult==null){
pipeRunResult=chain.apply(message);
if (pipeRunResult == null) {
pipeRunResult = chain.apply(message);
}
if (pipeRunResult==null){
throw new PipeRunException(pipe, "Pipeline of ["+pipeLine.getOwner().getName()+"] received null result from pipe ["+pipe.getName()+"]d");
if (pipeRunResult == null) {
throw new PipeRunException(pipe, "Pipeline of [" + pipeLine.getOwner().getName() + "] received null result from pipe [" + pipe.getName() + "]d");
}

if (pe !=null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public SenderResult sendMessage(Message message, PipeLineSession session) throws
if (session.getCorrelationId() != null) {
subAdapterSession.put(PipeLineSession.CORRELATION_ID_KEY, session.getCorrelationId());
}
if (paramList!=null) {
if (paramList != null) {
try {
Map<String,Object> paramValues = paramList.getValues(message, session).getValueMap();
subAdapterSession.putAll(paramValues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class InputOutputPipeProcessorTest {

private InputOutputPipeProcessor processor;
private PipeLine pipeLine;
private PipeLineSession session;
private PipeLineSession session;

@BeforeEach
public void setUp() {
processor = new InputOutputPipeProcessor();
Expand All @@ -39,17 +39,17 @@ public PipeRunResult validate(PipeLine pipeLine, IValidator validator, Message m
}
};
processor.setPipeProcessor(chain);

pipeLine = new PipeLine();
Adapter owner = new Adapter();
owner.setName("PipeLine owner");
pipeLine.setOwner(owner);

session = new PipeLineSession();
}

public void testRestoreMovedElement(Object sessionVarContents) throws Exception {

FixedResultPipe pipe = new FixedResultPipe();
pipe.setRestoreMovedElements(true);
pipe.setReturnString("result [{sessionKey:replaceThis}]");
Expand All @@ -58,16 +58,15 @@ public void testRestoreMovedElement(Object sessionVarContents) throws Exception
pipe.registerForward(forward);
pipe.configure();
pipe.start();

Message input = new Message("input");

session.put("replaceThis", sessionVarContents);



PipeRunResult prr = processor.processPipe(pipeLine, pipe, input, session);

assertEquals("result [ReplacedValue]", prr.getResult().asString());

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,20 @@ public void testSendMessageWithParamValuesAndReturnSessionKeys() throws Exceptio
IbisLocalSender sender = createIbisLocalSenderWithDummyServiceClient();

try (PipeLineSession session = new PipeLineSession()) {
session.put("my-parameter", "parameter-value");
Message message = new Message("my-parameter");
session.put("my-parameter1", "parameter1-value");
session.put("my-parameter2", Message.asMessage("parameter2-value"));
Message message = new Message("my-parameter1");

// Act
SenderResult result = sender.sendMessage(message, session);

// Assert
assertAll(
() -> assertEquals("parameter-value", result.getResult().asString()),
() -> assertTrue(session.containsKey("my-parameter"), "After request the pipeline-session should contain key [my-parameter]"),
() -> assertEquals("parameter-value", session.get("my-parameter")),
() -> assertEquals("parameter1-value", result.getResult().asString()),
() -> assertTrue(session.containsKey("my-parameter1"), "After request the pipeline-session should contain key [my-parameter1]"),
() -> assertEquals("parameter1-value", session.getString("my-parameter1")),
() -> assertTrue(session.containsKey("my-parameter2"), "After request the pipeline-session should contain key [my-parameter2]"),
() -> assertEquals("parameter2-value", session.getString("my-parameter2")),
() -> assertTrue(session.containsKey("this-doesnt-exist"), "After request the pipeline-session should contain key [this-doesnt-exist]"),
() -> assertNull(session.get("this-doesnt-exist"), "Key not in return from service should have value [NULL]"),
() -> assertFalse(session.containsKey("key-not-configured-for-copy"), "Session should not contain key 'key-not-configured-for-copy'")
Expand All @@ -171,17 +174,17 @@ public void testSendMessageReturnSessionKeysWhenNoneConfigured() throws Exceptio
sender.setReturnedSessionKeys(null);

try (PipeLineSession session = new PipeLineSession()) {
session.put("my-parameter", "parameter-value");
Message message = new Message("my-parameter");
session.put("my-parameter1", "parameter1-value");
Message message = new Message("my-parameter1");

// Act
SenderResult result = sender.sendMessage(message, session);

// Assert
assertAll(
() -> assertEquals("parameter-value", result.getResult().asString()),
() -> assertTrue(session.containsKey("my-parameter"), "After request the pipeline-session should contain key [my-parameter]"),
() -> assertEquals("parameter-value", session.get("my-parameter")),
() -> assertEquals("parameter1-value", result.getResult().asString()),
() -> assertTrue(session.containsKey("my-parameter1"), "After request the pipeline-session should contain key [my-parameter1]"),
() -> assertEquals("parameter1-value", session.get("my-parameter1")),
() -> assertFalse(session.containsKey("this-doesnt-exist"), "After request the pipeline-session should not contain key [this-doesnt-exist]"),
() -> assertTrue(session.containsKey("key-not-configured-for-copy"), "Session should contain key 'key-not-configured-for-copy' b/c all keys should be copied")
);
Expand All @@ -196,7 +199,7 @@ public void testSendMessageWithExitStateError() throws Exception {
try (PipeLineSession session = new PipeLineSession()) {
session.put(PipeLineSession.EXIT_STATE_CONTEXT_KEY, PipeLine.ExitState.ERROR);
session.put(PipeLineSession.EXIT_CODE_CONTEXT_KEY, "400");
Message message = new Message("my-parameter");
Message message = new Message("my-parameter1");

// Act / Assert
SenderResult result = sender.sendMessage(message, session);
Expand Down Expand Up @@ -352,9 +355,10 @@ private static IbisLocalSender createIbisLocalSenderWithDummyServiceClient() thr
sender.setServiceName(SERVICE_NAME);
sender.setSynchronous(true);
sender.setIsolated(false);
sender.setReturnedSessionKeys("my-parameter,this-doesnt-exist");
sender.setReturnedSessionKeys("my-parameter1,this-doesnt-exist");

addParameter("my-parameter", sender);
addParameter("my-parameter1", sender);
addParameter("my-parameter2", sender);
addParameter(PipeLineSession.EXIT_STATE_CONTEXT_KEY, sender);
addParameter(PipeLineSession.EXIT_CODE_CONTEXT_KEY, sender);

Expand Down
6 changes: 3 additions & 3 deletions ladybug/src/main/java/nl/nn/ibistesttool/Debugger.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* @author Jaco de Groot
*/
public class Debugger implements IbisDebugger, nl.nn.testtool.Debugger, ApplicationListener<DebuggerStatusChangedEvent> {
private Logger log = LogUtil.getLogger(this);
private final Logger log = LogUtil.getLogger(this);

private static final String STUB_STRATEGY_STUB_ALL_SENDERS = "Stub all senders";
protected static final String STUB_STRATEGY_NEVER = "Never";
Expand All @@ -64,7 +64,7 @@ public class Debugger implements IbisDebugger, nl.nn.testtool.Debugger, Applicat
private PipeDescriptionProvider pipeDescriptionProvider;
private List<String> testerRoles;

protected Set<String> inRerun = new HashSet<String>();
protected Set<String> inRerun = new HashSet<>();

public void setTestTool(TestTool testTool) {
this.testTool = testTool;
Expand Down Expand Up @@ -207,7 +207,7 @@ public Object capturedInput(String correlationId, String value) {
@Override
public Object parameterResolvedTo(Parameter parameter, String correlationId, Object value) {
if (parameter.isHidden()) {
String hiddenValue=null;
String hiddenValue;
try {
hiddenValue = StringUtil.hide(Message.asString(value));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ private Object getMessage(String name) {
return value;
}

private Object put(String name, Object value) {
Object oldValue = value;
value = ibisDebugger.storeInSessionKey(pipeLineSession.getCorrelationId(), name, value);
if (value != oldValue && value instanceof Message) {
private Object put(final String name, final Object originalValue) {
Object newValue = ibisDebugger.storeInSessionKey(pipeLineSession.getCorrelationId(), name, originalValue);
if (newValue != originalValue && newValue instanceof Message) {
// If a session key is stubbed with a stream and this session key is not used (stream is not read) it will
// keep the report in progress (waiting for the stream to be read, captured and closed).
((Message)value).closeOnCloseOf(pipeLineSession, this.getClass().getTypeName());
((Message)newValue).closeOnCloseOf(pipeLineSession, this.getClass().getTypeName());
}
return pipeLineSession.put(name, value);
return pipeLineSession.put(name, newValue);
}

private void putAll(Map<? extends String,? extends Object> entries) {
Expand Down

0 comments on commit d06ee3c

Please sign in to comment.