Andrew Brown | c46c160 | 2015-02-18 10:45:56 -0800 | [diff] [blame] | 1 | /* |
andrewsbrown | 7e6b9e8 | 2015-03-03 16:11:11 -0800 | [diff] [blame] | 2 | * jndn-management |
| 3 | * Copyright (c) 2015, Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU Lesser General Public License, |
| 7 | * version 3, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT ANY |
| 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
| 12 | * more details. |
Andrew Brown | c46c160 | 2015-02-18 10:45:56 -0800 | [diff] [blame] | 13 | */ |
| 14 | package com.intel.jndn.management; |
| 15 | |
| 16 | import com.intel.jndn.management.types.ControlResponse; |
| 17 | import junit.framework.Assert; |
| 18 | import net.named_data.jndn.ControlParameters; |
| 19 | import net.named_data.jndn.util.Blob; |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | /** |
| 23 | * Test encoding/decoding of ControlResponses. |
| 24 | * |
| 25 | * @author Andrew Brown <andrew.brown@intel.com> |
| 26 | */ |
| 27 | public class ControlResponseTest { |
| 28 | |
Andrew Brown | 211d2b6 | 2015-02-18 11:12:02 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Test encoding/decoding |
| 31 | * |
| 32 | * @throws java.lang.Exception |
| 33 | */ |
| 34 | @Test |
| 35 | public void testEncodeDecode() throws Exception { |
| 36 | ControlParameters parameters = new ControlParameters(); |
| 37 | parameters.setFaceId(3); |
| 38 | ControlResponse response = new ControlResponse(); |
| 39 | response.setStatusCode(404); |
| 40 | response.setStatusText("Not Found"); |
| 41 | response.getBody().add(parameters); |
Andrew Brown | c46c160 | 2015-02-18 10:45:56 -0800 | [diff] [blame] | 42 | |
Andrew Brown | 211d2b6 | 2015-02-18 11:12:02 -0800 | [diff] [blame] | 43 | // encode |
| 44 | Blob encoded = response.wireEncode(); |
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 | // decode |
| 47 | ControlResponse decoded = new ControlResponse(); |
| 48 | decoded.wireDecode(encoded.buf()); |
Andrew Brown | c46c160 | 2015-02-18 10:45:56 -0800 | [diff] [blame] | 49 | |
Andrew Brown | 211d2b6 | 2015-02-18 11:12:02 -0800 | [diff] [blame] | 50 | // test |
| 51 | Assert.assertEquals(response.getStatusCode(), decoded.getStatusCode()); |
| 52 | Assert.assertEquals(response.getStatusText(), decoded.getStatusText()); |
| 53 | Assert.assertEquals(response.getBody().size(), decoded.getBody().size()); |
| 54 | Assert.assertEquals(response.getBody().get(0).getFaceId(), decoded.getBody().get(0).getFaceId()); |
| 55 | } |
Andrew Brown | c46c160 | 2015-02-18 10:45:56 -0800 | [diff] [blame] | 56 | } |