Skip to content

Commit

Permalink
fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
l-trotta committed Jul 12, 2024
1 parent b07351f commit c430f6d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ public void testAdditionalPropertyOnContainer() {

{
SortOptions so = SortOptions.of(_0 -> _0
.script(_1 -> _1.script(_2 -> _2.inline(_3 -> _3.source("blah"))))
.script(_1 -> _1.script(_3 -> _3.source("blah")))
);
so = checkJsonRoundtrip(so, "{\"_script\":{\"script\":{\"source\":\"blah\"}}}");
assertEquals("blah", so.script().script().inline().source());
assertEquals("blah", so.script().script().source());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,24 @@ public void testScriptDeserializer() {
// A union discriminated by its field names (source -> inline, id -> stored)
{
Script s = Script.of(_1 -> _1
.inline(_2 -> _2
.source("a script")
)
);
s = checkJsonRoundtrip(s, "{\"source\":\"a script\"}");
assertEquals("a script", s.inline().source());
assertEquals("a script", s.source());
}

{
Script s = Script.of(_1 -> _1
.stored(_2 -> _2
.id("script_id")
)
);
s = checkJsonRoundtrip(s, "{\"id\":\"script_id\"}");
assertEquals("script_id", s.stored().id());
assertEquals("script_id", s.id());
}

{
// Test shortcut property
Script s = fromJson("\"a script\"", Script.class);
assertEquals("a script", s.inline().source());
assertEquals("a script", s.source());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ public void i0298_runtimeMappings() throws Exception {
RuntimeField runtimeField = RuntimeField.of(rf -> rf
.type(RuntimeFieldType.Double)
.script(Script.of(s -> s
.inline(i -> i.
source("emit(doc['price'].value * 1.19)")
)
.source("emit(doc['price'].value * 1.19)")
))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void testJsonString() {
{
IndicesPrivileges priv = IndicesPrivileges.of(i -> i
.names("bar")
.query(q -> q._custom("template", RoleTemplateScript.of(s -> s.stored(v -> v.id("foo")))))
.query(q -> q._custom("template", RoleTemplateScript.of(s -> s.id("foo"))))
.privileges(IndexPrivilege.All.jsonValue())
);

Expand All @@ -188,7 +188,7 @@ public void testJsonString() {
assertEquals(json, toJson(priv));

priv = fromJson(json, IndicesPrivileges.class);
assertEquals("foo", priv.query()._custom().to(RoleTemplateScript.class).stored().id());
assertEquals("foo", priv.query()._custom().to(RoleTemplateScript.class).id());
}

// Array value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package co.elastic.clients.json;

import co.elastic.clients.elasticsearch._types.InlineScript;
import co.elastic.clients.elasticsearch._types.Script;
import co.elastic.clients.elasticsearch._types.SlicedScroll;
import co.elastic.clients.elasticsearch._types.mapping.Property;
import co.elastic.clients.elasticsearch._types.mapping.TextProperty;
Expand All @@ -28,6 +28,7 @@
import co.elastic.clients.elasticsearch.core.IndexRequest;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.indices.PutIndicesSettingsRequest;
import co.elastic.clients.elasticsearch.security.RoleTemplateScript;
import co.elastic.clients.testkit.ModelTestCase;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -123,7 +124,7 @@ public void testTypeWithParent() {

String json = "{\"source\": \"return doc;\"}";

InlineScript is = InlineScript.of(b -> b
Script is = Script.of(b -> b
.withJson(new StringReader(json))
);

Expand Down Expand Up @@ -170,5 +171,16 @@ public void testInternallyTaggedUnion() {
TextProperty tp = p.text();
assertEquals("lowercase", tp.fields().get("some_field").keyword().normalizer());
}

@Test
public void testExternalTaggedUnion() {

RoleTemplateScript withSource = RoleTemplateScript.of(j -> j.withJson(new StringReader("{\"source\": {\"match\": {\"category\": \"click\"}}}")));
assertTrue(withSource.source().isQueryObject());
RoleTemplateScript withStringSource = RoleTemplateScript.of(j -> j.withJson(new StringReader("{\"source\": \"string\"}")));
assertTrue(withStringSource.source().isQueryString());
RoleTemplateScript withStoredScript = RoleTemplateScript.of(j -> j.withJson(new StringReader("{\"id\": \"foo\"}")));
assertTrue(!withStoredScript.id().isEmpty());
}
}

0 comments on commit c430f6d

Please sign in to comment.