From e3c31cee916480b2d9d169c1f5afb1c42efaabe1 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Fri, 29 Jul 2016 16:27:12 +0200 Subject: HONEYCOMB-130: Rename infra packages(remove vpp/v3po) Change-Id: Ic5b90e397e3743623d01b206bc60bc5c7df6b981 Signed-off-by: Maros Marsalek --- .../fd/honeycomb/data/impl/AbstractInfraTest.java | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/AbstractInfraTest.java (limited to 'infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/AbstractInfraTest.java') diff --git a/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/AbstractInfraTest.java b/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/AbstractInfraTest.java new file mode 100644 index 000000000..3c996f6a6 --- /dev/null +++ b/infra/it/it-test/src/test/java/io/fd/honeycomb/data/impl/AbstractInfraTest.java @@ -0,0 +1,106 @@ +/* + * 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.data.impl; + +import static org.mockito.Mockito.when; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.google.common.util.concurrent.Futures; +import java.util.Collections; +import java.util.Map; +import javassist.ClassPool; +import org.junit.Before; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.test.rev150105.$YangModuleInfoImpl; +import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; +import org.opendaylight.yangtools.binding.data.codec.gen.impl.DataObjectSerializerGenerator; +import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator; +import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext; +import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; +import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; + +/** + * Base IT test infrastructure. + */ +abstract class AbstractInfraTest { + + protected BindingNormalizedNodeSerializer serializer; + protected SchemaContext schemaContext; + + @Mock + protected org.opendaylight.controller.md.sal.binding.api.DataBroker contextBroker; + @Mock + private org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction ctxTx; + + static BindingToNormalizedNodeCodec getSerializer(final ModuleInfoBackedContext moduleInfoBackedContext, + final SchemaContext schemaContext) { + final DataObjectSerializerGenerator serializerGenerator = new StreamWriterGenerator(JavassistUtils.forClassPool( + ClassPool.getDefault())); + final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(serializerGenerator); + final BindingRuntimeContext ctx = + BindingRuntimeContext.create(moduleInfoBackedContext, schemaContext); + codecRegistry.onBindingRuntimeContextUpdated(ctx); + return new BindingToNormalizedNodeCodec(moduleInfoBackedContext, codecRegistry); + } + + static ModuleInfoBackedContext getSchemaContext() { + final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(); + moduleInfoBackedContext.addModuleInfos(Collections.singleton($YangModuleInfoImpl.getInstance())); + return moduleInfoBackedContext; + } + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + when(contextBroker.newReadWriteTransaction()).thenReturn(ctxTx); + when(ctxTx.submit()).thenReturn(Futures.immediateCheckedFuture(null)); + + initSerializer(); + postSetup(); + } + + abstract void postSetup(); + + private void initSerializer() { + final ModuleInfoBackedContext moduleInfoBackedContext = getSchemaContext(); + schemaContext = moduleInfoBackedContext.tryToCreateSchemaContext().get(); + serializer = getSerializer(moduleInfoBackedContext, schemaContext); + } + + protected Multimap, ? extends DataObject> toBinding( + final NormalizedNode read) { + Multimap, DataObject> baNodes = HashMultimap.create(); + + for (DataContainerChild o : ((DataContainerNode) read).getValue()) { + final YangInstanceIdentifier yid = YangInstanceIdentifier.of(o.getNodeType()); + final Map.Entry, DataObject> baEntry = serializer.fromNormalizedNode(yid, o); + baNodes.put(baEntry.getKey(), baEntry.getValue()); + } + return baNodes; + } +} -- cgit 1.2.3-korg