From 77bab3a554dfb2651d8ca1b822d7db3fe491a6c8 Mon Sep 17 00:00:00 2001
From: SAUVE Jean-Luc <68426990+SauveJeanLuc@users.noreply.github.com>
Date: Tue, 15 Jun 2021 14:24:21 +0200
Subject: [PATCH 1/5] Added Contribution section in README
---
README.md | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/README.md b/README.md
index 9bfe318d53..4ff94d8838 100755
--- a/README.md
+++ b/README.md
@@ -37,6 +37,17 @@ If this is your first time using Github, review http://help.github.com to learn
You can also download the zip file containing the code from https://github.com/shopizer-ecommerce/shopizer
+## Contributing
+
+Contributions are always welcome😁!
+
+- Fork the Project🍴
+- Make Changes
+- Push your commits to the forked repo
+- Make a Pull Request
+- Kindly wait for it to be merged
+- Buy yourself a ☕ if it's merged🎉
+
To build the application:
-------------------
From the command line:
From 6eb57bd03322f6d4e8b188d8db946557a6a68987 Mon Sep 17 00:00:00 2001
From: JustFlavi <90612115+JustFlavi@users.noreply.github.com>
Date: Wed, 15 Sep 2021 17:33:32 +0200
Subject: [PATCH 2/5] fix admin user renaming issues: * 'Imposible to save a
user if user name is changed #634' * 'Redirect is not working #635'
---
sm-shop/pom.xml | 6 +
.../admin/controller/user/UserController.java | 4 +-
.../admin/user/UsersIntegrationTest.java | 148 ++++++++++++++++++
3 files changed, 156 insertions(+), 2 deletions(-)
create mode 100644 sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/user/UsersIntegrationTest.java
diff --git a/sm-shop/pom.xml b/sm-shop/pom.xml
index 11b322dc32..8da3488ab2 100755
--- a/sm-shop/pom.xml
+++ b/sm-shop/pom.xml
@@ -169,6 +169,12 @@
test
+
+ org.springframework.security
+ spring-security-test
+ test
+
+
org.apache.commons
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/user/UserController.java b/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/user/UserController.java
index 7e8295bde9..e4ecebffe9 100755
--- a/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/user/UserController.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/user/UserController.java
@@ -489,9 +489,9 @@ public String saveUser(@Valid @ModelAttribute("user") User user, BindingResult r
//edit mode, need to get original user important information
if(user.getId()!=null) {
- dbUser = userService.getByUserName(user.getAdminName());
+ dbUser = userService.getById(user.getId());
if(dbUser==null) {
- return "redirect:///admin/users/displayUser.html";
+ return "redirect:/admin/users/displayUser.html";
}
}
diff --git a/sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/user/UsersIntegrationTest.java b/sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/user/UsersIntegrationTest.java
new file mode 100644
index 0000000000..c3bddfb0c0
--- /dev/null
+++ b/sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/user/UsersIntegrationTest.java
@@ -0,0 +1,148 @@
+package com.salesmanager.test.shop.integration.admin.user;
+
+import com.salesmanager.core.business.exception.ServiceException;
+import com.salesmanager.core.business.repositories.user.UserRepository;
+import com.salesmanager.core.business.services.merchant.MerchantStoreService;
+import com.salesmanager.core.business.services.reference.language.LanguageService;
+import com.salesmanager.core.business.services.system.EmailService;
+import com.salesmanager.core.model.merchant.MerchantStore;
+import com.salesmanager.core.model.user.User;
+import com.salesmanager.shop.admin.controller.ControllerConstants;
+import com.salesmanager.shop.application.ShopApplication;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.MediaType;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.ResultActions;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.context.WebApplicationContext;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+/**
+ * Contains tests targeting {@link com.salesmanager.shop.admin.controller.user.UserController}
+ */
+@SpringBootTest(classes = ShopApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@RunWith(SpringRunner.class)
+public class UsersIntegrationTest {
+
+ /** form param name for users 'adminName' */
+ private static final String PARAM_ADMIN_NAME = "adminName";
+
+ /** users for storing a test user */
+ @Autowired
+ private UserRepository userRepository;
+
+ /** used to retrieve an existing merchant (which is a mandatory field for users) */
+ @Autowired
+ private MerchantStoreService merchantService;
+
+ /** used to retrieve an existing Language instance */
+ @Autowired
+ private LanguageService languageService;
+
+ private MockMvc mvc;
+
+ @Autowired
+ private WebApplicationContext context;
+
+ /** in this test, we do not want to send real emails by tested controller */
+ @MockBean
+ private EmailService emailService;
+
+ @Before
+ public void setup() {
+ mvc = MockMvcBuilders
+ .webAppContextSetup(context)
+ .build();
+ }
+
+ @Test
+ @WithMockUser(roles = {"AUTH"})
+ public void renameUser() throws Exception {
+ // given a user in DB
+ User existingUser = createMinimalUser();
+ userRepository.save(existingUser);
+
+ // when we want to change users 'adminName'
+ Map requestParams = toRequestParams(existingUser);
+ String newName = "someNewName";
+ requestParams.put(PARAM_ADMIN_NAME, newName);
+ ResultActions resultActions = callSaveUserEndpoint(requestParams);
+
+ // then the correct view is expected without any error
+ resultActions
+ .andExpect(status().isOk())
+ .andExpect(view().name(ControllerConstants.Tiles.User.profile))
+ .andExpect(model().hasNoErrors());
+ // and the new 'adminName' is written to DB
+ User actualUser = userRepository.findOne(existingUser.getId());
+ assertThat(actualUser.getAdminName()).isEqualTo(newName);
+ }
+
+ /**
+ * Calls the endpoint for saving a user with the given request parameters
+ * @param requestParams the given request parameters
+ * @return the mockMvc ResultActions
+ * @throws Exception in case the call could not be performed
+ */
+ private ResultActions callSaveUserEndpoint(Map requestParams) throws Exception {
+ return mvc.perform(post("/admin/users/save.html")
+ .params(toMultiMap(requestParams))
+ .contentType(MediaType.APPLICATION_FORM_URLENCODED));
+ }
+
+ private MultiValueMap toMultiMap(Map requestParams) {
+ MultiValueMap mapResult = new LinkedMultiValueMap<>();
+ for (Map.Entry paramEntry : requestParams.entrySet()) {
+ mapResult.add(paramEntry.getKey(), paramEntry.getValue());
+ }
+ return mapResult;
+ }
+
+ private Map toRequestParams(User user) {
+ Map map = new HashMap<>();
+ map.put("id", user.getId().toString());
+ map.put(PARAM_ADMIN_NAME, user.getAdminName());
+ map.put("merchantStore.id", user.getMerchantStore().getId().toString());
+ map.put("adminEmail", user.getAdminEmail());
+ map.put("adminPassword", user.getAdminPassword());
+ map.put("defaultLanguage.id", user.getDefaultLanguage().getId().toString());
+ map.put("question1", user.getQuestion1());
+ map.put("question2", user.getQuestion2());
+ map.put("question3", user.getQuestion3());
+ map.put("answer1", user.getAnswer1());
+ map.put("answer2", user.getAnswer2());
+ map.put("answer3", user.getAnswer3());
+ return map;
+ }
+
+ private User createMinimalUser() throws ServiceException {
+ User user = new User("name", "password", "email@shopizer.no");
+ user.setMerchantStore(merchantService.getByCode(MerchantStore.DEFAULT_STORE));
+ user.setDefaultLanguage(languageService.defaultLanguage());
+ user.setQuestion1("q1");
+ user.setAnswer1("a1");
+ user.setQuestion2("q2");
+ user.setAnswer2("a2");
+ user.setQuestion3("q3");
+ user.setAnswer3("a3");
+ return user;
+ }
+}
+
From 4c5205f83aef13ecd52227320c5449234991be4a Mon Sep 17 00:00:00 2001
From: JustFlavi <90612115+JustFlavi@users.noreply.github.com>
Date: Fri, 8 Oct 2021 13:00:43 +0200
Subject: [PATCH 3/5] admin - favor HTTP status 400 over 500 for specific
exception types
---
sm-shop/pom.xml | 6 +
.../error/AdminErrorController.java | 82 ++++++++-----
.../ProductKeywordsIntegrationTest.java | 115 ++++++++++++++++++
3 files changed, 170 insertions(+), 33 deletions(-)
create mode 100644 sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/products/ProductKeywordsIntegrationTest.java
diff --git a/sm-shop/pom.xml b/sm-shop/pom.xml
index 11b322dc32..8da3488ab2 100755
--- a/sm-shop/pom.xml
+++ b/sm-shop/pom.xml
@@ -169,6 +169,12 @@
test
+
+ org.springframework.security
+ spring-security-test
+ test
+
+
org.apache.commons
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/store/controller/error/AdminErrorController.java b/sm-shop/src/main/java/com/salesmanager/shop/store/controller/error/AdminErrorController.java
index df81f1a97b..721a26649f 100644
--- a/sm-shop/src/main/java/com/salesmanager/shop/store/controller/error/AdminErrorController.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/store/controller/error/AdminErrorController.java
@@ -6,87 +6,103 @@
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.TypeMismatchException;
import org.springframework.http.HttpStatus;
+import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.ui.Model;
+import org.springframework.validation.BindException;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.MissingServletRequestParameterException;
+import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.multipart.support.MissingServletRequestPartException;
import org.springframework.web.servlet.ModelAndView;
@ControllerAdvice("com.salesmanager.shop.admin")
public class AdminErrorController {
-
-
+
+
private static final Logger LOGGER = LoggerFactory.getLogger(AdminErrorController.class);
-
+ private static final String LOG_ERROR_MESSAGE = "Error page controller";
+
+ /**
+ * Handles specific Spring MVC internal exceptions as HTTP status 400
+ * @param ex the actual exception
+ * @return an error model
+ */
+ // list of "BAD REQUEST"-related exceptions are taken over from Springs DefaultHandlerExceptionResolver
+ @ExceptionHandler({
+ MissingServletRequestParameterException.class,
+ ServletRequestBindingException.class,
+ TypeMismatchException.class,
+ HttpMessageNotReadableException.class,
+ MethodArgumentNotValidException.class,
+ MissingServletRequestPartException.class,
+ BindException.class
+ })
+ @ResponseStatus(value = HttpStatus.BAD_REQUEST)
+ @Produces({MediaType.APPLICATION_JSON})
+ public ModelAndView handleBadRequest(Exception ex) {
+
+ LOGGER.error(LOG_ERROR_MESSAGE,ex);
+ return createGenericErrorModel(ex);
+
+ }
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@Produces({MediaType.APPLICATION_JSON})
public ModelAndView handleException(Exception ex) {
- LOGGER.error("Error page controller",ex);
+ LOGGER.error(LOG_ERROR_MESSAGE,ex);
- ModelAndView model = null;
+ ModelAndView model;
if(ex instanceof AccessDeniedException) {
model = new ModelAndView("error/access_denied");
} else {
-
- model = new ModelAndView("error/generic_error");
- model.addObject("stackError", ExceptionUtils.getStackTrace(ex));
- model.addObject("errMsg", ex.getMessage());
-
+
+ model = createGenericErrorModel(ex);
+
}
return model;
}
-
-
@ExceptionHandler(RuntimeException.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@Produces({MediaType.APPLICATION_JSON})
public ModelAndView handleRuntimeException(Exception ex) {
- LOGGER.error("Error page controller",ex);
+ LOGGER.error(LOG_ERROR_MESSAGE,ex);
- ModelAndView model = null;
+ return createGenericErrorModel(ex);
-
- model = new ModelAndView("error/generic_error");
- model.addObject("stackError", ExceptionUtils.getStackTrace(ex));
- model.addObject("errMsg", ex.getMessage());
-
-
-
-
- return model;
-
}
/**
* Generic exception catch allpage
- * @param ex
+ * @param model
* @return
*/
@RequestMapping(value="/error", method=RequestMethod.GET)
public ModelAndView handleCatchAllException(Model model) {
-
- ModelAndView modelAndView = null;
+ return new ModelAndView("error/generic_error");
-
- modelAndView = new ModelAndView("error/generic_error");
-
- return modelAndView;
-
}
-
+ private ModelAndView createGenericErrorModel(Exception ex) {
+ ModelAndView model = new ModelAndView("error/generic_error");
+ model.addObject("stackError", ExceptionUtils.getStackTrace(ex));
+ model.addObject("errMsg", ex.getMessage());
+ return model;
+ }
}
diff --git a/sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/products/ProductKeywordsIntegrationTest.java b/sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/products/ProductKeywordsIntegrationTest.java
new file mode 100644
index 0000000000..78cf490861
--- /dev/null
+++ b/sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/products/ProductKeywordsIntegrationTest.java
@@ -0,0 +1,115 @@
+package com.salesmanager.test.shop.integration.admin.products;
+
+import com.salesmanager.core.business.exception.ServiceException;
+import com.salesmanager.core.business.repositories.catalog.product.ProductRepository;
+import com.salesmanager.core.business.services.merchant.MerchantStoreService;
+import com.salesmanager.core.model.catalog.product.Product;
+import com.salesmanager.shop.admin.controller.ControllerConstants;
+import com.salesmanager.shop.application.ShopApplication;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.ResultActions;
+import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+import static com.salesmanager.core.model.merchant.MerchantStore.DEFAULT_STORE;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+/**
+ * Contains tests targeting {@link com.salesmanager.shop.admin.controller.products.ProductKeywordsController}
+ */
+@SpringBootTest(classes = ShopApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@RunWith(SpringRunner.class)
+public class ProductKeywordsIntegrationTest {
+
+ private static final String QUERY_PARAM_ID = "id";
+
+ private MockMvc mvc;
+
+ @Autowired
+ private WebApplicationContext context;
+
+ /**
+ * used for storing a test product
+ */
+ @Autowired
+ private ProductRepository productRepository;
+
+ /**
+ * used to retrieve an existing merchant (which is a mandatory field for product)
+ */
+ @Autowired
+ private MerchantStoreService merchantService;
+
+ @Before
+ public void setup() {
+ mvc = MockMvcBuilders
+ .webAppContextSetup(context)
+ .build();
+ }
+
+ @Test
+ @WithMockUser(roles = {"PRODUCTS"})
+ public void displayKeywordsReturnsHttp400ForMissingID() throws Exception {
+ // when endpoint is called without any ID
+ ResultActions resultActions = callDisplayKeywordsEndpoint(null);
+
+ // then HTTP status 400 is expected
+ resultActions.andExpect(status().isBadRequest());
+ }
+
+ @Test
+ @WithMockUser(roles = {"PRODUCTS"})
+ public void displayKeywordsReturnsHttp400ForInvalidID() throws Exception {
+ // when endpoint is called with an invalid ID
+ String queryParam = "notANumber";
+ ResultActions resultActions = callDisplayKeywordsEndpoint(queryParam);
+
+ // then HTTP status 400 is expected
+ resultActions.andExpect(status().isBadRequest());
+ }
+
+ @Test
+ @WithMockUser(roles = {"PRODUCTS"})
+ public void displayKeywordsForExistingID() throws Exception {
+ // given a product in DB
+ int givenProductID = 1;
+ Product existingProduct = createMinimalProduct(givenProductID);
+ productRepository.save(existingProduct);
+
+ // when endpoint is called with an existing product ID
+ String queryParam = "" + givenProductID;
+ ResultActions resultActions = callDisplayKeywordsEndpoint(queryParam);
+
+ // then the correct view is expected without any error
+ resultActions
+ .andExpect(status().isOk())
+ .andExpect(view().name(ControllerConstants.Tiles.Product.productKeywords))
+ .andExpect(model().hasNoErrors());
+ }
+
+ private ResultActions callDisplayKeywordsEndpoint(String queryParam) throws Exception {
+ MockHttpServletRequestBuilder requestBuilder = get("/admin/products/product/keywords.html");
+ if (queryParam != null) {
+ requestBuilder.queryParam(QUERY_PARAM_ID, queryParam);
+ }
+ return mvc.perform(requestBuilder);
+ }
+
+ private Product createMinimalProduct(int id) throws ServiceException {
+ Product product = new Product();
+ product.setId((long) id);
+ product.setMerchantStore(merchantService.getByCode(DEFAULT_STORE));
+ return product;
+ }
+}
From 70a0fccf7ee47207408d69bb6698a63fb26ff870 Mon Sep 17 00:00:00 2001
From: JustFlavi <90612115+JustFlavi@users.noreply.github.com>
Date: Fri, 15 Oct 2021 15:17:00 +0200
Subject: [PATCH 4/5] admin - fix IllegalStateException when calling editStore
without mandatory 'id' parameter
@ModelAttribute for parameter types not having a default constructor is always dirty from technical perspective,
since Spring tries to create that property type in case the corresponding parameter is not provided.
Besides that, the "id" model attribute is never consumed.
Basically, the endpoint just wants to say, that the id parameter is mandatory, so it should result in an appropriate error.
---
sm-shop/pom.xml | 6 ++
.../admin/controller/ControllerConstants.java | 1 +
.../merchant/MerchantStoreController.java | 5 +-
.../MerchantStoreIntegrationTest.java | 85 +++++++++++++++++++
4 files changed, 95 insertions(+), 2 deletions(-)
create mode 100644 sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/merchant/MerchantStoreIntegrationTest.java
diff --git a/sm-shop/pom.xml b/sm-shop/pom.xml
index 11b322dc32..8da3488ab2 100755
--- a/sm-shop/pom.xml
+++ b/sm-shop/pom.xml
@@ -169,6 +169,12 @@
test
+
+ org.springframework.security
+ spring-security-test
+ test
+
+
org.apache.commons
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/ControllerConstants.java b/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/ControllerConstants.java
index 552c198b83..58c304ff14 100755
--- a/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/ControllerConstants.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/ControllerConstants.java
@@ -65,6 +65,7 @@ interface User{
interface Store{
final String stores="admin-stores";
+ final String store="admin-store";
}
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/merchant/MerchantStoreController.java b/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/merchant/MerchantStoreController.java
index acdfa45df4..0e2837c079 100755
--- a/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/merchant/MerchantStoreController.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/admin/controller/merchant/MerchantStoreController.java
@@ -28,6 +28,7 @@
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -175,7 +176,7 @@ public String displayMerchantStore(Model model, HttpServletRequest request, Http
@PreAuthorize("hasRole('STORE')")
@RequestMapping(value = "/admin/store/editStore.html", method = RequestMethod.GET)
- public String displayMerchantStore(@ModelAttribute("id") Integer id, Model model, HttpServletRequest request,
+ public String displayMerchantStore(@RequestParam("id") Integer id, Model model, HttpServletRequest request,
HttpServletResponse response, Locale locale) throws Exception {
setMenu(model, request);
@@ -226,7 +227,7 @@ public int compare(final Currency object1, final Currency object2) {
model.addAttribute("sizes", sizes);
model.addAttribute("store", store);
- return "admin-store";
+ return ControllerConstants.Tiles.Store.store;
}
diff --git a/sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/merchant/MerchantStoreIntegrationTest.java b/sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/merchant/MerchantStoreIntegrationTest.java
new file mode 100644
index 0000000000..efe765f735
--- /dev/null
+++ b/sm-shop/src/test/java/com/salesmanager/test/shop/integration/admin/merchant/MerchantStoreIntegrationTest.java
@@ -0,0 +1,85 @@
+package com.salesmanager.test.shop.integration.admin.merchant;
+
+import com.salesmanager.core.business.services.merchant.MerchantStoreService;
+import com.salesmanager.core.model.merchant.MerchantStore;
+import com.salesmanager.shop.admin.controller.ControllerConstants;
+import com.salesmanager.shop.application.ShopApplication;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.ResultActions;
+import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+/**
+ * Contains tests targeting {@link com.salesmanager.shop.admin.controller.merchant.MerchantStoreController}
+ */
+@SpringBootTest(classes = ShopApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@RunWith(SpringRunner.class)
+public class MerchantStoreIntegrationTest {
+ private static final String QUERY_PARAM_ID = "id";
+
+ private MockMvc mvc;
+
+ @Autowired
+ private WebApplicationContext context;
+
+ /**
+ * used to retrieve an existing merchant store
+ */
+ @Autowired
+ private MerchantStoreService merchantService;
+
+ @Before
+ public void setup() {
+ mvc = MockMvcBuilders
+ .webAppContextSetup(context)
+ .build();
+ }
+
+ @Test
+ @WithMockUser(roles = {"STORE"})
+ public void editStoreInformsAboutMissingID() throws Exception {
+ // when endpoint is called without any store ID
+ ResultActions resultActions = callEditStoreEndpoint(null);
+
+ // then a message indicating that the required request parameter is missing
+ String expectedErrorSubString = String.format("Required request parameter '%s'", QUERY_PARAM_ID);
+ resultActions.andExpect(model().attribute("errMsg", containsString(expectedErrorSubString)));
+ }
+
+ @Test
+ @WithMockUser(roles = {"STORE"})
+ public void callEditStoreWithExistingID() throws Exception {
+ // when endpoint is called with an existing store ID
+ Integer existingID = merchantService.getByCode(MerchantStore.DEFAULT_STORE).getId();
+ ResultActions resultActions = callEditStoreEndpoint(existingID.toString());
+
+ // then the correct view is expected without any error
+ resultActions
+ .andExpect(status().isOk())
+ .andExpect(view().name(ControllerConstants.Tiles.Store.store))
+ .andExpect(model().hasNoErrors())
+ .andExpect(model().attributeExists("store"));
+ }
+
+ private ResultActions callEditStoreEndpoint(String queryParam) throws Exception {
+ MockHttpServletRequestBuilder requestBuilder = get("/admin/store/editStore.html");
+ if (queryParam != null) {
+ requestBuilder.queryParam(QUERY_PARAM_ID, queryParam);
+ }
+ return mvc.perform(requestBuilder);
+ }
+}
From fdaae5645e6798409883e413f849586673927f52 Mon Sep 17 00:00:00 2001
From: Ralph Sommer
Date: Sun, 14 Nov 2021 11:01:46 -0300
Subject: [PATCH 5/5] Fix Javadoc's @param
---
.../shop/store/controller/user/facade/UserFacade.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/sm-shop-model/src/main/java/com/salesmanager/shop/store/controller/user/facade/UserFacade.java b/sm-shop-model/src/main/java/com/salesmanager/shop/store/controller/user/facade/UserFacade.java
index 95f4f8b88c..f8e2351617 100755
--- a/sm-shop-model/src/main/java/com/salesmanager/shop/store/controller/user/facade/UserFacade.java
+++ b/sm-shop-model/src/main/java/com/salesmanager/shop/store/controller/user/facade/UserFacade.java
@@ -38,7 +38,7 @@ public interface UserFacade {
/**
* Find user by id
* @param id
- * @param merchant
+ * @param store
* @param lang
* @return
*/
@@ -81,7 +81,7 @@ public interface UserFacade {
/**
* Determines if a user is in a specific group
* @param userName
- * @param groupName
+ * @param groupNames
*/
void authorizedGroup(String userName, List groupNames);
@@ -142,7 +142,6 @@ public interface UserFacade {
* Change password request
* @param userId
* @param authenticatedUser
- * @param storeCode
* @param changePassword
*/
void changePassword(Long userId, String authenticatedUser, UserPassword changePassword);