Skip to content
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

Reading and modifying text files through a helper class #4

Closed
shaburov opened this issue Feb 1, 2022 · 1 comment · Fixed by #11 or #16
Closed

Reading and modifying text files through a helper class #4

shaburov opened this issue Feb 1, 2022 · 1 comment · Fixed by #11 or #16
Assignees
Labels
enhancement New feature or request

Comments

@shaburov
Copy link
Member

shaburov commented Feb 1, 2022

Purpose: to replace certain test blocks through the fluent API.

Text file testNote.xml

<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>{note_body}</body>
</note>

TestFile class

@Getter
@Setter
@Accessors(chain = true, fluent = true)
public class NoteFile extends TestFile {

    public NoteFile() {
        super("testNote.xml");
    }

    @Replace("{note_body}")
    private String body;

}

Usage: API_CLI.addNote(new NoteFile().body("fooBar"));

@shaburov shaburov added the enhancement New feature or request label Feb 1, 2022
@shaburov shaburov self-assigned this Feb 1, 2022
@shaburov shaburov linked a pull request Feb 15, 2022 that will close this issue
@shaburov shaburov reopened this Feb 18, 2022
@shaburov
Copy link
Member Author

shaburov commented Feb 18, 2022

Template

  @TemplateSource(type = RESOURCE, path = "Notes.xml")
  public static final class Notes {

      @TemplateReplaceAll(regex = "\\[note.to]")
      private String to;
      @TemplateReplaceAll(regex = "replace_note_from")
      private String from;
      @TemplateReplaceAll(regex = "\\{note_body_content}")
      private String bodyContent;

  }
  • @TemplateSource.path - source file path
  • @TemplateSource.type - file / resource
  • @TemplateSource.charset - source file charset (UTF-8 by default)

Add TemplateSourceConverter for requests.
Register TemplateSourceConverter for @TemplateSource annotation

Usage

final Notes notes = new Notes().to("1").from("2").bodyContent("3");
CLIENT.apiMethodPostCall(notes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant