1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package com.jcabi.simpledb;
31
32 import com.amazonaws.services.simpledb.model.SelectRequest;
33 import com.jcabi.aspects.Tv;
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.Test;
39
40
41
42
43
44
45 final class RegionITCase {
46
47
48
49
50 private static final String KEY =
51 System.getProperty("failsafe.sdb.key");
52
53
54
55
56 private static final String SECRET =
57 System.getProperty("failsafe.sdb.secret");
58
59 @Test
60 void putsAndRemovesIndividualItems() {
61 final Domain domain = this.domain();
62 try {
63 final String name = RandomStringUtils.randomAlphanumeric(Tv.TEN);
64 final String attr = RandomStringUtils.randomAlphabetic(Tv.EIGHT);
65 final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
66 for (int idx = 0; idx < 2; ++idx) {
67 domain.item(name).put(attr, value);
68 MatcherAssert.assertThat(
69 domain.item(name), Matchers.hasKey(attr)
70 );
71 domain.item(name).remove(attr);
72 MatcherAssert.assertThat(
73 domain.item(name), Matchers.not(Matchers.hasKey(attr))
74 );
75 }
76 } finally {
77 domain.drop();
78 }
79 }
80
81 @Test
82 void selectsMultipleItems() {
83 final Domain domain = this.domain();
84 try {
85 final String attr = "alpha";
86 domain.item("first").put(attr, "val-99");
87 domain.item("second").put("beta", "");
88 MatcherAssert.assertThat(
89 domain.select(
90 new SelectRequest().withSelectExpression(
91 String.format(
92 "SELECT * FROM `%s` WHERE `%s` = 'val-99'",
93 domain.name(), attr
94 )
95 ).withConsistentRead(true)
96 ),
97 Matchers.hasItem(Matchers.hasKey(attr))
98 );
99 } finally {
100 domain.drop();
101 }
102 }
103
104
105
106
107 @Test
108 void selectsManyItems() {
109 final Domain domain = this.domain();
110 try {
111 for (int idx = 0; idx < Tv.TEN; ++idx) {
112 domain.item(String.format("i-%d", idx)).put("hey", "");
113 }
114 MatcherAssert.assertThat(
115 domain.select(
116 new SelectRequest().withSelectExpression(
117 String.format("SELECT * FROM `%s`", domain.name())
118 ).withConsistentRead(true)
119 ),
120 Matchers.iterableWithSize(Tv.TEN)
121 );
122 } finally {
123 domain.drop();
124 }
125 }
126
127
128
129
130
131 private Domain domain() {
132 Assumptions.assumeFalse(RegionITCase.KEY.isEmpty());
133 final Region region = new Region.Simple(
134 new Credentials.Simple(RegionITCase.KEY, RegionITCase.SECRET)
135 );
136 final Domain domain = region.domain(
137 String.format(
138 "jcabi-test-%s",
139 RandomStringUtils.randomAlphabetic(5)
140 )
141 );
142 domain.create();
143 return domain;
144 }
145
146 }