]> git.basschouten.com Git - openhab-addons.git/blob
357a0da9d15667e4bbc587cab3627ae782c31e93
[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.nest.internal.sdm.dto;
14
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;
19
20 import java.io.IOException;
21
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.nest.internal.sdm.dto.SDMError.SDMErrorDetails;
24
25 /**
26  * Tests deserialization of {@link org.openhab.binding.nest.internal.sdm.dto.SDMError}s from JSON.
27  *
28  * @author Wouter Born - Initial contribution
29  */
30 public class SDMErrorTest {
31
32     @Test
33     public void deserializeFailedPreconditionError() throws IOException {
34         SDMError error = fromJson("failed-precondition-error.json", SDMError.class);
35         assertThat(error, is(notNullValue()));
36
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"));
42     }
43
44     @Test
45     public void deserializeNotFoundError() throws IOException {
46         SDMError error = fromJson("not-found-error.json", SDMError.class);
47         assertThat(error, is(notNullValue()));
48
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"));
54     }
55
56     @Test
57     public void deserializeResponseWithoutError() throws IOException {
58         SDMError error = fromJson("list-devices-response.json", SDMError.class);
59         assertThat(error, is(notNullValue()));
60
61         SDMErrorDetails details = error.error;
62         assertThat(details, is(nullValue()));
63     }
64 }