keepcosmos / beanmother

A library for setting up Java objects as test data.
http://beanmother.io
Apache License 2.0
115 stars 23 forks source link

Query #18

Closed njchandu closed 6 years ago

njchandu commented 6 years ago
  1. Is it possible to create a bean object for an object which is not at the root level? Ex:

    my:
    book: &book
    id: ${sequence.number}
    title: ${faker.book.title}
    language: en
    publishedAt: ${faker.date.between('2000-01-01', '2010-01-01')}
    
    author:
    id: ${sequence.number}
    works:
      - <<: *book
      - <<: *book
      - <<: *book
    somethingElse: bla
  2. Is it possible to create a bean for a specific object in a specific file if there are duplicate yaml objects. Ex:

    first.yml
    book: &book
    id: 1
    title: ${faker.book.title}
    language: en
    publishedAt: ${faker.date.between('2000-01-01', '2010-01-01')}

    and

    second.yml
    book: &book
    id: 2
    title: ${faker.book.title}
    language: en
    publishedAt: ${faker.date.between('2000-01-01', '2010-01-01')}
keepcosmos commented 6 years ago
  1. Yes, it's possible just like example.

  2. No, I recommend using different key name. But you can if you create your own beanmother object https://github.com/keepcosmos/beanmother#customization

njchandu commented 6 years ago

@keepcosmos My bad. 1) I noticed my example was not correct. I updated it now.

my:
  book: &book
    id: ${sequence.number}
    title: ${faker.book.title}
    language: en
    publishedAt: ${faker.date.between('2000-01-01', '2010-01-01')}

  author:
    id: ${sequence.number}
    works:
      - <<: *book
      - <<: *book
      - <<: *book
    somethingElse: bla

Here the root node is my, is it possible to map object for book and author in this case? Apologies if the query is redundant.

keepcosmos commented 6 years ago

It's not possible. key must be a root :), is there any usecase you want?

njchandu commented 6 years ago

@keepcosmos I just realised that doesn't make sense. :) thanks for responding