Best Easymock code snippet using org.easymock.EasyMock.anyShort
Source:DeviceManagerImplTest.java
...84 IOFSwitch mockSwitch = createMock(IOFSwitch.class);85 expect(mockSwitch.getId()).andReturn(id).anyTimes();86 expect(mockSwitch.getStringId()).87 andReturn(HexString.toHexString(id, 6)).anyTimes();88 expect(mockSwitch.getPort(anyShort())).89 andReturn(new OFPhysicalPort()).anyTimes();90 expect(mockSwitch.portEnabled(isA(OFPhysicalPort.class))).91 andReturn(true).anyTimes();92 return mockSwitch;93 }94 @Before95 public void setUp() throws Exception {96 super.setUp();97 FloodlightModuleContext fmc = new FloodlightModuleContext();98 RestApiServer restApi = new RestApiServer();99 MockThreadPoolService tp = new MockThreadPoolService();100 ITopologyService topology = createMock(ITopologyService.class);101 fmc.addService(IThreadPoolService.class, tp);102 mockFloodlightProvider = getMockFloodlightProvider();103 deviceManager = new DeviceManagerImpl();104 flowReconcileMgr = new FlowReconcileManager();105 DefaultEntityClassifier entityClassifier = new DefaultEntityClassifier();106 fmc.addService(IDeviceService.class, deviceManager);107 storageSource = new MemoryStorageSource();108 fmc.addService(IStorageSourceService.class, storageSource);109 fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);110 fmc.addService(IRestApiService.class, restApi);111 fmc.addService(IFlowReconcileService.class, flowReconcileMgr);112 fmc.addService(IEntityClassifierService.class, entityClassifier);113 fmc.addService(ITopologyService.class, topology);114 tp.init(fmc);115 restApi.init(fmc);116 storageSource.init(fmc);117 deviceManager.init(fmc);118 flowReconcileMgr.init(fmc);119 entityClassifier.init(fmc);120 storageSource.startUp(fmc);121 deviceManager.startUp(fmc);122 flowReconcileMgr.startUp(fmc);123 tp.startUp(fmc);124 entityClassifier.startUp(fmc);125 reset(topology);126 topology.addListener(deviceManager);127 expectLastCall().anyTimes();128 replay(topology);129 IOFSwitch mockSwitch1 = makeSwitchMock(1L);130 IOFSwitch mockSwitch10 = makeSwitchMock(10L);131 IOFSwitch mockSwitch5 = makeSwitchMock(5L);132 IOFSwitch mockSwitch50 = makeSwitchMock(50L);133 Map<Long, IOFSwitch> switches = new HashMap<Long,IOFSwitch>();134 switches.put(1L, mockSwitch1);135 switches.put(10L, mockSwitch10);136 switches.put(5L, mockSwitch5);137 switches.put(50L, mockSwitch50);138 mockFloodlightProvider.setSwitches(switches);139 replay(mockSwitch1, mockSwitch5, mockSwitch10, mockSwitch50);140 // Build our test packet141 this.testARPReplyPacket_1 = new Ethernet()142 .setSourceMACAddress("00:44:33:22:11:01")143 .setDestinationMACAddress("00:11:22:33:44:55")144 .setEtherType(Ethernet.TYPE_ARP)145 .setVlanID((short)5)146 .setPayload(147 new ARP()148 .setHardwareType(ARP.HW_TYPE_ETHERNET)149 .setProtocolType(ARP.PROTO_TYPE_IP)150 .setHardwareAddressLength((byte) 6)151 .setProtocolAddressLength((byte) 4)152 .setOpCode(ARP.OP_REPLY)153 .setSenderHardwareAddress(Ethernet.toMACAddress("00:44:33:22:11:01"))154 .setSenderProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.1"))155 .setTargetHardwareAddress(Ethernet.toMACAddress("00:11:22:33:44:55"))156 .setTargetProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.2")));157 this.testARPReplyPacket_1_Srld = testARPReplyPacket_1.serialize();158 // Another test packet with a different source IP159 this.testARPReplyPacket_2 = new Ethernet()160 .setSourceMACAddress("00:44:33:22:11:01")161 .setDestinationMACAddress("00:11:22:33:44:55")162 .setEtherType(Ethernet.TYPE_ARP)163 .setPayload(164 new ARP()165 .setHardwareType(ARP.HW_TYPE_ETHERNET)166 .setProtocolType(ARP.PROTO_TYPE_IP)167 .setHardwareAddressLength((byte) 6)168 .setProtocolAddressLength((byte) 4)169 .setOpCode(ARP.OP_REPLY)170 .setSenderHardwareAddress(Ethernet.toMACAddress("00:44:33:22:11:01"))171 .setSenderProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.1"))172 .setTargetHardwareAddress(Ethernet.toMACAddress("00:11:22:33:44:55"))173 .setTargetProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.2")));174 this.testARPReplyPacket_2_Srld = testARPReplyPacket_2.serialize();175 this.testARPReplyPacket_3 = new Ethernet()176 .setSourceMACAddress("00:44:33:22:11:01")177 .setDestinationMACAddress("00:11:22:33:44:55")178 .setEtherType(Ethernet.TYPE_ARP)179 .setPayload(180 new ARP()181 .setHardwareType(ARP.HW_TYPE_ETHERNET)182 .setProtocolType(ARP.PROTO_TYPE_IP)183 .setHardwareAddressLength((byte) 6)184 .setProtocolAddressLength((byte) 4)185 .setOpCode(ARP.OP_REPLY)186 .setSenderHardwareAddress(Ethernet.toMACAddress("00:44:33:22:11:01"))187 .setSenderProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.3"))188 .setTargetHardwareAddress(Ethernet.toMACAddress("00:11:22:33:44:55"))189 .setTargetProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.2")));190 this.testARPReplyPacket_3_Serialized = testARPReplyPacket_3.serialize();191 192 // Build the PacketIn193 this.packetIn_1 = ((OFPacketIn) mockFloodlightProvider.194 getOFMessageFactory().getMessage(OFType.PACKET_IN))195 .setBufferId(-1)196 .setInPort((short) 1)197 .setPacketData(this.testARPReplyPacket_1_Srld)198 .setReason(OFPacketInReason.NO_MATCH)199 .setTotalLength((short) this.testARPReplyPacket_1_Srld.length);200 // Build the PacketIn201 this.packetIn_2 = ((OFPacketIn) mockFloodlightProvider.202 getOFMessageFactory().getMessage(OFType.PACKET_IN))203 .setBufferId(-1)204 .setInPort((short) 1)205 .setPacketData(this.testARPReplyPacket_2_Srld)206 .setReason(OFPacketInReason.NO_MATCH)207 .setTotalLength((short) this.testARPReplyPacket_2_Srld.length);208 // Build the PacketIn209 this.packetIn_3 = ((OFPacketIn) mockFloodlightProvider.210 getOFMessageFactory().getMessage(OFType.PACKET_IN))211 .setBufferId(-1)212 .setInPort((short) 1)213 .setPacketData(this.testARPReplyPacket_3_Serialized)214 .setReason(OFPacketInReason.NO_MATCH)215 .setTotalLength((short) this.testARPReplyPacket_3_Serialized.length);216 }217 218 @Test219 public void testLastSeen() throws Exception {220 Calendar c = Calendar.getInstance();221 Date d1 = c.getTime();222 Entity entity1 = new Entity(1L, null, null, null, null, d1);223 c.add(Calendar.SECOND, 1);224 Entity entity2 = new Entity(1L, null, 1, null, null, c.getTime());225 IDevice d = deviceManager.learnDeviceByEntity(entity2);226 assertEquals(c.getTime(), d.getLastSeen());227 d = deviceManager.learnDeviceByEntity(entity1);228 assertEquals(c.getTime(), d.getLastSeen());229 deviceManager.startUp(null);230 d = deviceManager.learnDeviceByEntity(entity1);231 assertEquals(d1, d.getLastSeen());232 d = deviceManager.learnDeviceByEntity(entity2);233 assertEquals(c.getTime(), d.getLastSeen());234 }235 @Test236 public void testEntityLearning() throws Exception {237 IDeviceListener mockListener =238 createStrictMock(IDeviceListener.class);239 deviceManager.addListener(mockListener);240 deviceManager.entityClassifier= new MockEntityClassifier();241 deviceManager.startUp(null);242 ITopologyService mockTopology = createMock(ITopologyService.class);243 expect(mockTopology.getL2DomainId(anyLong())).244 andReturn(1L).anyTimes();245 expect(mockTopology.isBroadcastDomainPort(anyLong(), anyShort())).246 andReturn(false).anyTimes();247 expect(mockTopology.isAttachmentPointPort(anyLong(),248 anyShort())).andReturn(true).anyTimes();249 expect(mockTopology.isConsistent(10L, (short)1, 10L, (short)1)).250 andReturn(true).anyTimes();251 expect(mockTopology.isConsistent(1L, (short)1, 1L, (short)1)).252 andReturn(true).anyTimes();253 expect(mockTopology.isConsistent(50L, (short)3, 50L, (short)3)).254 andReturn(true).anyTimes();255 Date topologyUpdateTime = new Date();256 expect(mockTopology.getLastUpdateTime()).andReturn(topologyUpdateTime).257 anyTimes();258 deviceManager.topology = mockTopology;259 Entity entity1 = new Entity(1L, null, null, 1L, 1, new Date());260 Entity entity2 = new Entity(1L, null, null, 10L, 1, new Date());261 Entity entity3 = new Entity(1L, null, 1, 10L, 1, new Date());262 Entity entity4 = new Entity(1L, null, 1, 1L, 1, new Date());263 Entity entity5 = new Entity(2L, (short)4, 1, 5L, 2, new Date());264 Entity entity6 = new Entity(2L, (short)4, 1, 50L, 3, new Date());265 Entity entity7 = new Entity(2L, (short)4, 2, 50L, 3, new Date());266 mockListener.deviceAdded(isA(IDevice.class));267 replay(mockListener, mockTopology);268 Device d1 = deviceManager.learnDeviceByEntity(entity1);269 assertSame(d1, deviceManager.learnDeviceByEntity(entity1));270 assertSame(d1, deviceManager.findDeviceByEntity(entity1));271 assertEquals(DefaultEntityClassifier.entityClass ,272 d1.entityClass);273 assertArrayEquals(new Short[] { -1 }, d1.getVlanId());274 assertArrayEquals(new Integer[] { }, d1.getIPv4Addresses());275 assertEquals(1, deviceManager.getAllDevices().size());276 verify(mockListener);277 reset(mockListener);278 mockListener.deviceAdded(isA(IDevice.class));279 replay(mockListener);280 Device d2 = deviceManager.learnDeviceByEntity(entity2);281 assertFalse(d1.equals(d2));282 assertNotSame(d1, d2);283 assertNotSame(d1.getDeviceKey(), d2.getDeviceKey());284 assertEquals(MockEntityClassifier.testEC, d2.entityClass);285 assertArrayEquals(new Short[] { -1 }, d2.getVlanId());286 assertArrayEquals(new Integer[] { }, d2.getIPv4Addresses());287 assertEquals(2, deviceManager.getAllDevices().size());288 verify(mockListener);289 reset(mockListener);290 mockListener.deviceIPV4AddrChanged(isA(IDevice.class));291 replay(mockListener);292 Device d3 = deviceManager.learnDeviceByEntity(entity3);293 assertNotSame(d2, d3);294 assertEquals(d2.getDeviceKey(), d3.getDeviceKey());295 assertEquals(MockEntityClassifier.testEC, d3.entityClass);296 assertArrayEquals(new Integer[] { 1 },297 d3.getIPv4Addresses());298 assertArrayEquals(new SwitchPort[] { new SwitchPort(10L, 1) },299 d3.getAttachmentPoints());300 assertArrayEquals(new SwitchPort[] { new SwitchPort(10L, 1) },301 d3.getAttachmentPoints(true));302 assertArrayEquals(new Short[] { -1 },303 d3.getVlanId());304 assertEquals(2, deviceManager.getAllDevices().size());305 verify(mockListener);306 reset(mockListener);307 mockListener.deviceIPV4AddrChanged(isA(IDevice.class));308 replay(mockListener);309 Device d4 = deviceManager.learnDeviceByEntity(entity4);310 assertNotSame(d1, d4);311 assertEquals(d1.getDeviceKey(), d4.getDeviceKey());312 assertEquals(DefaultEntityClassifier.entityClass, d4.entityClass);313 assertArrayEquals(new Integer[] { 1 },314 d4.getIPv4Addresses());315 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1) },316 d4.getAttachmentPoints());317 assertArrayEquals(new Short[] { -1 },318 d4.getVlanId());319 assertEquals(2, deviceManager.getAllDevices().size());320 verify(mockListener);321 reset(mockListener);322 mockListener.deviceAdded((isA(IDevice.class)));323 replay(mockListener);324 Device d5 = deviceManager.learnDeviceByEntity(entity5);325 assertArrayEquals(new SwitchPort[] { new SwitchPort(5L, 2) },326 d5.getAttachmentPoints());327 assertArrayEquals(new Short[] { (short) 4 },328 d5.getVlanId());329 assertEquals(2L, d5.getMACAddress());330 assertEquals("00:00:00:00:00:02", d5.getMACAddressString());331 verify(mockListener);332 reset(mockListener);333 mockListener.deviceAdded(isA(IDevice.class));334 replay(mockListener);335 Device d6 = deviceManager.learnDeviceByEntity(entity6);336 assertArrayEquals(new SwitchPort[] { new SwitchPort(50L, 3) },337 d6.getAttachmentPoints());338 assertArrayEquals(new Short[] { (short) 4 },339 d6.getVlanId());340 assertEquals(4, deviceManager.getAllDevices().size());341 verify(mockListener);342 reset(mockListener);343 mockListener.deviceIPV4AddrChanged(isA(IDevice.class));344 replay(mockListener);345 Device d7 = deviceManager.learnDeviceByEntity(entity7);346 assertNotSame(d6, d7);347 assertEquals(d6.getDeviceKey(), d7.getDeviceKey());348 assertArrayEquals(new SwitchPort[] { new SwitchPort(50L, 3) },349 d7.getAttachmentPoints());350 assertArrayEquals(new Short[] { (short) 4 },351 d7.getVlanId());352 assertEquals(4, deviceManager.getAllDevices().size());353 verify(mockListener);354 355 356 reset(mockListener);357 replay(mockListener);358 359 reset(deviceManager.topology);360 deviceManager.topology.addListener(deviceManager);361 expectLastCall().times(1);362 replay(deviceManager.topology);363 deviceManager.entityClassifier = new MockEntityClassifierMac();364 deviceManager.startUp(null);365 Entity entityNoClass = new Entity(5L, (short)1, 5, -1L, 1, new Date());366 assertEquals(null, deviceManager.learnDeviceByEntity(entityNoClass));367 368 verify(mockListener);369 }370 371 @Test372 public void testAttachmentPointLearning() throws Exception {373 IDeviceListener mockListener =374 createStrictMock(IDeviceListener.class);375 deviceManager.addListener(mockListener);376 ITopologyService mockTopology = createMock(ITopologyService.class);377 expect(mockTopology.getL2DomainId(1L)).378 andReturn(1L).anyTimes();379 expect(mockTopology.getL2DomainId(5L)).380 andReturn(1L).anyTimes();381 expect(mockTopology.getL2DomainId(10L)).382 andReturn(10L).anyTimes();383 expect(mockTopology.getL2DomainId(50L)).384 andReturn(10L).anyTimes();385 expect(mockTopology.isBroadcastDomainPort(anyLong(), anyShort())).386 andReturn(false).anyTimes();387 expect(mockTopology.isInSameBroadcastDomain(anyLong(), anyShort(),388 anyLong(), anyShort())).andReturn(false).anyTimes();389 expect(mockTopology.isAttachmentPointPort(anyLong(),390 anyShort())).andReturn(true).anyTimes();391 expect(mockTopology.isConsistent(1L, (short)1, 5L, (short)1)).392 andReturn(false).anyTimes();393 expect(mockTopology.isConsistent(5L, (short)1, 10L, (short)1)).394 andReturn(false).anyTimes();395 expect(mockTopology.isConsistent(10L, (short)1, 50L, (short)1)).396 andReturn(false).anyTimes();397 Date topologyUpdateTime = new Date();398 expect(mockTopology.getLastUpdateTime()).andReturn(topologyUpdateTime).399 anyTimes();400 replay(mockTopology);401 deviceManager.topology = mockTopology;402 Calendar c = Calendar.getInstance();403 Entity entity1 = new Entity(1L, null, 1, 1L, 1, c.getTime());404 Entity entity0 = new Entity(1L, null, null, null, null, c.getTime());405 c.add(Calendar.SECOND, 1);406 Entity entity2 = new Entity(1L, null, null, 5L, 1, c.getTime());407 c.add(Calendar.SECOND, 1);408 Entity entity3 = new Entity(1L, null, null, 10L, 1, c.getTime());409 c.add(Calendar.SECOND, 1);410 Entity entity4 = new Entity(1L, null, null, 50L, 1, c.getTime());411 IDevice d;412 SwitchPort[] aps;413 Integer[] ips;414 mockListener.deviceAdded(isA(IDevice.class));415 replay(mockListener);416 deviceManager.learnDeviceByEntity(entity1);417 d = deviceManager.learnDeviceByEntity(entity0);418 assertEquals(1, deviceManager.getAllDevices().size());419 aps = d.getAttachmentPoints();420 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1) }, aps);421 ips = d.getIPv4Addresses();422 assertArrayEquals(new Integer[] { 1 }, ips);423 verify(mockListener);424 reset(mockListener);425 mockListener.deviceMoved((isA(IDevice.class)));426 replay(mockListener);427 d = deviceManager.learnDeviceByEntity(entity2);428 assertEquals(1, deviceManager.getAllDevices().size());429 aps = d.getAttachmentPoints();430 assertArrayEquals(new SwitchPort[] { new SwitchPort(5L, 1) }, aps);431 ips = d.getIPv4Addresses();432 assertArrayEquals(new Integer[] { 1 }, ips);433 verify(mockListener);434 reset(mockListener);435 mockListener.deviceMoved((isA(IDevice.class)));436 replay(mockListener);437 d = deviceManager.learnDeviceByEntity(entity3);438 assertEquals(1, deviceManager.getAllDevices().size());439 aps = d.getAttachmentPoints();440 assertArrayEquals(new SwitchPort[] {new SwitchPort(5L, 1), new SwitchPort(10L, 1)}, aps);441 ips = d.getIPv4Addresses();442 assertArrayEquals(new Integer[] { 1 }, ips);443 verify(mockListener);444 reset(mockListener);445 mockListener.deviceMoved((isA(IDevice.class)));446 replay(mockListener);447 d = deviceManager.learnDeviceByEntity(entity4);448 assertEquals(1, deviceManager.getAllDevices().size());449 aps = d.getAttachmentPoints();450 assertArrayEquals(new SwitchPort[] { new SwitchPort(5L, 1),451 new SwitchPort(50L, 1) }, aps);452 ips = d.getIPv4Addresses();453 assertArrayEquals(new Integer[] { 1 }, ips);454 verify(mockListener);455 }456 @Test457 public void testAttachmentPointSuppression() throws Exception {458 IDeviceListener mockListener =459 createStrictMock(IDeviceListener.class);460 deviceManager.addListener(mockListener);461 ITopologyService mockTopology = createMock(ITopologyService.class);462 expect(mockTopology.getL2DomainId(1L)).463 andReturn(1L).anyTimes();464 expect(mockTopology.getL2DomainId(5L)).465 andReturn(1L).anyTimes();466 expect(mockTopology.getL2DomainId(10L)).467 andReturn(10L).anyTimes();468 expect(mockTopology.getL2DomainId(50L)).469 andReturn(10L).anyTimes();470 expect(mockTopology.isBroadcastDomainPort(anyLong(), anyShort())).471 andReturn(false).anyTimes();472 expect(mockTopology.isInSameBroadcastDomain(anyLong(), anyShort(),473 anyLong(), anyShort())).andReturn(false).anyTimes();474 expect(mockTopology.isAttachmentPointPort(anyLong(),475 anyShort())).andReturn(true).anyTimes();476 expect(mockTopology.isConsistent(5L, (short)1, 50L, (short)1)).477 andReturn(false).anyTimes();478 Date topologyUpdateTime = new Date();479 expect(mockTopology.getLastUpdateTime()).andReturn(topologyUpdateTime).480 anyTimes();481 replay(mockTopology);482 deviceManager.topology = mockTopology;483 // suppress (1L, 1) and (10L, 1)484 deviceManager.addSuppressAPs(1L, (short)1);485 deviceManager.addSuppressAPs(10L, (short)1);486 Calendar c = Calendar.getInstance();487 Entity entity1 = new Entity(1L, null, 1, 1L, 1, c.getTime());488 Entity entity0 = new Entity(1L, null, null, null, null, c.getTime());489 c.add(Calendar.SECOND, 1);490 Entity entity2 = new Entity(1L, null, null, 5L, 1, c.getTime());491 c.add(Calendar.SECOND, 1);492 Entity entity3 = new Entity(1L, null, null, 10L, 1, c.getTime());493 c.add(Calendar.SECOND, 1);494 Entity entity4 = new Entity(1L, null, null, 50L, 1, c.getTime());495 IDevice d;496 SwitchPort[] aps;497 Integer[] ips;498 mockListener.deviceAdded(isA(IDevice.class));499 replay(mockListener);500 deviceManager.learnDeviceByEntity(entity1);501 d = deviceManager.learnDeviceByEntity(entity0);502 assertEquals(1, deviceManager.getAllDevices().size());503 aps = d.getAttachmentPoints();504 assertEquals(aps.length, 0);505 ips = d.getIPv4Addresses();506 assertArrayEquals(new Integer[] { 1 }, ips);507 verify(mockListener);508 reset(mockListener);509 mockListener.deviceMoved((isA(IDevice.class)));510 replay(mockListener);511 d = deviceManager.learnDeviceByEntity(entity2);512 assertEquals(1, deviceManager.getAllDevices().size());513 aps = d.getAttachmentPoints();514 assertArrayEquals(new SwitchPort[] { new SwitchPort(5L, 1) }, aps);515 ips = d.getIPv4Addresses();516 assertArrayEquals(new Integer[] { 1 }, ips);517 verify(mockListener);518 reset(mockListener);519 mockListener.deviceMoved((isA(IDevice.class)));520 replay(mockListener);521 d = deviceManager.learnDeviceByEntity(entity3);522 assertEquals(1, deviceManager.getAllDevices().size());523 aps = d.getAttachmentPoints();524 assertArrayEquals(new SwitchPort[] { new SwitchPort(5L, 1) }, aps);525 ips = d.getIPv4Addresses();526 assertArrayEquals(new Integer[] { 1 }, ips);527 //verify(mockListener); // There is no device movement here; no not needed.528 reset(mockListener);529 mockListener.deviceMoved((isA(IDevice.class)));530 replay(mockListener);531 d = deviceManager.learnDeviceByEntity(entity4);532 assertEquals(1, deviceManager.getAllDevices().size());533 aps = d.getAttachmentPoints();534 assertArrayEquals(new SwitchPort[] { new SwitchPort(5L, 1),535 new SwitchPort(50L, 1) }, aps);536 ips = d.getIPv4Addresses();537 assertArrayEquals(new Integer[] { 1 }, ips);538 verify(mockListener);539 }540 @Test541 public void testBDAttachmentPointLearning() throws Exception {542 ITopologyService mockTopology = createMock(ITopologyService.class);543 expect(mockTopology.getL2DomainId(anyLong())).544 andReturn(1L).anyTimes();545 expect(mockTopology.isAttachmentPointPort(anyLong(), anyShort())).546 andReturn(true).anyTimes();547 expect(mockTopology.isBroadcastDomainPort(1L, (short)1)).548 andReturn(false).anyTimes();549 expect(mockTopology.isBroadcastDomainPort(1L, (short)2)).550 andReturn(true).anyTimes();551 expect(mockTopology.isInSameBroadcastDomain(1L, (short)1,552 1L, (short)2)).andReturn(true).anyTimes();553 expect(mockTopology.isInSameBroadcastDomain(1L, (short)2,554 1L, (short)1)).andReturn(true).anyTimes();555 expect(mockTopology.isConsistent(anyLong(), anyShort(), anyLong(), anyShort())).andReturn(false).anyTimes();556 Date topologyUpdateTime = new Date();557 expect(mockTopology.getLastUpdateTime()).andReturn(topologyUpdateTime).558 anyTimes();559 replay(mockTopology);560 deviceManager.topology = mockTopology;561 Calendar c = Calendar.getInstance();562 Entity entity1 = new Entity(1L, null, 1, 1L, 1, c.getTime());563 c.add(Calendar.MILLISECOND,564 (int)AttachmentPoint.OPENFLOW_TO_EXTERNAL_TIMEOUT/ 2);565 Entity entity2 = new Entity(1L, null, null, 1L, 2, c.getTime());566 c.add(Calendar.MILLISECOND,567 (int)AttachmentPoint.OPENFLOW_TO_EXTERNAL_TIMEOUT / 2 + 1);568 Entity entity3 = new Entity(1L, null, null, 1L, 2, c.getTime());569 IDevice d;570 SwitchPort[] aps;571 d = deviceManager.learnDeviceByEntity(entity1);572 assertEquals(1, deviceManager.getAllDevices().size());573 aps = d.getAttachmentPoints();574 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1) }, aps);575 // this timestamp is too soon; don't switch576 d = deviceManager.learnDeviceByEntity(entity2);577 assertEquals(1, deviceManager.getAllDevices().size());578 aps = d.getAttachmentPoints();579 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1) }, aps);580 // it should switch when we learn with a timestamp after the581 // timeout582 d = deviceManager.learnDeviceByEntity(entity3);583 assertEquals(1, deviceManager.getAllDevices().size());584 aps = d.getAttachmentPoints();585 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 2) }, aps);586 }587 @Test588 public void testPacketIn() throws Exception {589 byte[] dataLayerSource =590 ((Ethernet)this.testARPReplyPacket_1).getSourceMACAddress();591 // Mock up our expected behavior592 ITopologyService mockTopology = createMock(ITopologyService.class);593 deviceManager.topology = mockTopology;594 expect(mockTopology.isAttachmentPointPort(EasyMock.anyLong(),595 EasyMock.anyShort())).596 andReturn(true).anyTimes();597 expect(mockTopology.isConsistent(EasyMock.anyLong(),598 EasyMock.anyShort(),599 EasyMock.anyLong(),600 EasyMock.anyShort())).andReturn(false).601 anyTimes();602 expect(mockTopology.getL2DomainId(EasyMock.anyLong())).andReturn(1L).anyTimes();603 replay(mockTopology);604 Date currentDate = new Date();605 // build our expected Device606 Integer ipaddr = IPv4.toIPv4Address("192.168.1.1");607 Device device =608 new Device(deviceManager,609 new Long(deviceManager.deviceKeyCounter),610 new Entity(Ethernet.toLong(dataLayerSource),611 (short)5,612 ipaddr,613 1L,614 1,615 currentDate),616 DefaultEntityClassifier.entityClass);617 // Get the listener and trigger the packet in618 IOFSwitch switch1 = mockFloodlightProvider.getSwitches().get(1L);619 mockFloodlightProvider.dispatchMessage(switch1, this.packetIn_1);620 // Verify the replay matched our expectations621 // verify(mockTopology);622 // Verify the device623 Device rdevice = (Device)624 deviceManager.findDevice(Ethernet.toLong(dataLayerSource),625 (short)5, null, null, null);626 assertEquals(device, rdevice);627 assertEquals(new Short((short)5), rdevice.getVlanId()[0]);628 Device result = null;629 Iterator<? extends IDevice> dstiter =630 deviceManager.queryClassDevices(device, null, null, ipaddr,631 null, null);632 if (dstiter.hasNext()) {633 result = (Device)dstiter.next();634 }635 assertEquals(device, result);636 device =637 new Device(device,638 new Entity(Ethernet.toLong(dataLayerSource),639 (short)5,640 ipaddr,641 5L,642 2,643 currentDate));644 reset(mockTopology);645 expect(mockTopology.isAttachmentPointPort(anyLong(),646 anyShort())).647 andReturn(true).648 anyTimes();649 expect(mockTopology.isConsistent(EasyMock.anyLong(),650 EasyMock.anyShort(),651 EasyMock.anyLong(),652 EasyMock.anyShort())).andReturn(false).653 anyTimes();654 expect(mockTopology.isBroadcastDomainPort(EasyMock.anyLong(),655 EasyMock.anyShort()))656 .andReturn(false)657 .anyTimes();658 expect(mockTopology.getL2DomainId(1L)).andReturn(1L).anyTimes();659 expect(mockTopology.getL2DomainId(5L)).andReturn(1L).anyTimes();660 expect(mockTopology.isInSameBroadcastDomain(1L, (short)1, 5L, (short)2)).661 andReturn(false).anyTimes();662 // Start recording the replay on the mocks663 replay(mockTopology);664 // Get the listener and trigger the packet in665 IOFSwitch switch5 = mockFloodlightProvider.getSwitches().get(5L);666 mockFloodlightProvider.667 dispatchMessage(switch5, this.packetIn_1.setInPort((short)2));668 // Verify the replay matched our expectations669 verify(mockTopology);670 // Verify the device671 rdevice = (Device)672 deviceManager.findDevice(Ethernet.toLong(dataLayerSource),673 (short)5, null, null, null);674 assertEquals(device, rdevice);675 }676 677 /**678 * Note: Entity expiration does not result in device moved notification.679 * @throws Exception680 */681 public void doTestEntityExpiration() throws Exception {682 IDeviceListener mockListener =683 createStrictMock(IDeviceListener.class);684 mockListener.deviceIPV4AddrChanged(isA(IDevice.class));685 ITopologyService mockTopology = createMock(ITopologyService.class);686 expect(mockTopology.isAttachmentPointPort(anyLong(),687 anyShort())).688 andReturn(true).anyTimes();689 expect(mockTopology.isBroadcastDomainPort(1L, (short)1)).andReturn(false).anyTimes();690 expect(mockTopology.isBroadcastDomainPort(5L, (short)1)).andReturn(false).anyTimes();691 expect(mockTopology.getL2DomainId(1L)).andReturn(1L).anyTimes();692 expect(mockTopology.getL2DomainId(5L)).andReturn(5L).anyTimes();693 expect(mockTopology.isConsistent(1L, (short)1, 5L, (short)1)).694 andReturn(false).anyTimes();695 Date topologyUpdateTime = new Date();696 expect(mockTopology.getLastUpdateTime()).andReturn(topologyUpdateTime).697 anyTimes();698 replay(mockTopology);699 deviceManager.topology = mockTopology;700 Calendar c = Calendar.getInstance();701 Entity entity1 = new Entity(1L, null, 2, 1L, 1, c.getTime());702 c.add(Calendar.MILLISECOND, -DeviceManagerImpl.ENTITY_TIMEOUT-1);703 Entity entity2 = new Entity(1L, null, 1, 5L, 1, c.getTime());704 deviceManager.learnDeviceByEntity(entity1);705 IDevice d = deviceManager.learnDeviceByEntity(entity2);706 assertArrayEquals(new Integer[] { 1, 2 }, d.getIPv4Addresses());707 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),708 new SwitchPort(5L, 1)},709 d.getAttachmentPoints());710 Iterator<? extends IDevice> diter =711 deviceManager.queryClassDevices(d, null, null, 1, null, null);712 assertTrue(diter.hasNext());713 assertEquals(d.getDeviceKey(), diter.next().getDeviceKey());714 diter = deviceManager.queryClassDevices(d, null, null, 2, null, null);715 assertTrue(diter.hasNext());716 assertEquals(d.getDeviceKey(), diter.next().getDeviceKey());717 deviceManager.addListener(mockListener);718 replay(mockListener);719 deviceManager.entityCleanupTask.reschedule(0, null);720 d = deviceManager.getDevice(d.getDeviceKey());721 assertArrayEquals(new Integer[] { 2 }, d.getIPv4Addresses());722 // Attachment points are not removed, previous ones are still valid.723 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),724 new SwitchPort(5L, 1) },725 d.getAttachmentPoints());726 diter = deviceManager.queryClassDevices(d, null, null, 2, null, null);727 assertTrue(diter.hasNext());728 assertEquals(d.getDeviceKey(), diter.next().getDeviceKey());729 diter = deviceManager.queryClassDevices(d, null, null, 1, null, null);730 assertFalse(diter.hasNext());731 d = deviceManager.findDevice(1L, null, null, null, null);732 assertArrayEquals(new Integer[] { 2 }, d.getIPv4Addresses());733 // Attachment points are not removed, previous ones are still valid.734 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),735 new SwitchPort(5L, 1) },736 d.getAttachmentPoints());737 verify(mockListener);738 }739 public void doTestDeviceExpiration() throws Exception {740 IDeviceListener mockListener =741 createStrictMock(IDeviceListener.class);742 mockListener.deviceRemoved(isA(IDevice.class));743 744 Calendar c = Calendar.getInstance();745 c.add(Calendar.MILLISECOND, -DeviceManagerImpl.ENTITY_TIMEOUT-1);746 Entity entity1 = new Entity(1L, null, 1, 1L, 1, c.getTime());747 Entity entity2 = new Entity(1L, null, 2, 5L, 1, c.getTime());748 749 ITopologyService mockTopology = createMock(ITopologyService.class);750 deviceManager.topology = mockTopology;751 expect(mockTopology.isAttachmentPointPort(EasyMock.anyLong(),752 EasyMock.anyShort())).753 andReturn(true).754 anyTimes();755 expect(mockTopology.getL2DomainId(1L)).andReturn(1L).anyTimes();756 expect(mockTopology.getL2DomainId(5L)).andReturn(1L).anyTimes();757 expect(mockTopology.isConsistent(EasyMock.anyLong(),758 EasyMock.anyShort(),759 EasyMock.anyLong(),760 EasyMock.anyShort())).andReturn(false).761 anyTimes();762 expect(mockTopology.isBroadcastDomainPort(EasyMock.anyLong(),763 EasyMock.anyShort())).764 andReturn(false).anyTimes();765 replay(mockTopology);766 IDevice d = deviceManager.learnDeviceByEntity(entity2);767 d = deviceManager.learnDeviceByEntity(entity1);768 assertArrayEquals(new Integer[] { 1, 2 }, d.getIPv4Addresses());769 deviceManager.addListener(mockListener);770 replay(mockListener);771 deviceManager.entityCleanupTask.reschedule(0, null);772 IDevice r = deviceManager.getDevice(d.getDeviceKey());773 assertNull(r);774 Iterator<? extends IDevice> diter =775 deviceManager.queryClassDevices(d, null, null, 1, null, null);776 assertFalse(diter.hasNext());777 r = deviceManager.findDevice(1L, null, null, null, null);778 assertNull(r);779 780 verify(mockListener);781 }782 783 /*784 * A ConcurrentHashMap for devices (deviceMap) that can be used to test 785 * code that specially handles concurrent modification situations. In786 * particular, we overwrite values() and will replace / remove all the787 * elements returned by values. 788 * 789 * The remove flag in the constructor specifies if devices returned by 790 * values() should be removed or replaced.791 */792 protected static class ConcurrentlyModifiedDeviceMap793 extends ConcurrentHashMap<Long, Device> {794 private static final long serialVersionUID = 7784938535441180562L;795 protected boolean remove;796 public ConcurrentlyModifiedDeviceMap(boolean remove) {797 super();798 this.remove = remove;799 }800 801 @Override802 public Collection<Device> values() {803 // Get the values from the real map and copy them since804 // the collection returned by values can reflect changed805 Collection<Device> devs = new ArrayList<Device>(super.values());806 for (Device d: devs) {807 if (remove) {808 // We remove the device from the underlying map 809 super.remove(d.getDeviceKey());810 } else {811 super.remove(d.getDeviceKey());812 // We add a different Device instance with the same813 // key to the map. We'll do some hackery so the device814 // is different enough to compare differently in equals 815 // but otherwise looks the same.816 // It's ugly but it works. 817 Entity[] curEntities = new Entity[d.getEntities().length];818 int i = 0;819 // clone entities820 for (Entity e: d.getEntities()) {821 curEntities[i] = new Entity (e.macAddress,822 e.vlan,823 e.ipv4Address,824 e.switchDPID,825 e.switchPort,826 e.lastSeenTimestamp);827 if (e.vlan == null) 828 curEntities[i].vlan = (short)1;829 else 830 curEntities[i].vlan = (short)((e.vlan + 1 % 4095)+1);831 i++;832 }833 Device newDevice = new Device(d, curEntities[0]);834 newDevice.entities = curEntities;835 assertEquals(false, newDevice.equals(d));836 super.put(newDevice.getDeviceKey(), newDevice);837 }838 }839 return devs; 840 }841 }842 843 @Test844 public void testEntityExpiration() throws Exception {845 doTestEntityExpiration();846 }847 848 @Test849 public void testDeviceExpiration() throws Exception {850 doTestDeviceExpiration();851 }852 853 /* Test correct entity cleanup behavior when a concurrent modification854 * occurs. 855 */856 @Test857 public void testEntityExpirationConcurrentModification() throws Exception {858 deviceManager.deviceMap = new ConcurrentlyModifiedDeviceMap(false);859 doTestEntityExpiration();860 }861 862 /* Test correct entity cleanup behavior when a concurrent remove863 * occurs. 864 */865 @Test866 public void testDeviceExpirationConcurrentRemove() throws Exception {867 deviceManager.deviceMap = new ConcurrentlyModifiedDeviceMap(true);868 doTestDeviceExpiration();869 }870 871 /* Test correct entity cleanup behavior when a concurrent modification872 * occurs. 873 */874 @Test875 public void testDeviceExpirationConcurrentModification() throws Exception {876 deviceManager.deviceMap = new ConcurrentlyModifiedDeviceMap(false);877 doTestDeviceExpiration();878 }879 880 @Test881 public void testAttachmentPointFlapping() throws Exception {882 Calendar c = Calendar.getInstance();883 ITopologyService mockTopology = createMock(ITopologyService.class);884 expect(mockTopology.isAttachmentPointPort(anyLong(),885 anyShort())).andReturn(true).anyTimes();886 expect(mockTopology.isBroadcastDomainPort(anyLong(),887 anyShort())).888 andReturn(false).anyTimes();889 expect(mockTopology.isInSameBroadcastDomain(anyLong(), anyShort(),890 anyLong(), anyShort())).andReturn(false).anyTimes();891 expect(mockTopology.getL2DomainId(anyLong())).892 andReturn(1L).anyTimes();893 expect(mockTopology.isConsistent(1L, (short)1, 1L, (short)1)).894 andReturn(true).anyTimes();895 expect(mockTopology.isConsistent(1L, (short)1, 5L, (short)1)).896 andReturn(false).anyTimes();897 expect(mockTopology.isConsistent(1L, (short)1, 10L, (short)1)).898 andReturn(false).anyTimes();899 expect(mockTopology.isConsistent(5L, (short)1, 10L, (short)1)).900 andReturn(false).anyTimes();901 expect(mockTopology.isConsistent(10L, (short)1, 1L, (short)1)).902 andReturn(false).anyTimes();903 expect(mockTopology.isConsistent(5L, (short)1, 1L, (short)1)).904 andReturn(false).anyTimes();905 expect(mockTopology.isConsistent(10L, (short)1, 5L, (short)1)).906 andReturn(false).anyTimes();907 Date topologyUpdateTime = new Date();908 expect(mockTopology.getLastUpdateTime()).andReturn(topologyUpdateTime).909 anyTimes();910 replay(mockTopology);911 deviceManager.topology = mockTopology;912 Entity entity1 = new Entity(1L, null, null, 1L, 1, c.getTime());913 Entity entity1a = new Entity(1L, null, 1, 1L, 1, c.getTime());914 Entity entity2 = new Entity(1L, null, null, 5L, 1, c.getTime());915 Entity entity3 = new Entity(1L, null, null, 10L, 1, c.getTime());916 entity1.setLastSeenTimestamp(c.getTime());917 c.add(Calendar.MILLISECOND, Entity.ACTIVITY_TIMEOUT/2);918 entity1a.setLastSeenTimestamp(c.getTime());919 c.add(Calendar.MILLISECOND, 1);920 entity2.setLastSeenTimestamp(c.getTime());921 c.add(Calendar.MILLISECOND, 1);922 entity3.setLastSeenTimestamp(c.getTime());923 IDevice d;924 d = deviceManager.learnDeviceByEntity(entity1);925 d = deviceManager.learnDeviceByEntity(entity1a);926 d = deviceManager.learnDeviceByEntity(entity2);927 d = deviceManager.learnDeviceByEntity(entity3);928 // all entities are active, so entity3 should win929 assertArrayEquals(new SwitchPort[] { new SwitchPort(10L, 1) },930 d.getAttachmentPoints());931 assertArrayEquals(new SwitchPort[] { new SwitchPort(10L, 1),},932 d.getAttachmentPoints(true));933 c.add(Calendar.MILLISECOND, Entity.ACTIVITY_TIMEOUT/4);934 entity1.setLastSeenTimestamp(c.getTime());935 d = deviceManager.learnDeviceByEntity(entity1);936 // all are still active; entity3 should still win937 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1) },938 d.getAttachmentPoints());939 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),940 new SwitchPort(5L, 1,941 ErrorStatus.DUPLICATE_DEVICE),942 new SwitchPort(10L, 1,943 ErrorStatus.DUPLICATE_DEVICE) },944 d.getAttachmentPoints(true));945 c.add(Calendar.MILLISECOND, Entity.ACTIVITY_TIMEOUT+2000);946 entity1.setLastSeenTimestamp(c.getTime());947 d = deviceManager.learnDeviceByEntity(entity1);948 assertEquals(entity1.getActiveSince(), entity1.getLastSeenTimestamp());949 // entity1 should now be the only active entity950 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1) },951 d.getAttachmentPoints());952 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1) },953 d.getAttachmentPoints(true));954 }955 @Test956 public void testAttachmentPointFlappingTwoCluster() throws Exception {957 Calendar c = Calendar.getInstance();958 ITopologyService mockTopology = createMock(ITopologyService.class);959 expect(mockTopology.isAttachmentPointPort(anyLong(),960 anyShort())).andReturn(true).anyTimes();961 expect(mockTopology.isBroadcastDomainPort(anyLong(),962 anyShort())).963 andReturn(false).anyTimes();964 expect(mockTopology.isInSameBroadcastDomain(anyLong(), anyShort(),965 anyLong(), anyShort())).andReturn(false).anyTimes();966 expect(mockTopology.getL2DomainId(1L)).967 andReturn(1L).anyTimes();968 expect(mockTopology.getL2DomainId(5L)).969 andReturn(5L).anyTimes();970 expect(mockTopology.isConsistent(1L, (short)1, 1L, (short)2)).971 andReturn(false).anyTimes();972 expect(mockTopology.isConsistent(1L, (short)2, 5L, (short)1)).973 andReturn(false).anyTimes();974 expect(mockTopology.isConsistent(5L, (short)1, 5L, (short)2)).975 andReturn(false).anyTimes();976 expect(mockTopology.isConsistent(1L, (short)2, 1L, (short)1)).977 andReturn(false).anyTimes();978 expect(mockTopology.isConsistent(1L, (short)1, 5L, (short)1)).979 andReturn(false).anyTimes();980 expect(mockTopology.isConsistent(1L, (short)1, 5L, (short)2)).981 andReturn(false).anyTimes();982 expect(mockTopology.isConsistent(5L, (short)2, 5L, (short)1)).983 andReturn(false).anyTimes();984 Date topologyUpdateTime = new Date();985 expect(mockTopology.getLastUpdateTime()).andReturn(topologyUpdateTime).986 anyTimes();987 replay(mockTopology);988 deviceManager.topology = mockTopology;989 Entity entity1 = new Entity(1L, null, null, 1L, 1, c.getTime());990 Entity entity2 = new Entity(1L, null, null, 1L, 2, c.getTime());991 Entity entity3 = new Entity(1L, null, null, 5L, 1, c.getTime());992 Entity entity4 = new Entity(1L, null, null, 5L, 2, c.getTime());993 entity1.setLastSeenTimestamp(c.getTime());994 c.add(Calendar.MILLISECOND, Entity.ACTIVITY_TIMEOUT/2);995 c.add(Calendar.MILLISECOND, 1);996 entity2.setLastSeenTimestamp(c.getTime());997 c.add(Calendar.MILLISECOND, 1);998 entity3.setLastSeenTimestamp(c.getTime());999 c.add(Calendar.MILLISECOND, 1);1000 entity4.setLastSeenTimestamp(c.getTime());1001 deviceManager.learnDeviceByEntity(entity1);1002 deviceManager.learnDeviceByEntity(entity2);1003 deviceManager.learnDeviceByEntity(entity3);1004 IDevice d = deviceManager.learnDeviceByEntity(entity4);1005 // all entities are active, so entities 2,4 should win1006 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 2),1007 new SwitchPort(5L, 2) },1008 d.getAttachmentPoints());1009 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 2),1010 new SwitchPort(5L, 2)},1011 d.getAttachmentPoints(true));1012 c.add(Calendar.MILLISECOND, 1);1013 entity1.setLastSeenTimestamp(c.getTime());1014 d = deviceManager.learnDeviceByEntity(entity1);1015 // all entities are active, so entities 2,4 should win1016 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),1017 new SwitchPort(5L, 2) },1018 d.getAttachmentPoints());1019 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),1020 new SwitchPort(5L, 2),1021 new SwitchPort(1L, 2, ErrorStatus.DUPLICATE_DEVICE)},1022 d.getAttachmentPoints(true));1023 c.add(Calendar.MILLISECOND, Entity.ACTIVITY_TIMEOUT+1);1024 entity1.setLastSeenTimestamp(c.getTime());1025 d = deviceManager.learnDeviceByEntity(entity1);1026 // entities 3,4 are still in conflict, but 1 should be resolved1027 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),1028 new SwitchPort(5L, 2) },1029 d.getAttachmentPoints());1030 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),1031 new SwitchPort(5L, 2)},1032 d.getAttachmentPoints(true));1033 entity3.setLastSeenTimestamp(c.getTime());1034 d = deviceManager.learnDeviceByEntity(entity3);1035 // no conflicts, 1 and 3 will win1036 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),1037 new SwitchPort(5L, 1) },1038 d.getAttachmentPoints());1039 assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),1040 new SwitchPort(5L, 1) },1041 d.getAttachmentPoints(true));1042 }1043 protected void doTestDeviceQuery() throws Exception {1044 Entity entity1 = new Entity(1L, (short)1, 1, 1L, 1, new Date());1045 Entity entity2 = new Entity(2L, (short)2, 2, 1L, 2, new Date());1046 Entity entity3 = new Entity(3L, (short)3, 3, 5L, 1, new Date());1047 Entity entity4 = new Entity(4L, (short)4, 3, 5L, 2, new Date());1048 Entity entity5 = new Entity(1L, (short)4, 3, 5L, 2, new Date());1049 deviceManager.learnDeviceByEntity(entity1);1050 deviceManager.learnDeviceByEntity(entity2);1051 deviceManager.learnDeviceByEntity(entity3);1052 deviceManager.learnDeviceByEntity(entity4);1053 Iterator<? extends IDevice> iter =1054 deviceManager.queryDevices(null, (short)1, 1, null, null);1055 int count = 0;1056 while (iter.hasNext()) {1057 count += 1;1058 iter.next();1059 }1060 assertEquals(1, count);1061 iter = deviceManager.queryDevices(null, (short)3, 3, null, null);1062 count = 0;1063 while (iter.hasNext()) {1064 count += 1;1065 iter.next();1066 }1067 assertEquals(1, count);1068 iter = deviceManager.queryDevices(null, (short)1, 3, null, null);1069 count = 0;1070 while (iter.hasNext()) {1071 count += 1;1072 iter.next();1073 }1074 assertEquals(0, count);1075 deviceManager.learnDeviceByEntity(entity5);1076 iter = deviceManager.queryDevices(null, (short)4, 3, null, null);1077 count = 0;1078 while (iter.hasNext()) {1079 count += 1;1080 iter.next();1081 }1082 assertEquals(2, count);1083 }1084 @Test1085 public void testDeviceIndex() throws Exception {1086 EnumSet<IDeviceService.DeviceField> indexFields =1087 EnumSet.noneOf(IDeviceService.DeviceField.class);1088 indexFields.add(IDeviceService.DeviceField.IPV4);1089 indexFields.add(IDeviceService.DeviceField.VLAN);1090 deviceManager.addIndex(false, indexFields);1091 ITopologyService mockTopology = createMock(ITopologyService.class);1092 deviceManager.topology = mockTopology;1093 expect(mockTopology.isAttachmentPointPort(anyLong(),1094 anyShort())).1095 andReturn(true).anyTimes();1096 expect(mockTopology.getL2DomainId(EasyMock.anyLong())).andReturn(1L).anyTimes();1097 replay(mockTopology);1098 doTestDeviceQuery();1099 }1100 @Test1101 public void testDeviceQuery() throws Exception {1102 ITopologyService mockTopology = createMock(ITopologyService.class);1103 deviceManager.topology = mockTopology;1104 expect(mockTopology.isAttachmentPointPort(anyLong(),1105 anyShort())).1106 andReturn(true).anyTimes();1107 expect(mockTopology.getL2DomainId(EasyMock.anyLong())).andReturn(1L).anyTimes();1108 replay(mockTopology);1109 1110 doTestDeviceQuery();1111 }1112 protected void doTestDeviceClassQuery() throws Exception {1113 Entity entity1 = new Entity(1L, (short)1, 1, 1L, 1, new Date());1114 Entity entity2 = new Entity(2L, (short)2, 2, 1L, 2, new Date());1115 Entity entity3 = new Entity(3L, (short)3, 3, 5L, 1, new Date());1116 Entity entity4 = new Entity(4L, (short)4, 3, 5L, 2, new Date());1117 Entity entity5 = new Entity(1L, (short)4, 3, 5L, 2, new Date());1118 IDevice d = deviceManager.learnDeviceByEntity(entity1);1119 deviceManager.learnDeviceByEntity(entity2);1120 deviceManager.learnDeviceByEntity(entity3);1121 deviceManager.learnDeviceByEntity(entity4);1122 Iterator<? extends IDevice> iter =1123 deviceManager.queryClassDevices(d, null,1124 (short)1, 1, null, null);1125 int count = 0;1126 while (iter.hasNext()) {1127 count += 1;1128 iter.next();1129 }1130 assertEquals(1, count);1131 iter = deviceManager.queryClassDevices(d, null,1132 (short)3, 3, null, null);1133 count = 0;1134 while (iter.hasNext()) {1135 count += 1;1136 iter.next();1137 }1138 assertEquals(1, count);1139 iter = deviceManager.queryClassDevices(d, null,1140 (short)1, 3, null, null);1141 count = 0;1142 while (iter.hasNext()) {1143 count += 1;1144 iter.next();1145 }1146 assertEquals(0, count);1147 deviceManager.learnDeviceByEntity(entity5);1148 iter = deviceManager.queryClassDevices(d, null,1149 (short)4, 3, null, null);1150 count = 0;1151 while (iter.hasNext()) {1152 count += 1;1153 iter.next();1154 }1155 assertEquals(2, count);1156 }1157 @Test1158 public void testDeviceClassIndex() throws Exception {1159 EnumSet<IDeviceService.DeviceField> indexFields =1160 EnumSet.noneOf(IDeviceService.DeviceField.class);1161 indexFields.add(IDeviceService.DeviceField.IPV4);1162 indexFields.add(IDeviceService.DeviceField.VLAN);1163 deviceManager.addIndex(true, indexFields);1164 ITopologyService mockTopology = createMock(ITopologyService.class);1165 deviceManager.topology = mockTopology;1166 expect(mockTopology.isAttachmentPointPort(anyLong(),1167 anyShort())).1168 andReturn(true).anyTimes();1169 expect(mockTopology.getL2DomainId(EasyMock.anyLong())).andReturn(1L).anyTimes();1170 replay(mockTopology);1171 doTestDeviceClassQuery();1172 }1173 @Test1174 public void testDeviceClassQuery() throws Exception {1175 ITopologyService mockTopology = createMock(ITopologyService.class);1176 deviceManager.topology = mockTopology;1177 expect(mockTopology.isAttachmentPointPort(anyLong(),1178 anyShort())).1179 andReturn(true).anyTimes();1180 expect(mockTopology.getL2DomainId(EasyMock.anyLong())).andReturn(1L).anyTimes();1181 replay(mockTopology);1182 doTestDeviceClassQuery();1183 }1184 @Test1185 public void testFindDevice() {1186 boolean exceptionCaught;1187 deviceManager.entityClassifier= new MockEntityClassifierMac();1188 deviceManager.startUp(null);1189 ITopologyService mockTopology = createMock(ITopologyService.class);1190 deviceManager.topology = mockTopology;1191 expect(mockTopology.isAttachmentPointPort(anyLong(),1192 anyShort())).1193 andReturn(true).anyTimes();1194 expect(mockTopology.getL2DomainId(EasyMock.anyLong())).andReturn(1L).anyTimes();1195 replay(mockTopology);1196 Entity entity1 = new Entity(1L, (short)1, 1, 1L, 1, new Date());1197 Entity entity2 = new Entity(2L, (short)2, 2, 1L, 2, new Date());1198 Entity entity2b = new Entity(22L, (short)2, 2, 1L, 2, new Date());1199 1200 Entity entity3 = new Entity(3L, (short)1, 3, 2L, 1, new Date());1201 Entity entity4 = new Entity(4L, (short)2, 4, 2L, 2, new Date());1202 1203 Entity entity5 = new Entity(5L, (short)1, 5, 3L, 1, new Date());1204 1205 IDevice d1 = deviceManager.learnDeviceByEntity(entity1);1206 IDevice d2 = deviceManager.learnDeviceByEntity(entity2);1207 IDevice d3 = deviceManager.learnDeviceByEntity(entity3);1208 IDevice d4 = deviceManager.learnDeviceByEntity(entity4);1209 IDevice d5 = deviceManager.learnDeviceByEntity(entity5);1210 1211 // Make sure the entity classifier worked as expected1212 assertEquals(MockEntityClassifierMac.testECMac1, d1.getEntityClass());1213 assertEquals(MockEntityClassifierMac.testECMac1, d2.getEntityClass());1214 assertEquals(MockEntityClassifierMac.testECMac2, d3.getEntityClass());1215 assertEquals(MockEntityClassifierMac.testECMac2, d4.getEntityClass());1216 assertEquals(DefaultEntityClassifier.entityClass,1217 d5.getEntityClass());1218 1219 // Look up the device using findDevice() which uses only the primary1220 // index1221 assertEquals(d1, deviceManager.findDevice(entity1.getMacAddress(), 1222 entity1.getVlan(),1223 entity1.getIpv4Address(),1224 entity1.getSwitchDPID(),1225 entity1.getSwitchPort()));1226 // port changed. Device will be found through class index1227 assertEquals(d1, deviceManager.findDevice(entity1.getMacAddress(), 1228 entity1.getVlan(),1229 entity1.getIpv4Address(),1230 entity1.getSwitchDPID(),1231 entity1.getSwitchPort()+1));1232 // VLAN changed. No device matches1233 assertEquals(null, deviceManager.findDevice(entity1.getMacAddress(), 1234 (short)42,1235 entity1.getIpv4Address(),1236 entity1.getSwitchDPID(),1237 entity1.getSwitchPort()));1238 assertEquals(null, deviceManager.findDevice(entity1.getMacAddress(), 1239 null,1240 entity1.getIpv4Address(),1241 entity1.getSwitchDPID(),1242 entity1.getSwitchPort()));1243 assertEquals(d2, deviceManager.findDeviceByEntity(entity2));1244 assertEquals(null, deviceManager.findDeviceByEntity(entity2b));1245 assertEquals(d3, deviceManager.findDevice(entity3.getMacAddress(), 1246 entity3.getVlan(),1247 entity3.getIpv4Address(),1248 entity3.getSwitchDPID(),1249 entity3.getSwitchPort()));1250 // switch and port not set. throws exception1251 exceptionCaught = false;1252 try {1253 assertEquals(null, deviceManager.findDevice(entity3.getMacAddress(), 1254 entity3.getVlan(),1255 entity3.getIpv4Address(),1256 null,1257 null));1258 } 1259 catch (IllegalArgumentException e) {1260 exceptionCaught = true;1261 }1262 if (!exceptionCaught)1263 fail("findDevice() did not throw IllegalArgumentException");1264 assertEquals(d4, deviceManager.findDeviceByEntity(entity4));1265 assertEquals(d5, deviceManager.findDevice(entity5.getMacAddress(), 1266 entity5.getVlan(),1267 entity5.getIpv4Address(),1268 entity5.getSwitchDPID(),1269 entity5.getSwitchPort()));1270 // switch and port not set. throws exception (swith/port are key 1271 // fields of IEntityClassifier but not d5.entityClass1272 exceptionCaught = false;1273 try {1274 assertEquals(d5, deviceManager.findDevice(entity5.getMacAddress(), 1275 entity5.getVlan(),1276 entity5.getIpv4Address(),1277 null,1278 null));1279 } 1280 catch (IllegalArgumentException e) {1281 exceptionCaught = true;1282 }1283 if (!exceptionCaught)1284 fail("findDevice() did not throw IllegalArgumentException");1285 1286 1287 Entity entityNoClass = new Entity(5L, (short)1, 5, -1L, 1, new Date());1288 assertEquals(null, deviceManager.findDeviceByEntity(entityNoClass));1289 1290 1291 // Now look up destination devices1292 assertEquals(d1, deviceManager.findDestDevice(d2, 1293 entity1.getMacAddress(), 1294 entity1.getVlan(),1295 entity1.getIpv4Address()));1296 assertEquals(d1, deviceManager.findDestDevice(d2, 1297 entity1.getMacAddress(), 1298 entity1.getVlan(),1299 null));1300 assertEquals(null, deviceManager.findDestDevice(d2, 1301 entity1.getMacAddress(), 1302 (short) -1,1303 0));1304 }1305 1306 @Test1307 public void testGetIPv4Addresses() {1308 // Looks like Date is only 1s granularity1309 1310 ITopologyService mockTopology = createMock(ITopologyService.class);1311 deviceManager.topology = mockTopology;1312 expect(mockTopology.isAttachmentPointPort(anyLong(),1313 anyShort())).1314 andReturn(true).anyTimes();1315 expect(mockTopology.getL2DomainId(anyLong())).andReturn(1L).anyTimes();1316 expect(mockTopology.isConsistent(EasyMock.anyLong(),1317 EasyMock.anyShort(),1318 EasyMock.anyLong(),1319 EasyMock.anyShort()))1320 .andReturn(false)1321 .anyTimes();1322 expect(mockTopology.isBroadcastDomainPort(EasyMock.anyLong(),1323 EasyMock.anyShort()))1324 .andReturn(false)1325 .anyTimes();1326 expect(mockTopology.isInSameBroadcastDomain(EasyMock.anyLong(),1327 EasyMock.anyShort(),1328 EasyMock.anyLong(),1329 EasyMock.anyShort())).1330 andReturn(false).anyTimes();1331 replay(mockTopology);1332 Entity e1 = new Entity(1L, (short)1, null, null, null, new Date(2000));1333 Device d1 = deviceManager.learnDeviceByEntity(e1);1334 assertArrayEquals(new Integer[0], d1.getIPv4Addresses());1335 1336 1337 Entity e2 = new Entity(2L, (short)2, 2, null, null, new Date(2000));1338 Device d2 = deviceManager.learnDeviceByEntity(e2);1339 d2 = deviceManager.learnDeviceByEntity(e2);1340 assertArrayEquals(new Integer[] { 2 }, d2.getIPv4Addresses());1341 // More than one entity1342 Entity e2b = new Entity(2L, (short)2, null, 2L, 2, new Date(3000));1343 d2 = deviceManager.learnDeviceByEntity(e2b);1344 assertEquals(2, d2.entities.length);1345 assertArrayEquals(new Integer[] { 2 }, d2.getIPv4Addresses());1346 // and now add an entity with an IP1347 Entity e2c = new Entity(2L, (short)2, 2, 2L, 3, new Date(3000));1348 d2 = deviceManager.learnDeviceByEntity(e2c);1349 assertArrayEquals(new Integer[] { 2 }, d2.getIPv4Addresses());1350 assertEquals(3, d2.entities.length);1351 1352 // Other devices with different IPs shouldn't interfere1353 Entity e3 = new Entity(3L, (short)3, 3, null, null, new Date(4000));1354 Entity e3b = new Entity(3L, (short)3, 3, 3L, 3, new Date(4400));1355 Device d3 = deviceManager.learnDeviceByEntity(e3);1356 d3 = deviceManager.learnDeviceByEntity(e3b);1357 assertArrayEquals(new Integer[] { 2 }, d2.getIPv4Addresses());1358 assertArrayEquals(new Integer[] { 3 }, d3.getIPv4Addresses());1359 1360 // Add another IP to d31361 Entity e3c = new Entity(3L, (short)3, 33, 3L, 3, new Date(4400));1362 d3 = deviceManager.learnDeviceByEntity(e3c);1363 Integer[] ips = d3.getIPv4Addresses();1364 Arrays.sort(ips);1365 assertArrayEquals(new Integer[] { 3, 33 }, ips);1366 1367 // Add another device that also claims IP2 but is older than e21368 Entity e4 = new Entity(4L, (short)4, 2, null, null, new Date(1000));1369 Entity e4b = new Entity(4L, (short)4, null, 4L, 4, new Date(1000));1370 Device d4 = deviceManager.learnDeviceByEntity(e4);1371 assertArrayEquals(new Integer[] { 2 }, d2.getIPv4Addresses());1372 assertArrayEquals(new Integer[0], d4.getIPv4Addresses());1373 // add another entity to d41374 d4 = deviceManager.learnDeviceByEntity(e4b);1375 assertArrayEquals(new Integer[0], d4.getIPv4Addresses());1376 1377 // Make e4 and e4a newer1378 Entity e4c = new Entity(4L, (short)4, 2, null, null, new Date(5000));1379 Entity e4d = new Entity(4L, (short)4, null, 4L, 5, new Date(5000));1380 d4 = deviceManager.learnDeviceByEntity(e4c);1381 d4 = deviceManager.learnDeviceByEntity(e4d);1382 assertArrayEquals(new Integer[0], d2.getIPv4Addresses());1383 // FIXME: d4 should not return IP41384 assertArrayEquals(new Integer[] { 2 }, d4.getIPv4Addresses());1385 1386 // Add another newer entity to d2 but with different IP1387 Entity e2d = new Entity(2L, (short)2, 22, 4L, 6, new Date(6000));1388 d2 = deviceManager.learnDeviceByEntity(e2d);1389 assertArrayEquals(new Integer[] { 22 }, d2.getIPv4Addresses());1390 assertArrayEquals(new Integer[] { 2 }, d4.getIPv4Addresses());1391 // new IP for d2,d4 but with same timestamp. Both devices get the IP1392 Entity e2e = new Entity(2L, (short)2, 42, 2L, 4, new Date(7000));1393 d2 = deviceManager.learnDeviceByEntity(e2e);1394 ips= d2.getIPv4Addresses();1395 Arrays.sort(ips);1396 assertArrayEquals(new Integer[] { 22, 42 }, ips);1397 Entity e4e = new Entity(4L, (short)4, 42, 4L, 7, new Date(7000));1398 d4 = deviceManager.learnDeviceByEntity(e4e);1399 ips= d4.getIPv4Addresses();1400 Arrays.sort(ips);1401 assertArrayEquals(new Integer[] { 2, 42 }, ips);1402 1403 // add a couple more IPs1404 Entity e2f = new Entity(2L, (short)2, 4242, 2L, 5, new Date(8000));1405 d2 = deviceManager.learnDeviceByEntity(e2f);1406 ips= d2.getIPv4Addresses();1407 Arrays.sort(ips);1408 assertArrayEquals(new Integer[] { 22, 42, 4242 }, ips);1409 Entity e4f = new Entity(4L, (short)4, 4242, 4L, 8, new Date(9000));1410 d4 = deviceManager.learnDeviceByEntity(e4f);1411 ips= d4.getIPv4Addresses();1412 Arrays.sort(ips);1413 assertArrayEquals(new Integer[] { 2, 42, 4242 }, ips);1414 }1415 1416 // TODO: this test should really go into a separate class that collects1417 // unit tests for Device1418 @Test1419 public void testGetSwitchPortVlanId() {1420 Entity entity1 = new Entity(1L, (short)1, null, 10L, 1, new Date());1421 Entity entity2 = new Entity(1L, null, null, 10L, 1, new Date());1422 Entity entity3 = new Entity(1L, (short)3, null, 1L, 1, new Date());1423 Entity entity4 = new Entity(1L, (short)42, null, 1L, 1, new Date());1424 Entity[] entities = new Entity[] { entity1, entity2, 1425 entity3, entity41426 };1427 Device d = new Device(null,1L, null, null, Arrays.asList(entities), null);1428 SwitchPort swp1x1 = new SwitchPort(1L, 1);1429 SwitchPort swp1x2 = new SwitchPort(1L, 2);1430 SwitchPort swp2x1 = new SwitchPort(2L, 1);1431 SwitchPort swp10x1 = new SwitchPort(10L, 1);1432 assertArrayEquals(new Short[] { -1, 1}, 1433 d.getSwitchPortVlanIds(swp10x1));1434 assertArrayEquals(new Short[] { 3, 42}, 1435 d.getSwitchPortVlanIds(swp1x1));1436 assertArrayEquals(new Short[0],1437 d.getSwitchPortVlanIds(swp1x2));1438 assertArrayEquals(new Short[0],1439 d.getSwitchPortVlanIds(swp2x1));1440 }1441 1442 @Test1443 public void testReclassifyDevice() {1444 MockFlexEntityClassifier flexClassifier = 1445 new MockFlexEntityClassifier();1446 deviceManager.entityClassifier= flexClassifier;1447 deviceManager.startUp(null);1448 ITopologyService mockTopology = createMock(ITopologyService.class);1449 deviceManager.topology = mockTopology;1450 expect(mockTopology.isAttachmentPointPort(anyLong(),1451 anyShort())).1452 andReturn(true).anyTimes();1453 expect(mockTopology.getL2DomainId(anyLong())).andReturn(1L).anyTimes();1454 expect(mockTopology.isConsistent(EasyMock.anyLong(),1455 EasyMock.anyShort(),1456 EasyMock.anyLong(),1457 EasyMock.anyShort()))1458 .andReturn(false)1459 .anyTimes();1460 expect(mockTopology.isBroadcastDomainPort(EasyMock.anyLong(),1461 EasyMock.anyShort()))1462 .andReturn(false)1463 .anyTimes();1464 replay(mockTopology);1465 1466 //flexClassifier.createTestEntityClass("Class1");1467 1468 Entity entity1 = new Entity(1L, (short)1, 1, 1L, 1, new Date());1469 Entity entity1b = new Entity(1L, (short)2, 1, 1L, 1, new Date());1470 Entity entity2 = new Entity(2L, (short)1, 2, 2L, 2, new Date());1471 Entity entity2b = new Entity(2L, (short)2, 2, 2L, 2, new Date());1472 1473 1474 Device d1 = deviceManager.learnDeviceByEntity(entity1);1475 Device d2 = deviceManager.learnDeviceByEntity(entity2);...
anyShort
Using AI Code Generation
1import org.easymock.EasyMock;2import org.junit.Test;3public class EasyMockTest {4 public void test() {5 ClassToTest t = EasyMock.createMock(ClassToTest.class);6 EasyMock.expect(t.method1(EasyMock.anyShort())).andReturn(1);7 EasyMock.replay(t);8 t.method1((short) 1);9 EasyMock.verify(t);10 }11}12package org.easymock;13import org.junit.Test;14public class EasyMockTest {15 public void test() {16 ClassToTest t = EasyMock.createMock(ClassToTest.class);17 EasyMock.expect(t.method1(EasyMock.anyShort())).andReturn(1);18 EasyMock.replay(t);19 t.method1((short) 1);20 EasyMock.verify(t);21 }22}23java.lang.AssertionError: Unexpected method call ClassToTest.method1((short)1):24 ClassToTest.method1(anyShort): expected: 1, actual: 025public void testGetAll() {26 List<MockObject> mockList = new ArrayList<MockObject>();27 MockObject mockObject = EasyMock.createMock(MockObject.class);28 mockList.add(mockObject);29 EasyMock.expect(mockObject.getMockField()).andReturn("mock");30 EasyMock.replay(mockObject);31 EasyMock.expect(mockDao.getAll()).andReturn(mockList);32 EasyMock.replay(mockDao);33 List<MockObject> list = service.getAll();34 assertEquals("mock", list.get(0).getMockField());35}36java.lang.AssertionError: Unexpected method call MockDao.getAll():37 MockDao.getAll(): expected: 1, actual: 038I don't understand why EasyMock is expecting 1 call to MockDao.getAll() , when I am only calling it once in the test method. What am I doing wrong?
anyShort
Using AI Code Generation
1import static org.easymock.EasyMock.*;2import org.easymock.EasyMock;3import org.junit.Test;4import static org.junit.Assert.*;5import org.junit.Before;6public class EasyMockDemoTest {7 private EasyMockDemo demo;8 private Dependency dependency;9 public void setUp() {10 dependency = createMock(Dependency.class);11 demo = new EasyMockDemo(dependency);12 }13 public void testDoSomething() {14 dependency.doSomethingElse("something");15 expectLastCall().once();16 replay(dependency);17 demo.doSomething();18 verify(dependency);19 }20}21package com.mkyong.core;22public interface Dependency {23 void doSomethingElse(String arg);24}25package com.mkyong.core;26public class EasyMockDemo {27 private Dependency dependency;28 public EasyMockDemo(Dependency dependency) {29 this.dependency = dependency;30 }31 public void doSomething() {32 dependency.doSomethingElse("something");33 }34}35EasyMock – EasyMock in 5 Minutes (Video)36EasyMock – EasyMock in 5 Minutes (PDF)37EasyMock – EasyMock in 5 Minutes (PPT)38EasyMock – EasyMock in 5 Minutes (Source Code)
anyShort
Using AI Code Generation
1class AnyShort {2 static Short anyShort() {3 EasyMock.reportMatcher(new AnyShortMatcher())4 }5}6class AnyShortMatcher extends IArgumentMatcher {7 public boolean matches(Object o) {
anyShort
Using AI Code Generation
1import static org.easymock.EasyMock.anyShort;2private Foo foo;3public void testFoo() {4 expect(foo.doSomething(anyShort())).andReturn("foo");5 replayAll();6 assertEquals("foo", foo.doSomething((short) 1));7 assertEquals("foo", foo.doSomething((short) 2));8 verifyAll();9}10Example 2: Using anyShort() method of EasyMock class11package com.journaldev.easymock;12import static org.easymock.EasyMock.anyShort;13import static org.easymock.EasyMock.expect;14import static org.easymock.EasyMock.replay;15import static org.easymock.EasyMock.verify;16import static org.junit.Assert.assertEquals;17import org.easymock.EasyMock;18import org.junit.After;19import org.junit.Before;20import org.junit.Test;21public class EasyMockAnyShortTest {22 private Foo foo;23 public void setUp() {24 foo = EasyMock.createMock(Foo.class);25 }26 public void tearDown() {27 foo = null;28 }29 public void testFoo() {30 expect(foo.doSomething(anyShort())).andReturn("foo");31 replay(foo);32 assertEquals("foo", foo.doSomething((short) 1));33 assertEquals("foo", foo.doSomething((short) 2));34 verify(foo);35 }36}37EasyMock anyShort() method38EasyMock anyShort() Method Example39EasyMock anyInt() Method Example40EasyMock anyLong() Method Example41EasyMock anyFloat() Method Example42EasyMock anyDouble() Method Example43EasyMock anyBoolean() Method Example44EasyMock anyObject() Method Example45EasyMock anyString() Method Example46EasyMock any() Method Example47EasyMock anyVararg() Method Example48EasyMock anyCollection() Method Example49EasyMock anyList() Method Example50EasyMock anySet() Method
anyShort
Using AI Code Generation
1Short anyShort = EasyMock.anyShort();2assertNotNull(anyShort);3assertTrue(anyShort instanceof Short);4assertNotEquals(Short.MIN_VALUE, anyShort);5assertNotEquals(Short.MAX_VALUE, anyShort);6assertNotEquals(0, anyShort);7assertNotEquals(1, anyShort);8assertNotEquals(-1, anyShort);9assertNotEquals(2, anyShort);10assertNotEquals(-2, anyShort);11assertNotEquals(3, anyShort);12assertNotEquals(-3, anyShort);13assertNotEquals(4, anyShort);14assertNotEquals(-4, anyShort);15assertNotEquals(5, anyShort);16assertNotEquals(-5, anyShort);17assertNotEquals(6, anyShort);18assertNotEquals(-6, anyShort);19assertNotEquals(7, anyShort);20assertNotEquals(-7, anyShort);21assertNotEquals(8, anyShort);22assertNotEquals(-8, anyShort);23assertNotEquals(9, anyShort);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!