Merge "TCP_Flag extension model additions for OFPXMC_NXM_1 class"
[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.assertEquals;
11 import static org.junit.Assert.assertNull;
12 import static org.mockito.Mockito.mock;
13
14 import java.util.Collections;
15
16 import org.junit.Test;
17 import org.opendaylight.controller.sal.restconf.impl.RestCodec;
18 import org.opendaylight.yangtools.concepts.Codec;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
22 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
23 import org.opendaylight.yangtools.yang.model.util.BitsType;
24
25 public class RestCodecExceptionsTest {
26
27     private static final SchemaPath PATH = SchemaPath.create(true, QName.create("test", "2014-05-30", "test"));
28
29     @Test
30     public void serializeExceptionTest() {
31         Codec<Object, Object> codec = RestCodec.from(BitsType.create(PATH, Collections.<Bit>emptyList()), null);
32         String serializedValue = (String) codec.serialize("incorrect value"); // set
33                                                                               // expected
34         assertEquals("incorrect value", serializedValue);
35     }
36
37     @Test
38     public void deserializeExceptionTest() {
39         IdentityrefTypeDefinition mockedIidentityrefType = mock(IdentityrefTypeDefinition.class);
40
41         Codec<Object, Object> codec = RestCodec.from(mockedIidentityrefType, null);
42         assertNull(codec.deserialize("incorrect value"));
43     }
44
45 }