Skip to content

DeleteSpringProperty - glob / properties with children don't work as expected #582

@nmck257

Description

@nmck257

What version of OpenRewrite are you using?

I am using main

How are you running OpenRewrite?

unit tests

What is the smallest, simplest way to reproduce the problem?

    @Test
    void deleteParentProperty_properties() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie")),
          //language=properties
          properties(
            """
              some=value
              server.servlet.session.cookie.name=fred
              server.servlet.session.cookie.path=/cookie-monster
              other=value
              """,
            """
              some=value
              other=value
              """
          )
        );
    }

    @Test
    void deleteParentProperty_yaml() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie")),
          //language=yaml
          yaml(
            """
              some: value
              server:
                servlet:
                  session:
                    cookie:
                      name: fred
                      path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

    @Test
    void deleteParentProperty_yamlCoalesced() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie")),
          //language=yaml
          yaml(
            """
              some: value
              server.servlet.session.cookie.name: fred
              server.servlet.session.cookie.path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

    @Test
    void deleteParentPropertyViaGlob_properties() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie.*")),
          //language=properties
          properties(
            """
              some=value
              server.servlet.session.cookie.name=fred
              server.servlet.session.cookie.path=/cookie-monster
              other=value
              """,
            """
              some=value
              other=value
              """
          )
        );
    }

    @Test
    void deleteParentPropertyViaGlob_yaml() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie.*")),
          //language=yaml
          yaml(
            """
              some: value
              server:
                servlet:
                  session:
                    cookie:
                      name: fred
                      path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

    @Test
    void deleteParentPropertyViaGlob_yamlCoalesced() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie.*")),
          //language=yaml
          yaml(
            """
              some: value
              server.servlet.session.cookie.name: fred
              server.servlet.session.cookie.path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

What did you expect to see?

one of those two sets of tests (either using glob or not using glob) to pass, given that the recipe advertises glob support:

@Option(displayName = "Property key",
        description = "The property key to delete. Supports glob expressions",
        example = "management.endpoint.configprops.*")
    String propertyKey;

What did you see instead?

A mix of success and failure for both approaches:

  • fail: deleteParentProperty_properties
  • pass: deleteParentProperty_yaml
  • fail: deleteParentProperty_yamlCoalesced
  • pass: deleteParentPropertyViaGlob_properties
  • fail: deleteParentPropertyViaGlob_yaml
  • fail: deleteParentPropertyViaGlob_yamlCoalesced

What is the full stack trace of any errors you encountered?

no stack traces; failing test cases all failed with no changes

Are you interested in contributing a fix to OpenRewrite?

I think if we go fix #581, then for this issue we could mostly port the "targeting" logic over from ChangeSpringPropertyKey.
and similar to 581, I've got some time this week and will probably play with it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions