@@ -68,7 +68,7 @@ class MeasureFilterContext { | |||
@Override | |||
public String toString() { | |||
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) | |||
.append("json", json) | |||
.append("filter", json) | |||
.append("sql", sql) | |||
.append("user", userId) | |||
.toString(); |
@@ -64,7 +64,7 @@ public class MeasureFilterEngine implements ServerComponent { | |||
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()); |
@@ -36,6 +36,6 @@ public class MeasureFilterContextTest { | |||
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]"); | |||
} | |||
} |
@@ -21,13 +21,20 @@ package org.sonar.core.measure; | |||
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); | |||
@@ -52,4 +59,17 @@ public class MeasureFilterEngineTest { | |||
})); | |||
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); | |||
} | |||
} |