View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2012-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.dynamo;
6   
7   import org.apache.commons.lang3.RandomStringUtils;
8   import org.hamcrest.MatcherAssert;
9   import org.hamcrest.Matchers;
10  import org.junit.jupiter.api.Assumptions;
11  import org.junit.jupiter.api.BeforeEach;
12  import org.junit.jupiter.api.Test;
13  
14  /**
15   * Integration case with DynamoDB Local.
16   *
17   * @since 0.23
18   */
19  final class DynamodbLocalITCase {
20  
21      @BeforeEach
22      void itTestCheck() {
23          Assumptions.assumeFalse(
24              System.getProperty("failsafe.ddl.port", "").isEmpty()
25                  || System.getProperty("failsafe.ddl.key", "").isEmpty()
26                  || System.getProperty("failsafe.ddl.secret", "").isEmpty(),
27              "DynamoDbLocal is not up and running, that's why this test is skipped"
28          );
29      }
30  
31      @Test
32      void queriesWithLimit() throws Exception {
33          final String col = "room";
34          final Table tbl = new Region.Simple(
35              new Credentials.Direct(
36                  new Credentials.Simple(
37                      System.getProperty("failsafe.ddl.key"),
38                      System.getProperty("failsafe.ddl.secret")
39                  ),
40                  Integer.parseInt(System.getProperty("failsafe.ddl.port"))
41              )
42          ).table("talks");
43          for (int idx = 0; idx < 5; ++idx) {
44              tbl.put(
45                  new Attributes()
46                      .with(col, idx)
47                      .with("title", RandomStringUtils.secure().nextAlphanumeric(10))
48              );
49          }
50          MatcherAssert.assertThat(
51              "should has size 1",
52              tbl.frame()
53                  .where(col, Conditions.equalTo(0))
54                  .through(new QueryValve().withLimit(1)),
55              Matchers.hasSize(1)
56          );
57      }
58  
59      @Test
60      void scansAndReadsValue() throws Exception {
61          final String col = "room";
62          final Table tbl = new Region.Simple(
63              new Credentials.Direct(
64                  new Credentials.Simple(
65                      System.getProperty("failsafe.ddl.key"),
66                      System.getProperty("failsafe.ddl.secret")
67                  ),
68                  Integer.parseInt(System.getProperty("failsafe.ddl.port"))
69              )
70          ).table("talks");
71          tbl.put(
72              new Attributes()
73                  .with(col, 0)
74                  .with("title", RandomStringUtils.secure().nextAlphanumeric(10))
75          );
76          MatcherAssert.assertThat(
77              "should equals to 0",
78              tbl.frame()
79                  .where(col, Conditions.equalTo(0))
80                  .through(new ScanValve())
81                  .iterator().next()
82                  .get(col)
83                  .n(),
84              Matchers.equalTo("0")
85          );
86      }
87  
88  }