Advertisement
Guest User

Test

a guest
Jul 2nd, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 50.74 KB | None | 0 0
  1. package com.smedialink.mlisting.test;
  2.  
  3. import com.smedialink.mlisting.config.layers.RootWebApplicationLayer;
  4. import com.smedialink.mlisting.config.layers.WebApplicationLayer;
  5. import com.smedialink.mlisting.model.entities.User;
  6. import com.smedialink.mlisting.model.repositories.REObjectRepository;
  7. import com.smedialink.mlisting.model.repositories.UserRepository;
  8. import org.apache.commons.io.FileUtils;
  9. import org.junit.Assert;
  10. import org.junit.Before;
  11. import org.junit.FixMethodOrder;
  12. import org.junit.Test;
  13. import org.junit.runner.RunWith;
  14. import org.junit.runners.MethodSorters;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.context.MessageSource;
  17. import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers;
  18. import org.springframework.test.context.ContextConfiguration;
  19. import org.springframework.test.context.ContextHierarchy;
  20. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  21. import org.springframework.test.context.transaction.TransactionConfiguration;
  22. import org.springframework.test.context.web.WebAppConfiguration;
  23. import org.springframework.test.web.servlet.MockMvc;
  24. import org.springframework.test.web.servlet.setup.MockMvcBuilders;
  25. import org.springframework.transaction.PlatformTransactionManager;
  26. import org.springframework.transaction.TransactionStatus;
  27. import org.springframework.transaction.support.DefaultTransactionDefinition;
  28. import org.springframework.web.context.WebApplicationContext;
  29.  
  30. import java.io.File;
  31.  
  32. import static com.smedialink.mlisting.test.SecurityHelper.getUser;
  33. import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
  34. import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
  35. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
  36. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
  37.  
  38. @RunWith(SpringJUnit4ClassRunner.class)
  39. @WebAppConfiguration
  40. @ContextHierarchy({ @ContextConfiguration(classes = RootWebApplicationLayer.class),
  41.                     @ContextConfiguration(classes = WebApplicationLayer.class) })
  42. @TransactionConfiguration(defaultRollback = false)
  43. @FixMethodOrder(MethodSorters.NAME_ASCENDING)
  44. public class ObjectsTests {
  45.     @Autowired
  46.     private WebApplicationContext applicationContext;
  47.     @Autowired
  48.     private MessageSource messageSource;
  49.     @Autowired
  50.     private UserRepository userRepository;
  51.     @Autowired
  52.     private REObjectRepository objectRepository;
  53.     @Autowired
  54.     private PlatformTransactionManager transactionManager;
  55.     private MockMvc mockMvc;
  56.    
  57.     @Before
  58.     public void setup() {
  59.         mockMvc = MockMvcBuilders
  60.                       .webAppContextSetup(applicationContext)
  61.                       .apply(SecurityMockMvcConfigurers.springSecurity())
  62.                       .build();
  63.     }
  64.    
  65.     @Test
  66.     public void a_testMainFields() throws Exception {
  67.         User user = getUser();
  68.         userRepository.save(user);
  69.         /*--------------------------------------------------
  70.         * City
  71.         *--------------------------------------------------*/
  72.         mockMvc.perform(post("/objects/add")
  73.                             .param("city", "Qwerty")
  74.                             .with(user(user)))
  75.                .andExpect(status().isBadRequest())
  76.                .andExpect(jsonPath("$.city").value(messageSource.getMessage("valid.city.format", null, null)));
  77.         mockMvc.perform(post("/objects/add")
  78.                             .param("city", "")
  79.                             .with(user(user)))
  80.                .andExpect(status().isBadRequest())
  81.                .andExpect(jsonPath("$.city").value(messageSource.getMessage("valid.city.null", null, null)));
  82.         mockMvc.perform(post("/objects/add")
  83.                             .param("city", "й")
  84.                             .with(user(user)))
  85.                .andExpect(status().isBadRequest())
  86.                .andExpect(jsonPath("$.city").value(messageSource.getMessage("valid.city.size", null, null)));
  87.         mockMvc.perform(post("/objects/add")
  88.                             .with(user(user)))
  89.                .andExpect(status().isBadRequest())
  90.                .andExpect(jsonPath("$.city").value(messageSource.getMessage("valid.city.null", null, null)));
  91.        
  92.         /*--------------------------------------------------
  93.         * Operation
  94.         *--------------------------------------------------*/
  95.         mockMvc.perform(post("/objects/add")
  96.                             .param("operation", "Qwerty")
  97.                             .with(user(user)))
  98.                .andExpect(status().isBadRequest())
  99.                .andExpect(jsonPath("$.operation").value(messageSource.getMessage("typeMismatch.operation", null, null)));
  100.         mockMvc.perform(post("/objects/add")
  101.                             .param("operation", "")
  102.                             .with(user(user)))
  103.                .andExpect(status().isBadRequest())
  104.                .andExpect(jsonPath("$.operation").value(messageSource.getMessage("valid.operation.null", null, null)));
  105.         mockMvc.perform(post("/objects/add")
  106.                             .with(user(user)))
  107.                .andExpect(status().isBadRequest())
  108.                .andExpect(jsonPath("$.operation").value(messageSource.getMessage("valid.operation.null", null, null)));
  109.        
  110.         /*--------------------------------------------------
  111.         * Sqmain
  112.         *--------------------------------------------------*/
  113.         mockMvc.perform(post("/objects/add")
  114.                             .param("sqmain", "Qwerty")
  115.                             .with(user(user)))
  116.                .andExpect(status().isBadRequest())
  117.                .andExpect(jsonPath("$.sqmain").value(messageSource.getMessage("typeMismatch.sqmain", null, null)));
  118.         mockMvc.perform(post("/objects/add")
  119.                             .param("sqmain", "-1")
  120.                             .with(user(user)))
  121.                .andExpect(status().isBadRequest())
  122.                .andExpect(jsonPath("$.sqmain").value(messageSource.getMessage("valid.sqmain.min", null, null)));
  123.         mockMvc.perform(post("/objects/add")
  124.                             .param("sqmain", "")
  125.                             .with(user(user)))
  126.                .andExpect(status().isBadRequest())
  127.                .andExpect(jsonPath("$.sqmain").value(messageSource.getMessage("valid.sqmain.null", null, null)));
  128.         mockMvc.perform(post("/objects/add")
  129.                             .with(user(user)))
  130.                .andExpect(status().isBadRequest())
  131.                .andExpect(jsonPath("$.sqmain").value(messageSource.getMessage("valid.sqmain.null", null, null)));
  132.        
  133.         /*--------------------------------------------------
  134.         * Object
  135.         *--------------------------------------------------*/
  136.         mockMvc.perform(post("/objects/add")
  137.                             .param("object", "Qwerty")
  138.                             .with(user(user)))
  139.                .andExpect(status().isBadRequest())
  140.                .andExpect(jsonPath("$.object").value(messageSource.getMessage("typeMismatch.object", null, null)));
  141.         mockMvc.perform(post("/objects/add")
  142.                             .param("object", "")
  143.                             .with(user(user)))
  144.                .andExpect(status().isBadRequest())
  145.                .andExpect(jsonPath("$.object").value(messageSource.getMessage("valid.object.null", null, null)));
  146.         mockMvc.perform(post("/objects/add")
  147.                             .with(user(user)))
  148.                .andExpect(status().isBadRequest())
  149.                .andExpect(jsonPath("$.object").value(messageSource.getMessage("valid.object.null", null, null)));
  150.        
  151.         /*--------------------------------------------------
  152.         * Cost
  153.         *--------------------------------------------------*/
  154.         mockMvc.perform(post("/objects/add")
  155.                             .param("cost", "Qwerty")
  156.                             .with(user(user)))
  157.                .andExpect(status().isBadRequest())
  158.                .andExpect(jsonPath("$.cost").value(messageSource.getMessage("typeMismatch.cost", null, null)));
  159.         mockMvc.perform(post("/objects/add")
  160.                             .param("cost", "")
  161.                             .with(user(user)))
  162.                .andExpect(status().isBadRequest())
  163.                .andExpect(jsonPath("$.cost").value(messageSource.getMessage("valid.cost.null", null, null)));
  164.         mockMvc.perform(post("/objects/add")
  165.                             .with(user(user)))
  166.                .andExpect(status().isBadRequest())
  167.                .andExpect(jsonPath("$.cost").value(messageSource.getMessage("valid.cost.null", null, null)));
  168.         mockMvc.perform(post("/objects/add")
  169.                             .param("cost", "-1")
  170.                             .with(user(user)))
  171.                .andExpect(status().isBadRequest())
  172.                .andExpect(jsonPath("$.cost").value(messageSource.getMessage("valid.cost.min", null, null)));
  173.        
  174.         /*--------------------------------------------------
  175.         * Coordinate
  176.         *--------------------------------------------------*/
  177.         mockMvc.perform(post("/objects/add")
  178.                             .param("coordinate", "Qwerty")
  179.                             .with(user(user)))
  180.                .andExpect(status().isBadRequest())
  181.                .andExpect(jsonPath("$.coordinate").value(messageSource.getMessage("typeMismatch.coordinate", null, null)));
  182.         mockMvc.perform(post("/objects/add")
  183.                             .param("coordinate", "")
  184.                             .with(user(user)))
  185.                .andExpect(status().isBadRequest())
  186.                .andExpect(jsonPath("$.coordinate").value(messageSource.getMessage("valid.coordinate.null", null, null)));
  187.         mockMvc.perform(post("/objects/add")
  188.                             .with(user(user)))
  189.                .andExpect(status().isBadRequest())
  190.                .andExpect(jsonPath("$.coordinate").value(messageSource.getMessage("valid.coordinate.null", null, null)));
  191.        
  192.         /*--------------------------------------------------
  193.         * Address
  194.         *--------------------------------------------------*/
  195.         mockMvc.perform(post("/objects/add")
  196.                             .param("address", "Qwerty")
  197.                             .with(user(user)))
  198.                .andExpect(status().isBadRequest())
  199.                .andExpect(jsonPath("$.address").value(messageSource.getMessage("valid.address.format", null, null)));
  200.         mockMvc.perform(post("/objects/add")
  201.                             .param("address", "")
  202.                             .with(user(user)))
  203.                .andExpect(status().isBadRequest())
  204.                .andExpect(jsonPath("$.address").value(messageSource.getMessage("valid.address.null", null, null)));
  205.         mockMvc.perform(post("/objects/add")
  206.                             .with(user(user)))
  207.                .andExpect(status().isBadRequest())
  208.                .andExpect(jsonPath("$.address").value(messageSource.getMessage("valid.address.null", null, null)));
  209.         mockMvc.perform(post("/objects/add")
  210.                             .param("address", "й")
  211.                             .with(user(user)))
  212.                .andExpect(status().isBadRequest())
  213.                .andExpect(jsonPath("$.address").value(messageSource.getMessage("valid.address.size", null, null)));
  214.     }
  215.    
  216.     @Test
  217.     public void b_testApartmentRent() throws Exception {
  218.         User user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  219.         /*--------------------------------------------------
  220.         * Floor
  221.         *--------------------------------------------------*/
  222.         mockMvc.perform(post("/objects/add")
  223.                             .param("object", "APARTMENT")
  224.                             .param("operation", "RENT")
  225.                             .with(user(user)))
  226.                .andExpect(status().isBadRequest())
  227.                .andExpect(jsonPath("$.floor").value(messageSource.getMessage("valid.floor.null", null, null)));
  228.         mockMvc.perform(post("/objects/add")
  229.                             .param("object", "APARTMENT")
  230.                             .param("operation", "RENT")
  231.                             .param("floor", "")
  232.                             .with(user(user)))
  233.                .andExpect(status().isBadRequest())
  234.                .andExpect(jsonPath("$.floor").value(messageSource.getMessage("valid.floor.null", null, null)));
  235.         mockMvc.perform(post("/objects/add")
  236.                             .param("object", "APARTMENT")
  237.                             .param("operation", "RENT")
  238.                             .param("floor", "0")
  239.                             .with(user(user)))
  240.                .andExpect(status().isBadRequest())
  241.                .andExpect(jsonPath("$.floor").value(messageSource.getMessage("valid.floor.min", null, null)));
  242.         mockMvc.perform(post("/objects/add")
  243.                             .param("object", "APARTMENT")
  244.                             .param("operation", "RENT")
  245.                             .param("floor", "qwerty")
  246.                             .with(user(user)))
  247.                .andExpect(status().isBadRequest())
  248.                .andExpect(jsonPath("$.floor").value(messageSource.getMessage("typeMismatch.floor", null, null)));
  249.        
  250.         /*--------------------------------------------------
  251.         * Rooms
  252.         *--------------------------------------------------*/
  253.         mockMvc.perform(post("/objects/add")
  254.                             .param("object", "APARTMENT")
  255.                             .param("operation", "RENT")
  256.                             .with(user(user)))
  257.                .andExpect(status().isBadRequest())
  258.                .andExpect(jsonPath("$.rooms").value(messageSource.getMessage("valid.rooms.null", null, null)));
  259.         mockMvc.perform(post("/objects/add")
  260.                             .param("object", "APARTMENT")
  261.                             .param("operation", "RENT")
  262.                             .param("rooms", "")
  263.                             .with(user(user)))
  264.                .andExpect(status().isBadRequest())
  265.                .andExpect(jsonPath("$.rooms").value(messageSource.getMessage("valid.rooms.null", null, null)));
  266.         mockMvc.perform(post("/objects/add")
  267.                             .param("object", "APARTMENT")
  268.                             .param("operation", "RENT")
  269.                             .param("rooms", "0")
  270.                             .with(user(user)))
  271.                .andExpect(status().isBadRequest())
  272.                .andExpect(jsonPath("$.rooms").value(messageSource.getMessage("valid.rooms.min", null, null)));
  273.         mockMvc.perform(post("/objects/add")
  274.                             .param("object", "APARTMENT")
  275.                             .param("operation", "RENT")
  276.                             .param("rooms", "qwerty")
  277.                             .with(user(user)))
  278.                .andExpect(status().isBadRequest())
  279.                .andExpect(jsonPath("$.rooms").value(messageSource.getMessage("typeMismatch.rooms", null, null)));
  280.        
  281.         /*--------------------------------------------------
  282.         * Decor
  283.         *--------------------------------------------------*/
  284.         mockMvc.perform(post("/objects/add")
  285.                             .param("object", "APARTMENT")
  286.                             .param("operation", "RENT")
  287.                             .with(user(user)))
  288.                .andExpect(status().isBadRequest())
  289.                .andExpect(jsonPath("$.decor").value(messageSource.getMessage("valid.decor.null", null, null)));
  290.         mockMvc.perform(post("/objects/add")
  291.                             .param("object", "APARTMENT")
  292.                             .param("operation", "RENT")
  293.                             .param("decor", "")
  294.                             .with(user(user)))
  295.                .andExpect(status().isBadRequest())
  296.                .andExpect(jsonPath("$.decor").value(messageSource.getMessage("valid.decor.null", null, null)));
  297.         mockMvc.perform(post("/objects/add")
  298.                             .param("object", "APARTMENT")
  299.                             .param("operation", "RENT")
  300.                             .param("decor", "q")
  301.                             .with(user(user)))
  302.                .andExpect(status().isBadRequest())
  303.                .andExpect(jsonPath("$.decor").value(messageSource.getMessage("typeMismatch.decor", null, null)));
  304.        
  305.         /*--------------------------------------------------
  306.         * Type
  307.         *--------------------------------------------------*/
  308.         mockMvc.perform(post("/objects/add")
  309.                             .param("object", "APARTMENT")
  310.                             .param("operation", "RENT")
  311.                             .with(user(user)))
  312.                .andExpect(status().isBadRequest())
  313.                .andExpect(jsonPath("$.type").value(messageSource.getMessage("valid.type.null", null, null)));
  314.         mockMvc.perform(post("/objects/add")
  315.                             .param("object", "APARTMENT")
  316.                             .param("operation", "RENT")
  317.                             .param("type", "")
  318.                             .with(user(user)))
  319.                .andExpect(status().isBadRequest())
  320.                .andExpect(jsonPath("$.type").value(messageSource.getMessage("valid.type.null", null, null)));
  321.         mockMvc.perform(post("/objects/add")
  322.                             .param("object", "APARTMENT")
  323.                             .param("operation", "RENT")
  324.                             .param("type", "q")
  325.                             .with(user(user)))
  326.                .andExpect(status().isBadRequest())
  327.                .andExpect(jsonPath("$.type").value(messageSource.getMessage("typeMismatch.type", null, null)));
  328.        
  329.         /*--------------------------------------------------
  330.         * Internet, furniture, appliances
  331.         *--------------------------------------------------*/
  332.         mockMvc.perform(post("/objects/add")
  333.                             .param("object", "APARTMENT")
  334.                             .param("operation", "RENT")
  335.                             .param("internet", "q")
  336.                             .param("furniture", "q")
  337.                             .param("appliances", "q")
  338.                             .with(user(user)))
  339.                .andExpect(status().isBadRequest())
  340.                .andExpect(jsonPath("$.internet").value(messageSource.getMessage("typeMismatch.internet", null, null)))
  341.                .andExpect(jsonPath("$.furniture").value(messageSource.getMessage("typeMismatch.furniture", null, null)))
  342.                .andExpect(jsonPath("$.appliances").value(messageSource.getMessage("typeMismatch.appliances", null, null)));
  343.        
  344.         /*--------------------------------------------------
  345.         * Success
  346.         *--------------------------------------------------*/
  347.         mockMvc.perform(post("/objects/add")
  348.                             .param("city", "Краснодар")
  349.                             .param("sqmain", "40.5")
  350.                             .param("cost", "15000000")
  351.                             .param("coordinate", "POINT (15.1 16.5)")
  352.                             .param("address", "Российская 72/1")
  353.                             .param("object", "APARTMENT")
  354.                             .param("operation", "RENT")
  355.                             .param("floor", "7")
  356.                             .param("rooms", "1")
  357.                             .param("decor", "STANDARD")
  358.                             .param("type", "MONOLITHBRIK")
  359.                             .param("internet", "true")
  360.                             .param("furniture", "true")
  361.                             .param("appliances", "true")
  362.                             .with(user(user)))
  363.                .andExpect(status().isOk());
  364.         TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
  365.         user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  366.         Assert.assertTrue(user.getReObjects().size() == 1);
  367.         transactionManager.commit(status);
  368.     }
  369.    
  370.     @Test
  371.     public void c_testApartmentSell() throws Exception {
  372.         User user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  373.         /*--------------------------------------------------
  374.         * Floor
  375.         *--------------------------------------------------*/
  376.         mockMvc.perform(post("/objects/add")
  377.                             .param("object", "APARTMENT")
  378.                             .param("operation", "SELL")
  379.                             .with(user(user)))
  380.                .andExpect(status().isBadRequest())
  381.                .andExpect(jsonPath("$.floor").value(messageSource.getMessage("valid.floor.null", null, null)));
  382.        
  383.         /*--------------------------------------------------
  384.         * Rooms
  385.         *--------------------------------------------------*/
  386.         mockMvc.perform(post("/objects/add")
  387.                             .param("object", "APARTMENT")
  388.                             .param("operation", "SELL")
  389.                             .with(user(user)))
  390.                .andExpect(status().isBadRequest())
  391.                .andExpect(jsonPath("$.rooms").value(messageSource.getMessage("valid.rooms.null", null, null)));
  392.        
  393.         /*--------------------------------------------------
  394.         * Decor
  395.         *--------------------------------------------------*/
  396.         mockMvc.perform(post("/objects/add")
  397.                             .param("object", "APARTMENT")
  398.                             .param("operation", "SELL")
  399.                             .with(user(user)))
  400.                .andExpect(status().isBadRequest())
  401.                .andExpect(jsonPath("$.decor").value(messageSource.getMessage("valid.decor.null", null, null)));
  402.        
  403.         /*--------------------------------------------------
  404.         * Type
  405.         *--------------------------------------------------*/
  406.         mockMvc.perform(post("/objects/add")
  407.                             .param("object", "APARTMENT")
  408.                             .param("operation", "SELL")
  409.                             .with(user(user)))
  410.                .andExpect(status().isBadRequest())
  411.                .andExpect(jsonPath("$.type").value(messageSource.getMessage("valid.type.null", null, null)));
  412.        
  413.         /*--------------------------------------------------
  414.         * Hypothec, balcony, lift
  415.         *--------------------------------------------------*/
  416.         mockMvc.perform(post("/objects/add")
  417.                             .param("object", "APARTMENT")
  418.                             .param("operation", "SELL")
  419.                             .param("hypothec", "q")
  420.                             .param("balcony", "q")
  421.                             .param("lift", "q")
  422.                             .with(user(user)))
  423.                .andExpect(status().isBadRequest())
  424.                .andExpect(jsonPath("$.hypothec").value(messageSource.getMessage("typeMismatch.hypothec", null, null)))
  425.                .andExpect(jsonPath("$.balcony").value(messageSource.getMessage("typeMismatch.balcony", null, null)))
  426.                .andExpect(jsonPath("$.lift").value(messageSource.getMessage("typeMismatch.lift", null, null)));
  427.        
  428.         /*--------------------------------------------------
  429.         * Success
  430.         *--------------------------------------------------*/
  431.         mockMvc.perform(post("/objects/add")
  432.                             .param("city", "Краснодар")
  433.                             .param("sqmain", "40.5")
  434.                             .param("cost", "15000000")
  435.                             .param("coordinate", "POINT (15.1 16.5)")
  436.                             .param("address", "Российская 72/1")
  437.                             .param("object", "APARTMENT")
  438.                             .param("operation", "SELL")
  439.                             .param("floor", "7")
  440.                             .param("rooms", "1")
  441.                             .param("decor", "STANDARD")
  442.                             .param("type", "MONOLITHBRIK")
  443.                             .param("hypothec", "true")
  444.                             .param("balcony", "true")
  445.                             .param("lift", "true")
  446.                             .with(user(user)))
  447.                .andExpect(status().isOk());
  448.         TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
  449.         user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  450.         Assert.assertTrue(user.getReObjects().size() == 2);
  451.         transactionManager.commit(status);
  452.     }
  453.    
  454.     @Test
  455.     public void d_testHouseRent() throws Exception {
  456.         User user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  457.         /*--------------------------------------------------
  458.         * Floor
  459.         *--------------------------------------------------*/
  460.         mockMvc.perform(post("/objects/add")
  461.                             .param("object", "HOUSE")
  462.                             .param("operation", "RENT")
  463.                             .with(user(user)))
  464.                .andExpect(status().isBadRequest())
  465.                .andExpect(jsonPath("$.floor").value(messageSource.getMessage("valid.floor.null", null, null)));
  466.        
  467.         /*--------------------------------------------------
  468.         * Rooms
  469.         *--------------------------------------------------*/
  470.         mockMvc.perform(post("/objects/add")
  471.                             .param("object", "HOUSE")
  472.                             .param("operation", "RENT")
  473.                             .with(user(user)))
  474.                .andExpect(status().isBadRequest())
  475.                .andExpect(jsonPath("$.rooms").value(messageSource.getMessage("valid.rooms.null", null, null)));
  476.        
  477.         /*--------------------------------------------------
  478.         * Decor
  479.         *--------------------------------------------------*/
  480.         mockMvc.perform(post("/objects/add")
  481.                             .param("object", "HOUSE")
  482.                             .param("operation", "RENT")
  483.                             .with(user(user)))
  484.                .andExpect(status().isBadRequest())
  485.                .andExpect(jsonPath("$.decor").value(messageSource.getMessage("valid.decor.null", null, null)));
  486.        
  487.         /*--------------------------------------------------
  488.         * Sqarea
  489.         *--------------------------------------------------*/
  490.         mockMvc.perform(post("/objects/add")
  491.                             .param("object", "HOUSE")
  492.                             .param("operation", "RENT")
  493.                             .param("sqarea", "Qwerty")
  494.                             .with(user(user)))
  495.                .andExpect(status().isBadRequest())
  496.                .andExpect(jsonPath("$.sqarea").value(messageSource.getMessage("typeMismatch.sqarea", null, null)));
  497.         mockMvc.perform(post("/objects/add")
  498.                             .param("object", "HOUSE")
  499.                             .param("operation", "RENT")
  500.                             .param("sqarea", "-1")
  501.                             .with(user(user)))
  502.                .andExpect(status().isBadRequest())
  503.                .andExpect(jsonPath("$.sqarea").value(messageSource.getMessage("valid.sqarea.min", null, null)));
  504.         mockMvc.perform(post("/objects/add")
  505.                             .param("object", "HOUSE")
  506.                             .param("operation", "RENT")
  507.                             .param("sqarea", "")
  508.                             .with(user(user)))
  509.                .andExpect(status().isBadRequest())
  510.                .andExpect(jsonPath("$.sqarea").value(messageSource.getMessage("valid.sqarea.null", null, null)));
  511.         mockMvc.perform(post("/objects/add")
  512.                             .param("object", "HOUSE")
  513.                             .param("operation", "RENT")
  514.                             .with(user(user)))
  515.                .andExpect(status().isBadRequest())
  516.                .andExpect(jsonPath("$.sqarea").value(messageSource.getMessage("valid.sqarea.null", null, null)));
  517.        
  518.         /*--------------------------------------------------
  519.         * Internet, furniture, appliances
  520.         *--------------------------------------------------*/
  521.         mockMvc.perform(post("/objects/add")
  522.                             .param("object", "HOUSE")
  523.                             .param("operation", "RENT")
  524.                             .param("internet", "q")
  525.                             .param("furniture", "q")
  526.                             .param("appliances", "q")
  527.                             .with(user(user)))
  528.                .andExpect(status().isBadRequest())
  529.                .andExpect(jsonPath("$.internet").value(messageSource.getMessage("typeMismatch.internet", null, null)))
  530.                .andExpect(jsonPath("$.furniture").value(messageSource.getMessage("typeMismatch.furniture", null, null)))
  531.                .andExpect(jsonPath("$.appliances").value(messageSource.getMessage("typeMismatch.appliances", null, null)));
  532.        
  533.         /*--------------------------------------------------
  534.         * Success
  535.         *--------------------------------------------------*/
  536.         mockMvc.perform(post("/objects/add")
  537.                             .param("city", "Краснодар")
  538.                             .param("sqmain", "40.5")
  539.                             .param("cost", "15000000")
  540.                             .param("coordinate", "POINT (15.1 16.5)")
  541.                             .param("address", "Российская 72/1")
  542.                             .param("object", "HOUSE")
  543.                             .param("operation", "RENT")
  544.                             .param("floor", "2")
  545.                             .param("rooms", "4")
  546.                             .param("decor", "STANDARD")
  547.                             .param("sqarea", "100")
  548.                             .param("internet", "true")
  549.                             .param("furniture", "true")
  550.                             .param("appliances", "true")
  551.                             .with(user(user)))
  552.                .andExpect(status().isOk());
  553.         TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
  554.         user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  555.         Assert.assertTrue(user.getReObjects().size() == 3);
  556.         transactionManager.commit(status);
  557.     }
  558.    
  559.     @Test
  560.     public void e_testHouseSell() throws Exception {
  561.         User user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  562.         /*--------------------------------------------------
  563.         * Floor
  564.         *--------------------------------------------------*/
  565.         mockMvc.perform(post("/objects/add")
  566.                             .param("object", "HOUSE")
  567.                             .param("operation", "SELL")
  568.                             .with(user(user)))
  569.                .andExpect(status().isBadRequest())
  570.                .andExpect(jsonPath("$.floor").value(messageSource.getMessage("valid.floor.null", null, null)));
  571.        
  572.         /*--------------------------------------------------
  573.         * Rooms
  574.         *--------------------------------------------------*/
  575.         mockMvc.perform(post("/objects/add")
  576.                             .param("object", "HOUSE")
  577.                             .param("operation", "SELL")
  578.                             .with(user(user)))
  579.                .andExpect(status().isBadRequest())
  580.                .andExpect(jsonPath("$.rooms").value(messageSource.getMessage("valid.rooms.null", null, null)));
  581.        
  582.         /*--------------------------------------------------
  583.         * Decor
  584.         *--------------------------------------------------*/
  585.         mockMvc.perform(post("/objects/add")
  586.                             .param("object", "HOUSE")
  587.                             .param("operation", "SELL")
  588.                             .with(user(user)))
  589.                .andExpect(status().isBadRequest())
  590.                .andExpect(jsonPath("$.decor").value(messageSource.getMessage("valid.decor.null", null, null)));
  591.        
  592.         /*--------------------------------------------------
  593.         * Sqarea
  594.         *--------------------------------------------------*/
  595.         mockMvc.perform(post("/objects/add")
  596.                             .param("object", "HOUSE")
  597.                             .param("operation", "SELL")
  598.                             .with(user(user)))
  599.                .andExpect(status().isBadRequest())
  600.                .andExpect(jsonPath("$.sqarea").value(messageSource.getMessage("valid.sqarea.null", null, null)));
  601.        
  602.         /*--------------------------------------------------
  603.         * Hypothec
  604.         *--------------------------------------------------*/
  605.         mockMvc.perform(post("/objects/add")
  606.                             .param("object", "HOUSE")
  607.                             .param("operation", "SELL")
  608.                             .param("hypothec", "q")
  609.                             .with(user(user)))
  610.                .andExpect(status().isBadRequest())
  611.                .andExpect(jsonPath("$.hypothec").value(messageSource.getMessage("typeMismatch.hypothec", null, null)));
  612.        
  613.         /*--------------------------------------------------
  614.         * Success
  615.         *--------------------------------------------------*/
  616.         mockMvc.perform(post("/objects/add")
  617.                             .param("city", "Краснодар")
  618.                             .param("sqmain", "40.5")
  619.                             .param("cost", "15000000")
  620.                             .param("coordinate", "POINT (15.1 16.5)")
  621.                             .param("address", "Российская 72/1")
  622.                             .param("object", "HOUSE")
  623.                             .param("operation", "SELL")
  624.                             .param("floor", "2")
  625.                             .param("rooms", "4")
  626.                             .param("decor", "STANDARD")
  627.                             .param("sqarea", "100")
  628.                             .param("hypothec", "true")
  629.                             .with(user(user)))
  630.                .andExpect(status().isOk());
  631.         TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
  632.         user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  633.         Assert.assertTrue(user.getReObjects().size() == 4);
  634.         transactionManager.commit(status);
  635.     }
  636.    
  637.     @Test
  638.     public void f_testParcelRentSell() throws Exception {
  639.         User user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  640.         /*--------------------------------------------------
  641.         * Gas, canalization, water, electricity
  642.         *--------------------------------------------------*/
  643.         mockMvc.perform(post("/objects/add")
  644.                             .param("object", "PARCEL")
  645.                             .param("operation", "SELL")
  646.                             .param("gas", "q")
  647.                             .param("canalization", "q")
  648.                             .param("water", "q")
  649.                             .param("electricity", "q")
  650.                             .with(user(user)))
  651.                .andExpect(status().isBadRequest())
  652.                .andExpect(jsonPath("$.gas").value(messageSource.getMessage("typeMismatch.gas", null, null)))
  653.                .andExpect(jsonPath("$.canalization").value(messageSource.getMessage("typeMismatch.canalization", null, null)))
  654.                .andExpect(jsonPath("$.water").value(messageSource.getMessage("typeMismatch.water", null, null)))
  655.                .andExpect(jsonPath("$.electricity").value(messageSource.getMessage("typeMismatch.electricity", null, null)));
  656.         mockMvc.perform(post("/objects/add")
  657.                             .param("object", "PARCEL")
  658.                             .param("operation", "RENT")
  659.                             .param("gas", "q")
  660.                             .param("canalization", "q")
  661.                             .param("water", "q")
  662.                             .param("electricity", "q")
  663.                             .with(user(user)))
  664.                .andExpect(status().isBadRequest())
  665.                .andExpect(jsonPath("$.gas").value(messageSource.getMessage("typeMismatch.gas", null, null)))
  666.                .andExpect(jsonPath("$.canalization").value(messageSource.getMessage("typeMismatch.canalization", null, null)))
  667.                .andExpect(jsonPath("$.water").value(messageSource.getMessage("typeMismatch.water", null, null)))
  668.                .andExpect(jsonPath("$.electricity").value(messageSource.getMessage("typeMismatch.electricity", null, null)));
  669.        
  670.         /*--------------------------------------------------
  671.         * Success
  672.         *--------------------------------------------------*/
  673.         mockMvc.perform(post("/objects/add")
  674.                             .param("city", "Краснодар")
  675.                             .param("sqmain", "140.5")
  676.                             .param("cost", "15000000")
  677.                             .param("coordinate", "POINT (15.1 16.5)")
  678.                             .param("address", "Российская 72/1")
  679.                             .param("object", "PARCEL")
  680.                             .param("operation", "SELL")
  681.                             .param("gas", "true")
  682.                             .param("canalization", "true")
  683.                             .param("water", "true")
  684.                             .param("electricity", "true")
  685.                             .with(user(user)))
  686.                .andExpect(status().isOk());
  687.         mockMvc.perform(post("/objects/add")
  688.                             .param("city", "Краснодар")
  689.                             .param("sqmain", "140.5")
  690.                             .param("cost", "15000000")
  691.                             .param("coordinate", "POINT (15.1 16.5)")
  692.                             .param("address", "Российская 72/1")
  693.                             .param("object", "PARCEL")
  694.                             .param("operation", "RENT")
  695.                             .param("gas", "true")
  696.                             .param("canalization", "true")
  697.                             .param("water", "true")
  698.                             .param("electricity", "true")
  699.                             .with(user(user)))
  700.                .andExpect(status().isOk());
  701.         TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
  702.         user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  703.         Assert.assertTrue(user.getReObjects().size() == 6);
  704.         transactionManager.commit(status);
  705.     }
  706.    
  707.     @Test
  708.     public void g_testTownhouseRent() throws Exception {
  709.         User user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  710.         /*--------------------------------------------------
  711.         * Floor
  712.         *--------------------------------------------------*/
  713.         mockMvc.perform(post("/objects/add")
  714.                             .param("object", "TOWNHOUSE")
  715.                             .param("operation", "RENT")
  716.                             .with(user(user)))
  717.                .andExpect(status().isBadRequest())
  718.                .andExpect(jsonPath("$.floor").value(messageSource.getMessage("valid.floor.null", null, null)));
  719.        
  720.         /*--------------------------------------------------
  721.         * Rooms
  722.         *--------------------------------------------------*/
  723.         mockMvc.perform(post("/objects/add")
  724.                             .param("object", "TOWNHOUSE")
  725.                             .param("operation", "RENT")
  726.                             .with(user(user)))
  727.                .andExpect(status().isBadRequest())
  728.                .andExpect(jsonPath("$.rooms").value(messageSource.getMessage("valid.rooms.null", null, null)));
  729.        
  730.         /*--------------------------------------------------
  731.         * Decor
  732.         *--------------------------------------------------*/
  733.         mockMvc.perform(post("/objects/add")
  734.                             .param("object", "TOWNHOUSE")
  735.                             .param("operation", "RENT")
  736.                             .with(user(user)))
  737.                .andExpect(status().isBadRequest())
  738.                .andExpect(jsonPath("$.decor").value(messageSource.getMessage("valid.decor.null", null, null)));
  739.        
  740.         /*--------------------------------------------------
  741.         * Sqarea
  742.         *--------------------------------------------------*/
  743.         mockMvc.perform(post("/objects/add")
  744.                             .param("object", "TOWNHOUSE")
  745.                             .param("operation", "RENT")
  746.                             .with(user(user)))
  747.                .andExpect(status().isBadRequest())
  748.                .andExpect(jsonPath("$.sqarea").value(messageSource.getMessage("valid.sqarea.null", null, null)));
  749.        
  750.         /*--------------------------------------------------
  751.         * Success
  752.         *--------------------------------------------------*/
  753.         mockMvc.perform(post("/objects/add")
  754.                             .param("city", "Краснодар")
  755.                             .param("sqmain", "40.5")
  756.                             .param("cost", "15000000")
  757.                             .param("coordinate", "POINT (15.1 16.5)")
  758.                             .param("address", "Российская 72/1")
  759.                             .param("object", "TOWNHOUSE")
  760.                             .param("operation", "RENT")
  761.                             .param("floor", "2")
  762.                             .param("rooms", "4")
  763.                             .param("decor", "STANDARD")
  764.                             .param("sqarea", "100")
  765.                             .param("internet", "true")
  766.                             .param("furniture", "true")
  767.                             .param("appliances", "true")
  768.                             .with(user(user)))
  769.                .andExpect(status().isOk());
  770.         TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
  771.         user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  772.         Assert.assertTrue(user.getReObjects().size() == 7);
  773.         transactionManager.commit(status);
  774.     }
  775.    
  776.     @Test
  777.     public void h_testTownhouseSell() throws Exception {
  778.         User user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  779.         /*--------------------------------------------------
  780.         * Floor
  781.         *--------------------------------------------------*/
  782.         mockMvc.perform(post("/objects/add")
  783.                             .param("object", "TOWNHOUSE")
  784.                             .param("operation", "SELL")
  785.                             .with(user(user)))
  786.                .andExpect(status().isBadRequest())
  787.                .andExpect(jsonPath("$.floor").value(messageSource.getMessage("valid.floor.null", null, null)));
  788.        
  789.         /*--------------------------------------------------
  790.         * Rooms
  791.         *--------------------------------------------------*/
  792.         mockMvc.perform(post("/objects/add")
  793.                             .param("object", "TOWNHOUSE")
  794.                             .param("operation", "SELL")
  795.                             .with(user(user)))
  796.                .andExpect(status().isBadRequest())
  797.                .andExpect(jsonPath("$.rooms").value(messageSource.getMessage("valid.rooms.null", null, null)));
  798.        
  799.         /*--------------------------------------------------
  800.         * Decor
  801.         *--------------------------------------------------*/
  802.         mockMvc.perform(post("/objects/add")
  803.                             .param("object", "TOWNHOUSE")
  804.                             .param("operation", "SELL")
  805.                             .with(user(user)))
  806.                .andExpect(status().isBadRequest())
  807.                .andExpect(jsonPath("$.decor").value(messageSource.getMessage("valid.decor.null", null, null)));
  808.        
  809.         /*--------------------------------------------------
  810.         * Sqarea
  811.         *--------------------------------------------------*/
  812.         mockMvc.perform(post("/objects/add")
  813.                             .param("object", "TOWNHOUSE")
  814.                             .param("operation", "SELL")
  815.                             .with(user(user)))
  816.                .andExpect(status().isBadRequest())
  817.                .andExpect(jsonPath("$.sqarea").value(messageSource.getMessage("valid.sqarea.null", null, null)));
  818.        
  819.         /*--------------------------------------------------
  820.         * Success
  821.         *--------------------------------------------------*/
  822.         mockMvc.perform(post("/objects/add")
  823.                             .param("city", "Краснодар")
  824.                             .param("sqmain", "40.5")
  825.                             .param("cost", "15000000")
  826.                             .param("coordinate", "POINT (15.1 16.5)")
  827.                             .param("address", "Российская 72/1")
  828.                             .param("object", "TOWNHOUSE")
  829.                             .param("operation", "SELL")
  830.                             .param("floor", "2")
  831.                             .param("rooms", "4")
  832.                             .param("decor", "STANDARD")
  833.                             .param("sqarea", "100")
  834.                             .param("hypothec", "true")
  835.                             .with(user(user)))
  836.                .andExpect(status().isOk());
  837.         TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
  838.         user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  839.         Assert.assertTrue(user.getReObjects().size() == 8);
  840.         transactionManager.commit(status);
  841.     }
  842.    
  843.     @Test
  844.     public void i_testOfficeRentSell() throws Exception {
  845.         User user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  846.         /*--------------------------------------------------
  847.         * Floor
  848.         *--------------------------------------------------*/
  849.         mockMvc.perform(post("/objects/add")
  850.                             .param("object", "OFFICE")
  851.                             .param("operation", "RENT")
  852.                             .with(user(user)))
  853.                .andExpect(status().isBadRequest())
  854.                .andExpect(jsonPath("$.floor").value(messageSource.getMessage("valid.floor.null", null, null)));
  855.        
  856.         /*--------------------------------------------------
  857.         * Rooms
  858.         *--------------------------------------------------*/
  859.         mockMvc.perform(post("/objects/add")
  860.                             .param("object", "OFFICE")
  861.                             .param("operation", "RENT")
  862.                             .with(user(user)))
  863.                .andExpect(status().isBadRequest())
  864.                .andExpect(jsonPath("$.rooms").value(messageSource.getMessage("valid.rooms.null", null, null)));
  865.        
  866.         /*--------------------------------------------------
  867.         * Floor
  868.         *--------------------------------------------------*/
  869.         mockMvc.perform(post("/objects/add")
  870.                             .param("object", "OFFICE")
  871.                             .param("operation", "SELL")
  872.                             .with(user(user)))
  873.                .andExpect(status().isBadRequest())
  874.                .andExpect(jsonPath("$.floor").value(messageSource.getMessage("valid.floor.null", null, null)));
  875.        
  876.         /*--------------------------------------------------
  877.         * Rooms
  878.         *--------------------------------------------------*/
  879.         mockMvc.perform(post("/objects/add")
  880.                             .param("object", "OFFICE")
  881.                             .param("operation", "SELL")
  882.                             .with(user(user)))
  883.                .andExpect(status().isBadRequest())
  884.                .andExpect(jsonPath("$.rooms").value(messageSource.getMessage("valid.rooms.null", null, null)));
  885.        
  886.         /*--------------------------------------------------
  887.         * Gas, canalization, water, electricity
  888.         *--------------------------------------------------*/
  889.         mockMvc.perform(post("/objects/add")
  890.                             .param("object", "OFFICE")
  891.                             .param("operation", "SELL")
  892.                             .param("parking", "q")
  893.                             .param("centrCond", "q")
  894.                             .with(user(user)))
  895.                .andExpect(status().isBadRequest())
  896.                .andExpect(jsonPath("$.parking").value(messageSource.getMessage("typeMismatch.parking", null, null)))
  897.                .andExpect(jsonPath("$.centrCond").value(messageSource.getMessage("typeMismatch.centrCond", null, null)));
  898.        
  899.         /*--------------------------------------------------
  900.         * Success
  901.         *--------------------------------------------------*/
  902.         mockMvc.perform(post("/objects/add")
  903.                             .param("city", "Краснодар")
  904.                             .param("sqmain", "40.5")
  905.                             .param("cost", "15000000")
  906.                             .param("coordinate", "POINT (15.1 16.5)")
  907.                             .param("address", "Российская 72/1")
  908.                             .param("object", "OFFICE")
  909.                             .param("operation", "SELL")
  910.                             .param("floor", "2")
  911.                             .param("rooms", "4")
  912.                             .param("parking", "true")
  913.                             .param("centrCond", "true")
  914.                             .with(user(user)))
  915.                .andExpect(status().isOk());
  916.         mockMvc.perform(post("/objects/add")
  917.                             .param("city", "Краснодар")
  918.                             .param("sqmain", "40.5")
  919.                             .param("cost", "15000000")
  920.                             .param("coordinate", "POINT (15.1 16.5)")
  921.                             .param("address", "Российская 72/1")
  922.                             .param("object", "OFFICE")
  923.                             .param("operation", "RENT")
  924.                             .param("floor", "2")
  925.                             .param("rooms", "4")
  926.                             .param("parking", "true")
  927.                             .param("centrCond", "true")
  928.                             .with(user(user)))
  929.                .andExpect(status().isOk());
  930.         TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
  931.         user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  932.         Assert.assertTrue(user.getReObjects().size() == 10);
  933.         transactionManager.commit(status);
  934.     }
  935.    
  936.     @Test
  937.     public void j_testGarageRentSell() throws Exception {
  938.         User user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  939.         /*--------------------------------------------------
  940.         * Success
  941.         *--------------------------------------------------*/
  942.         mockMvc.perform(post("/objects/add")
  943.                             .param("city", "Краснодар")
  944.                             .param("sqmain", "40.5")
  945.                             .param("cost", "15000000")
  946.                             .param("coordinate", "POINT (15.1 16.5)")
  947.                             .param("address", "Российская 72/1")
  948.                             .param("object", "GARAGE")
  949.                             .param("operation", "SELL")
  950.                             .param("water", "true")
  951.                             .param("electricity", "true")
  952.                             .with(user(user)))
  953.                .andExpect(status().isOk());
  954.         mockMvc.perform(post("/objects/add")
  955.                             .param("city", "Краснодар")
  956.                             .param("sqmain", "40.5")
  957.                             .param("cost", "15000000")
  958.                             .param("coordinate", "POINT (15.1 16.5)")
  959.                             .param("address", "Российская 72/1")
  960.                             .param("object", "GARAGE")
  961.                             .param("operation", "RENT")
  962.                             .param("water", "true")
  963.                             .param("electricity", "true")
  964.                             .with(user(user)))
  965.                .andExpect(status().isOk());
  966.         TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
  967.         user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  968.         Assert.assertTrue(user.getReObjects().size() == 12);
  969.         transactionManager.commit(status);
  970.     }
  971.    
  972.     @Test
  973.     public void k_testApartmentWithFiles() throws Exception {
  974.         User user = userRepository.findFirstByEmail("mlisting@mlisting.com");
  975.         File userFolder = new File(WebApplicationLayer.fileFolderPath + "/" + user.getId());
  976.         userFolder.mkdir();
  977.        
  978.         File firstFile = new File(WebApplicationLayer.fileFolderPath + "/tmp/1.png");
  979.         firstFile.createNewFile();
  980.         File secondFile = new File(WebApplicationLayer.fileFolderPath + "/tmp/2.png");
  981.         secondFile.createNewFile();
  982.        
  983.         /*--------------------------------------------------
  984.         * Files errors
  985.         *--------------------------------------------------*/
  986.         String result = mockMvc.perform(post("/objects/add")
  987.                                             .param("city", "Краснодар")
  988.                                             .param("sqmain", "40.5")
  989.                                             .param("cost", "15000000")
  990.                                             .param("coordinate", "POINT (15.1 16.5)")
  991.                                             .param("address", "Российская 72/1")
  992.                                             .param("object", "APARTMENT")
  993.                                             .param("operation", "RENT")
  994.                                             .param("floor", "7")
  995.                                             .param("rooms", "1")
  996.                                             .param("decor", "STANDARD")
  997.                                             .param("type", "MONOLITHBRIK")
  998.                                             .param("internet", "true")
  999.                                             .param("furniture", "true")
  1000.                                             .param("appliances", "true")
  1001.                                             .param("files[0].path", "")
  1002.                                             .param("files[0].avatar", "true")
  1003.                                             .param("files[1].avatar", "false")
  1004.                                             .param("files[2].path", "qwert")
  1005.                                             .param("files[3].path", "/qwert/qwert.png")
  1006.                                             .with(user(user)))
  1007.                                .andExpect(status().isBadRequest())
  1008.                                .andReturn().getResponse().getContentAsString();
  1009.         Assert.assertTrue(result.matches(".+files\\[0]\\.path.+"));
  1010.         Assert.assertTrue(result.matches(".+files\\[1]\\.path.+"));
  1011.         Assert.assertTrue(result.matches(".+files\\[2]\\.path.+"));
  1012.        
  1013.         /*--------------------------------------------------
  1014.         * Post listing with files
  1015.         *--------------------------------------------------*/
  1016.         mockMvc.perform(post("/objects/add")
  1017.                             .param("city", "Краснодар")
  1018.                             .param("sqmain", "40.5")
  1019.                             .param("cost", "15000000")
  1020.                             .param("coordinate", "POINT (15.1 16.5)")
  1021.                             .param("address", "Российская 72/1")
  1022.                             .param("object", "APARTMENT")
  1023.                             .param("operation", "RENT")
  1024.                             .param("floor", "7")
  1025.                             .param("rooms", "1")
  1026.                             .param("decor", "STANDARD")
  1027.                             .param("type", "MONOLITHBRIK")
  1028.                             .param("internet", "true")
  1029.                             .param("furniture", "true")
  1030.                             .param("appliances", "true")
  1031.                             .param("files[0].path", "/static/tmp/1.png")
  1032.                             .param("files[0].avatar", "true")
  1033.                             .param("files[1].path", "/static/tmp/2.png")
  1034.                             .with(user(user)))
  1035.                .andExpect(status().isOk());
  1036.         Assert.assertTrue(new File(WebApplicationLayer.fileFolderPath + "/" + user.getId() + "/1.png").exists());
  1037.         Assert.assertTrue(new File(WebApplicationLayer.fileFolderPath + "/" + user.getId() + "/2.png").exists());
  1038.     }
  1039.    
  1040.     @Test
  1041.     public void l_testSearch() throws Exception {
  1042.         mockMvc.perform(post("/objects/search")
  1043.                             .param("city", "Краснодар")
  1044.                             .param("operation", "RENT")
  1045.                             .param("object", "APARTMENT")
  1046.                             .param("polygon", "POLYGON ((0 0, 0 17, 17 17, 17 0, 0 0))"))
  1047.                .andExpect(status().isOk());
  1048.        
  1049.         mockMvc.perform(post("/objects/search")
  1050.                             .param("city", "")
  1051.                             .param("object", "")
  1052.                             .param("polygon", "POLYGON ((0 0, 0 17, 17 17, 17 0, 0 0)"))
  1053.                .andExpect(status().isBadRequest())
  1054.                .andExpect(jsonPath("city").exists())
  1055.                .andExpect(jsonPath("object").exists())
  1056.                .andExpect(jsonPath("operation").exists())
  1057.                .andExpect(jsonPath("polygon").exists());
  1058.        
  1059.         for (File file : new File(WebApplicationLayer.fileFolderPath).listFiles()) {
  1060.             if (file.isDirectory() && !file.getName().equals("tmp")) {
  1061.                 FileUtils.deleteDirectory(file);
  1062.             }
  1063.         }
  1064.         userRepository.deleteAll();
  1065.         objectRepository.deleteAll();
  1066.     }
  1067. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement