0

Are the Create new Gatling tests that have another object as required supposed to fail ? Or did I broke something ? Is it a bug ?

For example, this Test on docField fails (doctTemplate --many--> docFields), I'm guessing that it fails because docField requires the docTemplate object and the generated tests does not add that object. This is my test result:

================================================================================
2017-06-02 19:06:23                                         100s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=400    KO=95    )
> First unauthenticated request                            (OK=100    KO=0     )
> Authentication                                           (OK=100    KO=0     )
> Authenticated request                                    (OK=100    KO=0     )
> Get all docFields                                        (OK=100    KO=0     )
> Create new docField                                      (OK=0      KO=95    )
---- Errors --------------------------------------------------------------------
> status.find.is(201), but actually found 400                        95 (100.0%)

This is the class

public class DocField implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
@Column(name = "name", nullable = false)
private String name;

@NotNull
@Lob
@Column(name = "default_value", nullable = false)
private String defaultValue;

@ManyToOne(optional = false)
@NotNull
private DocTemplate docTemplate;

And this is the test scenario:

val scn = scenario("Test the DocField entity")
        .exec(http("First unauthenticated request")
        .get("/api/account")
        .headers(headers_http)
        .check(status.is(401))
        .check(headerRegex("Set-Cookie", "XSRF-TOKEN=(.*);[\\s]").saveAs("xsrf_token"))).exitHereIfFailed
        .pause(10)
        .exec(http("Authentication")
        .post("/api/authentication")
        .headers(headers_http_authenticated)
        .formParam("j_username", "admin")
        .formParam("j_password", "admin")
        .formParam("remember-me", "true")
        .formParam("submit", "Login")
        .check(headerRegex("Set-Cookie", "XSRF-TOKEN=(.*);[\\s]").saveAs("xsrf_token"))).exitHereIfFailed
        .pause(1)
        .exec(http("Authenticated request")
        .get("/api/account")
        .headers(headers_http_authenticated)
        .check(status.is(200)))
        .pause(10)
        .repeat(2) {
            exec(http("Get all docFields")
            .get("/api/doc-fields")
            .headers(headers_http_authenticated)
            .check(status.is(200)))
            .pause(10 seconds, 20 seconds)
            .exec(http("Create new docField")
            .post("/api/doc-fields")
            .headers(headers_http_authenticated)
            .body(StringBody("""{"id":null, "name":"SAMPLE_TEXT", "defaultValue":"SAMPLE_TEXT"}""")).asJSON
            .check(status.is(201))
            .check(headerRegex("Location", "(.*)").saveAs("new_docField_url"))).exitHereIfFailed
            .pause(10)
            .repeat(5) {
                exec(http("Get created docField")
                .get("${new_docField_url}")
                .headers(headers_http_authenticated))
                .pause(10)
            }
            .exec(http("Delete created docField")
            .delete("${new_docField_url}")
            .headers(headers_http_authenticated))
            .pause(10)
        }

I don't see any creation of DocTemplate, so the test fails. Doesn't jhipster supposed to generate the test so it passes right after code generation ? or did I broke it somehow ?

Andrew Brēza
  • 7,705
  • 3
  • 34
  • 40
Ernest
  • 962
  • 3
  • 12
  • 28

1 Answers1

1

I think you're right. The generated gatling tests are not totally perfect and can be improved.

But IMO, it's hard to code in the generator-jhipster, because you need to create here a DocTemplate before creating a DocField. What about if DocTemplate need another entity before beeing created ?

The generated gatling tests are simple and you need to change the code to adapt to your use cases. That's what I did in my projects.

Pascal Grimaud
  • 1,161
  • 1
  • 8
  • 9
  • I understand and agree, it can get very complicated in some cases. I was just checking how should the feature work. Then if this is the expected behaviour, shouldn't it be documented on the jhipster performance test section of the docs ? – Ernest Jun 05 '17 at 08:57
  • Yes we should improve our documentation. Do you want to contribute and make a PR to improve it ? – Pascal Grimaud Jun 05 '17 at 09:12
  • It would be an honor, though I have no experience on how to contribute, I would love to. How can I get started? – Ernest Jun 05 '17 at 12:31
  • Follow these steps: 1) fork this project: https://github.com/jhipster/jhipster.github.io 2) clone your fork project 3) then in your local project, create a branch 4) edit the page you want 5) verify your local changes* 6) add, commit and push your branch to your fork 7) then at https://github.com/jhipster/jhipster.github.io, it will propose you to pull request For verify your change, you have to install jekyll. Read the README https://github.com/jhipster/jhipster.github.io/blob/master/README.md I never manage to install Jekyll, the best way for me is to use Docker. – Pascal Grimaud Jun 05 '17 at 16:02
  • pgrimaud, I got an error while using docker, not sure where should I report it: `An error occurred while installing nokogiri (1.8.0), and Bundler cannot continue. Make sure that `gem install nokogiri -v '1.8.0'` succeeds before bundling.` – Ernest Jun 07 '17 at 14:35
  • Thanks for your PR. About Jekyll with Docker, I will have a look. – Pascal Grimaud Jun 07 '17 at 16:18