X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-test%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Ftest%2Fimpl%2FNetconfTestImplModuleTest.java;h=441de1f9f23c5b73f6fe924cbdcfc97e907b2cb6;hp=41ceab0e55dee4da29a004d73f92eaa53354af9e;hb=ff8954525069beb80cb644e8694a1aef375d6737;hpb=54bed4dd6dfbada9a8e2ddf70ca84952aec3f55a diff --git a/opendaylight/config/yang-test/src/test/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleTest.java b/opendaylight/config/yang-test/src/test/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleTest.java index 41ceab0e55..441de1f9f2 100644 --- a/opendaylight/config/yang-test/src/test/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleTest.java +++ b/opendaylight/config/yang-test/src/test/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleTest.java @@ -1,25 +1,37 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.config.yang.test.impl; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + import com.google.common.collect.Lists; -import junit.framework.Assert; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import javax.management.InstanceAlreadyExistsException; +import javax.management.ObjectName; import org.junit.Before; import org.junit.Test; +import org.opendaylight.controller.config.api.IdentityAttributeRef; import org.opendaylight.controller.config.api.jmx.CommitStatus; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; - -import javax.management.InstanceAlreadyExistsException; -import javax.management.ObjectName; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity2; +import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry; +import org.opendaylight.yangtools.yang.data.impl.codec.IdentityCodec; public class NetconfTestImplModuleTest extends AbstractConfigTest { @@ -31,8 +43,32 @@ public class NetconfTestImplModuleTest extends AbstractConfigTest { public void setUp() { factory = new NetconfTestImplModuleFactory(); - super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(factory, - new DepTestImplModuleFactory())); + super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,factory, + new DepTestImplModuleFactory(), new IdentityTestModuleFactory())); + } + + @Override + protected CodecRegistry getCodecRegistry() { + final IdentityCodec codec = mock(IdentityCodec.class); + doReturn(TestIdentity1.class).when(codec).deserialize(TestIdentity1.QNAME); + doReturn(TestIdentity2.class).when(codec).deserialize(TestIdentity2.QNAME); + + final CodecRegistry ret = super.getCodecRegistry(); + doReturn(codec).when(ret).getIdentityCodec(); + return ret; + } + + @Test + public void testIdentities() throws Exception { + ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + + ObjectName nameCreated = transaction.createModule(IdentityTestModuleFactory.NAME, instanceName); + IdentityTestModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, IdentityTestModuleMXBean.class); + + final IdentitiesContainer c = new IdentitiesContainer(); + c.setAfi(new IdentityAttributeRef(TestIdentity2.QNAME.toString())); + mxBean.setIdentitiesContainer(c); + transaction.commit(); } @Test @@ -55,7 +91,7 @@ public class NetconfTestImplModuleTest extends AbstractConfigTest { List testingDeps = proxy.getTestingDeps(); ObjectName testingDep = proxy.getTestingDep(); - Assert.assertEquals(TESTING_DEP_PREFIX, ObjectNameUtil.getInstanceName(testingDep)); + assertEquals(TESTING_DEP_PREFIX, ObjectNameUtil.getInstanceName(testingDep)); assertTestingDeps(testingDeps, 4); transaction.abortConfig(); @@ -94,11 +130,11 @@ public class NetconfTestImplModuleTest extends AbstractConfigTest { } private void assertTestingDeps(List testingDeps, int i) { - Assert.assertEquals(i, testingDeps.size()); + assertEquals(i, testingDeps.size()); int c = 1; for (ObjectName testingDep : testingDeps) { - Assert.assertEquals(TESTING_DEP_PREFIX + Integer.toString(c++), ObjectNameUtil.getInstanceName(testingDep)); + assertEquals(TESTING_DEP_PREFIX + Integer.toString(c++), ObjectNameUtil.getInstanceName(testingDep)); } }