X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Ftest%2Futil%2FBindingTestContext.java;h=5227f30e3c13f872896896228a51f70520664db9;hb=698468cfa4cdc7d5ff7dfe0639058fea3e5d7d5b;hp=a5b55a3f9dc787b67831a7d69e8ec6f429567958;hpb=03c13bd8a8bb89a729d739eb2fcd501a4dfa5439;p=controller.git diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java index a5b55a3f9d..5227f30e3c 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java @@ -10,12 +10,10 @@ package org.opendaylight.controller.sal.binding.test.util; import static com.google.common.base.Preconditions.checkState; import com.google.common.annotations.Beta; -import com.google.common.collect.ClassToInstanceMap; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.MutableClassToInstanceMap; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import java.util.Set; import javassist.ClassPool; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.MountPointService; @@ -45,17 +43,12 @@ import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; import org.opendaylight.controller.sal.binding.impl.RootBindingAwareBroker; -import org.opendaylight.controller.sal.core.api.BrokerService; import org.opendaylight.controller.sal.core.spi.data.DOMStore; -import org.opendaylight.controller.sal.dom.broker.BrokerImpl; -import org.opendaylight.mdsal.binding.dom.codec.gen.impl.DataObjectSerializerGenerator; -import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator; import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry; import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy; import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; -import org.opendaylight.mdsal.binding.generator.util.JavassistUtils; +import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; import org.opendaylight.yangtools.yang.binding.YangModuleInfo; -import org.opendaylight.yangtools.yang.binding.util.BindingReflections; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @Beta @@ -67,10 +60,7 @@ public class BindingTestContext implements AutoCloseable { private HeliumNotificationProviderServiceAdapter baNotifyImpl; - private BrokerImpl biBrokerImpl; - private final ListeningExecutorService executor; - private final ClassPool classPool; private final boolean startWithSchema; @@ -88,6 +78,7 @@ public class BindingTestContext implements AutoCloseable { private BindingDOMRpcProviderServiceAdapter baProviderRpc; private DOMRpcRouter domRouter; + private org.opendaylight.mdsal.dom.broker.DOMRpcRouter delegateDomRouter; private NotificationPublishService publishService; @@ -97,7 +88,7 @@ public class BindingTestContext implements AutoCloseable { private DOMNotificationService domListenService; - + private Set schemaModuleInfos; public DOMDataBroker getDomAsyncDataBroker() { return this.newDOMDataBroker; @@ -107,13 +98,18 @@ public class BindingTestContext implements AutoCloseable { return this.codec; } - protected BindingTestContext(final ListeningExecutorService executor, final ClassPool classPool, - final boolean startWithSchema) { + + protected BindingTestContext(final ListeningExecutorService executor, final boolean startWithSchema) { this.executor = executor; - this.classPool = classPool; this.startWithSchema = startWithSchema; } + @Deprecated + protected BindingTestContext(final ListeningExecutorService executor, final ClassPool classPool, + final boolean startWithSchema) { + this(executor, startWithSchema); + } + public void startDomDataBroker() { } @@ -165,21 +161,17 @@ public class BindingTestContext implements AutoCloseable { } public void startBindingToDomMappingService() { - checkState(this.classPool != null, "ClassPool needs to be present"); - - final DataObjectSerializerGenerator generator = StreamWriterGenerator.create( - JavassistUtils.forClassPool(this.classPool)); - final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(generator); + final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(); final GeneratedClassLoadingStrategy loading = GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(); this.codec = new BindingToNormalizedNodeCodec(loading, codecRegistry); this.mockSchemaService.registerSchemaContextListener(this.codec); } - private void updateYangSchema(final ImmutableSet moduleInfos) { + private void updateYangSchema(final Set moduleInfos) { this.mockSchemaService.changeSchema(getContext(moduleInfos)); } - private SchemaContext getContext(final ImmutableSet moduleInfos) { + private static SchemaContext getContext(final Set moduleInfos) { final ModuleInfoBackedContext ctx = ModuleInfoBackedContext.create(); ctx.addModuleInfos(moduleInfos); return ctx.tryToCreateSchemaContext().get(); @@ -196,7 +188,10 @@ public class BindingTestContext implements AutoCloseable { startBindingBroker(); startForwarding(); - if (this.startWithSchema) { + + if (schemaModuleInfos != null) { + updateYangSchema(schemaModuleInfos); + } else if (this.startWithSchema) { loadYangSchemaFromClasspath(); } } @@ -208,14 +203,8 @@ public class BindingTestContext implements AutoCloseable { private void startDomBroker() { checkState(this.executor != null); - this.domRouter = new DOMRpcRouter(); - this.mockSchemaService.registerSchemaContextListener(this.domRouter); - - final ClassToInstanceMap services = MutableClassToInstanceMap.create(); - services.put(DOMRpcService.class, this.domRouter); - - this.biBrokerImpl = new BrokerImpl(this.domRouter,services); - + delegateDomRouter = org.opendaylight.mdsal.dom.broker.DOMRpcRouter.newInstance(mockSchemaService); + this.domRouter = new DOMRpcRouter(delegateDomRouter.getRpcService(), delegateDomRouter.getRpcProviderService()); } public void startBindingNotificationBroker() { @@ -230,8 +219,7 @@ public class BindingTestContext implements AutoCloseable { } public void loadYangSchemaFromClasspath() { - final ImmutableSet moduleInfos = BindingReflections.loadModuleInfos(); - updateYangSchema(moduleInfos); + updateYangSchema(BindingReflections.loadModuleInfos()); } public RpcProviderRegistry getBindingRpcRegistry() { @@ -246,8 +234,12 @@ public class BindingTestContext implements AutoCloseable { return this.domRouter; } + public org.opendaylight.mdsal.dom.broker.DOMRpcRouter getDelegateDomRouter() { + return delegateDomRouter; + } + @Override - public void close() throws Exception { + public void close() { } @@ -262,4 +254,8 @@ public class BindingTestContext implements AutoCloseable { public DataBroker getDataBroker() { return this.dataBroker; } + + public void setSchemaModuleInfos(Set moduleInfos) { + this.schemaModuleInfos = moduleInfos; + } }