@Override public void removeEndpointProfileByKeyHash(byte[] endpointProfileKeyHash) { validateHash(endpointProfileKeyHash, "Can't remove endpoint profile by key hash. Invalid key " + "hash " + endpointProfileKeyHash); EndpointProfile endpointProfile = endpointProfileDao.findByKeyHash(endpointProfileKeyHash); if (endpointProfile != null) { if (isValidId(endpointProfile.getEndpointUserId())) { detachEndpointFromUser(getDto(endpointProfile)); } endpointProfileDao.removeByKeyHash(endpointProfileKeyHash); } else { throw new DatabaseProcessingException("Endpoint profile is not present in db."); } }
@Test public void testRemoveByKeyHash() throws Exception { EndpointProfileDto expected = generateEndpointProfile(null, null, null, null); endpointProfileDao.removeByKeyHash(expected.getEndpointKeyHash()); EndpointProfile found = endpointProfileDao.findByKeyHash(expected.getEndpointKeyHash()); Assert.assertNull(found); }
@Test public void testRemoveByKeyHash() { EndpointProfileDto endpointProfile = generateEndpointProfileDto(null, null); Assert.assertNotNull(endpointProfile); endpointProfileDao.removeByKeyHash(endpointProfile.getEndpointKeyHash()); MongoEndpointProfile profile = endpointProfileDao.findByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertNull(profile); }