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 package com.jcabi.heroku.maven.plugin;
31
32 import com.jcabi.velocity.VelocityPage;
33 import com.rexsl.test.XhtmlMatchers;
34 import java.util.Arrays;
35 import org.apache.maven.artifact.DefaultArtifact;
36 import org.apache.maven.model.Build;
37 import org.apache.maven.model.Extension;
38 import org.apache.maven.project.MavenProject;
39 import org.apache.maven.settings.Server;
40 import org.apache.maven.settings.Settings;
41 import org.hamcrest.MatcherAssert;
42 import org.hamcrest.Matchers;
43 import org.junit.Test;
44
45
46
47
48
49
50
51 public final class DeployMojoTest {
52
53
54
55
56
57 @Test
58 public void skipsExecutionWhenRequired() throws Exception {
59 final DeployMojo mojo = new DeployMojo();
60 mojo.setSkip(true);
61 mojo.execute();
62 }
63
64
65
66
67
68 @Test
69 public void velocityTemplateCorrectlyBuildsSettingsXml() throws Exception {
70 final Server server = new Server();
71 server.setUsername("john");
72 server.setPassword("xxx");
73 final Settings settings = new Settings();
74 settings.addServer(server);
75 final String nspace = "http://maven.apache.org/SETTINGS/1.0.0";
76 MatcherAssert.assertThat(
77 new VelocityPage(
78 "com/jcabi/heroku/maven/plugin/settings.xml.vm"
79 ).set("settings", settings).toString(),
80 Matchers.allOf(
81 XhtmlMatchers.hasXPath(
82 "//ns1:server[ns1:username='john' and ns1:password='xxx']",
83 nspace
84 ),
85 XhtmlMatchers.hasXPath(
86 "//ns1:server[ns1:username='john' and not(ns1:privateKey)]",
87 nspace
88 )
89 )
90 );
91 }
92
93
94
95
96
97 @Test
98 public void velocityTemplateCorrectlyBuildsPomXml() throws Exception {
99 final Build build = new Build();
100 final Extension ext = new Extension();
101 ext.setArtifactId("test-foo");
102 build.addExtension(ext);
103 final MavenProject project = new MavenProject();
104 project.setBuild(build);
105 final String nspace = "http://maven.apache.org/POM/4.0.0";
106 MatcherAssert.assertThat(
107 new VelocityPage(
108 "com/jcabi/heroku/maven/plugin/pom.xml.vm"
109 ).set("project", project)
110 .set("timestamp", "332211")
111 .set(
112 "deps",
113 Arrays.asList(
114 new DefaultArtifact("fooo", "", "", "", "", "", null)
115 )
116 )
117 .toString(),
118 Matchers.allOf(
119 XhtmlMatchers.hasXPath(
120 "//ns1:name[.='332211']",
121 nspace
122 ),
123 XhtmlMatchers.hasXPath(
124 "//ns1:extension[ns1:artifactId='test-foo']",
125 nspace
126 ),
127 XhtmlMatchers.hasXPath(
128 "//ns1:dependency[ns1:groupId='fooo']",
129 nspace
130 ),
131 XhtmlMatchers.hasXPath(
132 "//ns1:configuration[ns1:outputDirectory='${basedir}']",
133 nspace
134 )
135 )
136 );
137 }
138
139 }