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