]> git.basschouten.com Git - openhab-addons.git/blob
791e304ba422ee36b0231b44f78aea243caece8e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.solax.internal.local;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.util.Set;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.solax.internal.connectivity.rawdata.local.LocalConnectRawDataBean;
22 import org.openhab.binding.solax.internal.model.InverterType;
23 import org.openhab.binding.solax.internal.model.local.LocalInverterData;
24 import org.openhab.binding.solax.internal.model.local.parsers.RawDataParser;
25
26 /**
27  * The {@link AbstractParserTest} Abstract class defining the common logic for testing local connections to the various
28  * inverters and their parsers
29  *
30  * @author Konstantin Polihronov - Initial contribution
31  */
32 @NonNullByDefault
33 public abstract class AbstractParserTest {
34     @Test
35     public void testParser() {
36         LocalConnectRawDataBean bean = LocalConnectRawDataBean.fromJson(getRawData());
37         int type = bean.getType();
38         InverterType inverterType = InverterType.fromIndex(type);
39         assertEquals(getInverterType(), inverterType, "Inverter type not recognized properly");
40
41         RawDataParser parser = inverterType.getParser();
42         assertNotNull(parser);
43
44         Set<String> supportedChannels = parser.getSupportedChannels();
45         assertFalse(supportedChannels.isEmpty());
46
47         LocalInverterData data = parser.getData(bean);
48         assertParserSpecific(data);
49     }
50
51     protected abstract InverterType getInverterType();
52
53     protected abstract String getRawData();
54
55     protected abstract void assertParserSpecific(LocalInverterData data);
56 }