-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a620f6
commit ea6dadb
Showing
4 changed files
with
108 additions
and
12 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
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
84 changes: 84 additions & 0 deletions
84
leshan-core-cf/src/test/java/org/eclipse/leshan/core/californium/ResponseCodeUtilTest.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,84 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.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.californium; | ||
|
||
import org.eclipse.californium.core.coap.CoAP.ResponseCode; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class ResponseCodeUtilTest { | ||
|
||
@Test | ||
public void known_coap_code_to_known_lwm2m_Code() { | ||
org.eclipse.leshan.ResponseCode lwM2mResponseCode = ResponseCodeUtil.toLwM2mResponseCode(ResponseCode.CREATED); | ||
|
||
Assert.assertEquals(org.eclipse.leshan.ResponseCode.CREATED, lwM2mResponseCode); | ||
Assert.assertEquals("CREATED", lwM2mResponseCode.toString()); | ||
} | ||
|
||
@Test | ||
public void known_coap_code_to_unknown_lwm2m_code() { | ||
org.eclipse.leshan.ResponseCode lwM2mResponseCode = ResponseCodeUtil | ||
.toLwM2mResponseCode(ResponseCode.GATEWAY_TIMEOUT); | ||
|
||
Assert.assertEquals(504, lwM2mResponseCode.getCode()); | ||
Assert.assertEquals(org.eclipse.leshan.ResponseCode.UNKNOWN, lwM2mResponseCode.getName()); | ||
Assert.assertEquals("UNKNOWN(504)", lwM2mResponseCode.toString()); | ||
} | ||
|
||
@Test | ||
public void known_lwm2m_code_to_known_coap_code() { | ||
ResponseCode coapResponseCode = ResponseCodeUtil | ||
.toCoapResponseCode(org.eclipse.leshan.ResponseCode.BAD_REQUEST); | ||
|
||
Assert.assertEquals(ResponseCode.BAD_REQUEST, coapResponseCode); | ||
} | ||
|
||
@Test | ||
public void unknown_lwm2m_code_to_known_coap_code() { | ||
ResponseCode coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(503)); | ||
|
||
Assert.assertEquals(ResponseCode.SERVICE_UNAVAILABLE, coapResponseCode); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void unknown_lwm2m_code_to_invalid_coap_code() { | ||
ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(301)); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void unknown_lwm2m_code_to_invalid_coap_code2() { | ||
ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(441)); | ||
} | ||
|
||
@Test | ||
public void unknown_lwm2m_code_to_unknown_coap_code() { | ||
// californium behavior is not really consistent | ||
|
||
// for success : code value is lost but we know we use an unknown code | ||
ResponseCode coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(206)); | ||
Assert.assertEquals(ResponseCode._UNKNOWN_SUCCESS_CODE, coapResponseCode); | ||
|
||
// for client error,: unknown code is replace by BAD REQUEST ... | ||
coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(425)); | ||
Assert.assertEquals(ResponseCode.BAD_REQUEST, coapResponseCode); | ||
|
||
// for server error : unknown code is replace by INTERNAL SERVER ERROR ... | ||
coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(509)); | ||
Assert.assertEquals(ResponseCode.INTERNAL_SERVER_ERROR, coapResponseCode); | ||
|
||
} | ||
} |
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