Skip to content

Commit 8bc2b49

Browse files
committed
Update tests
1 parent 04ff946 commit 8bc2b49

File tree

2 files changed

+63
-15
lines changed

2 files changed

+63
-15
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package co.elastic.clients.elasticsearch;
21+
22+
import org.junit.Test;
23+
24+
public class ScratchPad {
25+
26+
@Test
27+
public void testConstants() {
28+
29+
final int a = 1 << 0;
30+
final int b = 1 << 1;
31+
32+
int x = (int)System.currentTimeMillis();
33+
34+
int y;
35+
36+
switch(x) {
37+
case a+b:
38+
y = 1;
39+
break;
40+
41+
case a:
42+
y = 2;
43+
break;
44+
45+
default:
46+
y = 3;
47+
}
48+
49+
}
50+
51+
}

java-client/src/test/java/co/elastic/clients/elasticsearch/experiments/RequestTest.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import co.elastic.clients.elasticsearch.indices.CreateResponse;
2929
import co.elastic.clients.elasticsearch.indices.IndexState;
3030
import co.elastic.clients.json.jsonb.JsonbJsonpMapper;
31+
import jakarta.json.JsonValue;
3132
import org.apache.http.HttpHost;
3233
import org.elasticsearch.client.RequestOptions;
3334
import org.elasticsearch.client.RestClient;
@@ -102,50 +103,46 @@ public void testDataIngestion() throws Exception {
102103
BooleanResponse existsResponse = client.indices().exists(b -> b.index("test"));
103104
assertTrue(existsResponse.value());
104105

105-
// Would be nice to have index tagged as "preferred field" to generate this:
106-
// BooleanResponse existsResponse = client.indices().exists("test");
107-
108-
109106
// Ingest some data
110107
AppData appData = new AppData();
111108
appData.setIntValue(1337);
112109
appData.setMsg("foo");
113110

114-
String docId = client.create(b -> b
111+
String docId = client.index(b -> b
115112
.index("test")
116-
.type("_doc") // needed for now because of how paths are generated
117113
.id("myId")
118114
.value(appData)
115+
.refresh(JsonValue.TRUE) // Make it visible for search
119116
)._id();
120117

121118
// Query by id
122119
AppData esData = client.get(b -> b
123120
.index("test")
124-
.type("_doc")
125121
.id(docId)
126122
, AppData.class
127123
)._source();
128124

129125
assertEquals(1337, esData.getIntValue());
130126
assertEquals("foo", esData.getMsg());
131127

132-
// Search, adding some options
128+
// Search, adding some request options
133129
RequestOptions options = RequestOptions.DEFAULT.toBuilder()
134130
.addHeader("x-super-header", "bar")
135131
.build();
136132

137-
SearchResponse<String> search = client
133+
SearchResponse<AppData> search = client
138134
.withRequestOptions(options)
139135
.search(b -> b
140-
.index("test")//, "foo", "bar")
141-
.allowNoIndices(true)
142-
.explain(true),
143-
String.class
136+
.index("test")
137+
, AppData.class
144138
);
145139

146-
System.out.println(search.hits().total().asJsonObject().getInt("value") + " hits");
147-
140+
int hits = search.hits().total().asJsonObject().getInt("value"); // union types not handled yet
141+
assertEquals(1, hits);
148142

143+
esData = search.hits().hits().get(0)._source();
144+
assertEquals(1337, esData.getIntValue());
145+
assertEquals("foo", esData.getMsg());
149146
}
150147

151148
public static class AppData {

0 commit comments

Comments
 (0)