-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REST Compatible API] transformations for keys in do (#72823)
- Loading branch information
Showing
19 changed files
with
146 additions
and
1,032 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...c/main/java/org/elasticsearch/gradle/internal/test/rest/transform/do_/ReplaceKeyInDo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal.test.rest.transform.do_; // 'do' is a reserved word | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.elasticsearch.gradle.internal.test.rest.transform.ReplaceByKey; | ||
import org.gradle.api.tasks.Internal; | ||
|
||
/** | ||
* A transformation to replace the key in a do. For example, change from "do":{"some-thing":{}} to "do":{"some-other-thing":{}} | ||
*/ | ||
public class ReplaceKeyInDo extends ReplaceByKey { | ||
|
||
public ReplaceKeyInDo(String replaceKey, String newKeyName, String testName) { | ||
super(replaceKey, newKeyName, null, testName); | ||
} | ||
|
||
@Override | ||
@Internal | ||
public String getKeyToFind() { | ||
return "do"; | ||
} | ||
|
||
@Override | ||
public void transformTest(ObjectNode doParent) { | ||
ObjectNode doNode = (ObjectNode) doParent.get(getKeyToFind()); | ||
JsonNode previousValue = doNode.get(requiredChildKey()); | ||
doNode.remove(requiredChildKey()); | ||
doNode.set(getNewChildKey(), previousValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...t/java/org/elasticsearch/gradle/internal/test/rest/transform/do_/ReplaceKeyInDoTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal.test.rest.transform.do_; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.elasticsearch.gradle.internal.test.rest.transform.AssertObjectNodes; | ||
import org.elasticsearch.gradle.internal.test.rest.transform.TransformTests; | ||
import org.junit.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class ReplaceKeyInDoTests extends TransformTests { | ||
|
||
@Test | ||
public void testReplaceKeyInDo() throws Exception { | ||
|
||
String test_original = "/rest/transform/do/replace_key_in_do_original.yml"; | ||
List<ObjectNode> tests = getTests(test_original); | ||
|
||
String test_transformed = "/rest/transform/do/replace_key_in_do_transformed.yml"; | ||
List<ObjectNode> expectedTransformation = getTests(test_transformed); | ||
|
||
List<ObjectNode> transformedTests = transformTests( | ||
tests, | ||
Collections.singletonList(new ReplaceKeyInDo("do.key.to_replace", "do.key.replaced", null)) | ||
); | ||
|
||
AssertObjectNodes.areEqual(transformedTests, expectedTransformation); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
buildSrc/src/test/resources/rest/transform/do/replace_key_in_do_original.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
"First test": | ||
|
||
- do: | ||
do.key.to_replace: | ||
something_else.is: true | ||
|
||
- do: | ||
and: again | ||
|
||
do.key.to_replace: | ||
some_other.thing.is: true | ||
|
||
- length: { length.key: 1 } | ||
- match: { _shards.total: 2 } | ||
- match: { _shards.successful: 2 } |
16 changes: 16 additions & 0 deletions
16
buildSrc/src/test/resources/rest/transform/do/replace_key_in_do_transformed.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
"First test": | ||
|
||
- do: | ||
do.key.replaced: | ||
something_else.is: true | ||
|
||
- do: | ||
and: again | ||
|
||
do.key.replaced: | ||
some_other.thing.is: true | ||
|
||
- length: { length.key: 1 } | ||
- match: { _shards.total: 2 } | ||
- match: { _shards.successful: 2 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 0 additions & 80 deletions
80
.../qa/rest/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/10_basic_compat.yml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.