Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package de.agilecoders.wicket.logging;
 
 import org.junit.Test;
 
 import java.util.Date;
 
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

Tests the default implementation of IParamValueExtractor

Author(s):
miha
public class IParamValueExtractorTest {
    @Test
    public void clientInfoWillBeExtracted() {
        MockRequestParameters params = new MockRequestParameters();
        params.setParameterValue(."ajaxBaseUrl");
        params.setParameterValue(."screenSize");
        params.setParameterValue(."winSize");
        params.setParameterValue(."userAgent");
        IParamValueExtractor.Result result = extractor.parse(params);
        assertThat(result.clientInfos().ajaxBaseUrl(), is(equalTo("ajaxBaseUrl")));
        assertThat(result.clientInfos().screenSize(), is(equalTo("screenSize")));
        assertThat(result.clientInfos().windowSize(), is(equalTo("winSize")));
        assertThat(result.clientInfos().userAgent(), is(equalTo("userAgent")));
    }
    @Test
    public void logMessagesWillBeExtracted() {
        MockRequestParameters params = new MockRequestParameters();
        addMessage(1, params"error""message 1", Time.valueOf(new Date(1982, 12, 14, 8, 0)).toRfc1123TimestampString(), "file1""line1""stacktrace 1");
        addMessage(2, params"error""message 2", Time.valueOf(new Date(1982, 12, 14, 12, 0)).toRfc1123TimestampString(), "file2""line2""stacktrace 2");
        addMessage(3, params"error""message 3", Time.valueOf(new Date(1982, 12, 14, 16, 0)).toRfc1123TimestampString(), "file3""line3""stacktrace 3");
        params.setParameterValue(. + "_" + 4, "warn");
        params.setParameterValue(. + "_" + 5, "message 5");
        params.setParameterValue(. + "_" + 6, "timestamp 6");
        IParamValueExtractor.Result result = extractor.parse(params);
        assertThat(Lists.newArrayList(result.logObjects()).size(), is(equalTo(3)));
        assertThat(result.logObjects(), hasItem(new ClientSideLogObject("error""message 1", Time.valueOf(new Date(1982, 12, 14, 8, 0)).toRfc1123TimestampString(), "file1""line1""stacktrace 1", 1)));
        assertThat(result.logObjects(), hasItem(new ClientSideLogObject("error""message 2", Time.valueOf(new Date(1982, 12, 14, 12, 0)).toRfc1123TimestampString(), "file2""line2""stacktrace 2", 2)));
        assertThat(result.logObjects(), hasItem(new ClientSideLogObject("error""message 3", Time.valueOf(new Date(1982, 12, 14, 16, 0)).toRfc1123TimestampString(), "file3""line3""stacktrace 3", 3)));
    }
    private void addMessage(int indexMockRequestParameters paramsString levelString messageString utcTimestampString fileString lineString stacktrace) {
        params.setParameterValue(. + "_" + indexlevel);
        params.setParameterValue(. + "_" + indexmessage);
        params.setParameterValue(. + "_" + indexutcTimestamp);
        params.setParameterValue(. + "_" + indexline);
        params.setParameterValue(. + "_" + indexfile);
        params.setParameterValue(. + "_" + indexstacktrace);
    }
New to GrepCode? Check out our FAQ X