Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Merge be8109a into a5c31d4
Browse files Browse the repository at this point in the history
  • Loading branch information
mapingo committed Sep 26, 2019
2 parents a5c31d4 + be8109a commit e96f0f0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to

## [Unreleased]

## [2.0.10] - 2019-09-26
### Added
- Extra logging on exceptions, to output stack trace of other failure exceptions

## [2.0.9] - 2019-09-23
### Added
- Result code returned : 0 - completed, 1 - authentication failed, 2 - connection failed, 3 - other failure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.justice.framework.command.client;

import uk.gov.justice.framework.command.client.io.ToConsolePrinter;
import uk.gov.justice.services.jmx.api.SystemCommandFailedException;
import uk.gov.justice.services.jmx.system.command.client.MBeanClientConnectionException;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxAuthenticationException;

Expand All @@ -27,7 +28,13 @@ public int createFor(final Exception exception) {
return CONNECTION_FAILED;
}

toConsolePrinter.println(exception.getMessage());
if (exception instanceof SystemCommandFailedException) {
toConsolePrinter.printf(exception.getMessage());
toConsolePrinter.println(((SystemCommandFailedException) exception).getServerStackTrace());
return EXCEPTION_OCCURRED;
}

toConsolePrinter.println(exception);
return EXCEPTION_OCCURRED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public void printf(final String format, final Object... args) {
printStream.printf(format + "\n", args);
}

public void println(final Exception e) {
printStream.println(e.getMessage());
e.printStackTrace(printStream);
}

public void println(final Object x) {
printStream.println(x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient;
import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClientFactory;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxAuthenticationException;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters;

import javax.enterprise.context.ApplicationScoped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.mockito.Mockito.verify;

import uk.gov.justice.framework.command.client.io.ToConsolePrinter;
import uk.gov.justice.services.jmx.api.SystemCommandFailedException;
import uk.gov.justice.services.jmx.system.command.client.MBeanClientConnectionException;
import uk.gov.justice.services.jmx.system.command.client.connection.JmxAuthenticationException;

Expand Down Expand Up @@ -44,13 +45,26 @@ public void shouldReturnCorrectCodeForMBeanClientConnectionException() {
verify(toConsolePrinter).println("Test");
}

@Test
public void shouldReturnCorrectCodeForSystemCommandFailedException() {

final int resultCode = returnCodeFactory.createFor(new SystemCommandFailedException("Test", "Stack Trace"));

assertThat(resultCode, is(3));

verify(toConsolePrinter).printf("Test");
verify(toConsolePrinter).println("Stack Trace");
}

@Test
public void shouldReturnCorrectCodeForAnyOtherException() {

final int resultCode = returnCodeFactory.createFor(new Exception("Test"));
final Exception exception = new Exception("Test");

final int resultCode = returnCodeFactory.createFor(exception);

assertThat(resultCode, is(3));

verify(toConsolePrinter).println("Test");
verify(toConsolePrinter).println(exception);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package uk.gov.justice.framework.command.client.io;

import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.verify;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.junit.Test;
Expand Down Expand Up @@ -40,4 +43,17 @@ public void shouldCallPrintlnOnThePrintStream() throws Exception {

verify(printStream).println(format);
}

@Test
public void shouldPrintOutExceptionToPrintStream() {

final Exception exception = new Exception("Test Exception");
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ToConsolePrinter toConsolePrinter = new ToConsolePrinter(new PrintStream(out));

toConsolePrinter.println(exception);

assertThat(out.toString(), containsString("java.lang.Exception: Test Exception\n" +
"\tat uk.gov.justice.framework.command.client.io.ToConsolePrinterTest.shouldPrintOutExceptionToPrintStream(ToConsolePrinterTest.java:"));
}
}

0 comments on commit e96f0f0

Please sign in to comment.