From 757222979bc02d0aaba1870eea36413383d15bde Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Tue, 8 Nov 2016 10:13:36 +0100 Subject: HONEYCOMB-270 Add isPresent() to Readers/Customizers So that they can influence whether empty data is to be considered as present + Move registries implementations from util to impl + Introduce DelegatingReader trait + Extend GenericReader where possible to reduce duplication Change-Id: I5a416acd0c4eab1fbc30fcbe585719991dbe9215 Signed-off-by: Maros Marsalek --- .../util/read/registry/SubtreeReaderTest.java | 124 --------------------- 1 file changed, 124 deletions(-) delete mode 100644 infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReaderTest.java (limited to 'infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReaderTest.java') diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReaderTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReaderTest.java deleted file mode 100644 index 799b9553f..000000000 --- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/registry/SubtreeReaderTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.translate.util.read.registry; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import com.google.common.base.Optional; -import com.google.common.collect.Sets; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.Reader; -import io.fd.honeycomb.translate.util.DataObjects; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.ChildOf; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubtreeReaderTest { - - @Mock - private Reader> delegate; - @Mock - private Reader> delegateLocal; - @Mock - private ReadContext ctx; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - doReturn(DataObjects.DataObject4.IID).when(delegate).getManagedDataObjectType(); - doReturn(DataObject1.IID).when(delegateLocal).getManagedDataObjectType(); - } - - @Test - public void testCreate() throws Exception { - final Reader> subtreeR = - SubtreeReader.createForReader(Sets.newHashSet(DataObjects.DataObject4.DataObject41.IID), delegate); - - subtreeR.getBuilder(DataObjects.DataObject4.IID); - verify(delegate).getBuilder(DataObjects.DataObject4.IID); - - subtreeR.getManagedDataObjectType(); - verify(delegate, atLeastOnce()).getManagedDataObjectType(); - } - - @Test(expected = IllegalArgumentException.class) - public void testCreateInvalid() throws Exception { - SubtreeReader.createForReader(Sets.newHashSet(DataObjects.DataObject1.IID), delegate); - } - - @Test(expected = IllegalStateException.class) - public void testReadOnlySubtreeCannotFilter() throws Exception { - final Reader> subtreeR = - SubtreeReader.createForReader(Sets.newHashSet(DataObjects.DataObject4.DataObject41.IID), delegate); - - doReturn(Optional.fromNullable(mock(DataObjects.DataObject4.class))).when(delegate).read(DataObjects.DataObject4.IID, ctx); - subtreeR.read(DataObjects.DataObject4.DataObject41.IID, ctx); - } - - @Test - public void testReadOnlySubtreeNotPresent() throws Exception { - final Reader> subtreeR = - SubtreeReader.createForReader(Sets.newHashSet(DataObjects.DataObject4.DataObject41.IID), delegate); - - doReturn(Optional.absent()).when(delegate).read(DataObjects.DataObject4.IID, ctx); - assertFalse(subtreeR.read(DataObjects.DataObject4.DataObject41.IID, ctx).isPresent()); - } - - @Test - public void testReadOnlySubtreeChild() throws Exception { - final Reader> subtreeR = - SubtreeReader.createForReader(Sets.newHashSet(DataObject1.DataObject11.IID), delegateLocal); - - final DataObject1 mock = mock(DataObject1.class); - final DataObject1.DataObject11 mock11 = mock(DataObject1.DataObject11.class); - doReturn(mock11).when(mock).getDataObject11(); - doReturn(Optional.fromNullable(mock)).when(delegateLocal).read(DataObject1.IID, ctx); - assertEquals(mock11, subtreeR.read(DataObject1.DataObject11.IID, ctx).get()); - } - - @Test - public void testReadEntireSubtree() throws Exception { - final Reader> subtreeR = - SubtreeReader.createForReader(Sets.newHashSet(DataObject1.DataObject11.IID), delegateLocal); - - final DataObject1 mock = mock(DataObject1.class); - final DataObject1.DataObject11 mock11 = mock(DataObject1.DataObject11.class); - doReturn(mock11).when(mock).getDataObject11(); - doReturn(Optional.fromNullable(mock)).when(delegateLocal).read(DataObject1.IID, ctx); - assertEquals(mock, subtreeR.read(DataObject1.IID, ctx).get()); - } - - public abstract static class DataObject1 implements DataObject { - public static InstanceIdentifier IID = InstanceIdentifier.create(DataObject1.class); - - public abstract DataObject11 getDataObject11(); - - public abstract static class DataObject11 implements DataObject, ChildOf { - public static InstanceIdentifier IID = DataObject1.IID.child(DataObject11.class); - } - } -} -- cgit 1.2.3-korg