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; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
|
38 |
|
import info.magnolia.cms.beans.runtime.FileProperties; |
39 |
|
import info.magnolia.cms.core.Content; |
40 |
|
import info.magnolia.cms.core.HierarchyManager; |
41 |
|
import info.magnolia.cms.core.NodeData; |
42 |
|
import info.magnolia.cms.util.ContentUtil; |
43 |
|
import info.magnolia.cms.util.NodeDataUtil; |
44 |
|
import info.magnolia.context.MgnlContext; |
45 |
|
import info.magnolia.imaging.caching.CachingStrategy; |
46 |
|
import info.magnolia.imaging.caching.ContentBasedCachingStrategy; |
47 |
|
import info.magnolia.imaging.parameters.ContentParameterProvider; |
48 |
|
|
49 |
|
import java.io.ByteArrayInputStream; |
50 |
|
import java.io.ByteArrayOutputStream; |
51 |
|
import java.io.InputStream; |
52 |
|
import java.util.Calendar; |
53 |
|
import java.util.concurrent.TimeUnit; |
54 |
|
|
55 |
|
import javax.jcr.PropertyType; |
56 |
|
|
57 |
|
import org.apache.commons.io.IOUtils; |
58 |
|
import org.junit.Test; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (39) |
Complexity: 2 |
Complexity Density: 0.05 |
|
63 |
|
public class SelfTest extends AbstractRepositoryTestCase { |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
65 |
1 |
@Test... |
66 |
|
public void testCanGetBinaryStreamOutOfTheSamePropertyInstanceTwice() throws Exception { |
67 |
1 |
final HierarchyManager hm = MgnlContext.getHierarchyManager("website"); |
68 |
1 |
final Content content = ContentUtil.createPath(hm, "/foo/bar"); |
69 |
1 |
final NodeData prop = NodeDataUtil.getOrCreate(content, "test", PropertyType.BINARY); |
70 |
|
|
71 |
1 |
final ByteArrayInputStream tempIn = new ByteArrayInputStream("HELLO".getBytes()); |
72 |
1 |
prop.setValue(tempIn); |
73 |
1 |
prop.setAttribute(FileProperties.PROPERTY_CONTENTTYPE, "text/plain"); |
74 |
1 |
prop.setAttribute(FileProperties.PROPERTY_LASTMODIFIED, Calendar.getInstance()); |
75 |
1 |
hm.save(); |
76 |
|
|
77 |
|
|
78 |
1 |
final NodeData p = hm.getNodeData("/foo/bar/test"); |
79 |
1 |
final InputStream in1 = p.getStream(); |
80 |
1 |
final InputStream in2 = p.getStream(); |
81 |
|
|
82 |
1 |
final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
83 |
1 |
IOUtils.copy(in1, out); |
84 |
1 |
IOUtils.copy(in2, out); |
85 |
1 |
IOUtils.copy(in1, out); |
86 |
1 |
assertEquals("HELLOHELLO", out.toString()); |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
89 |
1 |
@Test... |
90 |
|
public void testNodeParameterProviderHandlesTimestampsProperly() throws Exception { |
91 |
1 |
final HierarchyManager hm = MgnlContext.getHierarchyManager("website"); |
92 |
|
|
93 |
1 |
final Content src = ContentUtil.createPath(hm, "/cha/lala", true); |
94 |
1 |
src.getMetaData().setCreationDate(); |
95 |
1 |
src.getMetaData().setModificationDate(); |
96 |
1 |
System.out.println("src.getMetaData().getModificationDate() = " + src.getMetaData().getModificationDate()); |
97 |
1 |
TimeUnit.MILLISECONDS.sleep(3); |
98 |
|
|
99 |
|
|
100 |
1 |
final Content cachedNode = ContentUtil.createPath(hm, "/foo/bar", true); |
101 |
1 |
cachedNode.getMetaData().setCreationDate(); |
102 |
1 |
cachedNode.getMetaData().setModificationDate(); |
103 |
1 |
final NodeData cachedBinaryProp = NodeDataUtil.getOrCreate(cachedNode, "test", PropertyType.BINARY); |
104 |
|
|
105 |
1 |
final ByteArrayInputStream tempIn = new ByteArrayInputStream("HELLO".getBytes()); |
106 |
1 |
cachedBinaryProp.setValue(tempIn); |
107 |
1 |
cachedBinaryProp.setAttribute(FileProperties.PROPERTY_CONTENTTYPE, "text/plain"); |
108 |
1 |
cachedBinaryProp.setAttribute(FileProperties.PROPERTY_LASTMODIFIED, Calendar.getInstance()); |
109 |
1 |
hm.save(); |
110 |
|
|
111 |
1 |
final ContentParameterProvider pp = new ContentParameterProvider(src); |
112 |
1 |
final CachingStrategy<Content> cachingStrategy = new ContentBasedCachingStrategy(); |
113 |
1 |
assertFalse(cachingStrategy.shouldRegenerate(cachedBinaryProp, pp)); |
114 |
|
|
115 |
1 |
TimeUnit.MILLISECONDS.sleep(25); |
116 |
|
|
117 |
1 |
src.getMetaData().setModificationDate(); |
118 |
1 |
assertTrue(cachingStrategy.shouldRegenerate(cachedBinaryProp, pp)); |
119 |
|
} |
120 |
|
|
121 |
|
} |