DeviceDaoImpl extends AbstractDao<Device, DevicePK> implements DeviceDao { @Override public Device getDeviceByName(String deviceName) { EntityDataStoreManager entityDataStoreManager = getPersistenceManager(); Map<String, Object> matchedValues = new HashMap<String, Object>(); matchedValues.put(JPAEntityDataStoreManager.buildQueryPath(DEVICE_NAME), deviceName); List<Device> devices = entityDataStoreManager.findByMatchValue(Device.class, matchedValues); if (devices != null && !devices.isEmpty()) { return devices.get(0); } return null; } DeviceDaoImpl(PersistenceManagerUtil persistenceManagerUtil); @Override List<Device> findAllDevices(); @Override Device getDeviceByName(String deviceName); @Override Device findDeviceWithDuid(String duid); @Override DeviceState getDeviceState(String deviceName); @Override void updateDeviceAlignmentState(String deviceName, String verdict); static final String DEVICE_NAME; }
@Test public void createTwoDeviceAndAssert() throws Exception { beginTx(); createTwoDevices(); List<Device> deviceList = m_deviceDao.findAll(); assertEquals(2, deviceList.size()); assertEquals(DEVICE_A, m_deviceDao.getDeviceByName(DEVICE_A).getDeviceName()); assertEquals(DEVICE_B, m_deviceDao.getDeviceByName(DEVICE_B).getDeviceName()); assertNull(m_deviceDao.getDeviceByName(DEVICE_C)); m_deviceDao.deleteAll(); closeTx(); }
@Test public void deleteOneDeviceAndAssert() throws Exception { beginTx(); createTwoDevices(); List<Device> deviceList = m_deviceDao.findAll(); assertEquals(2, deviceList.size()); Device deviceA = m_deviceDao.getDeviceByName(DEVICE_A); Device deviceB = m_deviceDao.getDeviceByName(DEVICE_B); assertEquals(DEVICE_A, deviceA.getDeviceName()); assertEquals(DEVICE_B, deviceB.getDeviceName()); assertNull(m_deviceDao.getDeviceByName(DEVICE_C)); m_deviceDao.delete(deviceA); deviceList = m_deviceDao.findAll(); assertEquals(1, deviceList.size()); deviceA = m_deviceDao.getDeviceByName(DEVICE_A); deviceB = m_deviceDao.getDeviceByName(DEVICE_B); assertNull(deviceA); assertEquals(DEVICE_B, deviceB.getDeviceName()); m_deviceDao.deleteAll(); closeTx(); }