@Test public void SaveWithAppCallbackDTOTest() { AppCallbackDTO reqBody = new AppCallbackDTO(); reqBody.setName("Test Name"); reqBody.setDeveloper("developer@conductor.com.br"); appPersist.setClientId("8d19n91d8"); Mockito.when(appRepository.findByClientId(Mockito.anyString())).thenReturn(null); Mockito.when(appRepository.save(Mockito.any(App.class))).thenReturn(app); Mockito.when(devRepository.findOne(Mockito.anyLong())).thenReturn(developer); Mockito.when(devRepository.findByEmail(Mockito.anyString())).thenReturn(developer); App saved = this.appService.save(reqBody); assertEquals(app.getId(), saved.getId()); }
public App save(AppPersist appDTO) { if (appDTO.getClientId() != null) { App app = appRepository.findByClientId(appDTO.getClientId()); HeimdallException.checkThrow(Objects.nonNull(app), CLIENT_ID_ALREADY); } else { RandomString randomString = new RandomString(12); String token = randomString.nextString(); while (appRepository.findByClientId(token) != null) { token = randomString.nextString(); } appDTO.setClientId(token); } App app = GenericConverter.mapper(appDTO, App.class); Developer dev = devRepository.findOne(app.getDeveloper().getId()); HeimdallException.checkThrow(dev == null, DEVELOPER_NOT_EXIST); amqpCacheService.dispatchClean(); return appRepository.save(app); }
AppService { public App save(AppPersist appDTO) { if (appDTO.getClientId() != null) { App app = appRepository.findByClientId(appDTO.getClientId()); HeimdallException.checkThrow(Objects.nonNull(app), CLIENT_ID_ALREADY); } else { RandomString randomString = new RandomString(12); String token = randomString.nextString(); while (appRepository.findByClientId(token) != null) { token = randomString.nextString(); } appDTO.setClientId(token); } App app = GenericConverter.mapper(appDTO, App.class); Developer dev = devRepository.findOne(app.getDeveloper().getId()); HeimdallException.checkThrow(dev == null, DEVELOPER_NOT_EXIST); amqpCacheService.dispatchClean(); return appRepository.save(app); } }
AppService { public App save(AppPersist appDTO) { if (appDTO.getClientId() != null) { App app = appRepository.findByClientId(appDTO.getClientId()); HeimdallException.checkThrow(Objects.nonNull(app), CLIENT_ID_ALREADY); } else { RandomString randomString = new RandomString(12); String token = randomString.nextString(); while (appRepository.findByClientId(token) != null) { token = randomString.nextString(); } appDTO.setClientId(token); } App app = GenericConverter.mapper(appDTO, App.class); Developer dev = devRepository.findOne(app.getDeveloper().getId()); HeimdallException.checkThrow(dev == null, DEVELOPER_NOT_EXIST); amqpCacheService.dispatchClean(); return appRepository.save(app); }  }
AppService { public App save(AppPersist appDTO) { if (appDTO.getClientId() != null) { App app = appRepository.findByClientId(appDTO.getClientId()); HeimdallException.checkThrow(Objects.nonNull(app), CLIENT_ID_ALREADY); } else { RandomString randomString = new RandomString(12); String token = randomString.nextString(); while (appRepository.findByClientId(token) != null) { token = randomString.nextString(); } appDTO.setClientId(token); } App app = GenericConverter.mapper(appDTO, App.class); Developer dev = devRepository.findOne(app.getDeveloper().getId()); HeimdallException.checkThrow(dev == null, DEVELOPER_NOT_EXIST); amqpCacheService.dispatchClean(); return appRepository.save(app); }  @Transactional(readOnly = true) App find(Long id); @Transactional(readOnly = true) AppPage list(AppRequestDTO appDTO, PageableDTO pageableDTO); @Transactional(readOnly = true) List<App> list(AppRequestDTO appDTO); App save(AppPersist appDTO); App update(Long id, AppDTO appDTO); void delete(Long id); @Transactional App save(AppCallbackDTO reqBody); }
AppService { public App save(AppPersist appDTO) { if (appDTO.getClientId() != null) { App app = appRepository.findByClientId(appDTO.getClientId()); HeimdallException.checkThrow(Objects.nonNull(app), CLIENT_ID_ALREADY); } else { RandomString randomString = new RandomString(12); String token = randomString.nextString(); while (appRepository.findByClientId(token) != null) { token = randomString.nextString(); } appDTO.setClientId(token); } App app = GenericConverter.mapper(appDTO, App.class); Developer dev = devRepository.findOne(app.getDeveloper().getId()); HeimdallException.checkThrow(dev == null, DEVELOPER_NOT_EXIST); amqpCacheService.dispatchClean(); return appRepository.save(app); }  @Transactional(readOnly = true) App find(Long id); @Transactional(readOnly = true) AppPage list(AppRequestDTO appDTO, PageableDTO pageableDTO); @Transactional(readOnly = true) List<App> list(AppRequestDTO appDTO); App save(AppPersist appDTO); App update(Long id, AppDTO appDTO); void delete(Long id); @Transactional App save(AppCallbackDTO reqBody);  }