blob: 5f64625fc0c8da8e07748ac080a17ede266f9c1d [file] [log] [blame]
Andrew Brownc46c1602015-02-18 10:45:56 -08001/*
andrewsbrown7e6b9e82015-03-03 16:11:11 -08002 * 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 Brownc46c1602015-02-18 10:45:56 -080013 */
14package com.intel.jndn.management;
15
16import com.intel.jndn.management.types.ControlResponse;
17import junit.framework.Assert;
18import net.named_data.jndn.ControlParameters;
19import net.named_data.jndn.util.Blob;
20import org.junit.Test;
21
22/**
23 * Test encoding/decoding of ControlResponses.
24 *
25 * @author Andrew Brown <andrew.brown@intel.com>
26 */
27public class ControlResponseTest {
28
Andrew Brown211d2b62015-02-18 11:12:02 -080029 /**
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 Brownc46c1602015-02-18 10:45:56 -080042
Andrew Brown211d2b62015-02-18 11:12:02 -080043 // encode
44 Blob encoded = response.wireEncode();
Andrew Brownc46c1602015-02-18 10:45:56 -080045
Andrew Brown211d2b62015-02-18 11:12:02 -080046 // decode
47 ControlResponse decoded = new ControlResponse();
48 decoded.wireDecode(encoded.buf());
Andrew Brownc46c1602015-02-18 10:45:56 -080049
Andrew Brown211d2b62015-02-18 11:12:02 -080050 // 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 Brownc46c1602015-02-18 10:45:56 -080056}