Skip to content

Commit

Permalink
Modify tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Bescos Gascon <[email protected]>
  • Loading branch information
jbescos committed Nov 3, 2022
1 parent 899196c commit df582e8
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Payara Foundation and/or its affiliates.
*
* This program and the accompanying materials are made available under the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,27 @@ protected ContainerResponse getResponseContext(String requestUri, String accept,
return apply(requestBuilder.build());
}

protected void _test(String requestUri, String accept, Cookie... cookies)
protected void _test(int expectedStatus, String requestUri, String accept, Cookie... cookies)
throws ExecutionException, InterruptedException {
ContainerResponse response = getResponseContext(requestUri, accept, cookies);
assertEquals(expectedStatus, response.getStatus());
if (200 == expectedStatus) {
assertEquals("content", response.getEntity());
}
}

assertEquals("content", getResponseContext(requestUri, accept, cookies).getEntity());
protected void _test(String requestUri, String accept, Cookie... cookies)
throws ExecutionException, InterruptedException {
_test(200, requestUri, accept, cookies);
}

protected void _test(String requestUri, Cookie... cookies) throws ExecutionException, InterruptedException {
_test(requestUri, null, cookies);
_test(200, requestUri, null, cookies);
}

protected void _test(int expectedStatus, String requestUri, Cookie... cookies)
throws ExecutionException, InterruptedException {
_test(expectedStatus, requestUri, null, cookies);
}

public ApplicationHandler app() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public static class ResourceStringListEmpty {

@GET
public String doGetString(@CookieParam("args") List<BigDecimal> args) {
assertEquals(1, args.size());
assertEquals(null, args.get(0));
return "content";
}
}
Expand Down Expand Up @@ -157,10 +155,18 @@ public void testStringConstructorListGet() throws ExecutionException, Interrupte
}

@Test
public void testStringConstructorListEmptyGet() throws ExecutionException, InterruptedException {
public void testStringConstructorListWrongTypeGet() throws ExecutionException, InterruptedException {
initiateWebApplication(ResourceStringListEmpty.class);
// When parameters are wrong, status is not 200
// FIXME Why 400 instead of 404 like in other cases?. Investigate it.
_test(400, "/", "application/stringlist", new Cookie("args", ""));
}

_test("/", "application/stringlist", new Cookie("args", ""));
@Test
public void testStringConstructorListEmptyGet() throws ExecutionException, InterruptedException {
initiateWebApplication(ResourceStringListEmpty.class);
// When no parameters, the list is empty
_test("/");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -72,10 +72,6 @@ public static class ResourceStringListEmpty {

@GET
public String doGetString(@HeaderParam("args") List<BigDecimal> args) {
assertEquals(3, args.size());
assertEquals(null, args.get(0));
assertEquals(null, args.get(1));
assertEquals(null, args.get(2));
return "content";
}
}
Expand Down Expand Up @@ -173,17 +169,25 @@ public void testStringConstructorListGet() throws ExecutionException, Interrupte
}

@Test
public void testStringConstructorListEmptyGet() throws ExecutionException, InterruptedException {
public void testStringConstructorListWrongTypeGet() throws ExecutionException, InterruptedException {
initiateWebApplication(ResourceStringListEmpty.class);

assertEquals("content", apply(
// When parameters are wrong, status is not 200
// FIXME Why 400 instead of 404 like in other cases?. Investigate it.
assertEquals(400, apply(
RequestContextBuilder.from("/", "GET")
.accept("application/stringlist")
.header("args", "")
.header("args", "")
.header("args", "")
.build()
).getEntity());
).getStatus());
}

@Test
public void testStringConstructorListEmptyGet() throws ExecutionException, InterruptedException {
initiateWebApplication(ResourceStringListEmpty.class);
// When no parameters, the list is empty
_test("/");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -68,10 +68,6 @@ public String doGetString(@MatrixParam("args") List<BigDecimal> args) {
public static class ResourceStringListEmpty {
@GET
public String doGetString(@MatrixParam("args") List<BigDecimal> args) {
assertEquals(3, args.size());
assertEquals(null, args.get(0));
assertEquals(null, args.get(1));
assertEquals(null, args.get(2));
return "content";
}
}
Expand Down Expand Up @@ -150,10 +146,17 @@ public void testStringConstructorListGet() throws ExecutionException, Interrupte
}

@Test
public void testStringConstructorListEmptyGet() throws ExecutionException, InterruptedException {
public void testStringConstructorListWrognTypeGet() throws ExecutionException, InterruptedException {
initiateWebApplication(ResourceStringListEmpty.class);
// When parameters are wrong, status is not 200
_test(404, "/;args;args;args", "application/stringlist");
}

_test("/;args;args;args", "application/stringlist");
@Test
public void testStringConstructorListEmptyGet() throws ExecutionException, InterruptedException {
initiateWebApplication(ResourceStringListEmpty.class);
// When no parameters, the list is empty
_test("/");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -68,10 +68,6 @@ public String doGetString(@QueryParam("args") List<BigDecimal> args) {
public static class ResourceStringListEmpty {
@GET
public String doGetString(@QueryParam("args") List<BigDecimal> args) {
assertEquals(3, args.size());
assertEquals(null, args.get(0));
assertEquals(null, args.get(1));
assertEquals(null, args.get(2));
return "content";
}
}
Expand Down Expand Up @@ -162,17 +158,24 @@ public void testStringConstructorListGet() throws ExecutionException, Interrupte
}

@Test
public void testStringConstructorListEmptyGet() throws ExecutionException, InterruptedException {
public void testStringConstructorListEmptyWrongTypeGet() throws ExecutionException, InterruptedException {
initiateWebApplication(ResourceStringListEmpty.class);

_test("/?args&args&args", "application/stringlist");
// When parameters are wrong, status is not 200
_test(404, "/?args&args&args", "application/stringlist");
}

@Test
public void testStringConstructorNullGet() throws ExecutionException, InterruptedException {
initiateWebApplication(ResourceStringNull.class);
// When parameters are wrong, status is not 200
_test(404, "/?arg1=&arg2=", null);
}

_test("/?arg1=&arg2=");
@Test
public void testStringConstructorListEmptyGet() throws ExecutionException, InterruptedException {
initiateWebApplication(ResourceStringListEmpty.class);
// When no parameters, the list is empty
_test("/", "application/stringlist");
}

@Test
Expand Down Expand Up @@ -203,6 +206,13 @@ public void testStringConstructorListEmptyDefault() throws ExecutionException, I
_test("/");
}

@Test
public void testStringConstructorListEmpty() throws ExecutionException, InterruptedException {
initiateWebApplication(ResourceStringListEmptyDefault.class);
// When parameters are wrong, status is not 200
_test(404, "/?args=");
}

@Test
public void testStringConstructorListDefault() throws ExecutionException, InterruptedException {
initiateWebApplication(ResourceStringListDefault.class);
Expand Down

0 comments on commit df582e8

Please sign in to comment.