Search in sources :

Example 1 with ProductInfo

use of com.baeldung.dynamodb.entity.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.dynamodb.entity.ProductInfo) List(java.util.List) Test(org.junit.Test)

Example 2 with ProductInfo

use of com.baeldung.dynamodb.entity.ProductInfo in project tutorials by eugenp.

the class ProductInfoRepositoryIntegrationTest method setup.

@Before
public void setup() {
    try {
        repository = new ProductInfoRepository();
        repository.setMapper(dynamoDBMapper);
        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 : ProductInfoRepository(com.baeldung.dynamodb.repository.ProductInfoRepository) ProductInfo(com.baeldung.dynamodb.entity.ProductInfo) ResourceInUseException(com.amazonaws.services.dynamodbv2.model.ResourceInUseException) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) Before(org.junit.Before)

Aggregations

ProductInfo (com.baeldung.dynamodb.entity.ProductInfo)2 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)1 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)1 ResourceInUseException (com.amazonaws.services.dynamodbv2.model.ResourceInUseException)1 ProductInfoRepository (com.baeldung.dynamodb.repository.ProductInfoRepository)1 List (java.util.List)1 Before (org.junit.Before)1 Test (org.junit.Test)1