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.nest.internal.sdm.dto;
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.hamcrest.core.Is.is;
18 import static org.openhab.binding.nest.internal.sdm.dto.SDMDataUtil.fromJson;
20 import java.io.IOException;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.nest.internal.sdm.dto.SDMError.SDMErrorDetails;
26 * Tests deserialization of {@link org.openhab.binding.nest.internal.sdm.dto.SDMError}s from JSON.
28 * @author Wouter Born - Initial contribution
30 public class SDMErrorTest {
33 public void deserializeFailedPreconditionError() throws IOException {
34 SDMError error = fromJson("failed-precondition-error.json", SDMError.class);
35 assertThat(error, is(notNullValue()));
37 SDMErrorDetails details = error.error;
38 assertThat(details, is(notNullValue()));
39 assertThat(details.code, is(400));
40 assertThat(details.message, is("Thermostat fan unavailable."));
41 assertThat(details.status, is("FAILED_PRECONDITION"));
45 public void deserializeNotFoundError() throws IOException {
46 SDMError error = fromJson("not-found-error.json", SDMError.class);
47 assertThat(error, is(notNullValue()));
49 SDMErrorDetails details = error.error;
50 assertThat(details, is(notNullValue()));
51 assertThat(details.code, is(404));
52 assertThat(details.message, is("Device enterprises/project-id/devices/device-id not found."));
53 assertThat(details.status, is("NOT_FOUND"));
57 public void deserializeResponseWithoutError() throws IOException {
58 SDMError error = fromJson("list-devices-response.json", SDMError.class);
59 assertThat(error, is(notNullValue()));
61 SDMErrorDetails details = error.error;
62 assertThat(details, is(nullValue()));