### Question:
Migrator { public void migratePersistedModel() { RedisWrapper wrapper = new RedisWrapper(host, port, database); RedisDao dao = RedisDaoFactory.getInstance(); for (String id : wrapper.getAllSubscriptionIds()) { String address = wrapper.getHypervisorUrl(id); String type = wrapper.getHypervisorType(id); String username = wrapper.getUser(id); String password = wrapper.getPassword(id); String virtualMachineName = wrapper.getVirtualSystemId(id); PhysicalMachine machine = insertMachine(dao, address, type, username, password); if (machine != null) { VirtualMachine virtualMachine = dao.findVirtualMachineByName(virtualMachineName); if (virtualMachine == null) { virtualMachine = new VirtualMachine(); virtualMachine.setName(virtualMachineName); virtualMachine.setPhysicalMachine(machine); dao.save(virtualMachine); this.subscriptionsCount++; logger.info("Subscription migrated: {}", virtualMachineName); } wrapper.deleteSubscription(id); } } } Migrator(String host, int port, int database); void migratePersistedModel(); void migrateNonPersistedModelFromFile(final File file); void migrateNonPersistedModelFromRedis(); int getMachinesCount(); int getSubscriptionsCount(); static void main(String[] args); final static String MachineListKey; }### Answer:
@Test(enabled = false) public void test_persitedMigration() { String es = "http: String uuid0 = randomUUID(); String uuid1 = randomUUID(); String uuid2 = randomUUID(); String uuid3 = randomUUID(); RedisWrapper wrapper = new RedisWrapper(TEST_HOST, TEST_PORT, TEST_DATABASE); wrapper.insertSubscription(uuid0, es, "http: "password0"); wrapper.insertSubscription(uuid1, es, "http: "password1"); wrapper.insertSubscription(uuid2, es, "http: "password1"); wrapper.insertSubscription(uuid3, es, "http: "password1"); new Migrator(TEST_HOST, TEST_PORT, TEST_DATABASE).migratePersistedModel(); assertTrue(wrapper.getAllSubscriptionIds().isEmpty()); RedisTestDaoFactory.selectDatabase(TEST_HOST, TEST_PORT, TEST_DATABASE); assertEquals(dao.findAllPhysicalMachines().size(), 2); assertEquals(dao.findAllVirtualMachines().size(), 4); PhysicalMachine machine79 = dao.findPhysicalMachineByAddress("http: PhysicalMachine machine80 = dao.findPhysicalMachineByAddress("http: assertNotNull(machine79); assertNotNull(machine80); assertEquals(machine79.getAddress(), "http: assertEquals(machine79.getType(), "KVM"); assertEquals(machine79.getUsername(), "user0"); assertEquals(machine79.getPassword(), "password0"); assertEquals(machine80.getAddress(), "http: assertEquals(machine80.getType(), "VMX_04"); assertEquals(machine80.getUsername(), "user1"); assertEquals(machine80.getPassword(), "password1"); VirtualMachine vmachine0 = dao.findVirtualMachineByName(uuid0); VirtualMachine vmachine1 = dao.findVirtualMachineByName(uuid1); VirtualMachine vmachine2 = dao.findVirtualMachineByName(uuid2); VirtualMachine vmachine3 = dao.findVirtualMachineByName(uuid3); assertNotNull(vmachine0); assertNotNull(vmachine1); assertNotNull(vmachine2); assertNotNull(vmachine3); assertEquals(vmachine0.getName(), uuid0); assertEquals(vmachine0.getPhysicalMachine().getId(), machine79.getId()); assertNull(vmachine0.getLastKnownState()); assertEquals(vmachine1.getName(), uuid1); assertEquals(vmachine1.getPhysicalMachine().getId(), machine80.getId()); assertNull(vmachine1.getLastKnownState()); assertEquals(vmachine2.getName(), uuid2); assertEquals(vmachine2.getPhysicalMachine().getId(), machine80.getId()); assertNull(vmachine2.getLastKnownState()); assertEquals(vmachine3.getName(), uuid3); assertEquals(vmachine3.getPhysicalMachine().getId(), machine80.getId()); assertNull(vmachine3.getLastKnownState()); }