if (logger.isDebugEnabled()) {
StringBuilder log = new StringBuilder();
log.append(SystemUtils.LINE_SEPARATOR);
- log.append(" json: ").append(context.getJson()).append(SystemUtils.LINE_SEPARATOR);
+ log.append(" filter: ").append(context.getJson()).append(SystemUtils.LINE_SEPARATOR);
log.append(" sql: ").append(context.getSql()).append(SystemUtils.LINE_SEPARATOR);
log.append("results: ").append(rows.size()).append(" rows in ").append(durationMs).append("ms").append(SystemUtils.LINE_SEPARATOR);
logger.debug(log.toString());
context.setJson("{}");
context.setSql("SELECT *");
context.setUserId(50L);
- assertThat(context.toString()).isEqualTo("MeasureFilterContext[json={},sql=SELECT *,user=50]");
+ assertThat(context.toString()).isEqualTo("MeasureFilterContext[filter={},sql=SELECT *,user=50]");
}
}
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
+import org.json.simple.parser.ParseException;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.*;
public class MeasureFilterEngineTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Test
public void should_decode_json_and_execute_filter() throws Exception {
MeasureFilterDecoder decoder = mock(MeasureFilterDecoder.class);
}));
verify(logger).debug(anyString());
}
+
+ @Test
+ public void throw_definition_of_filter_on_error() throws Exception {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("filter=<xml>");
+
+ MeasureFilterDecoder decoder = mock(MeasureFilterDecoder.class);
+ when(decoder.decode("<xml>")).thenThrow(new ParseException(0));
+ MeasureFilterExecutor executor = mock(MeasureFilterExecutor.class);
+
+ MeasureFilterEngine engine = new MeasureFilterEngine(decoder, executor);
+ engine.execute("<xml>", 50L);
+ }
}