Signed-off-by: Pekka Helenius <fincer89@hotmail.com>v0.0.4-alpha
@ -0,0 +1,33 @@ | |||
// Pekka Helenius <fincer89@hotmail.com>, Fjordtek 2020 | |||
package com.fjordtek.bookstore.web.rest.endpoint; | |||
import org.junit.Test; | |||
import org.junit.jupiter.api.MethodOrderer.Alphanumeric; | |||
import org.junit.jupiter.api.TestMethodOrder; | |||
import org.springframework.security.test.context.support.WithUserDetails; | |||
import com.fjordtek.bookstore.web.BookStoreTestWebContextBuilder; | |||
/** | |||
* | |||
* TODO: N/A | |||
* | |||
* @author Pekka Helenius | |||
*/ | |||
@TestMethodOrder(Alphanumeric.class) | |||
public class IndexTest extends BookStoreTestWebContextBuilder { | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testA_getIndexPageExpectRedirectAsAdminUser() throws Exception { | |||
loadPageGet(restApiBaseUrl, 302); | |||
} | |||
@Test | |||
public void testB_getIndexPageExpectUnauthorizedAsNologin() throws Exception { | |||
loadPageGet(restApiBaseUrl, 401); | |||
} | |||
} |
@ -0,0 +1,107 @@ | |||
// Pekka Helenius <fincer89@hotmail.com>, Fjordtek 2020 | |||
package com.fjordtek.bookstore.web.rest.endpoint; | |||
import org.junit.Test; | |||
import org.springframework.http.MediaType; | |||
import org.springframework.security.test.context.support.WithUserDetails; | |||
import com.fjordtek.bookstore.web.BookStoreTestWebContextBuilder; | |||
/** | |||
* | |||
* TODO: N/A | |||
* | |||
* @author Pekka Helenius | |||
*/ | |||
public class RestAddTest extends BookStoreTestWebContextBuilder { | |||
@Test | |||
@WithUserDetails("salesmanager") | |||
public void testA_postAddBookExpectForbiddenAsMarketingUser() throws Exception { | |||
loadPagePost( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.books"), 403, | |||
MediaType.APPLICATION_JSON, | |||
"{\"title\":\"Halo: The Flood\"," + | |||
"\"year\":2003," + | |||
"\"isbn\":\"0345459-210\"," + | |||
"\"price\":24.99," + | |||
"\"category\":{\"name\":\"sCi-fI\"}," + | |||
"\"author\":{\"lastname\":\"Dietz\"}}" | |||
); | |||
} | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testB_postAddBookWithCategoryWithAuthorAsAdminUser() throws Exception { | |||
loadPagePost( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.books"), 200, | |||
MediaType.APPLICATION_JSON, | |||
"{\"title\":\"Halo: The Flood\"," + | |||
"\"year\":2003," + | |||
"\"isbn\":\"0345459-210\"," + | |||
"\"price\":24.99," + | |||
"\"category\":{\"name\":\"sCi-fI\"}," + | |||
"\"author\":{\"lastname\":\"Dietz\"}}" | |||
); | |||
} | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testC_postAddBookWithoutCategoryWithAuthorAsAdminUser() throws Exception { | |||
loadPagePost( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.books"), 200, | |||
MediaType.APPLICATION_JSON, | |||
"{\"title\":\"Mass Effect: Retribution\"," + | |||
"\"year\":2010," + | |||
"\"isbn\":\"0345520-722\"," + | |||
"\"price\":29.90," + | |||
// "\"category\":{\"name\":\"Sci-Fi\"}," + | |||
"\"author\":{\"firstname\":\"Drew\",\"lastname\":\"Karpyshyn\"}}" | |||
); | |||
} | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testD_postAddAuthorAsAdminUser() throws Exception { | |||
loadPagePost( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.authors"), 201, | |||
MediaType.APPLICATION_JSON, | |||
"{\"firstname\":\"Food\"," + | |||
"\"lastname\":\"Carter\"}" | |||
); | |||
} | |||
@Test | |||
@WithUserDetails("helpdesk") | |||
public void testE_postAddAuthorExpectForbiddenAsHelpdeskUser() throws Exception { | |||
loadPagePost( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.authors"), 403, | |||
MediaType.APPLICATION_JSON, | |||
"{\"firstname\":\"Jessica\"," + | |||
"\"lastname\":\"Retina\"}" | |||
); | |||
} | |||
@Test | |||
@WithUserDetails("helpdesk") | |||
public void testF_postAddRoleExpectForbiddenAsHelpdeskUser() throws Exception { | |||
loadPagePost( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.roles"), 403, | |||
MediaType.APPLICATION_JSON, | |||
"{\"name\":\"SUPERADMIN\"}" | |||
); | |||
} | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testG_postAddRoleAsAdminUser() throws Exception { | |||
loadPagePost( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.roles"), 201, | |||
MediaType.APPLICATION_JSON, | |||
"{\"name\":\"ROOT\"}" | |||
); | |||
} | |||
} |
@ -0,0 +1,44 @@ | |||
// Pekka Helenius <fincer89@hotmail.com>, Fjordtek 2020 | |||
package com.fjordtek.bookstore.web.rest.endpoint; | |||
import org.junit.Test; | |||
import org.springframework.security.test.context.support.WithUserDetails; | |||
import com.fjordtek.bookstore.web.BookStoreTestWebContextBuilder; | |||
/** | |||
* | |||
* TODO: N/A | |||
* | |||
* @author Pekka Helenius | |||
*/ | |||
public class RestDeleteTest extends BookStoreTestWebContextBuilder { | |||
@Test | |||
@WithUserDetails("user") | |||
public void testA_deleteExistingBookExpectForbiddenAsNormalUser() throws Exception { | |||
loadPageDelete( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.books") + "/2", 403 | |||
); | |||
} | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testB_deleteExistingBookAsAdminUser() throws Exception { | |||
loadPageDelete( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.books") + "/2", 204 | |||
); | |||
} | |||
/* | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testC_deleteExistingUserRoleAsAdminUser() throws Exception { | |||
// | |||
loadPageDelete( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.userroles") + "/[user_id: 3, role_id: 4]", 204 | |||
); | |||
} | |||
*/ | |||
} |
@ -0,0 +1,49 @@ | |||
// Pekka Helenius <fincer89@hotmail.com>, Fjordtek 2020 | |||
package com.fjordtek.bookstore.web.rest.endpoint; | |||
import org.junit.Test; | |||
import org.junit.jupiter.api.MethodOrderer.Alphanumeric; | |||
import org.junit.jupiter.api.TestMethodOrder; | |||
import org.springframework.http.MediaType; | |||
import org.springframework.security.test.context.support.WithUserDetails; | |||
import com.fjordtek.bookstore.web.BookStoreTestWebContextBuilder; | |||
/** | |||
* | |||
* TODO: N/A | |||
* | |||
* @author Pekka Helenius | |||
*/ | |||
@TestMethodOrder(Alphanumeric.class) | |||
public class RestEditTest extends BookStoreTestWebContextBuilder { | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testA_putBookEditAsAdminUser() throws Exception { | |||
loadPagePut( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.books") + "/2", 200, | |||
MediaType.APPLICATION_JSON, | |||
"{\"title\":\"The Witcher: Blood of Elves\"," + | |||
"\"year\":1999," + | |||
"\"isbn\":\"3213221-3\"," + | |||
"\"price\":22.49}" | |||
); | |||
} | |||
@Test | |||
@WithUserDetails("user") | |||
public void testB_putBookEditExpectForbiddenAsNormalUser() throws Exception { | |||
loadPagePut( | |||
restApiBaseUrl + env.getProperty("page.url.restapi.books") + "/2", 403, | |||
MediaType.APPLICATION_JSON, | |||
"{\"title\":\"Root flag captured backdoor H4X3DV4LU3!!\"," + | |||
"\"year\":1999," + | |||
"\"isbn\":\"8919312-7\"," + | |||
"\"price\":9950.49}" | |||
); | |||
} | |||
} |
@ -0,0 +1,86 @@ | |||
// Pekka Helenius <fincer89@hotmail.com>, Fjordtek 2020 | |||
package com.fjordtek.bookstore.web.rest.endpoint; | |||
import org.junit.Test; | |||
import org.junit.jupiter.api.MethodOrderer.Alphanumeric; | |||
import org.junit.jupiter.api.TestMethodOrder; | |||
import org.springframework.security.test.context.support.WithUserDetails; | |||
import com.fjordtek.bookstore.web.BookStoreTestWebContextBuilder; | |||
/** | |||
* | |||
* TODO: N/A | |||
* | |||
* @author Pekka Helenius | |||
*/ | |||
@TestMethodOrder(Alphanumeric.class) | |||
public class RootUriTests extends BookStoreTestWebContextBuilder { | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testA_getBookListPageAsAdminUser() throws Exception { | |||
loadPageGet(restApiBaseUrl + env.getProperty("page.url.restapi.books"), 200); | |||
} | |||
@Test | |||
@WithUserDetails("user") | |||
public void testB_getBookListPageExpectForbiddenAsNormalUser() throws Exception { | |||
loadPageGet(restApiBaseUrl + env.getProperty("page.url.restapi.books"), 403); | |||
} | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testC_getAuthorsPageAsAdminUser() throws Exception { | |||
loadPageGet(restApiBaseUrl + env.getProperty("page.url.restapi.authors"), 200); | |||
} | |||
@Test | |||
public void testD_getAuthorsPageExpectUnauthorizedAsNologin() throws Exception { | |||
loadPageGet(restApiBaseUrl + env.getProperty("page.url.restapi.authors"), 401); | |||
} | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testE_getCategoriesPageAsAdminUser() throws Exception { | |||
loadPageGet(restApiBaseUrl + env.getProperty("page.url.restapi.categories"), 200); | |||
} | |||
@Test | |||
public void testF_getCategoriesPageExpectUnauthorizedAsNologin() throws Exception { | |||
loadPageGet(restApiBaseUrl + env.getProperty("page.url.restapi.categories"), 401); | |||
} | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testG_getUsersPageAsAdminUser() throws Exception { | |||
loadPageGet(restApiBaseUrl + env.getProperty("page.url.restapi.users"), 200); | |||
} | |||
@Test | |||
@WithUserDetails("salesmanager") | |||
public void testH_getUsersPageExpectForbiddenAsMarketingUser() throws Exception { | |||
loadPageGet(restApiBaseUrl + env.getProperty("page.url.restapi.users"), 403); | |||
} | |||
@Test | |||
@WithUserDetails("admin") | |||
public void testI_getRolesPageAsAdminUser() throws Exception { | |||
loadPageGet(restApiBaseUrl + env.getProperty("page.url.restapi.roles"), 200); | |||
} | |||
@Test | |||
@WithUserDetails("user") | |||
public void testJ_getRolesPageExpectForbiddenAsNormalUser() throws Exception { | |||
loadPageGet(restApiBaseUrl + env.getProperty("page.url.restapi.roles"), 403); | |||
} | |||
} |