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.imaging.operations.load; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
|
38 |
|
import info.magnolia.cms.core.Content; |
39 |
|
import info.magnolia.cms.core.HierarchyManager; |
40 |
|
import info.magnolia.cms.util.ContentUtil; |
41 |
|
import info.magnolia.context.MgnlContext; |
42 |
|
import info.magnolia.imaging.AbstractRepositoryTestCase; |
43 |
|
import info.magnolia.imaging.ImagingException; |
44 |
|
import info.magnolia.imaging.ParameterProvider; |
45 |
|
import info.magnolia.imaging.ParameterProviderFactory; |
46 |
|
import info.magnolia.imaging.caching.CachingStrategy; |
47 |
|
import info.magnolia.imaging.caching.ContentBasedCachingStrategy; |
48 |
|
import info.magnolia.imaging.parameters.ContentParameterProvider; |
49 |
|
|
50 |
|
import org.junit.Before; |
51 |
|
import org.junit.Test; |
52 |
|
|
53 |
|
|
54 |
|
@link |
55 |
|
|
|
|
| 90.9% |
Uncovered Elements: 2 (22) |
Complexity: 5 |
Complexity Density: 0.26 |
|
56 |
|
public class FromContentTest extends AbstractRepositoryTestCase { |
57 |
|
private Content src; |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
59 |
2 |
@Override... |
60 |
|
@Before |
61 |
|
public void setUp() throws Exception { |
62 |
2 |
super.setUp(); |
63 |
2 |
final HierarchyManager srcHM = MgnlContext.getHierarchyManager("website"); |
64 |
2 |
src = ContentUtil.createPath(srcHM, "/some/node"); |
65 |
2 |
src.createNodeData("chalala", "tralala"); |
66 |
2 |
srcHM.save(); |
67 |
|
} |
68 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
69 |
1 |
@Test... |
70 |
|
public void testNonBinaryPropertyYieldsAProperException() throws Exception { |
71 |
1 |
final ParameterProviderFactory<Object, Content> ppf = new TestParameterProviderFactory(src); |
72 |
|
|
73 |
1 |
final FromContent op = new FromContent(); |
74 |
1 |
op.setPropertyName("chalala"); |
75 |
|
|
76 |
1 |
try { |
77 |
1 |
op.apply(null, ppf.newParameterProviderFor(null)); |
78 |
0 |
fail(); |
79 |
|
} catch (ImagingException e) { |
80 |
1 |
assertEquals("Nodedata /some/node/chalala doesn't exist or is not of type binary.", e.getMessage()); |
81 |
|
} |
82 |
|
} |
83 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
84 |
1 |
@Test... |
85 |
|
public void testUnexistingPropertyYieldsAProperException() throws Exception { |
86 |
1 |
final ParameterProviderFactory<Object, Content> ppf = new TestParameterProviderFactory(src); |
87 |
|
|
88 |
1 |
final FromContent op = new FromContent(); |
89 |
1 |
op.setPropertyName("foobar"); |
90 |
|
|
91 |
1 |
try { |
92 |
1 |
op.apply(null, ppf.newParameterProviderFor(null)); |
93 |
0 |
fail(); |
94 |
|
} catch (ImagingException e) { |
95 |
1 |
assertEquals("There is no 'foobar' property at /some/node", e.getMessage()); |
96 |
|
} |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
99 |
|
private class TestParameterProviderFactory implements ParameterProviderFactory<Object, Content> { |
100 |
|
private final Content src; |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
2 |
public TestParameterProviderFactory(final Content src) {... |
103 |
2 |
this.src = src; |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
2 |
@Override... |
107 |
|
public ParameterProvider<Content> newParameterProviderFor(Object environment) { |
108 |
2 |
return new ContentParameterProvider(src); |
109 |
|
} |
110 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
111 |
|
@Override... |
112 |
|
public CachingStrategy getCachingStrategy() { |
113 |
|
return new ContentBasedCachingStrategy(); |
114 |
|
} |
115 |
|
} |
116 |
|
} |