-
Notifications
You must be signed in to change notification settings - Fork 25.3k
[Rest Api Compatibility] Add transformation for simple text replaces #71118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pgomulka
merged 7 commits into
elastic:master
from
pgomulka:compat/textual_transformation
Apr 12, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5e511ba
[Rest Api Compatibility] Add transformation for simple text replaces
pgomulka f707d14
code style
pgomulka f7aa5b9
Merge remote-tracking branch 'upstream/master' into compat/textual_tr…
pgomulka ceaa4e8
javadoc
pgomulka 9fbf67f
code review followup
pgomulka a88970d
extarct two sublasses per keyword
pgomulka 5f6df12
flip human debug to false
pgomulka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
package org.elasticsearch.gradle.test.rest.transform; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
/** | ||
|
@@ -27,4 +28,12 @@ public interface RestTestTransformByParentObject extends RestTestTransform<Objec | |
default String requiredChildKey() { | ||
return null; | ||
} | ||
|
||
/** | ||
* @param child a node on which the transformation will be applied. | ||
* @return true if the transformation should be applied on child node, otherwise false. | ||
*/ | ||
default boolean matches(JsonNode child) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Javadoc please. |
||
return child.has(requiredChildKey()); | ||
} | ||
} |
This file contains hidden or 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
17 changes: 17 additions & 0 deletions
17
buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/transform/text/ReplaceIsFalse.java
This file contains hidden or 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,17 @@ | ||
/* | ||
* 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.test.rest.transform.text; | ||
|
||
import com.fasterxml.jackson.databind.node.TextNode; | ||
|
||
public class ReplaceIsFalse extends ReplaceTextual { | ||
public ReplaceIsFalse(String valueToBeReplaced, TextNode replacementNode) { | ||
super("is_false", valueToBeReplaced, replacementNode); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/transform/text/ReplaceIsTrue.java
This file contains hidden or 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,17 @@ | ||
/* | ||
* 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.test.rest.transform.text; | ||
|
||
import com.fasterxml.jackson.databind.node.TextNode; | ||
|
||
public class ReplaceIsTrue extends ReplaceTextual { | ||
public ReplaceIsTrue(String valueToBeReplaced, TextNode replacementNode) { | ||
super("is_true", valueToBeReplaced, replacementNode); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/transform/text/ReplaceTextual.java
This file contains hidden or 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,85 @@ | ||
/* | ||
* 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.test.rest.transform.text; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fasterxml.jackson.databind.node.TextNode; | ||
import org.elasticsearch.gradle.test.rest.transform.RestTestContext; | ||
import org.elasticsearch.gradle.test.rest.transform.RestTestTransformByParentObject; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.Internal; | ||
import org.gradle.api.tasks.Optional; | ||
|
||
/** | ||
* A transformation to replace the flat textual fields. | ||
*/ | ||
class ReplaceTextual implements RestTestTransformByParentObject { | ||
private final String keyToReplaceName; | ||
private final String valueToBeReplaced; | ||
private final TextNode replacementNode; | ||
private final String testName; | ||
|
||
ReplaceTextual(String keyToReplaceName, String valueToBeReplaced, TextNode replacementNode) { | ||
this.keyToReplaceName = keyToReplaceName; | ||
this.valueToBeReplaced = valueToBeReplaced; | ||
this.replacementNode = replacementNode; | ||
this.testName = null; | ||
} | ||
|
||
ReplaceTextual(String keyToReplaceName, String valueToBeReplaced, TextNode replacementNode, String testName) { | ||
this.keyToReplaceName = keyToReplaceName; | ||
this.valueToBeReplaced = valueToBeReplaced; | ||
this.replacementNode = replacementNode; | ||
this.testName = testName; | ||
} | ||
|
||
@Override | ||
@Internal | ||
public String getKeyToFind() { | ||
return keyToReplaceName; | ||
} | ||
|
||
@Override | ||
public String requiredChildKey() { | ||
return valueToBeReplaced; | ||
} | ||
|
||
@Override | ||
public boolean shouldApply(RestTestContext testContext) { | ||
return testName == null || testContext.getTestName().equals(testName); | ||
} | ||
|
||
@Override | ||
public void transformTest(ObjectNode matchParent) { | ||
matchParent.set(getKeyToFind(), replacementNode); | ||
} | ||
|
||
@Input | ||
public String getValueToBeReplaced() { | ||
return valueToBeReplaced; | ||
} | ||
|
||
@Input | ||
public JsonNode getReplacementNode() { | ||
return replacementNode; | ||
} | ||
|
||
@Input | ||
@Optional | ||
public String getTestName() { | ||
return testName; | ||
} | ||
|
||
@Override | ||
public boolean matches(JsonNode child) { | ||
return child.asText().equals(requiredChildKey()); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a Gradle test for these 2 to YamlRestCompatTestPluginFuncTest / "transform task executes and works as configured" ?
When updating these just add the task configuration to the build file, the thing you want to change to the test.yml. The test should fail and output the result. In the past I just copy/paste that output and ensure that the diff looks correct (e.g. the only thing that changed is what is expected).