2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.emotiva.internal.dto;
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;
19 import java.util.List;
21 import javax.xml.bind.JAXBException;
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;
30 * Unit tests for EmotivaUnsubscribe requests.
32 * @author Espen Fossen - Initial contribution
35 class EmotivaUnsubscriptionTest extends AbstractDTOTestBase {
37 public EmotivaUnsubscriptionTest() throws JAXBException {
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>"));
51 void marshallWithTwoUnsubscriptions() {
52 EmotivaCommandDTO command1 = new EmotivaCommandDTO(EmotivaControlCommands.volume);
53 EmotivaCommandDTO command2 = new EmotivaCommandDTO(EmotivaControlCommands.power_off);
55 EmotivaUnsubscribeDTO dto = new EmotivaUnsubscribeDTO(List.of(command1, command2));
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>")));