+/*
+ * 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 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.sal.binding.generator.util.BindingRuntimeContext;
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 BindingRuntimeContext getBindingRuntimeContext() {
+ final BindingRuntimeContext ret = super.getBindingRuntimeContext();
+ doReturn(TestIdentity1.class).when(ret).getIdentityClass(TestIdentity1.QNAME);
+ doReturn(TestIdentity2.class).when(ret).getIdentityClass(TestIdentity2.QNAME);
+ 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
List<ObjectName> 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();
}
private void assertTestingDeps(List<ObjectName> 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));
}
}