1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.rest.tools.app; |
35 |
|
|
36 |
|
import static org.hamcrest.CoreMatchers.equalTo; |
37 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
38 |
|
import static org.mockito.Mockito.mock; |
39 |
|
|
40 |
|
import info.magnolia.context.MgnlContext; |
41 |
|
import info.magnolia.rest.tools.RestToolsModule; |
42 |
|
import info.magnolia.test.mock.MockWebContext; |
43 |
|
import info.magnolia.ui.api.app.SubAppContext; |
44 |
|
import info.magnolia.ui.framework.app.embedded.EmbeddedPageView; |
45 |
|
|
46 |
|
import org.junit.After; |
47 |
|
import org.junit.Before; |
48 |
|
import org.junit.Test; |
49 |
|
|
50 |
|
|
51 |
|
@link |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 4 |
Complexity Density: 0.22 |
|
53 |
|
public class SwaggerUIEmbeddedPageSubAppTest { |
54 |
|
|
55 |
|
public static final String CONTEXT_PATH = "/magnoliaAuthor"; |
56 |
|
private SwaggerUIEmbeddedPageSubApp swagggerSubApp; |
57 |
|
private SubAppContext subAppContext; |
58 |
|
private RestToolsModule module; |
59 |
|
private EmbeddedPageView embeddedPageView; |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
61 |
2 |
@Before... |
62 |
|
public void setUp() { |
63 |
2 |
MockWebContext ctx = new MockWebContext(); |
64 |
2 |
ctx.setContextPath(CONTEXT_PATH); |
65 |
2 |
MgnlContext.setInstance(ctx); |
66 |
2 |
subAppContext = mock(SubAppContext.class); |
67 |
2 |
embeddedPageView = mock(EmbeddedPageView.class); |
68 |
2 |
module = new RestToolsModule(); |
69 |
2 |
swagggerSubApp = new SwaggerUIEmbeddedPageSubApp(subAppContext, embeddedPageView, module); |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
2 |
@After... |
73 |
|
public void tearDown() { |
74 |
2 |
MgnlContext.setInstance(null); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
77 |
1 |
@Test... |
78 |
|
public void testWhenApiBasepathContainsProtocolAndHost() { |
79 |
|
|
80 |
1 |
final String fullApiBasepath = "http://localhost:8080" + CONTEXT_PATH +"/.rest"; |
81 |
1 |
module.setApiBasepath(fullApiBasepath); |
82 |
1 |
final String originalUrl = "/.resources/swagger-ui/index.html"; |
83 |
|
|
84 |
|
|
85 |
1 |
final String result = swagggerSubApp.updateUrl(originalUrl); |
86 |
|
|
87 |
|
|
88 |
1 |
assertThat(result, equalTo(CONTEXT_PATH + "/.resources/swagger-ui/index.html?apiBasepath=" + fullApiBasepath)); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
91 |
1 |
@Test... |
92 |
|
public void testWhenOriginalUrlAlreadyContainsFullApiBasepath() { |
93 |
|
|
94 |
1 |
final String fullApiBasepath = "http://localhost:8080" + CONTEXT_PATH +"/.rest"; |
95 |
1 |
module.setApiBasepath(fullApiBasepath); |
96 |
1 |
final String originalUrl = "/.resources/swagger-ui/index.html?apiBasepath=" + fullApiBasepath; |
97 |
|
|
98 |
|
|
99 |
1 |
final String result = swagggerSubApp.updateUrl(originalUrl); |
100 |
|
|
101 |
|
|
102 |
1 |
assertThat(result, equalTo(CONTEXT_PATH + "/.resources/swagger-ui/index.html?apiBasepath=" + fullApiBasepath)); |
103 |
|
} |
104 |
|
|
105 |
|
} |