-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SendRequest constructor should send InvalidRequestException
- Loading branch information
1 parent
583807b
commit 8281f23
Showing
2 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
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
60 changes: 60 additions & 0 deletions
60
leshan-lwm2m-core/src/test/java/org/eclipse/leshan/core/request/SendRequestTest.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,60 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.core.request; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrowsExactly; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.leshan.core.node.LwM2mNode; | ||
import org.eclipse.leshan.core.node.LwM2mPath; | ||
import org.eclipse.leshan.core.node.LwM2mSingleResource; | ||
import org.eclipse.leshan.core.request.exception.InvalidRequestException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class SendRequestTest { | ||
|
||
@Test | ||
public void send_request_with_empty_nodes_should_fail() { | ||
assertThrowsExactly(InvalidRequestException.class, () -> { | ||
new SendRequest(ContentFormat.SENML_JSON, Collections.emptyMap()); | ||
}); | ||
} | ||
|
||
@Test | ||
public void send_request_with_node_without_path_should_fail() { | ||
final Map<LwM2mPath, LwM2mNode> nodes = new HashMap<>(); | ||
nodes.put(null, LwM2mSingleResource.newBooleanResource(1, false)); | ||
|
||
assertThrowsExactly(InvalidRequestException.class, () -> { | ||
|
||
new SendRequest(ContentFormat.SENML_JSON, nodes); | ||
}); | ||
} | ||
|
||
@Test | ||
public void send_request_with_path_without_node_should_fail() { | ||
final Map<LwM2mPath, LwM2mNode> nodes = new HashMap<>(); | ||
nodes.put(new LwM2mPath(3, 0, 0), null); | ||
|
||
assertThrowsExactly(InvalidRequestException.class, () -> { | ||
|
||
new SendRequest(ContentFormat.SENML_JSON, nodes); | ||
}); | ||
} | ||
} |