@Test(expected = Exception.class) public void createMapperShouldFailIfDBClientFailsToCreate() throws Exception { when(awsSessionService.getDynamoDBClient(any())).thenThrow(new Exception()); dynamoDBService.createMapper("BAD_ACCOUNT_NAME", "bad_region", "table"); }
public DynamoDBMapper createMapper(String account, String region, String tableName) { AWSEnvironment awsenv = new AWSEnvironment(account, region); AmazonDynamoDBClient dbclient; try { dbclient = awsSessionService.getDynamoDBClient(awsenv); } catch (AWSSecurityTokenServiceException ex) { String message = String.format("User not authorized to access credential table on account: %s in region: %s", account, region); logger.error(message, ex); throw new FideliusException(message, HttpStatus.FORBIDDEN); } catch (RuntimeException re) { String message = re.getMessage(); logger.error(message, re); throw new FideliusException(message, HttpStatus.INTERNAL_SERVER_ERROR); } DynamoDBMapperConfig config = new DynamoDBMapperConfig.Builder() .withTableNameOverride(DynamoDBMapperConfig.TableNameOverride.withTableNameReplacement(tableName)) .build(); return new DynamoDBMapper(dbclient, config); }
DynamoDBService { public DynamoDBMapper createMapper(String account, String region, String tableName) { AWSEnvironment awsenv = new AWSEnvironment(account, region); AmazonDynamoDBClient dbclient; try { dbclient = awsSessionService.getDynamoDBClient(awsenv); } catch (AWSSecurityTokenServiceException ex) { String message = String.format("User not authorized to access credential table on account: %s in region: %s", account, region); logger.error(message, ex); throw new FideliusException(message, HttpStatus.FORBIDDEN); } catch (RuntimeException re) { String message = re.getMessage(); logger.error(message, re); throw new FideliusException(message, HttpStatus.INTERNAL_SERVER_ERROR); } DynamoDBMapperConfig config = new DynamoDBMapperConfig.Builder() .withTableNameOverride(DynamoDBMapperConfig.TableNameOverride.withTableNameReplacement(tableName)) .build(); return new DynamoDBMapper(dbclient, config); } }
DynamoDBService { public DynamoDBMapper createMapper(String account, String region, String tableName) { AWSEnvironment awsenv = new AWSEnvironment(account, region); AmazonDynamoDBClient dbclient; try { dbclient = awsSessionService.getDynamoDBClient(awsenv); } catch (AWSSecurityTokenServiceException ex) { String message = String.format("User not authorized to access credential table on account: %s in region: %s", account, region); logger.error(message, ex); throw new FideliusException(message, HttpStatus.FORBIDDEN); } catch (RuntimeException re) { String message = re.getMessage(); logger.error(message, re); throw new FideliusException(message, HttpStatus.INTERNAL_SERVER_ERROR); } DynamoDBMapperConfig config = new DynamoDBMapperConfig.Builder() .withTableNameOverride(DynamoDBMapperConfig.TableNameOverride.withTableNameReplacement(tableName)) .build(); return new DynamoDBMapper(dbclient, config); }  }
DynamoDBService { public DynamoDBMapper createMapper(String account, String region, String tableName) { AWSEnvironment awsenv = new AWSEnvironment(account, region); AmazonDynamoDBClient dbclient; try { dbclient = awsSessionService.getDynamoDBClient(awsenv); } catch (AWSSecurityTokenServiceException ex) { String message = String.format("User not authorized to access credential table on account: %s in region: %s", account, region); logger.error(message, ex); throw new FideliusException(message, HttpStatus.FORBIDDEN); } catch (RuntimeException re) { String message = re.getMessage(); logger.error(message, re); throw new FideliusException(message, HttpStatus.INTERNAL_SERVER_ERROR); } DynamoDBMapperConfig config = new DynamoDBMapperConfig.Builder() .withTableNameOverride(DynamoDBMapperConfig.TableNameOverride.withTableNameReplacement(tableName)) .build(); return new DynamoDBMapper(dbclient, config); }  List<T> scanDynamoDB(DynamoDBScanExpression scanExp, Class<T> clazz, DynamoDBMapper mapper); List<T> queryDynamoDB(DynamoDBQueryExpression queryRequest, Class<T> clazz, DynamoDBMapper dynamoDBMapper); DynamoDBMapper createMapper(String account, String region, String tableName); }
DynamoDBService { public DynamoDBMapper createMapper(String account, String region, String tableName) { AWSEnvironment awsenv = new AWSEnvironment(account, region); AmazonDynamoDBClient dbclient; try { dbclient = awsSessionService.getDynamoDBClient(awsenv); } catch (AWSSecurityTokenServiceException ex) { String message = String.format("User not authorized to access credential table on account: %s in region: %s", account, region); logger.error(message, ex); throw new FideliusException(message, HttpStatus.FORBIDDEN); } catch (RuntimeException re) { String message = re.getMessage(); logger.error(message, re); throw new FideliusException(message, HttpStatus.INTERNAL_SERVER_ERROR); } DynamoDBMapperConfig config = new DynamoDBMapperConfig.Builder() .withTableNameOverride(DynamoDBMapperConfig.TableNameOverride.withTableNameReplacement(tableName)) .build(); return new DynamoDBMapper(dbclient, config); }  List<T> scanDynamoDB(DynamoDBScanExpression scanExp, Class<T> clazz, DynamoDBMapper mapper); List<T> queryDynamoDB(DynamoDBQueryExpression queryRequest, Class<T> clazz, DynamoDBMapper dynamoDBMapper); DynamoDBMapper createMapper(String account, String region, String tableName);  }