package org.opendaylight.controller.sal.binding.test; import static org.junit.Assert.*; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import javassist.ClassPool; import org.junit.Before; import org.junit.Test; import static org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper.*; import org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator; import org.opendaylight.controller.sal.binding.test.mock.FooService; import org.opendaylight.controller.sal.binding.test.mock.ReferencableObject; import org.opendaylight.controller.sal.binding.test.mock.ReferencableObjectKey; import org.opendaylight.controller.sal.binding.test.mock.SimpleInput; import org.opendaylight.yangtools.yang.binding.Augmentation; import org.opendaylight.yangtools.yang.binding.BaseIdentity; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; import static org.mockito.Mockito.*; public class RuntimeCodeGeneratorTest { private RuntimeCodeGenerator codeGenerator; @Before public void initialize() { this.codeGenerator = new RuntimeCodeGenerator(ClassPool.getDefault()); } @Test public void testGenerateDirectProxy() { Class product = codeGenerator.generateDirectProxy(FooService.class); assertNotNull(product); } @Test public void testGenerateRouter() throws Exception { Class product = codeGenerator.generateRouter(FooService.class); assertNotNull(product); assertNotNull(product.getSimpleName()); assertEquals("2 fields should be generated.",2,product.getFields().length); verifyRouting(product.newInstance()); } private void verifyRouting(FooService product) { Map routingTable = new HashMap<>(); setRoutingTable(product, BaseIdentity.class, routingTable); assertSame("Returned routing table should be same instance",routingTable,getRoutingTable(product, BaseIdentity.class)); int servicesCount = 2; int instancesPerService = 3; InstanceIdentifier[][] identifiers = identifiers(servicesCount,instancesPerService); FooService service[] = new FooService[] { mock(FooService.class, "Instance 0"), mock(FooService.class,"Instance 1") }; for(int i = 0;i pathArg = new IdentifiableItem<>(ReferencableObject.class,key); return new InstanceIdentifier(Arrays.asList(pathArg), ReferencableObject.class); } private static class SimpleInputImpl implements SimpleInput { private final InstanceIdentifier identifier; public SimpleInputImpl(InstanceIdentifier _identifier) { this.identifier = _identifier; } @Override public > E getAugmentation(Class augmentationType) { return null; } @Override public InstanceIdentifier getIdentifier() { return this.identifier; } } }