]> git.basschouten.com Git - openhab-addons.git/blob
29bf399e7fb05a79e1649be13e2fe484e427237a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.dsmr.internal.device.p1telegram;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.util.Arrays;
18 import java.util.List;
19
20 import org.junit.jupiter.params.ParameterizedTest;
21 import org.junit.jupiter.params.provider.MethodSource;
22 import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
23 import org.openhab.binding.dsmr.internal.device.p1telegram.P1Telegram.TelegramState;
24
25 /**
26  * Test class for {@link P1TelegramParser}.
27  *
28  * @author Hilbrand Bouwkamp - Initial contribution
29  */
30 public class P1TelegramParserTest {
31
32     // @formatter:off
33     public static final List<Object[]> data() {
34         return Arrays.asList(new Object[][] {
35             { "ace4000", 59, },
36             { "dsmr_40", 39, },
37             { "dsmr_42", 39, },
38             { "dsmr_50", 41, },
39             { "flu5", 21, },
40             { "Iskra_AM550", 41, },
41             { "Landis_Gyr_E350", 10, },
42             { "Landis_Gyr_ZCF110", 25, },
43             { "Sagemcom_XS210", 41, },
44             { "smarty", 28, },
45             { "smarty_with_units", 23, },
46         });
47     }
48     // @formatter:on
49
50     @ParameterizedTest
51     @MethodSource("data")
52     public void testParsing(final String telegramName, final int numberOfCosemObjects) {
53         P1Telegram telegram = TelegramReaderUtil.readTelegram(telegramName, TelegramState.OK);
54         assertEquals(0, telegram.getUnknownCosemObjects().size(), "Should not have any unknown cosem objects");
55         assertEquals(numberOfCosemObjects,
56                 telegram.getCosemObjects().stream().mapToInt(co -> co.getCosemValues().size()).sum(),
57                 "Expected number of objects");
58     }
59 }