/**
 * Copyright © 2016-2022 The Thingsboard Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.thingsboard.rule.engine.metadata;

import org.junit.Before;
import org.junit.Test;
import org.thingsboard.server.common.data.kv.Aggregation;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.willCallRealMethod;
import static org.mockito.Mockito.mock;

public class TbGetTelemetryNodeTest {

    TbGetTelemetryNode node;

    @Before
    public void setUp() throws Exception {
        node = mock(TbGetTelemetryNode.class);
        willCallRealMethod().given(node).parseAggregationConfig(any());
    }

    @Test
    public void givenAggregationAsString_whenParseAggregation_thenReturnEnum() {
        //compatibility with old configs without "aggregation" parameter
        assertThat(node.parseAggregationConfig(null), is(Aggregation.NONE));
        assertThat(node.parseAggregationConfig(""), is(Aggregation.NONE));

        //common values
        assertThat(node.parseAggregationConfig("MIN"), is(Aggregation.MIN));
        assertThat(node.parseAggregationConfig("MAX"), is(Aggregation.MAX));
        assertThat(node.parseAggregationConfig("AVG"), is(Aggregation.AVG));
        assertThat(node.parseAggregationConfig("SUM"), is(Aggregation.SUM));
        assertThat(node.parseAggregationConfig("COUNT"), is(Aggregation.COUNT));
        assertThat(node.parseAggregationConfig("NONE"), is(Aggregation.NONE));

        //all possible values in future
        for (Aggregation aggEnum : Aggregation.values()) {
            assertThat(node.parseAggregationConfig(aggEnum.name()), is(aggEnum));
        }
    }

    @Test(expected = IllegalArgumentException.class)
    public void givenAggregationWhiteSpace_whenParseAggregation_thenException() {
        node.parseAggregationConfig(" ");
    }

    @Test(expected = IllegalArgumentException.class)
    public void givenAggregationIncorrect_whenParseAggregation_thenException() {
        node.parseAggregationConfig("TOP");
    }

}

@@ -666,47 +666,257 @@
 ort 
-org.junit.Before;%0Aimport org.junit.Test
+com.fasterxml.jackson.databind.ObjectMapper;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.thingsboard.common.util.JacksonUtil;%0Aimport org.thingsboard.rule.engine.api.TbContext;%0Aimport org.thingsboard.rule.engine.api.TbNodeConfiguration
 ;%0Aim
@@ -1213,16 +1213,55 @@
 to.mock;
+%0Aimport static org.mockito.Mockito.spy;
 %0A%0Apublic
@@ -1326,110 +1326,526 @@
 de;%0A
-%0A    @Before%0A    public void setUp() throws Exception %7B%0A        node = mock(TbGetTelemetryNode.class);
+    TbGetTelemetryNodeConfiguration config;%0A    TbNodeConfiguration nodeConfiguration;%0A    TbContext ctx;%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        ctx = mock(TbContext.class);%0A        node = spy(new TbGetTelemetryNode());%0A        config = new TbGetTelemetryNodeConfiguration();%0A        config.setFetchMode(%22ALL%22);%0A        ObjectMapper mapper = JacksonUtil.OBJECT_MAPPER;%0A        nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config));%0A        node.init(ctx, nodeConfiguration);%0A
 %0A   

update test