]> git.basschouten.com Git - openhab-addons.git/blob
62ca657bb5c31e63a5b146a856d9d845148a43a4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.vdr.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.vdr.internal.svdrp.SVDRPException;
20 import org.openhab.binding.vdr.internal.svdrp.SVDRPParseResponseException;
21 import org.openhab.binding.vdr.internal.svdrp.SVDRPVolume;
22 import org.openhab.binding.vdr.internal.svdrp.SVDRPWelcome;
23
24 /**
25  * Specific unit tests to check if {@link SVDRPWelcome} parses SVDRP responses correctly
26  *
27  * @author Matthias Klocke - Initial contribution
28  *
29  */
30 @NonNullByDefault
31 public class SVDRPWelcomeTest {
32     private final String welcomeResponseOk = "srv SVDRP VideoDiskRecorder 2.5.1; Mon Jan 11 19:46:54 2021; UTF-8";
33     private final String welcomeResponseParseError1 = "srv SVDRP VideoDiskRecorder 2.5.1; Mon Jan 11 19:46:54 2021 UTF-8";
34     private final String welcomeResponseParseError2 = "srv SVDRP VideoDiskRecorder2.5.1; Mon Jan 11 19:46:54 2021 UTF-8";
35
36     @Test
37     public void testParseWelcomeData() throws SVDRPException {
38         SVDRPWelcome welcome = SVDRPWelcome.parse(welcomeResponseOk);
39         assertEquals("UTF-8", welcome.getCharset());
40         assertEquals("2.5.1", welcome.getVersion());
41         assertEquals("Mon Jan 11 19:46:54 2021", welcome.getDateAndTime());
42     }
43
44     @Test
45     public void testParseExceptionVolumeData() {
46         assertThrows(SVDRPParseResponseException.class, () -> {
47             SVDRPVolume.parse(welcomeResponseParseError1);
48         });
49         assertThrows(SVDRPParseResponseException.class, () -> {
50             SVDRPVolume.parse(welcomeResponseParseError2);
51         });
52     }
53 }