DynamoDbUsersDaoFactory implements UsersDaoFactory { @Override @SuppressWarnings("ConstantConditions") public UsersDao createUsersDao(ObjectMapper mapper) { LOG.info("Creating DynamoDB implementation of UsersDao"); initializeDynamoDbClient(); initializeDynamoDbTable(); return new DynamoDbUsersDao(dynamoDbClient, tableName, mapper); }  String getEndpoint(); String getRegion(); String getTableName(); @Override @SuppressWarnings("ConstantConditions") UsersDao createUsersDao(ObjectMapper mapper); @Override DatabaseHealthCheck createHealthCheck();  }
@Test void testCreateUsersDaoTableExists() throws Exception { UsersDaoFactory usersDaoFactory = FACTORY.build(new File(Resources.getResource( "fixtures/configuration/dao/dynamodb-config.yaml").toURI())); assertTrue(usersDaoFactory instanceof DynamoDbUsersDaoFactory); DynamoDbUsersDaoFactory dynamoDbUsersDaoFactory = (DynamoDbUsersDaoFactory) usersDaoFactory; DynamoDbClient client = mock(DynamoDbClient.class); when(client.listTables()) .thenReturn(ListTablesResponse.builder().tableNames("test-table").build()); dynamoDbUsersDaoFactory.dynamoDbClient = client; usersDaoFactory.createUsersDao(OBJECT_MAPPER); verify(client, times(1)).listTables(); verify(client, times(0)).createTable(any(CreateTableRequest.class)); }
@Test void testCreateUsersDaoTableNotExists() throws Exception { UsersDaoFactory usersDaoFactory = FACTORY.build(new File(Resources.getResource( "fixtures/configuration/dao/dynamodb-config.yaml").toURI())); assertTrue(usersDaoFactory instanceof DynamoDbUsersDaoFactory); DynamoDbUsersDaoFactory dynamoDbUsersDaoFactory = (DynamoDbUsersDaoFactory) usersDaoFactory; DynamoDbClient client = mock(DynamoDbClient.class); when(client.listTables()) .thenReturn(ListTablesResponse.builder().tableNames("wrong-test-table").build()); dynamoDbUsersDaoFactory.dynamoDbClient = client; usersDaoFactory.createUsersDao(OBJECT_MAPPER); verify(client, times(1)).listTables(); verify(client, times(1)).createTable(any(CreateTableRequest.class)); }