View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2012-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.dynamo.mock;
6   
7   import com.jcabi.dynamo.Attributes;
8   import com.jcabi.dynamo.Region;
9   import com.jcabi.dynamo.Table;
10  import org.hamcrest.MatcherAssert;
11  import org.hamcrest.Matchers;
12  import org.junit.jupiter.api.Test;
13  
14  /**
15   * Test case for {@link MkTable}.
16   * @since 0.10
17   */
18  final class MkTableTest {
19  
20      @Test
21      void returnsTableName() throws Exception {
22          final String name = "n\u00e4me";
23          MatcherAssert.assertThat(
24              "does not return correct table name",
25              new MkRegion(
26                  new H2Data().with(name, new String[]{"cl\u00e9"})
27              ).table(name).name(),
28              Matchers.equalTo(name)
29          );
30      }
31  
32      @Test
33      void returnsRegion() throws Exception {
34          final String name = "r\u00e9gion";
35          MatcherAssert.assertThat(
36              "does not return region",
37              new MkRegion(
38                  new H2Data().with(name, new String[]{"schl\u00fcssel"})
39              ).table(name).region(),
40              Matchers.instanceOf(MkRegion.class)
41          );
42      }
43  
44      @Test
45      void returnsFrame() throws Exception {
46          final String name = "fr\u00e4me";
47          MatcherAssert.assertThat(
48              "does not return frame",
49              new MkRegion(
50                  new H2Data().with(name, new String[]{"k\u00e9y"})
51              ).table(name).frame(),
52              Matchers.notNullValue()
53          );
54      }
55  
56      @Test
57      void putsItemAndReturnsIt() throws Exception {
58          final String name = "\u00fcbung";
59          final String key = "k\u00e9y";
60          final String attr = "\u00e4ttr";
61          MatcherAssert.assertThat(
62              "does not return item after put",
63              new MkRegion(
64                  new H2Data().with(name, new String[]{key}, attr)
65              ).table(name).put(
66                  new Attributes()
67                      .with(key, "47381")
68                      .with(attr, "v\u00e4lue")
69              ),
70              Matchers.notNullValue()
71          );
72      }
73  
74      @Test
75      void deletesItem() throws Exception {
76          final String name = "d\u00e9l";
77          final String key = "k\u00e9y";
78          final String attr = "\u00e4ttr";
79          final Region region = new MkRegion(
80              new H2Data().with(name, new String[]{key}, attr)
81          );
82          final Table table = region.table(name);
83          table.put(
84              new Attributes()
85                  .with(key, "89213")
86                  .with(attr, "to-d\u00e9lete")
87          );
88          table.delete(new Attributes().with(key, "89213"));
89          MatcherAssert.assertThat(
90              "does not delete item from table",
91              table.frame(),
92              Matchers.emptyIterable()
93          );
94      }
95  }