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