View Javadoc
1   /*
2    * Copyright (c) 2012-2023, jcabi.com
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met: 1) Redistributions of source code must retain the above
8    * copyright notice, this list of conditions and the following
9    * disclaimer. 2) Redistributions in binary form must reproduce the above
10   * copyright notice, this list of conditions and the following
11   * disclaimer in the documentation and/or other materials provided
12   * with the distribution. 3) Neither the name of the jcabi.com nor
13   * the names of its contributors may be used to endorse or promote
14   * products derived from this software without specific prior written
15   * permission.
16   *
17   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21   * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28   * OF THE POSSIBILITY OF SUCH DAMAGE.
29   */
30  package com.jcabi.dynamo;
31  
32  import com.jcabi.aspects.Tv;
33  import java.util.Iterator;
34  import org.apache.commons.lang3.RandomStringUtils;
35  import org.hamcrest.MatcherAssert;
36  import org.hamcrest.Matchers;
37  import org.junit.jupiter.api.Assumptions;
38  import org.junit.jupiter.api.BeforeEach;
39  import org.junit.jupiter.api.Test;
40  
41  /**
42   * Integration case with DynamoDB Local.
43   *
44   * @since 0.23
45   */
46  @SuppressWarnings("PMD.AvoidDuplicateLiterals")
47  final class DynamodbLocalITCase {
48  
49      @BeforeEach
50      void itTestCheck() {
51          Assumptions.assumeFalse(
52              System.getProperty("failsafe.ddl.port", "").isEmpty()
53                  || System.getProperty("failsafe.ddl.key", "").isEmpty()
54                  || System.getProperty("failsafe.ddl.secret", "").isEmpty(),
55              "DynamoDbLocal is not up and running, that's why this test is skipped"
56          );
57      }
58  
59      @Test
60      @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
61      void worksWithAmazon() throws Exception {
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          for (int idx = 0; idx < Tv.FIVE; ++idx) {
72              tbl.put(
73                  new Attributes()
74                      .with("room", idx)
75                      .with("title", RandomStringUtils.randomAlphanumeric(Tv.TEN))
76              );
77          }
78          MatcherAssert.assertThat(
79              tbl.frame()
80                  .where("room", Conditions.equalTo(0))
81                  .through(new QueryValve().withLimit(1)),
82              Matchers.hasSize(1)
83          );
84          MatcherAssert.assertThat(
85              tbl.frame()
86                  .where("room", Conditions.equalTo(0))
87                  .through(new ScanValve())
88                  .iterator().next()
89                  .get("room")
90                  .getN(),
91              Matchers.equalTo("0")
92          );
93          final Iterator<Item> items = tbl.frame().iterator();
94          items.next();
95          items.remove();
96      }
97  
98  }