1 /**
2 * Copyright (c) 2012-2014, jcabi.com
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met: 1) Redistributions of source code must retain the above
8 * copyright notice, this list of conditions and the following
9 * disclaimer. 2) Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution. 3) Neither the name of the jcabi.com nor
13 * the names of its contributors may be used to endorse or promote
14 * products derived from this software without specific prior written
15 * permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
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 * Test case for {@link DeployMojo} (more detailed test is in maven invoker).
47 * @author Yegor Bugayenko (yegor@tpc2.com)
48 * @version $Id$
49 * @checkstyle ClassDataAbstractionCoupling (500 lines)
50 */
51 public final class DeployMojoTest {
52
53 /**
54 * DeployMojo can skip execution when flag is set.
55 * @throws Exception If something is wrong
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 * DeployMojo can generate correct settings.xml file.
66 * @throws Exception If something is wrong
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 * DeployMojo can generate correct settings.xml file.
95 * @throws Exception If something is wrong
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 }