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