Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public class OpenApiConfiguration {
* @return the OpenAPI document metadata
*/
@Bean
public OpenAPI worldCupPlayersOpenApi() {
public OpenAPI dynamoDbOpenApi() {
return new OpenAPI().info(new Info()
.title("World Cup Players API")
.description("DynamoDB query sample for World Cup players")
.title("DynamoDB E2E API")
.description("DynamoDB samples used by EvoMaster end-to-end tests")
.version("1.0"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.dynamodb.operations;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;

import java.net.URI;

/**
* Spring application exercising every supported DynamoDB operation and client variant.
*/
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@ComponentScan({"com.dynamodb.config", "com.dynamodb.operations"})
public class DynamoDbOperationsApp {

/**
* Starts the DynamoDB operations application.
*
* @param args application arguments
*/
public static void main(String[] args) {
SpringApplication.run(DynamoDbOperationsApp.class, args);
}

/**
* Creates the synchronous SDK client used by the SUT.
*
* @param endpoint DynamoDB Local endpoint
* @return configured synchronous client
*/
@Bean(destroyMethod = "close")
public DynamoDbClient dynamoDbClient(@Value("${dynamodb.endpoint}") String endpoint) {
return DynamoDbClient.builder()
.endpointOverride(URI.create(endpoint))
.region(Region.US_EAST_1)
.credentialsProvider(credentialsProvider())
.build();
}

/**
* Creates the asynchronous SDK client used by the SUT.
*
* @param endpoint DynamoDB Local endpoint
* @return configured asynchronous client
*/
@Bean(destroyMethod = "close")
public DynamoDbAsyncClient dynamoDbAsyncClient(@Value("${dynamodb.endpoint}") String endpoint) {
return DynamoDbAsyncClient.builder()
.endpointOverride(URI.create(endpoint))
.region(Region.US_EAST_1)
.credentialsProvider(credentialsProvider())
.build();
}

/**
* Creates deterministic credentials accepted by DynamoDB Local.
*
* @return static local credentials provider
*/
private StaticCredentialsProvider credentialsProvider() {
return StaticCredentialsProvider.create(AwsBasicCredentials.create("local", "local"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.dynamodb.operations;

import software.amazon.awssdk.services.dynamodb.model.AttributeValue;

import java.util.HashMap;
import java.util.Map;

/**
* Shared table schema and deterministic World Cup fixture for DynamoDB operation tests.
*/
public final class DynamoDbOperationsData {

public static final String TABLE_NAME = "DynamoDbOperations";
public static final String SCENARIO_ATTRIBUTE = "scenario";
public static final String SHIRT_NUMBER_ATTRIBUTE = "shirtNumber";
public static final String PLAYER_NAME_ATTRIBUTE = "playerName";
public static final int MISSING_SHIRT_NUMBER = 9;
public static final int TARGET_SHIRT_NUMBER = 10;

private DynamoDbOperationsData() {
}

/**
* DynamoDB SDK client variants exercised by the SUT.
*/
public enum ClientMode {
SYNC,
ASYNC
}

/**
* DynamoDB operations exercised by the SUT.
*/
public enum Operation {
GET_ITEM,
BATCH_GET_ITEM,
PUT_ITEM,
UPDATE_ITEM,
DELETE_ITEM,
QUERY,
SCAN
}

/**
* Builds the partition-key value for one client and operation pair.
*
* @param clientMode SDK client variant
* @param operation DynamoDB operation
* @return deterministic scenario name
*/
public static String scenario(ClientMode clientMode, Operation operation) {
return clientMode.name() + "_" + operation.name();
}

/**
* Builds a DynamoDB key for one operation scenario and shirt number.
*
* @param clientMode SDK client variant
* @param operation DynamoDB operation
* @param shirtNumber requested shirt number
* @return DynamoDB key attributes
*/
public static Map<String, AttributeValue> key(
ClientMode clientMode, Operation operation, int shirtNumber) {
Map<String, AttributeValue> key = new HashMap<>();
key.put(SCENARIO_ATTRIBUTE, AttributeValue.builder().s(scenario(clientMode, operation)).build());
key.put(SHIRT_NUMBER_ATTRIBUTE, AttributeValue.builder().n(Integer.toString(shirtNumber)).build());
return key;
}

/**
* Builds the canonical Lionel Messi item for one operation scenario.
*
* @param clientMode SDK client variant
* @param operation DynamoDB operation
* @return complete DynamoDB item
*/
public static Map<String, AttributeValue> item(ClientMode clientMode, Operation operation) {
Map<String, AttributeValue> item = key(clientMode, operation, TARGET_SHIRT_NUMBER);
item.put(PLAYER_NAME_ATTRIBUTE, AttributeValue.builder().s("Lionel Messi").build());
item.put("country", AttributeValue.builder().s("Argentina").build());
return item;
}
}
Loading
Loading