Search in sources :

Example 16 with MockControl

use of org.easymock.MockControl in project maven-archetype by apache.

the class DefaultArchetypeGenerationQueryerTest method testPropertyRegexValidationRetry.

public void testPropertyRegexValidationRetry() throws PrompterException {
    MockControl control = MockControl.createControl(Prompter.class);
    Prompter prompter = (Prompter) control.getMock();
    prompter.prompt("");
    control.setMatcher(createArgumentMatcher());
    control.setReturnValue("invalid-answer");
    queryer.setPrompter(prompter);
    prompter.prompt("");
    control.setReturnValue("valid-answer");
    queryer.setPrompter(prompter);
    control.replay();
    String value = queryer.getPropertyValue("custom-property", null, Pattern.compile("^valid-.*"));
    assertEquals("valid-answer", value);
}
Also used : Prompter(org.codehaus.plexus.components.interactivity.Prompter) MockControl(org.easymock.MockControl)

Example 17 with MockControl

use of org.easymock.MockControl in project maven-archetype by apache.

the class DefaultArchetypeSelectionQueryerTest method testDefaultArchetypeInMapDefaultSelection.

public void testDefaultArchetypeInMapDefaultSelection() throws PrompterException {
    Map<String, List<Archetype>> map = createDefaultArchetypeCatalog();
    MockControl control = MockControl.createControl(Prompter.class);
    Prompter prompter = (Prompter) control.getMock();
    prompter.prompt("", "2");
    control.setMatcher(createArgumentMatcher());
    control.setReturnValue("2");
    queryer.setPrompter(prompter);
    control.replay();
    ArchetypeDefinition defaultDefinition = new ArchetypeDefinition();
    defaultDefinition.setGroupId("default-groupId");
    defaultDefinition.setArtifactId("default-artifactId");
    defaultDefinition.setVersion("default-version");
    Archetype archetype = queryer.selectArchetype(map, defaultDefinition);
    control.verify();
    assertEquals("default-groupId", archetype.getGroupId());
    assertEquals("default-artifactId", archetype.getArtifactId());
    assertEquals("default-version", archetype.getVersion());
}
Also used : Prompter(org.codehaus.plexus.components.interactivity.Prompter) ArchetypeDefinition(org.apache.maven.archetype.ui.ArchetypeDefinition) MockControl(org.easymock.MockControl) Archetype(org.apache.maven.archetype.catalog.Archetype) List(java.util.List) ArrayList(java.util.ArrayList)

Example 18 with MockControl

use of org.easymock.MockControl in project maven-archetype by apache.

the class DefaultArchetypeSelectionQueryerTest method testDefaultArchetypeNotInMap.

public void testDefaultArchetypeNotInMap() throws PrompterException {
    Map<String, List<Archetype>> map = createDefaultArchetypeCatalog();
    MockControl control = MockControl.createControl(Prompter.class);
    Prompter prompter = (Prompter) control.getMock();
    prompter.prompt("");
    control.setMatcher(createArgumentMatcher());
    control.setReturnValue("1");
    queryer.setPrompter(prompter);
    control.replay();
    ArchetypeDefinition defaultDefinition = new ArchetypeDefinition();
    defaultDefinition.setGroupId("invalid-groupId");
    defaultDefinition.setArtifactId("invalid-artifactId");
    defaultDefinition.setVersion("invalid-version");
    Archetype archetype = queryer.selectArchetype(map, defaultDefinition);
    control.verify();
    assertEquals("set-groupId", archetype.getGroupId());
    assertEquals("set-artifactId", archetype.getArtifactId());
    assertEquals("set-version", archetype.getVersion());
}
Also used : Prompter(org.codehaus.plexus.components.interactivity.Prompter) ArchetypeDefinition(org.apache.maven.archetype.ui.ArchetypeDefinition) MockControl(org.easymock.MockControl) Archetype(org.apache.maven.archetype.catalog.Archetype) List(java.util.List) ArrayList(java.util.ArrayList)

Example 19 with MockControl

use of org.easymock.MockControl in project maven-archetype by apache.

the class DefaultArchetypeSelectorTest method testArchetypeCoordinatesInRequest.

public void testArchetypeCoordinatesInRequest() throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype, ArchetypeNotDefined {
    ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
    request.setArchetypeArtifactId("preset-artifactId");
    request.setArchetypeGroupId("preset-groupId");
    request.setArchetypeVersion("preset-version");
    MockControl control = MockControl.createControl(ArchetypeSelectionQueryer.class);
    ArchetypeSelectionQueryer queryer = (ArchetypeSelectionQueryer) control.getMock();
    // expect it to not be called
    control.replay();
    selector.setArchetypeSelectionQueryer(queryer);
    selector.selectArchetype(request, Boolean.TRUE, "");
    control.verify();
    assertEquals("preset-groupId", request.getArchetypeGroupId());
    assertEquals("preset-artifactId", request.getArchetypeArtifactId());
    assertEquals("preset-version", request.getArchetypeVersion());
}
Also used : MockControl(org.easymock.MockControl) ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest)

Example 20 with MockControl

use of org.easymock.MockControl in project maven-archetype by apache.

the class DefaultArchetypeSelectorTest method testArchetypeArtifactIdNotInRequest.

public void testArchetypeArtifactIdNotInRequest() throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype, ArchetypeNotDefined {
    ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
    MockControl control = MockControl.createControl(ArchetypeSelectionQueryer.class);
    ArchetypeSelectionQueryer queryer = (ArchetypeSelectionQueryer) control.getMock();
    queryer.selectArchetype(Collections.<String, List<Archetype>>emptyMap(), new ArchetypeDefinition());
    control.setMatcher(MockControl.ALWAYS_MATCHER);
    Archetype archetype = new Archetype();
    archetype.setArtifactId("set-artifactId");
    archetype.setGroupId("set-groupId");
    archetype.setVersion("set-version");
    control.setReturnValue(archetype);
    control.replay();
    selector.setArchetypeSelectionQueryer(queryer);
    selector.selectArchetype(request, Boolean.TRUE, "");
    control.verify();
    assertEquals("set-groupId", request.getArchetypeGroupId());
    assertEquals("set-artifactId", request.getArchetypeArtifactId());
    assertEquals("set-version", request.getArchetypeVersion());
}
Also used : ArchetypeDefinition(org.apache.maven.archetype.ui.ArchetypeDefinition) MockControl(org.easymock.MockControl) Archetype(org.apache.maven.archetype.catalog.Archetype) UnknownArchetype(org.apache.maven.archetype.exception.UnknownArchetype) ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest)

Aggregations

MockControl (org.easymock.MockControl)21 Hashtable (java.util.Hashtable)8 Bundle (org.osgi.framework.Bundle)8 BundleContext (org.osgi.framework.BundleContext)8 ServiceRegistration (org.osgi.framework.ServiceRegistration)8 Archetype (org.apache.maven.archetype.catalog.Archetype)7 Prompter (org.codehaus.plexus.components.interactivity.Prompter)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)5 Collection (java.util.Collection)4 ArchetypeDefinition (org.apache.maven.archetype.ui.ArchetypeDefinition)4 ServiceFactory (org.osgi.framework.ServiceFactory)3 EventHook (org.osgi.framework.hooks.service.EventHook)3 FindHook (org.osgi.framework.hooks.service.FindHook)3 ListenerHook (org.osgi.framework.hooks.service.ListenerHook)3 ArchetypeArtifactManager (org.apache.maven.archetype.common.ArchetypeArtifactManager)2 UnknownArchetype (org.apache.maven.archetype.exception.UnknownArchetype)2 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)2 ServiceEvent (org.osgi.framework.ServiceEvent)2