2 * Copyright (c) 2010-2023 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.yamahareceiver.internal.protocol.xml;
15 import static org.mockito.ArgumentMatchers.eq;
16 import static org.mockito.Mockito.when;
17 import static org.openhab.binding.yamahareceiver.internal.protocol.xml.XMLConstants.Commands.SYSTEM_STATUS_CONFIG_CMD;
18 import static org.openhab.binding.yamahareceiver.internal.protocol.xml.XMLConstants.Commands.ZONE_BASIC_STATUS_CMD;
20 import java.io.FileNotFoundException;
21 import java.io.IOException;
23 import org.openhab.binding.yamahareceiver.internal.ResponseLoader;
26 * Testing context for a selected Yamaha model.
28 * @author Tomasz Maruszak - Initial contribution
30 public class ModelContext {
32 private final ResponseLoader rl = new ResponseLoader();
33 private final XMLConnection connection;
36 public XMLConnection getConnection() {
40 public ModelContext(XMLConnection connection) {
41 this.connection = connection;
44 public void prepareForModel(String model) throws IOException {
47 String descFile = String.format("/desc_%s.xml", model);
48 String desc = rl.load(descFile, model);
50 throw new FileNotFoundException("Could not load " + descFile);
53 when(connection.getResponse(eq("/YamahaRemoteControl/desc.xml"))).thenReturn(desc);
54 when(connection.getHost()).thenReturn("localhost");
56 respondWith(SYSTEM_STATUS_CONFIG_CMD, "System_Config.xml");
57 respondWith(String.format("<Main_Zone>%s</Main_Zone>", ZONE_BASIC_STATUS_CMD), "Main_Zone_Basic_Status.xml");
60 public void respondWith(String command, String path) {
62 String response = rl.load(path, model);
63 if (response != null) {
64 when(connection.sendReceive(eq(command))).thenReturn(response);
66 } catch (IOException e) {
67 throw new RuntimeException(e);