diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-07-14 10:41:49 +0200 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-07-25 10:34:16 +0200 |
commit | f15aed916c69b0766c7bed2dc7fe534f48b97ac9 (patch) | |
tree | 529281c96caf3c5325c17ec89cb3e4a154121091 /v3po/translate-utils/src | |
parent | 4e6b846c342b2c9e9443e3d3472685e5acb32fa3 (diff) |
HONEYCOMB-122: Reader registry integration tests
Add IT test for read infrastructure + some additional unit tests
+ Make Read/Write Factory autoCloseable
Change-Id: I6eab8e6df2c2132af01cea0a9c4b9bece7dc9b74
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/translate-utils/src')
15 files changed, 470 insertions, 139 deletions
diff --git a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java index ba9d8e16f..2a565d9f2 100644 --- a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java +++ b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java @@ -117,7 +117,7 @@ public final class RWUtils { } /** - * Create a map from a collection, checking for duplicity in the process + * Create an ordered map from a collection, checking for duplicity in the process. */ @Nonnull public static <K, V> Map<K, V> uniqueLinkedIndex(@Nonnull final Collection<V> values, @Nonnull final Function<? super V, K> keyFunction) { @@ -152,6 +152,9 @@ public final class RWUtils { /** * Transform a keyed instance identifier into a wildcarded one. + * <p/> + * ! This has to be called also for wildcarded List instance identifiers + * due to weird behavior of equals in InstanceIdentifier ! */ @SuppressWarnings("unchecked") public static <D extends DataObject> InstanceIdentifier<D> makeIidWildcarded(final InstanceIdentifier<D> id) { @@ -162,6 +165,19 @@ public final class RWUtils { return (InstanceIdentifier<D>) InstanceIdentifier.create(transformedPathArguments); } + /** + * Transform a keyed instance identifier into a wildcarded one, keeping keys except the last item. + */ + @SuppressWarnings("unchecked") + public static <D extends DataObject> InstanceIdentifier<D> makeIidLastWildcarded(final InstanceIdentifier<D> id) { + final InstanceIdentifier.Item<D> wildcardedItem = new InstanceIdentifier.Item<>(id.getTargetType()); + final Iterable<InstanceIdentifier.PathArgument> pathArguments = id.getPathArguments(); + return (InstanceIdentifier<D>) InstanceIdentifier.create( + Iterables.concat( + Iterables.limit(pathArguments, Iterables.size(pathArguments) - 1), + Collections.singleton(wildcardedItem))); + } + private static InstanceIdentifier.PathArgument cleanPathArgumentFromKeys(final InstanceIdentifier.PathArgument pathArgument) { return pathArgument instanceof InstanceIdentifier.IdentifiableItem<?, ?> ? new InstanceIdentifier.Item<>(pathArgument.getType()) diff --git a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/ReflectionUtils.java b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/ReflectionUtils.java index ea0b3b2c4..728c4f80d 100644 --- a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/ReflectionUtils.java +++ b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/ReflectionUtils.java @@ -44,7 +44,7 @@ public final class ReflectionUtils { @Nonnull final List<Class<?>> paramTypes, @Nonnull final Class<?> retType) { for (Method method : managedType.getMethods()) { - if(isMethodMatch(prefix, paramTypes, retType, method)) { + if (isMethodMatch(prefix, paramTypes, retType, method)) { return Optional.of(method); } } diff --git a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/ReflexiveListReaderCustomizer.java b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/ReflexiveListReaderCustomizer.java new file mode 100644 index 000000000..8ad323cc3 --- /dev/null +++ b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/ReflexiveListReaderCustomizer.java @@ -0,0 +1,65 @@ +/* + * 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.v3po.translate.util.read; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.base.Optional; +import io.fd.honeycomb.v3po.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.v3po.translate.util.ReflectionUtils; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.Identifiable; +import org.opendaylight.yangtools.yang.binding.Identifier; + +/** + * Might be slow ! + */ +public abstract class ReflexiveListReaderCustomizer<C extends DataObject & Identifiable<K>, K extends Identifier<C>, B extends Builder<C>> + extends ReflexiveReaderCustomizer<C, B> + implements ListReaderCustomizer<C, K, B> { + + + public ReflexiveListReaderCustomizer(final Class<C> typeClass, final Class<B> builderClass) { + super(typeClass, builderClass); + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final C readValue) { + merge(parentBuilder, Collections.singletonList(readValue)); + } + + @Override + public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final List<C> readData) { + final Optional<Method> method = + ReflectionUtils.findMethodReflex(parentBuilder.getClass(), "set" + getTypeClass().getSimpleName(), + Collections.singletonList(List.class), parentBuilder.getClass()); + + checkArgument(method.isPresent(), "Unable to set %s to %s", readData, parentBuilder); + + try { + method.get().invoke(parentBuilder, readData); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new IllegalArgumentException("Unable to set " + readData + " to " + parentBuilder, e); + } + } +} diff --git a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/ReflexiveReader.java b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/ReflexiveReader.java index 51725e728..2b2d9300b 100644 --- a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/ReflexiveReader.java +++ b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/ReflexiveReader.java @@ -28,7 +28,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; * <p/> * Might be slow due to reflection ! */ -public final class ReflexiveReader<C extends DataObject, B extends Builder<C>> extends AbstractGenericReader<C, B> { +public class ReflexiveReader<C extends DataObject, B extends Builder<C>> extends AbstractGenericReader<C, B> { private final ReflexiveReaderCustomizer<C, B> customizer; diff --git a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/ReflexiveReaderCustomizer.java b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/ReflexiveReaderCustomizer.java index f9efca3dc..a6b9bf08e 100644 --- a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/ReflexiveReaderCustomizer.java +++ b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/ReflexiveReaderCustomizer.java @@ -33,7 +33,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Might be slow ! */ -final class ReflexiveReaderCustomizer<C extends DataObject, B extends Builder<C>> extends NoopReaderCustomizer<C, B> { +class ReflexiveReaderCustomizer<C extends DataObject, B extends Builder<C>> extends NoopReaderCustomizer<C, B> { private final Class<C> typeClass; private final Class<B> builderClass; diff --git a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/CompositeReader.java b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/CompositeReader.java index 64ecaf095..aa9b2dc92 100644 --- a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/CompositeReader.java +++ b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/CompositeReader.java @@ -18,6 +18,7 @@ package io.fd.honeycomb.v3po.translate.util.read.registry; import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; @@ -53,6 +54,11 @@ class CompositeReader<D extends DataObject, B extends Builder<D>> extends Abstra this.childReaders = childReaders; } + @VisibleForTesting + ImmutableMap<Class<?>, Reader<? extends DataObject, ? extends Builder<?>>> getChildReaders() { + return childReaders; + } + @SuppressWarnings("unchecked") public static <D extends DataObject> InstanceIdentifier<D> appendTypeToId( final InstanceIdentifier<? extends DataObject> parentId, final InstanceIdentifier<D> type) { @@ -66,11 +72,14 @@ class CompositeReader<D extends DataObject, B extends Builder<D>> extends Abstra public Optional<? extends DataObject> read(@Nonnull final InstanceIdentifier<? extends DataObject> id, @Nonnull final ReadContext ctx) throws ReadFailedException { if (shouldReadCurrent(id)) { + LOG.trace("{}: Reading current: {}", this, id); return readCurrent((InstanceIdentifier<D>) id, ctx); } else if (shouldDelegateToChild(id)) { + LOG.trace("{}: Reading child: {}", this, id); return readSubtree(id, ctx); } else { // Fallback + LOG.trace("{}: Delegating read: {}", this, id); return delegate.read(id, ctx); } } @@ -95,10 +104,11 @@ class CompositeReader<D extends DataObject, B extends Builder<D>> extends Abstra @SuppressWarnings("unchecked") private void readChildren(final InstanceIdentifier<D> id, @Nonnull final ReadContext ctx, final B builder) throws ReadFailedException { + LOG.debug("{}: Reading children: {}", this, childReaders.keySet()); for (Reader child : childReaders.values()) { - LOG.debug("{}: Reading child node from: {}", this, child); final InstanceIdentifier childId = appendTypeToId(id, child.getManagedDataObjectType()); + LOG.debug("{}: Reading child from: {}", this, child); if (child instanceof ListReader) { final List<? extends DataObject> list = ((ListReader) child).readList(childId, ctx); ((ListReader) child).merge(builder, list); diff --git a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/CompositeReaderRegistry.java b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/CompositeReaderRegistry.java index 0a948c7a8..a9f606ae2 100644 --- a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/CompositeReaderRegistry.java +++ b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/CompositeReaderRegistry.java @@ -18,6 +18,7 @@ package io.fd.honeycomb.v3po.translate.util.read.registry; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; import com.google.common.collect.Iterables; import com.google.common.collect.LinkedListMultimap; @@ -31,6 +32,7 @@ import io.fd.honeycomb.v3po.translate.util.RWUtils; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; @@ -59,6 +61,11 @@ public final class CompositeReaderRegistry implements ReaderRegistry { this.rootReaders = RWUtils.uniqueLinkedIndex(checkNotNull(rootReaders), RWUtils.MANAGER_CLASS_FUNCTION); } + @VisibleForTesting + Map<Class<? extends DataObject>, Reader<? extends DataObject, ? extends Builder<?>>> getRootReaders() { + return rootReaders; + } + @Override @Nonnull public Multimap<InstanceIdentifier<? extends DataObject>, ? extends DataObject> readAll( @@ -101,4 +108,10 @@ public final class CompositeReaderRegistry implements ReaderRegistry { LOG.debug("Reading from delegate: {}", reader); return reader.read(id, ctx); } + + @Override + public String toString() { + return getClass().getSimpleName() + + rootReaders.keySet().stream().map(Class::getSimpleName).collect(Collectors.toList()); + } } diff --git a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/SubtreeReader.java b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/SubtreeReader.java index 98fcac673..50a20656e 100644 --- a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/SubtreeReader.java +++ b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/read/registry/SubtreeReader.java @@ -89,7 +89,7 @@ class SubtreeReader<D extends DataObject, B extends Builder<D>> implements Reade LOG.debug("{}: Subtree node managed by this writer requested: {}. Reading current and filtering", this, id); // If there's no dedicated reader, use read current final InstanceIdentifier<D> currentId = RWUtils.cutId(id, getManagedDataObjectType()); - final Optional<? extends DataObject> current = read(currentId, ctx); + final Optional<? extends DataObject> current = delegate.read(currentId, ctx); // then perform post-reading filtering (return only requested sub-node) final Optional<? extends DataObject> readSubtree = current.isPresent() ? filterSubtree(current.get(), id, getManagedDataObjectType().getTargetType()) diff --git a/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/DataObjects.java b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/DataObjects.java new file mode 100644 index 000000000..d823465bd --- /dev/null +++ b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/DataObjects.java @@ -0,0 +1,52 @@ +/* + * 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.v3po.translate.util; + +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class DataObjects { + public interface DataObject1 extends DataObject { + InstanceIdentifier<DataObject1> IID = InstanceIdentifier.create(DataObject1.class); + } + + public interface DataObject2 extends DataObject { + InstanceIdentifier<DataObject2> IID = InstanceIdentifier.create(DataObject2.class); + } + + public interface DataObject3 extends DataObject { + InstanceIdentifier<DataObject3> IID = InstanceIdentifier.create(DataObject3.class); + interface DataObject31 extends DataObject, ChildOf<DataObject3> { + InstanceIdentifier<DataObject31> IID = DataObject3.IID.child(DataObject31.class); + } + } + + public interface DataObject4 extends DataObject { + InstanceIdentifier<DataObject4> IID = InstanceIdentifier.create(DataObject4.class); + interface DataObject41 extends DataObject, ChildOf<DataObject4> { + InstanceIdentifier<DataObject41> IID = DataObject4.IID.child(DataObject41.class); + interface DataObject411 extends DataObject, ChildOf<DataObject41> { + InstanceIdentifier<DataObject411> IID = DataObject41.IID.child(DataObject411.class); + } + } + + interface DataObject42 extends DataObject, ChildOf<DataObject4> { + InstanceIdentifier<DataObject42> IID = DataObject4.IID.child(DataObject42.class); + } + } +} diff --git a/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/read/registry/CompositeReaderRegistryBuilderTest.java b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/read/registry/CompositeReaderRegistryBuilderTest.java new file mode 100644 index 000000000..e57dcee43 --- /dev/null +++ b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/read/registry/CompositeReaderRegistryBuilderTest.java @@ -0,0 +1,114 @@ +/* + * 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.v3po.translate.util.read.registry; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import io.fd.honeycomb.v3po.translate.read.Reader; +import io.fd.honeycomb.v3po.translate.read.registry.ReaderRegistry; +import io.fd.honeycomb.v3po.translate.util.DataObjects; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.mockito.Mockito; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class CompositeReaderRegistryBuilderTest { + + private Reader<DataObjects.DataObject1, Builder<DataObjects.DataObject1>> reader1 = + mock(DataObjects.DataObject1.class); + private Reader<DataObjects.DataObject2, Builder<DataObjects.DataObject2>> reader2 = + mock(DataObjects.DataObject2.class); + private Reader<DataObjects.DataObject3, Builder<DataObjects.DataObject3>> reader3 = + mock(DataObjects.DataObject3.class); + private Reader<DataObjects.DataObject3.DataObject31, Builder<DataObjects.DataObject3.DataObject31>> reader31 = + mock(DataObjects.DataObject3.DataObject31.class); + + private Reader<DataObjects.DataObject4, Builder<DataObjects.DataObject4>> reader4 = + mock(DataObjects.DataObject4.class); + private Reader<DataObjects.DataObject4.DataObject41, Builder<DataObjects.DataObject4.DataObject41>> reader41 = + mock(DataObjects.DataObject4.DataObject41.class); + private Reader<DataObjects.DataObject4.DataObject41.DataObject411, Builder<DataObjects.DataObject4.DataObject41.DataObject411>> reader411 = + mock(DataObjects.DataObject4.DataObject41.DataObject411.class); + private Reader<DataObjects.DataObject4.DataObject42, Builder<DataObjects.DataObject4.DataObject42>> reader42 = + mock(DataObjects.DataObject4.DataObject42.class); + + @SuppressWarnings("unchecked") + private <D extends DataObject> Reader<D, Builder<D>> mock(final Class<D> dataObjectType) { + final Reader<D, Builder<D>> mock = Mockito.mock(Reader.class); + try { + when(mock.getManagedDataObjectType()) + .thenReturn(((InstanceIdentifier<D>) dataObjectType.getDeclaredField("IID").get(null))); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + return mock; + } + + @Test + public void testCompositeStructure() throws Exception { + final CompositeReaderRegistryBuilder compositeReaderRegistryBuilder = new CompositeReaderRegistryBuilder(); + /* + Composite reader structure ordered left from right + + 1, 2, 3, 4 + 31 42, 41 + 411 + */ + compositeReaderRegistryBuilder.add(reader1); + compositeReaderRegistryBuilder.addAfter(reader2, reader1.getManagedDataObjectType()); + compositeReaderRegistryBuilder.addAfter(reader3, reader2.getManagedDataObjectType()); + compositeReaderRegistryBuilder.addAfter(reader31, reader1.getManagedDataObjectType()); + compositeReaderRegistryBuilder.addAfter(reader4, reader3.getManagedDataObjectType()); + compositeReaderRegistryBuilder.add(reader41); + compositeReaderRegistryBuilder.addBefore(reader42, reader41.getManagedDataObjectType()); + compositeReaderRegistryBuilder.add(reader411); + + final ReaderRegistry build = compositeReaderRegistryBuilder.build(); + + final Map<Class<? extends DataObject>, Reader<? extends DataObject, ? extends Builder<?>>> rootReaders = + ((CompositeReaderRegistry) build).getRootReaders(); + final List<Class<? extends DataObject>> rootReaderOrder = Lists.newArrayList(rootReaders.keySet()); + + assertEquals(reader1.getManagedDataObjectType().getTargetType(), rootReaderOrder.get(0)); + assertEquals(reader2.getManagedDataObjectType().getTargetType(), rootReaderOrder.get(1)); + assertEquals(reader3.getManagedDataObjectType().getTargetType(), rootReaderOrder.get(2)); + assertEquals(reader4.getManagedDataObjectType().getTargetType(), rootReaderOrder.get(3)); + + assertFalse(rootReaders.get(DataObjects.DataObject1.class) instanceof CompositeReader); + assertFalse(rootReaders.get(DataObjects.DataObject2.class) instanceof CompositeReader); + assertTrue(rootReaders.get(DataObjects.DataObject3.class) instanceof CompositeReader); + assertTrue(rootReaders.get(DataObjects.DataObject4.class) instanceof CompositeReader); + + final ImmutableMap<Class<?>, Reader<? extends DataObject, ? extends Builder<?>>> childReaders = + ((CompositeReader<? extends DataObject, ? extends Builder<?>>) rootReaders + .get(DataObjects.DataObject4.class)).getChildReaders(); + final List<Class<?>> orderedChildReaders = Lists.newArrayList(childReaders.keySet()); + + assertEquals(reader42.getManagedDataObjectType().getTargetType(), orderedChildReaders.get(0)); + assertEquals(reader41.getManagedDataObjectType().getTargetType(), orderedChildReaders.get(1)); + assertTrue(childReaders.get(DataObjects.DataObject4.DataObject41.class) instanceof CompositeReader); + assertFalse(childReaders.get(DataObjects.DataObject4.DataObject42.class) instanceof CompositeReader); + } +}
\ No newline at end of file diff --git a/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/read/registry/SubtreeReaderTest.java b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/read/registry/SubtreeReaderTest.java new file mode 100644 index 000000000..324d71daa --- /dev/null +++ b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/read/registry/SubtreeReaderTest.java @@ -0,0 +1,124 @@ +/* + * 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.v3po.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.v3po.translate.read.ReadContext; +import io.fd.honeycomb.v3po.translate.read.Reader; +import io.fd.honeycomb.v3po.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<DataObjects.DataObject4, Builder<DataObjects.DataObject4>> delegate; + @Mock + private Reader<DataObject1, Builder<DataObject1>> 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<DataObjects.DataObject4, Builder<DataObjects.DataObject4>> 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<DataObjects.DataObject4, Builder<DataObjects.DataObject4>> 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<DataObjects.DataObject4, Builder<DataObjects.DataObject4>> 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<DataObject1, Builder<DataObject1>> 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<DataObject1, Builder<DataObject1>> 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<DataObject1> IID = InstanceIdentifier.create(DataObject1.class); + + public abstract DataObject11 getDataObject11(); + + public abstract static class DataObject11 implements DataObject, ChildOf<DataObject1> { + public static InstanceIdentifier<DataObject11> IID = DataObject1.IID.child(DataObject11.class); + } + } +} diff --git a/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/read/registry/TypeHierarchyTest.java b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/read/registry/TypeHierarchyTest.java index 92449af28..7a664eef1 100644 --- a/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/read/registry/TypeHierarchyTest.java +++ b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/read/registry/TypeHierarchyTest.java @@ -24,65 +24,46 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import com.google.common.collect.Sets; +import io.fd.honeycomb.v3po.translate.util.DataObjects.DataObject1; +import io.fd.honeycomb.v3po.translate.util.DataObjects.DataObject3; +import io.fd.honeycomb.v3po.translate.util.DataObjects.DataObject4; import org.junit.Test; -import org.opendaylight.yangtools.yang.binding.ChildOf; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class TypeHierarchyTest { @Test public void testHierarchy() throws Exception { final TypeHierarchy typeHierarchy = TypeHierarchy.create(Sets.newHashSet( - DataObject3.DataObject31.DataObject311.IID, - DataObject3.DataObject31.IID,/* Included in previous already */ + DataObject4.DataObject41.DataObject411.IID, + DataObject4.DataObject41.IID,/* Included in previous already */ DataObject1.IID, - DataObject2.DataObject21.IID)); + DataObject3.DataObject31.IID)); // Roots assertThat(typeHierarchy.getRoots().size(), is(3)); - assertThat(typeHierarchy.getRoots(), hasItems(DataObject1.IID, DataObject2.IID, DataObject3.IID)); + assertThat(typeHierarchy.getRoots(), hasItems(DataObject1.IID, DataObject3.IID, DataObject4.IID)); // Leaves assertThat(typeHierarchy.getDirectChildren(DataObject1.IID).size(), is(0)); - assertThat(typeHierarchy.getDirectChildren(DataObject2.DataObject21.IID).size(), is(0)); - assertThat(typeHierarchy.getDirectChildren(DataObject3.DataObject31.DataObject311.IID).size(), is(0)); + assertThat(typeHierarchy.getDirectChildren(DataObject3.DataObject31.IID).size(), is(0)); + assertThat(typeHierarchy.getDirectChildren(DataObject4.DataObject41.DataObject411.IID).size(), is(0)); // Intermediate leaves - assertThat(typeHierarchy.getDirectChildren(DataObject2.IID).size(), is(1)); - assertThat(typeHierarchy.getDirectChildren(DataObject2.IID), hasItem(DataObject2.DataObject21.IID)); - assertEquals(typeHierarchy.getDirectChildren(DataObject2.IID), typeHierarchy.getAllChildren(DataObject2.IID)); - - assertThat(typeHierarchy.getDirectChildren(DataObject3.DataObject31.IID).size(), is(1)); - assertThat(typeHierarchy.getDirectChildren(DataObject3.DataObject31.IID), hasItem( - DataObject3.DataObject31.DataObject311.IID)); - assertEquals(typeHierarchy.getDirectChildren(DataObject3.DataObject31.IID), typeHierarchy.getAllChildren( - DataObject3.DataObject31.IID)); - assertThat(typeHierarchy.getDirectChildren(DataObject3.IID).size(), is(1)); assertThat(typeHierarchy.getDirectChildren(DataObject3.IID), hasItem(DataObject3.DataObject31.IID)); - assertThat(typeHierarchy.getAllChildren(DataObject3.IID).size(), is(2)); - assertTrue(typeHierarchy.getAllChildren(DataObject3.IID).contains(DataObject3.DataObject31.IID)); - assertTrue(typeHierarchy.getAllChildren(DataObject3.IID).contains(DataObject3.DataObject31.DataObject311.IID)); - } + assertEquals(typeHierarchy.getDirectChildren(DataObject3.IID), typeHierarchy.getAllChildren(DataObject3.IID)); - private abstract static class DataObject1 implements DataObject { - static InstanceIdentifier<DataObject1> IID = InstanceIdentifier.create(DataObject1.class); - } - private abstract static class DataObject2 implements DataObject { - static InstanceIdentifier<DataObject2> IID = InstanceIdentifier.create(DataObject2.class); - private abstract static class DataObject21 implements DataObject, ChildOf<DataObject2> { - static InstanceIdentifier<DataObject21> IID = DataObject2.IID.child(DataObject21.class); - } - } - private abstract static class DataObject3 implements DataObject { - static InstanceIdentifier<DataObject3> IID = InstanceIdentifier.create(DataObject3.class); - private abstract static class DataObject31 implements DataObject, ChildOf<DataObject3> { - static InstanceIdentifier<DataObject31> IID = DataObject3.IID.child(DataObject31.class); - private abstract static class DataObject311 implements DataObject, ChildOf<DataObject31> { - static InstanceIdentifier<DataObject311> IID = DataObject31.IID.child(DataObject311.class); - } - } + assertThat(typeHierarchy.getDirectChildren(DataObject4.DataObject41.IID).size(), is(1)); + assertThat(typeHierarchy.getDirectChildren(DataObject4.DataObject41.IID), hasItem( + DataObject4.DataObject41.DataObject411.IID)); + assertEquals(typeHierarchy.getDirectChildren(DataObject4.DataObject41.IID), typeHierarchy.getAllChildren( + DataObject4.DataObject41.IID)); + + assertThat(typeHierarchy.getDirectChildren(DataObject4.IID).size(), is(1)); + assertThat(typeHierarchy.getDirectChildren(DataObject4.IID), hasItem(DataObject4.DataObject41.IID)); + assertThat(typeHierarchy.getAllChildren(DataObject4.IID).size(), is(2)); + assertTrue(typeHierarchy.getAllChildren(DataObject4.IID).contains(DataObject4.DataObject41.IID)); + assertTrue(typeHierarchy.getAllChildren(DataObject4.IID).contains(DataObject4.DataObject41.DataObject411.IID)); } } diff --git a/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/FlatWriterRegistryBuilderTest.java b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/FlatWriterRegistryBuilderTest.java index da7ac0947..743d84cbf 100644 --- a/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/FlatWriterRegistryBuilderTest.java +++ b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/FlatWriterRegistryBuilderTest.java @@ -13,11 +13,11 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import io.fd.honeycomb.v3po.translate.util.DataObjects; import io.fd.honeycomb.v3po.translate.write.Writer; import java.util.ArrayList; import java.util.List; import org.junit.Test; -import org.opendaylight.yangtools.yang.binding.ChildOf; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -31,19 +31,19 @@ public class FlatWriterRegistryBuilderTest { 1 -> 2 -> 3 -> 4 */ - flatWriterRegistryBuilder.add(mockWriter(DataObject3.class)); - flatWriterRegistryBuilder.add(mockWriter(DataObject4.class)); - flatWriterRegistryBuilder.addBefore(mockWriter(DataObject2.class), - Lists.newArrayList(DataObject3.IID, DataObject4.IID)); - flatWriterRegistryBuilder.addBefore(mockWriter(DataObject1.class), DataObject2.IID); + flatWriterRegistryBuilder.add(mockWriter(DataObjects.DataObject3.class)); + flatWriterRegistryBuilder.add(mockWriter(DataObjects.DataObject4.class)); + flatWriterRegistryBuilder.addBefore(mockWriter(DataObjects.DataObject2.class), + Lists.newArrayList(DataObjects.DataObject3.IID, DataObjects.DataObject4.IID)); + flatWriterRegistryBuilder.addBefore(mockWriter(DataObjects.DataObject1.class), DataObjects.DataObject2.IID); final ImmutableMap<InstanceIdentifier<?>, Writer<?>> mappedWriters = flatWriterRegistryBuilder.getMappedHandlers(); final ArrayList<InstanceIdentifier<?>> typesInList = Lists.newArrayList(mappedWriters.keySet()); - assertEquals(DataObject1.IID, typesInList.get(0)); - assertEquals(DataObject2.IID, typesInList.get(1)); - assertThat(typesInList.get(2), anyOf(equalTo(DataObject3.IID), equalTo(DataObject4.IID))); - assertThat(typesInList.get(3), anyOf(equalTo(DataObject3.IID), equalTo(DataObject4.IID))); + assertEquals(DataObjects.DataObject1.IID, typesInList.get(0)); + assertEquals(DataObjects.DataObject2.IID, typesInList.get(1)); + assertThat(typesInList.get(2), anyOf(equalTo(DataObjects.DataObject3.IID), equalTo(DataObjects.DataObject4.IID))); + assertThat(typesInList.get(3), anyOf(equalTo(DataObjects.DataObject3.IID), equalTo(DataObjects.DataObject4.IID))); } @Test @@ -53,18 +53,18 @@ public class FlatWriterRegistryBuilderTest { 1 -> 2 -> 3 -> 4 */ - flatWriterRegistryBuilder.add(mockWriter(DataObject1.class)); - flatWriterRegistryBuilder.addAfter(mockWriter(DataObject2.class), DataObject1.IID); - flatWriterRegistryBuilder.addAfter(mockWriter(DataObject3.class), DataObject2.IID); - flatWriterRegistryBuilder.addAfter(mockWriter(DataObject4.class), DataObject2.IID); + flatWriterRegistryBuilder.add(mockWriter(DataObjects.DataObject1.class)); + flatWriterRegistryBuilder.addAfter(mockWriter(DataObjects.DataObject2.class), DataObjects.DataObject1.IID); + flatWriterRegistryBuilder.addAfter(mockWriter(DataObjects.DataObject3.class), DataObjects.DataObject2.IID); + flatWriterRegistryBuilder.addAfter(mockWriter(DataObjects.DataObject4.class), DataObjects.DataObject2.IID); final ImmutableMap<InstanceIdentifier<?>, Writer<?>> mappedWriters = flatWriterRegistryBuilder.getMappedHandlers(); final List<InstanceIdentifier<?>> typesInList = Lists.newArrayList(mappedWriters.keySet()); - assertEquals(DataObject1.IID, typesInList.get(0)); - assertEquals(DataObject2.IID, typesInList.get(1)); - assertThat(typesInList.get(2), anyOf(equalTo(DataObject3.IID), equalTo(DataObject4.IID))); - assertThat(typesInList.get(3), anyOf(equalTo(DataObject3.IID), equalTo(DataObject4.IID))); + assertEquals(DataObjects.DataObject1.IID, typesInList.get(0)); + assertEquals(DataObjects.DataObject2.IID, typesInList.get(1)); + assertThat(typesInList.get(2), anyOf(equalTo(DataObjects.DataObject3.IID), equalTo(DataObjects.DataObject4.IID))); + assertThat(typesInList.get(3), anyOf(equalTo(DataObjects.DataObject3.IID), equalTo(DataObjects.DataObject4.IID))); } @Test(expected = IllegalArgumentException.class) @@ -73,51 +73,51 @@ public class FlatWriterRegistryBuilderTest { /* 1 -> 2 -> 1 */ - flatWriterRegistryBuilder.add(mockWriter(DataObject1.class)); - flatWriterRegistryBuilder.addAfter(mockWriter(DataObject2.class), DataObject1.IID); - flatWriterRegistryBuilder.addAfter(mockWriter(DataObject1.class), DataObject2.IID); + flatWriterRegistryBuilder.add(mockWriter(DataObjects.DataObject1.class)); + flatWriterRegistryBuilder.addAfter(mockWriter(DataObjects.DataObject2.class), DataObjects.DataObject1.IID); + flatWriterRegistryBuilder.addAfter(mockWriter(DataObjects.DataObject1.class), DataObjects.DataObject2.IID); } @Test(expected = IllegalArgumentException.class) public void testAddWriterTwice() throws Exception { final FlatWriterRegistryBuilder flatWriterRegistryBuilder = new FlatWriterRegistryBuilder(); - flatWriterRegistryBuilder.add(mockWriter(DataObject1.class)); - flatWriterRegistryBuilder.add(mockWriter(DataObject1.class)); + flatWriterRegistryBuilder.add(mockWriter(DataObjects.DataObject1.class)); + flatWriterRegistryBuilder.add(mockWriter(DataObjects.DataObject1.class)); } @Test public void testAddSubtreeWriter() throws Exception { final FlatWriterRegistryBuilder flatWriterRegistryBuilder = new FlatWriterRegistryBuilder(); flatWriterRegistryBuilder.subtreeAdd( - Sets.newHashSet(DataObject4.DataObject5.IID, - DataObject4.DataObject5.IID), - mockWriter(DataObject4.class)); + Sets.newHashSet(DataObjects.DataObject4.DataObject41.IID, + DataObjects.DataObject4.DataObject41.IID), + mockWriter(DataObjects.DataObject4.class)); final ImmutableMap<InstanceIdentifier<?>, Writer<?>> mappedWriters = flatWriterRegistryBuilder.getMappedHandlers(); final ArrayList<InstanceIdentifier<?>> typesInList = Lists.newArrayList(mappedWriters.keySet()); - assertEquals(DataObject4.IID, typesInList.get(0)); + assertEquals(DataObjects.DataObject4.IID, typesInList.get(0)); assertEquals(1, typesInList.size()); } @Test public void testCreateSubtreeWriter() throws Exception { final Writer<?> forWriter = SubtreeWriter.createForWriter(Sets.newHashSet( - DataObject4.DataObject5.IID, - DataObject4.DataObject5.DataObject51.IID, - DataObject4.DataObject6.IID), - mockWriter(DataObject4.class)); + DataObjects.DataObject4.DataObject41.IID, + DataObjects.DataObject4.DataObject41.DataObject411.IID, + DataObjects.DataObject4.DataObject42.IID), + mockWriter(DataObjects.DataObject4.class)); assertThat(forWriter, instanceOf(SubtreeWriter.class)); assertThat(((SubtreeWriter<?>) forWriter).getHandledChildTypes().size(), is(3)); - assertThat(((SubtreeWriter<?>) forWriter).getHandledChildTypes(), hasItems(DataObject4.DataObject5.IID, - DataObject4.DataObject6.IID, DataObject4.DataObject5.DataObject51.IID)); + assertThat(((SubtreeWriter<?>) forWriter).getHandledChildTypes(), hasItems(DataObjects.DataObject4.DataObject41.IID, + DataObjects.DataObject4.DataObject42.IID, DataObjects.DataObject4.DataObject41.DataObject411.IID)); } @Test(expected = IllegalArgumentException.class) public void testCreateInvalidSubtreeWriter() throws Exception { SubtreeWriter.createForWriter(Sets.newHashSet( - InstanceIdentifier.create(DataObject3.class).child(DataObject3.DataObject31.class)), - mockWriter(DataObject4.class)); + InstanceIdentifier.create(DataObjects.DataObject3.class).child(DataObjects.DataObject3.DataObject31.class)), + mockWriter(DataObjects.DataObject4.class)); } @SuppressWarnings("unchecked") @@ -128,29 +128,4 @@ public class FlatWriterRegistryBuilderTest { return mock; } - private abstract static class DataObject1 implements DataObject { - static InstanceIdentifier<DataObject1> IID = InstanceIdentifier.create(DataObject1.class); - } - private abstract static class DataObject2 implements DataObject { - static InstanceIdentifier<DataObject2> IID = InstanceIdentifier.create(DataObject2.class); - } - private abstract static class DataObject3 implements DataObject { - static InstanceIdentifier<DataObject3> IID = InstanceIdentifier.create(DataObject3.class); - private abstract static class DataObject31 implements DataObject, ChildOf<DataObject3> { - static InstanceIdentifier<DataObject31> IID = DataObject3.IID.child(DataObject31.class); - } - } - private abstract static class DataObject4 implements DataObject { - static InstanceIdentifier<DataObject4> IID = InstanceIdentifier.create(DataObject4.class); - private abstract static class DataObject5 implements DataObject, ChildOf<DataObject4> { - static InstanceIdentifier<DataObject5> IID = DataObject4.IID.child(DataObject5.class); - private abstract static class DataObject51 implements DataObject, ChildOf<DataObject5> { - static InstanceIdentifier<DataObject51> IID = DataObject5.IID.child(DataObject51.class); - } - } - private abstract static class DataObject6 implements DataObject, ChildOf<DataObject4> { - static InstanceIdentifier<DataObject6> IID = DataObject4.IID.child(DataObject6.class); - } - } - }
\ No newline at end of file diff --git a/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/FlatWriterRegistryTest.java b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/FlatWriterRegistryTest.java index 1b4a059ea..a72cb4fa7 100644 --- a/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/FlatWriterRegistryTest.java +++ b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/FlatWriterRegistryTest.java @@ -17,6 +17,9 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; +import io.fd.honeycomb.v3po.translate.util.DataObjects.DataObject1; +import io.fd.honeycomb.v3po.translate.util.DataObjects.DataObject2; +import io.fd.honeycomb.v3po.translate.util.DataObjects.DataObject3; import io.fd.honeycomb.v3po.translate.write.DataObjectUpdate; import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.Writer; @@ -258,14 +261,4 @@ public class FlatWriterRegistryTest { final InstanceIdentifier<D> iid = (InstanceIdentifier<D>) type.getDeclaredField("IID").get(null); updates.put(iid, DataObjectUpdate.create(iid, mock(type), mock(type))); } - - private abstract static class DataObject1 implements DataObject { - static final InstanceIdentifier<DataObject1> IID = InstanceIdentifier.create(DataObject1.class); - } - private abstract static class DataObject2 implements DataObject { - static final InstanceIdentifier<DataObject2> IID = InstanceIdentifier.create(DataObject2.class); - } - private abstract static class DataObject3 implements DataObject { - static final InstanceIdentifier<DataObject3> IID = InstanceIdentifier.create(DataObject3.class); - } }
\ No newline at end of file diff --git a/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/SubtreeWriterTest.java b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/SubtreeWriterTest.java index b7dcadc73..627c69c92 100644 --- a/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/SubtreeWriterTest.java +++ b/v3po/translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/util/write/registry/SubtreeWriterTest.java @@ -22,28 +22,28 @@ import static org.junit.Assert.assertThat; import static org.mockito.Mockito.when; import com.google.common.collect.Sets; +import io.fd.honeycomb.v3po.translate.util.DataObjects; import io.fd.honeycomb.v3po.translate.write.Writer; import java.util.Collections; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.yangtools.yang.binding.ChildOf; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class SubtreeWriterTest { @Mock - Writer<DataObject1> writer; + Writer<DataObjects.DataObject4> writer; @Mock - Writer<DataObject1.DataObject11> writer11; + Writer<DataObjects.DataObject4.DataObject41> writer11; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - when(writer.getManagedDataObjectType()).thenReturn(DataObject1.IID); - when(writer11.getManagedDataObjectType()).thenReturn(DataObject1.DataObject11.IID); + when(writer.getManagedDataObjectType()).thenReturn(DataObjects.DataObject4.IID); + when(writer11.getManagedDataObjectType()).thenReturn(DataObjects.DataObject4.DataObject41.IID); } @Test(expected = IllegalArgumentException.class) @@ -55,15 +55,15 @@ public class SubtreeWriterTest { @Test(expected = IllegalArgumentException.class) public void testSubtreeWriterCreationFailInvalidIid() throws Exception { // The subtree node identified by IID.c(DataObject.class) is not a child of writer.getManagedDataObjectType - SubtreeWriter.createForWriter(Collections.singleton(DataObject1.IID), writer); + SubtreeWriter.createForWriter(Collections.singleton(DataObjects.DataObject4.IID), writer); } @Test public void testSubtreeWriterCreation() throws Exception { final SubtreeWriter<?> forWriter = (SubtreeWriter<?>) SubtreeWriter.createForWriter(Sets.newHashSet( - DataObject1.DataObject11.IID, - DataObject1.DataObject11.DataObject111.IID, - DataObject1.DataObject12.IID), + DataObjects.DataObject4.DataObject41.IID, + DataObjects.DataObject4.DataObject41.DataObject411.IID, + DataObjects.DataObject4.DataObject42.IID), writer); assertEquals(writer.getManagedDataObjectType(), forWriter.getManagedDataObjectType()); @@ -73,24 +73,12 @@ public class SubtreeWriterTest { @Test public void testSubtreeWriterHandledTypes() throws Exception { final SubtreeWriter<?> forWriter = (SubtreeWriter<?>) SubtreeWriter.createForWriter(Sets.newHashSet( - DataObject1.DataObject11.DataObject111.IID), + DataObjects.DataObject4.DataObject41.DataObject411.IID), writer); assertEquals(writer.getManagedDataObjectType(), forWriter.getManagedDataObjectType()); assertEquals(1, forWriter.getHandledChildTypes().size()); - assertThat(forWriter.getHandledChildTypes(), hasItem(DataObject1.DataObject11.DataObject111.IID)); + assertThat(forWriter.getHandledChildTypes(), hasItem(DataObjects.DataObject4.DataObject41.DataObject411.IID)); } - private abstract static class DataObject1 implements DataObject { - static InstanceIdentifier<DataObject1> IID = InstanceIdentifier.create(DataObject1.class); - private abstract static class DataObject11 implements DataObject, ChildOf<DataObject1> { - static InstanceIdentifier<DataObject11> IID = DataObject1.IID.child(DataObject11.class); - private abstract static class DataObject111 implements DataObject, ChildOf<DataObject11> { - static InstanceIdentifier<DataObject111> IID = DataObject11.IID.child(DataObject111.class); - } - } - private abstract static class DataObject12 implements DataObject, ChildOf<DataObject1> { - static InstanceIdentifier<DataObject12> IID = DataObject1.IID.child(DataObject12.class); - } - } }
\ No newline at end of file |