-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce TestResource to catch error during handleRequest.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
- Loading branch information
Showing
5 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
californium-core/src/test/java/org/eclipse/californium/core/coap/TestResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License | ||
* v1.0 which is available at | ||
* https://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
********************************************************************************/ | ||
package org.eclipse.californium.core.coap; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.californium.core.CoapResource; | ||
import org.eclipse.californium.core.network.Exchange; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Test resource to handles junit asserts of the scopes of other thread. | ||
* | ||
* Intended to use assert with {@link #handleRequest(Exchange)} execution. | ||
* | ||
* @since 3.11 | ||
*/ | ||
public class TestResource extends CoapResource { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(TestResource.class); | ||
|
||
private List<Error> errors = new ArrayList<>(); | ||
|
||
public TestResource(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public void handleRequest(final Exchange exchange) { | ||
try { | ||
super.handleRequest(exchange); | ||
} catch (Error e) { | ||
LOGGER.warn("{}", e.getMessage(), e); | ||
errors.add(e); | ||
} | ||
} | ||
|
||
/** | ||
* Report errors catched during execution of | ||
* {@link #handleRequest(Exchange)}. | ||
* | ||
* @throw Errors if occurred execution {@link #handleRequest(Exchange)} | ||
*/ | ||
public void report() { | ||
if (!errors.isEmpty()) { | ||
throw errors.get(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters