View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.mappers;
12  
13  import com.opensymphony.module.sitemesh.Config;
14  import com.opensymphony.module.sitemesh.DecoratorMapper;
15  import com.opensymphony.module.sitemesh.Page;
16  
17  import jakarta.servlet.http.HttpServletRequest;
18  
19  import java.util.Properties;
20  
21  import mockit.Expectations;
22  import mockit.Mocked;
23  
24  import org.junit.jupiter.api.Assertions;
25  import org.junit.jupiter.api.BeforeEach;
26  import org.junit.jupiter.api.Test;
27  
28  /**
29   * The Class AjaxDecoratorMapperTest.
30   */
31  class AjaxDecoratorMapperTest {
32  
33    /** The mapper. */
34    AjaxDecoratorMapper mapper;
35  
36    /** The config. */
37    @Mocked
38    Config config;
39  
40    /** The properties. */
41    Properties properties;
42  
43    /** The decorator mapper. */
44    @Mocked
45    DecoratorMapper decoratorMapper;
46  
47    /** The request. */
48    @Mocked
49    HttpServletRequest request;
50  
51    /** The page. */
52    @Mocked
53    Page page;
54  
55    /**
56     * Before.
57     */
58    @BeforeEach
59    void before() {
60      mapper = new AjaxDecoratorMapper();
61      properties = new Properties();
62    }
63  
64    /**
65     * Ajax decorator mapper test.
66     *
67     * @throws InstantiationException the instantiation exception
68     */
69    @Test
70    void ajaxDecoratorMapperTest() throws InstantiationException {
71      properties.setProperty("ajaxExtension", ".ajax");
72      mapper.init(config, properties, decoratorMapper);
73  
74      new Expectations() {
75        {
76          request.getAttribute("jakarta.servlet.error.request_uri");
77          result = "https://localhost:8443/probe";
78  
79          request.getServletPath();
80          result = "probe/ws";
81        }
82      };
83      Assertions.assertNotNull(mapper.getDecorator(request, page));
84    }
85  
86  }