use of org.apache.maven.plugins.help.DescribeMojo.PluginInfo in project maven-plugins by apache.
the class DescribeMojoTest method testLookupPluginDescriptorGAV.
public void testLookupPluginDescriptorGAV() throws Throwable {
DescribeMojo mojo = new DescribeMojo();
PluginInfo pi = new PluginInfo();
pi.setGroupId("org.test");
pi.setArtifactId("test");
pi.setVersion("1.0");
PluginDescriptor pd = new PluginDescriptor();
MojoDescriptorCreator mojoDescriptorCreator = mock(MojoDescriptorCreator.class);
PluginVersionResolver pluginVersionResolver = mock(PluginVersionResolver.class);
MavenPluginManagerHelper pluginManager = mock(MavenPluginManagerHelper.class);
MavenSession session = mock(MavenSession.class);
PrivateAccessor.setField(mojo, "mojoDescriptorCreator", mojoDescriptorCreator);
PrivateAccessor.setField(mojo, "pluginVersionResolver", pluginVersionResolver);
PrivateAccessor.setField(mojo, "pluginManager", pluginManager);
PrivateAccessor.setField(mojo, "session", session);
when(pluginManager.getPluginDescriptor(any(Plugin.class), eq(session))).thenReturn(pd);
PluginDescriptor returned = (PluginDescriptor) PrivateAccessor.invoke(mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, new Object[] { pi });
assertEquals(pd, returned);
verify(mojoDescriptorCreator, never()).findPluginForPrefix(any(String.class), any(MavenSession.class));
verify(pluginVersionResolver, never()).resolve(any(PluginVersionRequest.class));
ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass(Plugin.class);
verify(pluginManager).getPluginDescriptor(argument.capture(), eq(session));
Plugin capturedPlugin = argument.getValue();
assertEquals("org.test", capturedPlugin.getGroupId());
assertEquals("test", capturedPlugin.getArtifactId());
assertEquals("1.0", capturedPlugin.getVersion());
}
use of org.apache.maven.plugins.help.DescribeMojo.PluginInfo in project maven-plugins by apache.
the class DescribeMojoTest method testLookupPluginDescriptorPrefixWithVersion.
public void testLookupPluginDescriptorPrefixWithVersion() throws Throwable {
DescribeMojo mojo = new DescribeMojo();
PluginInfo pi = new PluginInfo();
pi.setPrefix("help");
pi.setVersion("1.0");
Plugin plugin = new Plugin();
plugin.setGroupId("org.test");
plugin.setArtifactId("test");
PluginDescriptor pd = new PluginDescriptor();
MojoDescriptorCreator mojoDescriptorCreator = mock(MojoDescriptorCreator.class);
PluginVersionResolver pluginVersionResolver = mock(PluginVersionResolver.class);
MavenPluginManagerHelper pluginManager = mock(MavenPluginManagerHelper.class);
MavenSession session = mock(MavenSession.class);
PrivateAccessor.setField(mojo, "mojoDescriptorCreator", mojoDescriptorCreator);
PrivateAccessor.setField(mojo, "pluginVersionResolver", pluginVersionResolver);
PrivateAccessor.setField(mojo, "pluginManager", pluginManager);
PrivateAccessor.setField(mojo, "session", session);
when(mojoDescriptorCreator.findPluginForPrefix("help", session)).thenReturn(plugin);
when(pluginManager.getPluginDescriptor(any(Plugin.class), eq(session))).thenReturn(pd);
PluginDescriptor returned = (PluginDescriptor) PrivateAccessor.invoke(mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, new Object[] { pi });
assertEquals(pd, returned);
verify(mojoDescriptorCreator).findPluginForPrefix("help", session);
verify(pluginVersionResolver, never()).resolve(any(PluginVersionRequest.class));
ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass(Plugin.class);
verify(pluginManager).getPluginDescriptor(argument.capture(), eq(session));
Plugin capturedPlugin = argument.getValue();
assertEquals("org.test", capturedPlugin.getGroupId());
assertEquals("test", capturedPlugin.getArtifactId());
assertEquals("1.0", capturedPlugin.getVersion());
}
use of org.apache.maven.plugins.help.DescribeMojo.PluginInfo in project maven-plugins by apache.
the class DescribeMojoTest method testLookupPluginDescriptorPrefixWithoutVersion.
public void testLookupPluginDescriptorPrefixWithoutVersion() throws Throwable {
DescribeMojo mojo = new DescribeMojo();
PluginInfo pi = new PluginInfo();
pi.setPrefix("help");
Plugin plugin = new Plugin();
plugin.setGroupId("org.test");
plugin.setArtifactId("test");
PluginDescriptor pd = new PluginDescriptor();
MojoDescriptorCreator mojoDescriptorCreator = mock(MojoDescriptorCreator.class);
PluginVersionResolver pluginVersionResolver = mock(PluginVersionResolver.class);
MavenPluginManagerHelper pluginManager = mock(MavenPluginManagerHelper.class);
PluginVersionResult versionResult = mock(PluginVersionResult.class);
MavenSession session = mock(MavenSession.class);
PrivateAccessor.setField(mojo, "mojoDescriptorCreator", mojoDescriptorCreator);
PrivateAccessor.setField(mojo, "pluginVersionResolver", pluginVersionResolver);
PrivateAccessor.setField(mojo, "pluginManager", pluginManager);
PrivateAccessor.setField(mojo, "session", session);
PrivateAccessor.setField(mojo, "project", new MavenProject());
when(mojoDescriptorCreator.findPluginForPrefix("help", session)).thenReturn(plugin);
when(pluginVersionResolver.resolve(any(PluginVersionRequest.class))).thenReturn(versionResult);
when(versionResult.getVersion()).thenReturn("1.0");
when(pluginManager.getPluginDescriptor(any(Plugin.class), eq(session))).thenReturn(pd);
PluginDescriptor returned = (PluginDescriptor) PrivateAccessor.invoke(mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, new Object[] { pi });
assertEquals(pd, returned);
verify(mojoDescriptorCreator).findPluginForPrefix("help", session);
ArgumentCaptor<PluginVersionRequest> versionArgument = ArgumentCaptor.forClass(PluginVersionRequest.class);
verify(pluginVersionResolver).resolve(versionArgument.capture());
assertEquals("org.test", versionArgument.getValue().getGroupId());
assertEquals("test", versionArgument.getValue().getArtifactId());
ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass(Plugin.class);
verify(pluginManager).getPluginDescriptor(argument.capture(), eq(session));
Plugin capturedPlugin = argument.getValue();
assertEquals("org.test", capturedPlugin.getGroupId());
assertEquals("test", capturedPlugin.getArtifactId());
assertEquals("1.0", capturedPlugin.getVersion());
}
use of org.apache.maven.plugins.help.DescribeMojo.PluginInfo in project maven-plugins by apache.
the class DescribeMojoTest method testParsePluginInfoPluginPrefix.
public void testParsePluginInfoPluginPrefix() throws Throwable {
DescribeMojo mojo = new DescribeMojo();
PrivateAccessor.setField(mojo, "plugin", "help");
PluginInfo pi = (PluginInfo) PrivateAccessor.invoke(mojo, "parsePluginLookupInfo", null, null);
assertNull(pi.getGroupId());
assertNull(pi.getArtifactId());
assertNull(pi.getVersion());
assertEquals("help", pi.getPrefix());
PrivateAccessor.setField(mojo, "plugin", "help2:::");
pi = (PluginInfo) PrivateAccessor.invoke(mojo, "parsePluginLookupInfo", null, null);
assertEquals("help2", pi.getPrefix());
}
use of org.apache.maven.plugins.help.DescribeMojo.PluginInfo in project maven-plugins by apache.
the class DescribeMojoTest method testLookupPluginDescriptorGMissingA.
public void testLookupPluginDescriptorGMissingA() throws Throwable {
DescribeMojo mojo = new DescribeMojo();
PluginInfo pi = new PluginInfo();
pi.setGroupId("org.test");
try {
PrivateAccessor.invoke(mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, new Object[] { pi });
fail();
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("You must specify either"));
}
}
Aggregations