983377e1e8c161000c7e3a684feef2292d065ed1
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / RestCodecExceptionsTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.restconf.impl.test;
9
10 import static org.junit.Assert.*;
11 import static org.mockito.Mockito.mock;
12
13 import org.junit.Test;
14 import org.opendaylight.controller.sal.restconf.impl.RestCodec;
15 import org.opendaylight.yangtools.concepts.Codec;
16 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
17 import org.opendaylight.yangtools.yang.model.util.BitsType;
18
19 public class RestCodecExceptionsTest {
20
21     @Test
22     public void serializeExceptionTest() {
23         Codec<Object, Object> codec = RestCodec.from(new BitsType(null), null);
24         String serializedValue = (String) codec.serialize("incorrect value"); // set
25                                                                               // expected
26         assertEquals("incorrect value", serializedValue);
27     }
28
29     @Test
30     public void deserializeExceptionTest() {
31         IdentityrefTypeDefinition mockedIidentityrefType = mock(IdentityrefTypeDefinition.class);
32
33         Codec<Object, Object> codec = RestCodec.from(mockedIidentityrefType, null);
34         assertNull(codec.deserialize("incorrect value"));
35     }
36
37 }