### Question:
CloudRegionDao extends NamedParameterJdbcDaoSupport { public AbstractCloudRegion create(final AbstractCloudRegion region) { return create(region, null); } CloudRegionDao(final String loadRegionByIdQuery,
                          final String loadRegionByNameQuery,
                          final String loadAllRegionsQuery,
                          final String createRegionQuery,
                          final String updateRegionQuery,
                          final String deleteRegionQuery,
                          final String loadDefaultRegionQuery,
                          final String loadRegionByRegionNameQuery,
                          final String loadByProviderAndRegionCodeQuery,
                          final String loadCredentialsByRegionId,
                          final List<CloudRegionDaoHelper> helpers); Optional<AbstractCloudRegion> loadById(final long id); Optional<AbstractCloudRegion> loadDefaultRegion(); Optional<AbstractCloudRegion> loadByName(final String name); Optional<AbstractCloudRegion> loadByRegionName(final String regionName); List<? extends AbstractCloudRegion> loadAll(); AbstractCloudRegion create(final AbstractCloudRegion region); AbstractCloudRegion create(final AbstractCloudRegion region,
                                      final AbstractCloudRegionCredentials credentials); void update(final AbstractCloudRegion region, final AbstractCloudRegionCredentials credentials); void delete(final Long id); Optional<AbstractCloudRegion> loadByProviderAndRegionCode(final CloudProvider provider,
                                                                     final String regionCode); Optional<AbstractCloudRegionCredentials> loadCredentials(final Long id);  }### Answer:
@Test public void createShouldSaveEntityWithAllSpecifiedParameters() { final AwsRegion expectedRegion = getAwsRegion(); expectedRegion.setCorsRules(CORS_RULES); expectedRegion.setPolicy(POLICY); expectedRegion.setKmsKeyId(KMS_KEY_ID); expectedRegion.setKmsKeyArn(KMS_KEY_ARN); final AbstractCloudRegion createdRegion = cloudRegionDao.create(expectedRegion); final AwsRegion actualRegion = loadAndCheckType(createdRegion.getId(), AwsRegion.class); assertRegionEquals(expectedRegion, actualRegion); }
@Test public void createShouldSaveGCPEntityWithAllSpecifiedParameters() { final GCPRegion expectedRegion = getGCPRegion(); expectedRegion.setProject("project"); expectedRegion.setImpersonatedAccount("acc"); expectedRegion.setAuthFile(AUTH_FILE); expectedRegion.setSshPublicKeyPath(SSH_PUBLIC_KEY_PATH); expectedRegion.setApplicationName("App"); expectedRegion.setCustomInstanceTypes(Arrays.asList( GCPCustomInstanceType.withCpu(CPU, RAM), GCPCustomInstanceType.withGpu(CPU, RAM, GPU, GPU_TYPE) )); final AbstractCloudRegion createdRegion = cloudRegionDao.create(expectedRegion); final GCPRegion actualRegion = loadAndCheckType(createdRegion.getId(), GCPRegion.class); assertRegionEquals(expectedRegion, actualRegion); }
@Test public void createShouldReturnEntityWithGeneratedId() { final AwsRegion region = getAwsRegion(); assertNull(region.getId()); final AbstractCloudRegion createdRegion = cloudRegionDao.create(region); assertNotNull(createdRegion.getId()); }
@Test public void createShouldThrowIfNameIsNotSpecified() { final AwsRegion regionWithoutName = getAwsRegion(); regionWithoutName.setName(null); assertThrows(DataIntegrityViolationException.class, () -> cloudRegionDao.create(regionWithoutName)); }
@Test public void createShouldThrowIfRegionIdIsNotSpecified() { final AwsRegion regionWithoutRegionId = getAwsRegion(); regionWithoutRegionId.setRegionCode(null); assertThrows(DataIntegrityViolationException.class, () -> cloudRegionDao.create(regionWithoutRegionId)); }