protected SdkProfile generateSdkProfile(Application application, String token) { SdkProfile entity = new SdkProfile(); if (application == null) { application = this.generateApplication(null); } entity.setApplication(application); if (token == null) { token = "token"; } entity.setToken(token); return sdkProfileDao.save(entity); }
@Test public void constructorTest() { SdkProfileDto sdkProfileDto1 = generateSdkProfileDto("1234", "token1234"); SdkProfileDto sdkProfileDto2 = generateSdkProfileDto("1234", "token1234"); SdkProfileDto sdkProfileDto3 = generateSdkProfileDto("1235", "token1235"); SdkProfile sdkProfile1 = new SdkProfile(sdkProfileDto1); SdkProfile sdkProfile2 = new SdkProfile(sdkProfileDto2); SdkProfile sdkProfile3 = new SdkProfile(sdkProfileDto3); Assert.assertEquals(sdkProfile1.toDto(), sdkProfile2.toDto()); Assert.assertEquals(sdkProfile1.getToken(), sdkProfile2.getToken()); Assert.assertNotEquals(sdkProfile1.toDto(), sdkProfile3.toDto()); Assert.assertNotEquals(sdkProfile1.getToken(), sdkProfile3.getToken()); Assert.assertEquals(SDK_TOKEN_SIZE, sdkProfile1.getToken().length()); for (int i = 0; i < 100000; i++) { SdkProfileDto tmp = generateSdkProfileDto("1235" + i, "token1235" + i); Assert.assertEquals(SDK_TOKEN_SIZE, tmp.getToken().length(), SDK_TOKEN_SIZE); } }
@Override public SdkProfileDto saveSdkProfile(SdkProfileDto sdkProfileDto) { SdkProfileDto saved = null; if (Validator.isValidSqlObject(sdkProfileDto)) { if (StringUtils.isNotBlank(sdkProfileDto.getId())) { throw new IncorrectParameterException("Update of existing SDK profile is prohibited."); } else { applicationDao.findById(sdkProfileDto.getApplicationId()); SdkTokenGenerator.generateSdkToken(sdkProfileDto); SdkProfile entity = new SdkProfile(sdkProfileDto); SdkProfile loaded = sdkProfileDao.findSdkProfileByToken(entity.getToken()); if (loaded == null) { saved = DaoUtil.getDto(sdkProfileDao.save(entity)); } else { throw new IncorrectParameterException("An SDK profile with token [" + entity.getToken() + "] already exists."); } } } return saved; }
@Override protected GenericModel<SdkProfileDto> newInstance(Long id) { return new SdkProfile(id); }
@Override public SdkProfileDto toDto() { SdkProfileDto dto = this.createDto(); dto.setId(this.getStringId()); dto.setToken(this.token); if (this.application != null) { dto.setApplicationId(this.application.getStringId()); dto.setApplicationToken(this.application.getApplicationToken()); } dto.setName(this.name); dto.setConfigurationSchemaVersion(this.configurationSchemaVersion); dto.setProfileSchemaVersion(this.profileSchemaVersion); dto.setNotificationSchemaVersion(this.notificationSchemaVersion); dto.setLogSchemaVersion(this.logSchemaVersion); if (this.aefMapIds != null) { dto.setAefMapIds(new ArrayList<String>(this.aefMapIds.size())); for (String id : this.aefMapIds) { dto.getAefMapIds().add(id); } } dto.setDefaultVerifierToken(this.defaultVerifierToken); dto.setCreatedUsername(this.createdUsername); dto.setCreatedTime(this.createdTime); dto.setEndpointCount(this.endpointCount); return dto; }
@Test public void findSdkProfilesByApplicationIdTest() { SdkProfile saved = this.generateSdkProfile(null, null); List<SdkProfile> loaded = sdkProfileDao.findSdkProfileByApplicationId(saved.getApplication().getId().toString()); Assert.assertEquals(1, loaded.size()); Assert.assertEquals(saved, loaded.get(0)); } }
@Test public void saveTest() { SdkProfile saved = this.generateSdkProfile(null, null); Assert.assertNotNull(saved.getId()); }