2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.v3po.translate.util.write.registry;
19 import static org.hamcrest.CoreMatchers.hasItem;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertThat;
22 import static org.mockito.Mockito.when;
24 import com.google.common.collect.Sets;
25 import io.fd.honeycomb.v3po.translate.util.DataObjects;
26 import io.fd.honeycomb.v3po.translate.write.Writer;
27 import java.util.Collections;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.mockito.MockitoAnnotations;
32 import org.opendaylight.yangtools.yang.binding.DataObject;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 public class SubtreeWriterTest {
38 Writer<DataObjects.DataObject4> writer;
40 Writer<DataObjects.DataObject4.DataObject41> writer11;
43 public void setUp() throws Exception {
44 MockitoAnnotations.initMocks(this);
45 when(writer.getManagedDataObjectType()).thenReturn(DataObjects.DataObject4.IID);
46 when(writer11.getManagedDataObjectType()).thenReturn(DataObjects.DataObject4.DataObject41.IID);
49 @Test(expected = IllegalArgumentException.class)
50 public void testSubtreeWriterCreationFail() throws Exception {
51 // The subtree node identified by IID.c(DataObject.class) is not a child of writer.getManagedDataObjectType
52 SubtreeWriter.createForWriter(Collections.singleton(InstanceIdentifier.create(DataObject.class)), writer);
55 @Test(expected = IllegalArgumentException.class)
56 public void testSubtreeWriterCreationFailInvalidIid() throws Exception {
57 // The subtree node identified by IID.c(DataObject.class) is not a child of writer.getManagedDataObjectType
58 SubtreeWriter.createForWriter(Collections.singleton(DataObjects.DataObject4.IID), writer);
62 public void testSubtreeWriterCreation() throws Exception {
63 final SubtreeWriter<?> forWriter = (SubtreeWriter<?>) SubtreeWriter.createForWriter(Sets.newHashSet(
64 DataObjects.DataObject4.DataObject41.IID,
65 DataObjects.DataObject4.DataObject41.DataObject411.IID,
66 DataObjects.DataObject4.DataObject42.IID),
69 assertEquals(writer.getManagedDataObjectType(), forWriter.getManagedDataObjectType());
70 assertEquals(3, forWriter.getHandledChildTypes().size());
74 public void testSubtreeWriterHandledTypes() throws Exception {
75 final SubtreeWriter<?> forWriter = (SubtreeWriter<?>) SubtreeWriter.createForWriter(Sets.newHashSet(
76 DataObjects.DataObject4.DataObject41.DataObject411.IID),
79 assertEquals(writer.getManagedDataObjectType(), forWriter.getManagedDataObjectType());
80 assertEquals(1, forWriter.getHandledChildTypes().size());
81 assertThat(forWriter.getHandledChildTypes(), hasItem(DataObjects.DataObject4.DataObject41.DataObject411.IID));