Andrew Brown | c46c160 | 2015-02-18 10:45:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * File name: ControlResponseTest.java |
| 3 | * |
| 4 | * Purpose: Test encoding/decoding of ControlResponses. |
| 5 | * |
| 6 | * © Copyright Intel Corporation. All rights reserved. |
| 7 | * Intel Corporation, 2200 Mission College Boulevard, |
| 8 | * Santa Clara, CA 95052-8119, USA |
| 9 | */ |
| 10 | package com.intel.jndn.management; |
| 11 | |
| 12 | import com.intel.jndn.management.types.ControlResponse; |
| 13 | import junit.framework.Assert; |
| 14 | import net.named_data.jndn.ControlParameters; |
| 15 | import net.named_data.jndn.util.Blob; |
| 16 | import org.junit.Test; |
| 17 | |
| 18 | /** |
| 19 | * Test encoding/decoding of ControlResponses. |
| 20 | * |
| 21 | * @author Andrew Brown <andrew.brown@intel.com> |
| 22 | */ |
| 23 | public class ControlResponseTest { |
| 24 | |
Andrew Brown | 211d2b6 | 2015-02-18 11:12:02 -0800 | [diff] [blame^] | 25 | /** |
| 26 | * Test encoding/decoding |
| 27 | * |
| 28 | * @throws java.lang.Exception |
| 29 | */ |
| 30 | @Test |
| 31 | public void testEncodeDecode() throws Exception { |
| 32 | ControlParameters parameters = new ControlParameters(); |
| 33 | parameters.setFaceId(3); |
| 34 | ControlResponse response = new ControlResponse(); |
| 35 | response.setStatusCode(404); |
| 36 | response.setStatusText("Not Found"); |
| 37 | response.getBody().add(parameters); |
Andrew Brown | c46c160 | 2015-02-18 10:45:56 -0800 | [diff] [blame] | 38 | |
Andrew Brown | 211d2b6 | 2015-02-18 11:12:02 -0800 | [diff] [blame^] | 39 | // encode |
| 40 | Blob encoded = response.wireEncode(); |
Andrew Brown | c46c160 | 2015-02-18 10:45:56 -0800 | [diff] [blame] | 41 | |
Andrew Brown | 211d2b6 | 2015-02-18 11:12:02 -0800 | [diff] [blame^] | 42 | // decode |
| 43 | ControlResponse decoded = new ControlResponse(); |
| 44 | decoded.wireDecode(encoded.buf()); |
Andrew Brown | c46c160 | 2015-02-18 10:45:56 -0800 | [diff] [blame] | 45 | |
Andrew Brown | 211d2b6 | 2015-02-18 11:12:02 -0800 | [diff] [blame^] | 46 | // test |
| 47 | Assert.assertEquals(response.getStatusCode(), decoded.getStatusCode()); |
| 48 | Assert.assertEquals(response.getStatusText(), decoded.getStatusText()); |
| 49 | Assert.assertEquals(response.getBody().size(), decoded.getBody().size()); |
| 50 | Assert.assertEquals(response.getBody().get(0).getFaceId(), decoded.getBody().get(0).getFaceId()); |
| 51 | } |
Andrew Brown | c46c160 | 2015-02-18 10:45:56 -0800 | [diff] [blame] | 52 | } |