]> git.basschouten.com Git - openhab-addons.git/blob
95f4101e65ecabf51926acc3d1a5839b16dafa9f
[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.emotiva.internal.dto;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_TUNER_RDS;
18
19 import java.util.List;
20
21 import javax.xml.bind.JAXBException;
22
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.junit.jupiter.api.Test;
25 import org.openhab.binding.emotiva.internal.AbstractDTOTestBase;
26 import org.openhab.binding.emotiva.internal.protocol.EmotivaControlCommands;
27 import org.openhab.binding.emotiva.internal.protocol.EmotivaSubscriptionTags;
28
29 /**
30  * Unit tests for EmotivaUnsubscribe requests.
31  *
32  * @author Espen Fossen - Initial contribution
33  */
34 @NonNullByDefault
35 class EmotivaUnsubscriptionTest extends AbstractDTOTestBase {
36
37     public EmotivaUnsubscriptionTest() throws JAXBException {
38     }
39
40     @Test
41     void marshalFromChannelUID() {
42         EmotivaSubscriptionTags subscriptionChannel = EmotivaSubscriptionTags.fromChannelUID(CHANNEL_TUNER_RDS);
43         EmotivaUnsubscribeDTO emotivaSubscriptionRequest = new EmotivaUnsubscribeDTO(subscriptionChannel);
44         String xmlString = xmlUtils.marshallJAXBElementObjects(emotivaSubscriptionRequest);
45         assertThat(xmlString, containsString("<emotivaUnsubscribe>"));
46         assertThat(xmlString, containsString("<tuner_RDS />"));
47         assertThat(xmlString, containsString("</emotivaUnsubscribe>"));
48     }
49
50     @Test
51     void marshallWithTwoUnsubscriptions() {
52         EmotivaCommandDTO command1 = new EmotivaCommandDTO(EmotivaControlCommands.volume);
53         EmotivaCommandDTO command2 = new EmotivaCommandDTO(EmotivaControlCommands.power_off);
54
55         EmotivaUnsubscribeDTO dto = new EmotivaUnsubscribeDTO(List.of(command1, command2));
56
57         String xmlString = xmlUtils.marshallJAXBElementObjects(dto);
58         assertThat(xmlString, containsString("<emotivaUnsubscribe>"));
59         assertThat(xmlString, containsString("<volume />"));
60         assertThat(xmlString, containsString("<power_off />"));
61         assertThat(xmlString, containsString("</emotivaUnsubscribe>"));
62         assertThat(xmlString, not(containsString("<volume>")));
63         assertThat(xmlString, not(containsString("<command>")));
64     }
65 }