1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint
|
---|
3 | import java.awt.Color
|
---|
4 |
|
---|
5 | import org.junit.*
|
---|
6 | import org.openstreetmap.josm.JOSMFixture
|
---|
7 | import org.openstreetmap.josm.data.osm.Node
|
---|
8 | import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy
|
---|
9 | import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.TagLookupCompositionStrategy
|
---|
10 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.TagKeyReference
|
---|
11 |
|
---|
12 | class MapCSSWithExtendedTextDirectivesTest {
|
---|
13 |
|
---|
14 | @BeforeClass
|
---|
15 | public static void createJOSMFixture(){
|
---|
16 | JOSMFixture.createUnitTestFixture().init()
|
---|
17 | }
|
---|
18 |
|
---|
19 | @Test
|
---|
20 | public void createAutoTextElement() {
|
---|
21 | MultiCascade mc = new MultiCascade()
|
---|
22 | Cascade c = mc.getOrCreateCascade("default")
|
---|
23 | c.put("text", new Keyword("auto"))
|
---|
24 | Node osm = new Node()
|
---|
25 | osm.put("ref", "A456");
|
---|
26 | Environment env = new Environment(osm, mc, "default", null)
|
---|
27 |
|
---|
28 | TextElement te = TextElement.create(env, Color.WHITE, false /* no default annotate */)
|
---|
29 | assert te.labelCompositionStrategy != null
|
---|
30 | assert te.labelCompositionStrategy instanceof DeriveLabelFromNameTagsCompositionStrategy
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Test
|
---|
34 | public void createTextElementComposingTextFromTag() {
|
---|
35 | MultiCascade mc = new MultiCascade()
|
---|
36 | Cascade c = mc.getOrCreateCascade("default")
|
---|
37 | c.put("text", new TagKeyReference("my_name"))
|
---|
38 | Node osm = new Node()
|
---|
39 | osm.put("my_name", "foobar");
|
---|
40 | Environment env = new Environment(osm, mc, "default", null)
|
---|
41 |
|
---|
42 | TextElement te = TextElement.create(env, Color.WHITE, false /* no default annotate */)
|
---|
43 | assert te.labelCompositionStrategy != null
|
---|
44 | assert te.labelCompositionStrategy instanceof TagLookupCompositionStrategy
|
---|
45 | assert te.labelCompositionStrategy.getDefaultLabelTag() == "my_name"
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Test
|
---|
49 | public void createNullStrategy() {
|
---|
50 | MultiCascade mc = new MultiCascade()
|
---|
51 | Node osm = new Node()
|
---|
52 | Environment env = new Environment(osm, mc, "default", null)
|
---|
53 |
|
---|
54 | TextElement te = TextElement.create(env, Color.WHITE, false /* no default annotate */)
|
---|
55 | assert te == null
|
---|
56 | }
|
---|
57 | }
|
---|