Search in sources :

Example 1 with ProductInfo

use of com.baeldung.spring.data.dynamodb.model.ProductInfo in project tutorials by eugenp.

the class ProductInfoRepositoryIntegrationTest method setup.

@Before
public void setup() throws Exception {
    try {
        dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB);
        CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(ProductInfo.class);
        tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
        amazonDynamoDB.createTable(tableRequest);
    } catch (ResourceInUseException e) {
    // Do nothing, table already created
    }
    // TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfo on table
    dynamoDBMapper.batchDelete((List<ProductInfo>) repository.findAll());
}
Also used : ProductInfo(com.baeldung.spring.data.dynamodb.model.ProductInfo) ResourceInUseException(com.amazonaws.services.dynamodbv2.model.ResourceInUseException) DynamoDBMapper(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) Before(org.junit.Before)

Example 2 with ProductInfo

use of com.baeldung.spring.data.dynamodb.model.ProductInfo in project tutorials by eugenp.

the class ProductInfoRepositoryIntegrationTest method givenItemWithExpectedCost_whenRunFindAll_thenItemIsFound.

@Test
public void givenItemWithExpectedCost_whenRunFindAll_thenItemIsFound() {
    ProductInfo productInfo = new ProductInfo(EXPECTED_COST, EXPECTED_PRICE);
    repository.save(productInfo);
    List<ProductInfo> result = (List<ProductInfo>) repository.findAll();
    assertThat(result.size(), is(greaterThan(0)));
    assertThat(result.get(0).getCost(), is(equalTo(EXPECTED_COST)));
}
Also used : ProductInfo(com.baeldung.spring.data.dynamodb.model.ProductInfo) List(java.util.List) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProductInfo (com.baeldung.spring.data.dynamodb.model.ProductInfo)2 DynamoDBMapper (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)1 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)1 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)1 ResourceInUseException (com.amazonaws.services.dynamodbv2.model.ResourceInUseException)1 List (java.util.List)1 Before (org.junit.Before)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1