DBManager implements Closeable { public void deleteUser(UserKey userKey) { if (isDBEnabled() && userKey != null) { blockingIOProcessor.executeDB(() -> userDBDao.deleteUser(userKey)); } } DBManager(BlockingIOProcessor blockingIOProcessor, boolean isEnabled);  DBManager(String propsFilename, BlockingIOProcessor blockingIOProcessor, boolean isEnabled); void deleteUser(UserKey userKey); void saveUsers(ArrayList<User> users); Redeem selectRedeemByToken(String token); boolean updateRedeem(String email, String token); void insertRedeems(List<Redeem> redeemList); FlashedToken selectFlashedToken(String token); boolean activateFlashedToken(String token); boolean insertFlashedTokens(FlashedToken... flashedTokenList); void insertPurchase(Purchase purchase); boolean insertClonedProject(String token, String projectJson); String selectClonedProject(String token); boolean dbIsNotEnabled(); boolean isDBEnabled(); void executeSQL(String sql); String getUserServerIp(String email, String appName); String getServerByToken(String token); void assignServerToToken(String token, String serverIp, String email, int dashId, int deviceId); void removeToken(String... tokens); Connection getConnection(); @Override void close(); public UserDBDao userDBDao; public ForwardingTokenDBDao forwardingTokenDBDao; }
@Test public void testInsertGetDeleteUser() throws Exception { ArrayList<User> users = new ArrayList<>(); User user = new User("test@gmail.com", "pass", AppNameUtil.BLYNK, "local", "127.0.0.1", true, true); user.lastModifiedTs = 0; user.lastLoggedAt = 1; user.lastLoggedIP = "127.0.0.1"; user.profile = new Profile(); DashBoard dash = new DashBoard(); dash.id = 1; dash.name = "123"; user.profile.dashBoards = new DashBoard[]{dash}; users.add(user); dbManager.userDBDao.save(users); Map<UserKey, User> dbUsers = dbManager.userDBDao.getAllUsers("local"); assertNotNull(dbUsers); assertEquals(1, dbUsers.size()); User dbUser = dbUsers.get(new UserKey(user.email, user.appName)); assertEquals("test@gmail.com", dbUser.email); assertEquals(AppNameUtil.BLYNK, dbUser.appName); assertEquals("local", dbUser.region); assertEquals("pass", dbUser.pass); assertEquals(0, dbUser.lastModifiedTs); assertEquals(1, dbUser.lastLoggedAt); assertEquals("127.0.0.1", dbUser.lastLoggedIP); assertEquals("{\"dashBoards\":[{\"id\":1,\"parentId\":-1,\"isPreview\":false,\"name\":\"123\",\"createdAt\":0,\"updatedAt\":0,\"theme\":\"Blynk\",\"keepScreenOn\":false,\"isAppConnectedOn\":false,\"isNotificationsOff\":false,\"isShared\":false,\"isActive\":false,\"widgetBackgroundOn\":false,\"color\":-1,\"isDefaultColor\":true}]}", dbUser.profile.toString()); assertTrue(dbUser.isFacebookUser); assertTrue(dbUser.isSuperAdmin); assertEquals(2000, dbUser.energy); assertEquals("{\"dashBoards\":[{\"id\":1,\"parentId\":-1,\"isPreview\":false,\"name\":\"123\",\"createdAt\":0,\"updatedAt\":0,\"theme\":\"Blynk\",\"keepScreenOn\":false,\"isAppConnectedOn\":false,\"isNotificationsOff\":false,\"isShared\":false,\"isActive\":false,\"widgetBackgroundOn\":false,\"color\":-1,\"isDefaultColor\":true}]}", dbUser.profile.toString()); assertTrue(dbManager.userDBDao.deleteUser(new UserKey(user.email, user.appName))); dbUsers = dbManager.userDBDao.getAllUsers("local"); assertNotNull(dbUsers); assertEquals(0, dbUsers.size()); }