@Test
public void testReclassifyDevice() throws FloodlightModuleException {

	MockFlexEntityClassifier flexClassifier =
			new MockFlexEntityClassifier();
	deviceManager.entityClassifier= flexClassifier;
	deviceManager.startUp(null);
	ITopologyService mockTopology = createMock(ITopologyService.class);
	deviceManager.topology = mockTopology;
	expect(mockTopology.isAttachmentPointPort(DatapathId.of(anyLong()),
			OFPort.of(anyShort()))).
			andReturn(true).anyTimes();
	expect(mockTopology.getOpenflowDomainId(DatapathId.of(anyLong()))).andReturn(DatapathId.of(1L)).anyTimes();
	expect(mockTopology.isConsistent(DatapathId.of(EasyMock.anyLong()),
			OFPort.of(EasyMock.anyShort()),
			DatapathId.of(EasyMock.anyLong()),
			OFPort.of(EasyMock.anyShort())))
			.andReturn(false)
			.anyTimes();
	expect(mockTopology.isBroadcastDomainPort(DatapathId.of(EasyMock.anyLong()),
			OFPort.of(EasyMock.anyShort())))
			.andReturn(false)
			.anyTimes();
	replay(mockTopology);
	//flexClassifier.createTestEntityClass("Class1");
	Entity entity1 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(1), IPv4Address.of(1), IPv6Address.NONE, DatapathId.of(1L), OFPort.of(1), new Date());
	Entity entity1b = new Entity(MacAddress.of(1L), VlanVid.ofVlan(2), IPv4Address.of(1), IPv6Address.NONE, DatapathId.of(1L), OFPort.of(1), new Date());
	Entity entity2 = new Entity(MacAddress.of(2L), VlanVid.ofVlan(1), IPv4Address.of(2), IPv6Address.NONE, DatapathId.of(2L), OFPort.of(2), new Date());
	Entity entity2b = new Entity(MacAddress.of(2L), VlanVid.ofVlan(2), IPv4Address.of(2), IPv6Address.NONE, DatapathId.of(2L), OFPort.of(2), new Date());
	Device d1 = deviceManager.learnDeviceByEntity(entity1);
	Device d2 = deviceManager.learnDeviceByEntity(entity2);
	Device d1b = deviceManager.learnDeviceByEntity(entity1b);
	Device d2b = deviceManager.learnDeviceByEntity(entity2b);
	d1 = deviceManager.getDeviceIteratorForQuery(entity1.getMacAddress(),
			entity1.getVlan(), entity1.getIpv4Address(), entity1.getIpv6Address(),
			entity1.getSwitchDPID(), entity1.getSwitchPort())
			.next();
	d1b = deviceManager.getDeviceIteratorForQuery(entity1b.getMacAddress(),
			entity1b.getVlan(), entity1b.getIpv4Address(), entity1b.getIpv6Address(),
			entity1b.getSwitchDPID(), entity1b.getSwitchPort()).next();
	assertEquals(d1, d1b);
	d2 = deviceManager.getDeviceIteratorForQuery(entity2.getMacAddress(),
			entity2.getVlan(), entity2.getIpv4Address(), entity2.getIpv6Address(),
			entity2.getSwitchDPID(), entity2.getSwitchPort()).next();
	d2b = deviceManager.getDeviceIteratorForQuery(entity2b.getMacAddress(),
			entity2b.getVlan(), entity2b.getIpv4Address(), entity2b.getIpv6Address(),
			entity2b.getSwitchDPID(), entity2b.getSwitchPort()).next();
	assertEquals(d2, d2b);
	IEntityClass eC1 = flexClassifier.createTestEntityClass("C1");
	IEntityClass eC2 = flexClassifier.createTestEntityClass("C2");
	flexClassifier.addVlanEntities((short)1, eC1);
	flexClassifier.addVlanEntities((short)2, eC1);
	deviceManager.reclassifyDevice(d1);
	deviceManager.reclassifyDevice(d2);
	d1 = deviceManager.deviceMap.get(
			deviceManager.primaryIndex.findByEntity(entity1));
	d1b = deviceManager.deviceMap.get(
			deviceManager.primaryIndex.findByEntity(entity1b));
	assertEquals(d1, d1b);
	d2 = deviceManager.deviceMap.get(
			deviceManager.primaryIndex.findByEntity(entity2));
	d2b = deviceManager.deviceMap.get(
			deviceManager.primaryIndex.findByEntity(entity2b));
	assertEquals(d2, d2b);
	flexClassifier.addVlanEntities((short)1, eC2);
	deviceManager.reclassifyDevice(d1);
	deviceManager.reclassifyDevice(d2);
	d1 = deviceManager.deviceMap.get(
			deviceManager.primaryIndex.findByEntity(entity1));
	d1b = deviceManager.deviceMap.get(
			deviceManager.primaryIndex.findByEntity(entity1b));
	d2 = deviceManager.deviceMap.get(
			deviceManager.primaryIndex.findByEntity(entity2));
	d2b = deviceManager.deviceMap.get(
			deviceManager.primaryIndex.findByEntity(entity2b));
	assertNotSame(d1, d1b);
	assertNotSame(d2, d2b);
	flexClassifier.addVlanEntities((short)1, eC1);
	deviceManager.reclassifyDevice(d1);
	deviceManager.reclassifyDevice(d2);
	ClassState classState = deviceManager.classStateMap.get(eC1.getName());
	Long deviceKey1 = null;
	Long deviceKey1b = null;
	Long deviceKey2 = null;
	Long deviceKey2b = null;
	deviceKey1 =
			classState.classIndex.findByEntity(entity1);
	deviceKey1b =
			classState.classIndex.findByEntity(entity1b);
	deviceKey2 =
			classState.classIndex.findByEntity(entity2);
	deviceKey2b =
			classState.classIndex.findByEntity(entity2b);
	assertEquals(deviceKey1, deviceKey1b);
	assertEquals(deviceKey2, deviceKey2b);
}