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.mielecloud.internal.webservice;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.Mockito.*;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jetty.client.api.Response;
20 import org.eclipse.jetty.http.HttpFields;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.mielecloud.internal.webservice.exception.TooManyRequestsException;
25 * @author Björn Lange - Initial contribution
28 public class HttpUtilTest {
30 public void whenTheResponseHasARetryAfterHeaderThenItIsParsedAndPassedWithTheException() {
32 HttpFields httpFields = mock(HttpFields.class);
33 when(httpFields.containsKey("Retry-After")).thenReturn(true);
34 when(httpFields.get("Retry-After")).thenReturn("100");
36 Response response = mock(Response.class);
37 when(response.getStatus()).thenReturn(429);
38 when(response.getReason()).thenReturn("Too many requests!");
39 when(response.getHeaders()).thenReturn(httpFields);
43 HttpUtil.checkHttpSuccess(response);
45 } catch (TooManyRequestsException e) {
47 assertEquals(100L, e.getSecondsUntilRetry());