@@ -0,0 +1,3560 @@
+/*%0A * Copyright (c) 2016, Groupon, Inc.%0A * All rights reserved.%0A *%0A * Redistribution and use in source and binary forms, with or without%0A * modification, are permitted provided that the following conditions%0A * are met:%0A *%0A * Redistributions of source code must retain the above copyright notice,%0A * this list of conditions and the following disclaimer.%0A *%0A * Redistributions in binary form must reproduce the above copyright%0A * notice, this list of conditions and the following disclaimer in the%0A * documentation and/or other materials provided with the distribution.%0A *%0A * Neither the name of GROUPON nor the names of its contributors may be%0A * used to endorse or promote products derived from this software without%0A * specific prior written permission.%0A *%0A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS %22AS%0A * IS%22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED%0A * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A%0A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT%0A * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,%0A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED%0A * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR%0A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF%0A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING%0A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS%0A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.%0A */%0Apackage com.groupon.lex.metrics.config;%0A%0Aimport com.groupon.lex.metrics.GroupName;%0Aimport com.groupon.lex.metrics.Histogram;%0Aimport com.groupon.lex.metrics.MetricValue;%0Aimport com.groupon.lex.metrics.timeseries.TimeSeriesMetricExpression;%0Aimport com.groupon.lex.metrics.timeseries.expression.Context;%0Aimport java.util.Optional;%0Aimport static org.junit.Assert.assertEquals;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mock;%0Aimport static org.mockito.Mockito.verifyZeroInteractions;%0Aimport org.mockito.runners.MockitoJUnitRunner;%0A%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class ParserSupportTest %7B%0A    @Mock%0A    private Context ctx;%0A%0A    @Test%0A    public void group_name() throws Exception %7B%0A        assertEquals(GroupName.valueOf(%22com%22, %22groupon%22, %22lex%22, %22%5Cu10ff%22, %22%5C010%22),%0A                new ParserSupport(%22com.groupon.'lex'.'%5C%5Cu10ff'.'%5C%5Cv'%22).group_name());%0A    %7D%0A%0A    @Test(expected = ConfigurationException.class)%0A    public void bad_group_name() throws Exception %7B%0A        new ParserSupport(%22com.17.bla%22).group_name();%0A    %7D%0A%0A    @Test%0A    public void expression() throws Exception %7B%0A        final TimeSeriesMetricExpression expr = new ParserSupport(%2217+19%22).expression();%0A%0A        assertEquals(%2217 + 19%22, expr.configString().toString());%0A%0A        // Use calculation to check if it actually works properly.%0A        assertEquals(Optional.of(MetricValue.fromIntValue(17 + 19)), expr.apply(ctx).asScalar());%0A%0A        verifyZeroInteractions(ctx);%0A    %7D%0A%0A    @Test(expected = ConfigurationException.class)%0A    public void bad_expression() throws Exception %7B%0A        new ParserSupport(%2217 19%22).expression();%0A    %7D%0A%0A    @Test%0A    public void histogram() throws Exception %7B%0A        assertEquals(new Histogram(new Histogram.RangeWithCount(0, 1, 12)),%0A                new ParserSupport(%22%5B0..1=12%5D%22).histogram());%0A    %7D%0A%0A    @Test(expected = ConfigurationException.class)%0A    public void bad_histogram() throws Exception %7B%0A        new ParserSupport(%22%5B0..1..12%5D%22).histogram();%0A    %7D%0A%7D%0A

Add parser test.