-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements _Launch on App Engine_ (#1070)
- Loading branch information
1 parent
1205d85
commit 4f11a22
Showing
17 changed files
with
632 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
...ogle/cloud/tools/eclipse/appengine/localserver/ui/LaunchAppEngineStandardHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Copyright 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.tools.eclipse.appengine.localserver.ui; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.google.cloud.tools.eclipse.appengine.facets.AppEngineStandardFacet; | ||
import com.google.cloud.tools.eclipse.test.util.project.TestProjectCreator; | ||
import com.google.cloud.tools.eclipse.test.util.ui.ExecutionEventBuilder; | ||
import com.google.common.collect.Lists; | ||
import org.eclipse.core.commands.ExecutionEvent; | ||
import org.eclipse.core.commands.ExecutionException; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.SubMonitor; | ||
import org.eclipse.debug.core.ILaunch; | ||
import org.eclipse.debug.core.ILaunchManager; | ||
import org.eclipse.jst.common.project.facet.core.JavaFacet; | ||
import org.eclipse.jst.j2ee.web.project.facet.WebFacetUtils; | ||
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; | ||
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; | ||
import org.eclipse.wst.server.core.IModule; | ||
import org.eclipse.wst.server.core.IServer; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
/** | ||
* Tests for the {@link LaunchAppEngineStandardHandler}. | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class LaunchAppEngineStandardHandlerTest { | ||
private static final IProjectFacetVersion APPENGINE_STANDARD_FACET_VERSION_1 = | ||
ProjectFacetsManager.getProjectFacet(AppEngineStandardFacet.ID).getVersion("1"); | ||
|
||
@Rule | ||
public ServerTracker tracker = new ServerTracker(); | ||
|
||
private LaunchAppEngineStandardHandler handler; | ||
private IServer serverToReturn = null; | ||
|
||
@Rule | ||
public TestProjectCreator appEngineStandardProject1 = | ||
new TestProjectCreator().withFacetVersions(Lists.newArrayList(JavaFacet.VERSION_1_7, | ||
WebFacetUtils.WEB_25, APPENGINE_STANDARD_FACET_VERSION_1)); | ||
@Rule | ||
public TestProjectCreator appEngineStandardProject2 = | ||
new TestProjectCreator().withFacetVersions(Lists.newArrayList(JavaFacet.VERSION_1_7, | ||
WebFacetUtils.WEB_25, APPENGINE_STANDARD_FACET_VERSION_1)); | ||
|
||
|
||
@Before | ||
public void setUp() { | ||
handler = new LaunchAppEngineStandardHandler() { | ||
@Override | ||
protected void launch(IServer server, String launchMode, SubMonitor progress) | ||
throws CoreException { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
protected IServer findExistingServer(IModule[] modules, SubMonitor progress) { | ||
if (serverToReturn != null) { | ||
return serverToReturn; | ||
} | ||
return super.findExistingServer(modules, progress); | ||
} | ||
}; | ||
} | ||
|
||
|
||
@Test | ||
public void testWithDefaultModule() throws ExecutionException, CoreException { | ||
IModule module1 = appEngineStandardProject1.getModule(); | ||
|
||
ExecutionEvent event = new ExecutionEventBuilder().withCurrentSelection(module1).build(); | ||
handler.execute(event); | ||
assertEquals("new server should have been created", 1, tracker.getServers().size()); | ||
} | ||
|
||
@Test | ||
public void testWithTwoModules() throws ExecutionException, CoreException { | ||
appEngineStandardProject1.setAppEngineServiceId("default"); | ||
IModule module1 = appEngineStandardProject1.getModule(); | ||
appEngineStandardProject2.setAppEngineServiceId("other"); | ||
IModule module2 = appEngineStandardProject2.getModule(); | ||
|
||
ExecutionEvent event = | ||
new ExecutionEventBuilder().withCurrentSelection(module1, module2).build(); | ||
handler.execute(event); | ||
assertEquals("new server should have been created", 1, tracker.getServers().size()); | ||
} | ||
|
||
@Test(expected = ExecutionException.class) | ||
public void failsIfAlreadyLaunched() throws ExecutionException, CoreException { | ||
IModule module1 = appEngineStandardProject1.getModule(); | ||
|
||
ExecutionEvent event = new ExecutionEventBuilder().withCurrentSelection(module1).build(); | ||
serverToReturn = mock(IServer.class); | ||
ILaunch launch = mock(ILaunch.class); | ||
when(serverToReturn.getServerState()).thenReturn(IServer.STATE_STARTED); | ||
when(serverToReturn.getLaunch()).thenReturn(launch); | ||
when(launch.getLaunchMode()).thenReturn(ILaunchManager.DEBUG_MODE); | ||
handler.execute(event); | ||
} | ||
|
||
public void testInvariantToModuleOrder() throws ExecutionException, CoreException { | ||
appEngineStandardProject1.setAppEngineServiceId("default"); | ||
IModule module1 = appEngineStandardProject1.getModule(); | ||
appEngineStandardProject2.setAppEngineServiceId("other"); | ||
IModule module2 = appEngineStandardProject2.getModule(); | ||
|
||
ExecutionEvent event = | ||
new ExecutionEventBuilder().withCurrentSelection(module1, module2).build(); | ||
handler.execute(event); | ||
assertEquals("new server should have been created", 1, tracker.getServers().size()); | ||
|
||
// because we don't actually launch the servers, we won't get an ExecutionException | ||
ExecutionEvent swappedEvent = | ||
new ExecutionEventBuilder().withCurrentSelection(module2, module1).build(); | ||
handler.execute(swappedEvent); | ||
assertEquals("no new servers should be created", 1, tracker.getServers().size()); | ||
} | ||
|
||
@Test(expected = ExecutionException.class) | ||
public void failsWithClashingServiceIds() throws ExecutionException, CoreException { | ||
appEngineStandardProject1.setAppEngineServiceId("other"); | ||
IModule module1 = appEngineStandardProject1.getModule(); | ||
appEngineStandardProject2.setAppEngineServiceId("other"); | ||
IModule module2 = appEngineStandardProject2.getModule(); | ||
|
||
ExecutionEvent event = | ||
new ExecutionEventBuilder().withCurrentSelection(module1, module2).build(); | ||
handler.execute(event); | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
...erver.test/src/com/google/cloud/tools/eclipse/appengine/localserver/ui/ServerTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.tools.eclipse.appengine.localserver.ui; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.wst.server.core.IServer; | ||
import org.eclipse.wst.server.core.IServerLifecycleListener; | ||
import org.eclipse.wst.server.core.ServerCore; | ||
import org.junit.rules.ExternalResource; | ||
|
||
/** Track creation of WTP {@link IServer} instances and ensure they are deleted. */ | ||
public class ServerTracker extends ExternalResource { | ||
private List<IServer> servers = Collections.synchronizedList(new ArrayList<IServer>()); | ||
|
||
private IServerLifecycleListener lifecycleListener = new IServerLifecycleListener() { | ||
@Override | ||
public void serverAdded(IServer server) { | ||
servers.add(server); | ||
} | ||
|
||
@Override | ||
public void serverChanged(IServer server) {} | ||
|
||
@Override | ||
public void serverRemoved(IServer server) { | ||
servers.remove(server); | ||
} | ||
}; | ||
|
||
@Override | ||
protected void before() { | ||
ServerCore.addServerLifecycleListener(lifecycleListener); | ||
} | ||
|
||
public List<IServer> getServers() { | ||
return servers; | ||
} | ||
|
||
@Override | ||
protected void after() { | ||
ServerCore.removeServerLifecycleListener(lifecycleListener); | ||
for (IServer server : servers) { | ||
try { | ||
server.delete(); | ||
} catch (CoreException ex) { | ||
/* ignore */ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.