Ejemplo n.º 1
0
  @Test
  public void queryWithHashKeyAndNumericRangeKeyConditionBETWEENTest() {
    AttributeValue hashKey = setupNumericRangeTableWithSeveralItems();

    QueryRequest request = new QueryRequest().withTableName(tableName).withHashKeyValue(hashKey);

    Condition rangeKeyCondition = new Condition();
    List<AttributeValue> attributeValueList = new ArrayList<AttributeValue>();
    attributeValueList.add(createNumberAttribute(2));
    attributeValueList.add(createNumberAttribute(3));
    rangeKeyCondition.setAttributeValueList(attributeValueList);
    rangeKeyCondition.setComparisonOperator(ComparisonOperator.BETWEEN);
    request.setRangeKeyCondition(rangeKeyCondition);
    QueryResult result = getClient().query(request);
    Assert.assertNotNull("Null result.", result);
    Assert.assertNotNull("No items returned.", result.getItems());
    Assert.assertEquals("Should return two items.", 2, result.getItems().size());
  }
Ejemplo n.º 2
0
  @Test
  public void queryWithHashKeyAndNumericRangeKeyConditionGETest() {
    AttributeValue hashKey = setupNumericRangeTableWithSeveralItems();

    QueryRequest request = new QueryRequest().withTableName(tableName).withHashKeyValue(hashKey);

    Condition rangeKeyCondition = new Condition();
    List<AttributeValue> attributeValueList = new ArrayList<AttributeValue>();
    attributeValueList.add(createNumberAttribute(2));
    rangeKeyCondition.setAttributeValueList(attributeValueList);
    rangeKeyCondition.setComparisonOperator(ComparisonOperator.GE);
    request.setRangeKeyCondition(rangeKeyCondition);
    QueryResult result = getClient().query(request);
    Assert.assertNotNull("Null result.", result);
    Assert.assertNotNull("No items returned.", result.getItems());
    // NOTE: GE is currently a string comparison, so "11" is NOT > "2".
    Assert.assertEquals("Should return four items.", 4, result.getItems().size());
  }
Ejemplo n.º 3
0
  @Test
  public void queryWithHashKeyAndNumericRangeKeyConditionEQTest() {
    AttributeValue hashKey = setupNumericRangeTableWithSeveralItems();

    QueryRequest request = new QueryRequest().withTableName(tableName).withHashKeyValue(hashKey);

    Condition rangeKeyCondition = new Condition();
    List<AttributeValue> attributeValueList = new ArrayList<AttributeValue>();
    attributeValueList.add(createNumberAttribute(2));
    rangeKeyCondition.setAttributeValueList(attributeValueList);
    rangeKeyCondition.setComparisonOperator(ComparisonOperator.EQ);
    request.setRangeKeyCondition(rangeKeyCondition);
    QueryResult result = getClient().query(request);
    Assert.assertNotNull("Null result.", result);
    Assert.assertNotNull("No items returned.", result.getItems());
    Assert.assertEquals("Should return one item.", 1, result.getItems().size());
    for (Map<String, AttributeValue> item : result.getItems()) {
      Assert.assertEquals(item.get("range").getN(), "2");
    }
  }
Ejemplo n.º 4
0
  @Test
  public void queryWithHashKeyAndRangeKeyConditionCONTAINSTest() {
    AttributeValue hashKey = setupTableWithSeveralItems();

    QueryRequest request = new QueryRequest().withTableName(tableName).withHashKeyValue(hashKey);

    Condition rangeKeyCondition = new Condition();
    List<AttributeValue> attributeValueList = new ArrayList<AttributeValue>();
    attributeValueList.add(new AttributeValue().withS("ange1"));
    rangeKeyCondition.setAttributeValueList(attributeValueList);
    rangeKeyCondition.setComparisonOperator(ComparisonOperator.CONTAINS);
    request.setRangeKeyCondition(rangeKeyCondition);
    QueryResult result = getClient().query(request);
    Assert.assertNotNull("Null result.", result);
    Assert.assertNotNull("No items returned.", result.getItems());
    Assert.assertEquals("Should return two items.", 2, result.getItems().size());
    for (Map<String, AttributeValue> item : result.getItems()) {
      Assert.assertTrue(item.get("range").getS().contains("ange1"));
    }
  }
Ejemplo n.º 5
0
  @Test
  public void queryWithHashKeyAndNumericRangeKeyConditionCONTAINSTest() {
    AttributeValue hashKey = setupNumericRangeTableWithSeveralItems();

    QueryRequest request = new QueryRequest().withTableName(tableName).withHashKeyValue(hashKey);

    Condition rangeKeyCondition = new Condition();
    List<AttributeValue> attributeValueList = new ArrayList<AttributeValue>();
    attributeValueList.add(createNumberAttribute(1));
    rangeKeyCondition.setAttributeValueList(attributeValueList);
    rangeKeyCondition.setComparisonOperator(ComparisonOperator.CONTAINS);
    request.setRangeKeyCondition(rangeKeyCondition);
    QueryResult result = getClient().query(request);
    Assert.assertNotNull("Null result.", result);
    Assert.assertNotNull("No items returned.", result.getItems());
    // NOTE: CONTAINS is currently a string comparison, so "1", "11", "51" all contain "1".
    Assert.assertEquals("Should return three items.", 3, result.getItems().size());
    for (Map<String, AttributeValue> item : result.getItems()) {
      Assert.assertTrue(item.get("range").getN().contains("1"));
    }
  }