From 27a8334070021e4b72242e67f7730c08debdeda8 Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Mon, 2 Jul 2018 13:12:00 -0400 Subject: [PATCH] Move ConfigurationFileUtils to .test.util (#3185) --- .../AppEngineContentProviderTest.java | 1 + .../ui/navigator/model/ModelRefreshTests.java | 50 ++++++++----------- .../model/AppEngineProjectElement.java | 8 +-- .../appengine/SwtBotAppEngineActions.java | 2 +- .../CloudSdkPreferenceAreaTest.java | 1 - .../util/project}/ConfigurationFileUtils.java | 2 +- .../test/util/project/TestProjectCreator.java | 14 ++---- 7 files changed, 33 insertions(+), 45 deletions(-) rename plugins/{com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator => com.google.cloud.tools.eclipse.test.util/src/com/google/cloud/tools/eclipse/test/util/project}/ConfigurationFileUtils.java (97%) diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/AppEngineContentProviderTest.java b/plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/AppEngineContentProviderTest.java index 73efff20a4..ac0ee610df 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/AppEngineContentProviderTest.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/AppEngineContentProviderTest.java @@ -41,6 +41,7 @@ import com.google.cloud.tools.eclipse.appengine.facets.ui.navigator.model.DenialOfServiceDescriptor; import com.google.cloud.tools.eclipse.appengine.facets.ui.navigator.model.DispatchRoutingDescriptor; import com.google.cloud.tools.eclipse.appengine.facets.ui.navigator.model.TaskQueuesDescriptor; +import com.google.cloud.tools.eclipse.test.util.project.ConfigurationFileUtils; import com.google.cloud.tools.eclipse.test.util.project.TestProjectCreator; import com.google.common.io.ByteSource; import java.io.ByteArrayInputStream; diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/model/ModelRefreshTests.java b/plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/model/ModelRefreshTests.java index d52f728746..63179e25da 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/model/ModelRefreshTests.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/model/ModelRefreshTests.java @@ -26,7 +26,7 @@ import com.google.cloud.tools.appengine.api.AppEngineException; import com.google.cloud.tools.eclipse.appengine.facets.AppEngineStandardFacet; -import com.google.cloud.tools.eclipse.appengine.facets.ui.navigator.ConfigurationFileUtils; +import com.google.cloud.tools.eclipse.test.util.project.ConfigurationFileUtils; import com.google.cloud.tools.eclipse.test.util.project.ProjectUtils; import com.google.cloud.tools.eclipse.test.util.project.TestProjectCreator; import com.google.cloud.tools.eclipse.util.io.ResourceUtils; @@ -78,8 +78,7 @@ public void testAppEngineProjectElementCreate_initial() throws AppEngineExceptio IFile dosXml = ConfigurationFileUtils.createEmptyDosXml(project); IFile queueXml = ConfigurationFileUtils.createEmptyQueueXml(project); - AppEngineProjectElement projectElement = - AppEngineProjectElement.create(project); + AppEngineProjectElement projectElement = AppEngineProjectElement.create(project); AppEngineResourceElement[] subElements = projectElement.getConfigurations(); assertNotNull(subElements); assertEquals(5, subElements.length); @@ -105,8 +104,7 @@ public void testAppEngineProjectElementCreate_initial() throws AppEngineExceptio @Test public void testAppEngineProjectElementCreate_staggered() throws AppEngineException { IProject project = projectCreator.getProject(); - AppEngineProjectElement projectElement = - AppEngineProjectElement.create(project); + AppEngineProjectElement projectElement = AppEngineProjectElement.create(project); AppEngineResourceElement[] subElements = projectElement.getConfigurations(); assertNotNull(subElements); assertEquals(0, subElements.length); @@ -119,8 +117,7 @@ public void testAppEngineProjectElementCreate_staggered() throws AppEngineExcept CronDescriptor cron = findInstance(subElements, CronDescriptor.class); assertThat(subElements, hasItemInArray(cron)); - IFile datastoreIndexesXml = - ConfigurationFileUtils.createEmptyDatastoreIndexesXml(project); + IFile datastoreIndexesXml = ConfigurationFileUtils.createEmptyDatastoreIndexesXml(project); projectElement.resourcesChanged(Collections.singleton(datastoreIndexesXml)); subElements = projectElement.getConfigurations(); assertNotNull(subElements); @@ -181,9 +178,8 @@ public void testChangeToDefaultPreservesConfigurationElements() throws AppEngine ConfigurationFileUtils.createEmptyDispatchXml(project); ConfigurationFileUtils.createEmptyDosXml(project); ConfigurationFileUtils.createEmptyQueueXml(project); - AppEngineProjectElement projectElement = - AppEngineProjectElement.create(project); - final AppEngineResourceElement[] subElements = projectElement.getConfigurations(); + AppEngineProjectElement projectElement = AppEngineProjectElement.create(project); + AppEngineResourceElement[] subElements = projectElement.getConfigurations(); assertEquals(5, subElements.length); assertThat(subElements, hasItemInArray(instanceOf(CronDescriptor.class))); assertThat(subElements, hasItemInArray(instanceOf(DatastoreIndexesDescriptor.class))); @@ -213,9 +209,8 @@ public void testChangeToNonDefaultDiscardsConfigurationElements() throws AppEngi ConfigurationFileUtils.createEmptyDispatchXml(project); ConfigurationFileUtils.createEmptyDosXml(project); ConfigurationFileUtils.createEmptyQueueXml(project); - AppEngineProjectElement projectElement = - AppEngineProjectElement.create(project); - final AppEngineResourceElement[] subElements = projectElement.getConfigurations(); + AppEngineProjectElement projectElement = AppEngineProjectElement.create(project); + AppEngineResourceElement[] subElements = projectElement.getConfigurations(); assertEquals(5, subElements.length); assertThat(subElements, hasItemInArray(instanceOf(CronDescriptor.class))); assertThat(subElements, hasItemInArray(instanceOf(DatastoreIndexesDescriptor.class))); @@ -245,10 +240,9 @@ public void testChildElementPreservedOnChange() throws AppEngineException { files.add(ConfigurationFileUtils.createEmptyDosXml(project)); files.add(ConfigurationFileUtils.createEmptyQueueXml(project)); - AppEngineProjectElement projectElement = - AppEngineProjectElement.create(project); + AppEngineProjectElement projectElement = AppEngineProjectElement.create(project); files.add(projectElement.getDescriptorFile()); - final AppEngineResourceElement[] subElements = projectElement.getConfigurations(); + AppEngineResourceElement[] subElements = projectElement.getConfigurations(); for (IFile file : files) { boolean changed = projectElement.resourcesChanged(Collections.singleton(file)); @@ -268,8 +262,7 @@ public void testNonDefaultServiceIgnoresNewFiles() throws AppEngineException { IProject project = projectCreator.getProject(); ConfigurationFileUtils.createAppEngineWebXml(project, "non-default"); - AppEngineProjectElement projectElement = - AppEngineProjectElement.create(project); + AppEngineProjectElement projectElement = AppEngineProjectElement.create(project); AppEngineResourceElement[] subElements = projectElement.getConfigurations(); assertEquals(0, subElements.length); @@ -289,17 +282,16 @@ public void testRejigDeploymentAssembly() throws AppEngineException, CoreExcepti IProject project = projectCreator.getProject(); // verify the new files are not picked up yet IFile oldCronXml = ConfigurationFileUtils.createEmptyCronXml(project); - AppEngineProjectElement projectElement = - AppEngineProjectElement.create(project); - final AppEngineResourceElement[] oldElements = projectElement.getConfigurations(); + AppEngineProjectElement projectElement = AppEngineProjectElement.create(project); + AppEngineResourceElement[] oldElements = projectElement.getConfigurations(); assertEquals(1, oldElements.length); assertThat(oldElements, hasItemInArray(instanceOf(CronDescriptor.class))); // create the new WEB-INF location and populate it - final IFolder newWebRoot = project.getFolder("newWebRoot"); - final IFolder newWebInf = newWebRoot.getFolder("WEB-INF"); + IFolder newWebRoot = project.getFolder("newWebRoot"); + IFolder newWebInf = newWebRoot.getFolder("WEB-INF"); ResourceUtils.createFolders(newWebInf, null); - final IFile newDispatchXml = newWebInf.getFile("dispatch.xml"); + IFile newDispatchXml = newWebInf.getFile("dispatch.xml"); newDispatchXml.create( new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)), true, @@ -307,8 +299,8 @@ public void testRejigDeploymentAssembly() throws AppEngineException, CoreExcepti assertTrue("error creating new dispatch.xml", newDispatchXml.exists()); // now link in the new WEB-INF into the overlay - final IWorkspace workspace = project.getWorkspace(); - final Set changed = + IWorkspace workspace = project.getWorkspace(); + Set changed = recordChangedFilesDuring( workspace, monitor -> { @@ -325,7 +317,7 @@ public void testRejigDeploymentAssembly() throws AppEngineException, CoreExcepti Iterables.getOnlyElement(changed)); assertTrue(projectElement.resourcesChanged(changed)); - final AppEngineResourceElement[] newElements = projectElement.getConfigurations(); + AppEngineResourceElement[] newElements = projectElement.getConfigurations(); assertEquals(2, newElements.length); assertThat(newElements, hasItemInArray(instanceOf(CronDescriptor.class))); assertThat(newElements, hasItemInArray(instanceOf(DispatchRoutingDescriptor.class))); @@ -339,8 +331,8 @@ public void testRejigDeploymentAssembly() throws AppEngineException, CoreExcepti /** Record and return the set of files altered when running the provided block. */ private static Set recordChangedFilesDuring(IWorkspace workspace, ICoreRunnable block) throws CoreException { - final Set changed = new LinkedHashSet<>(); - final IResourceChangeListener listener = + Set changed = new LinkedHashSet<>(); + IResourceChangeListener listener = event -> { try { changed.addAll(ResourceUtils.getAffectedFiles(event.getDelta()).values()); diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.facets/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/model/AppEngineProjectElement.java b/plugins/com.google.cloud.tools.eclipse.appengine.facets/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/model/AppEngineProjectElement.java index a0ffa7b28e..2fe1d0baec 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.facets/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/model/AppEngineProjectElement.java +++ b/plugins/com.google.cloud.tools.eclipse.appengine.facets/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/model/AppEngineProjectElement.java @@ -165,7 +165,7 @@ public static boolean hasAppEngineDescriptor(Collection changedFiles) { private AppEngineProjectElement(IProject project) throws AppEngineException { this.project = project; - this.descriptorFile = findAppEngineDescriptor(project); + descriptorFile = findAppEngineDescriptor(project); } /** Return the project. */ @@ -211,7 +211,8 @@ public String getServiceId() { } /** Return the App Engine environment type: {@code standard} or {@code flex}. */ - public String getEnvironmentType() { + @VisibleForTesting + String getEnvironmentType() { return environmentType; } @@ -219,7 +220,8 @@ public String getEnvironmentType() { * Return the App Engine runtime type, which may depend on the {@link #getEnvironmentType() * environment type}. */ - public String getRuntime() { + @VisibleForTesting + String getRuntime() { return runtime; } diff --git a/plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/SwtBotAppEngineActions.java b/plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/SwtBotAppEngineActions.java index dfc548f03a..ceddeda866 100644 --- a/plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/SwtBotAppEngineActions.java +++ b/plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/SwtBotAppEngineActions.java @@ -191,7 +191,7 @@ public static IProject importMavenProject( } /** - * Spin until the given project actually exists and is facetd. + * Spin until the given project actually exists and is faceted. * * @return the project */ diff --git a/plugins/com.google.cloud.tools.eclipse.sdk.ui.test/src/com/google/cloud/tools/eclipse/sdk/ui/preferences/CloudSdkPreferenceAreaTest.java b/plugins/com.google.cloud.tools.eclipse.sdk.ui.test/src/com/google/cloud/tools/eclipse/sdk/ui/preferences/CloudSdkPreferenceAreaTest.java index 3fc327a1e0..3ebc4f2f1d 100644 --- a/plugins/com.google.cloud.tools.eclipse.sdk.ui.test/src/com/google/cloud/tools/eclipse/sdk/ui/preferences/CloudSdkPreferenceAreaTest.java +++ b/plugins/com.google.cloud.tools.eclipse.sdk.ui.test/src/com/google/cloud/tools/eclipse/sdk/ui/preferences/CloudSdkPreferenceAreaTest.java @@ -115,7 +115,6 @@ public void testInvalidPath() { assertTrue(area.getStatus().isOK()); } - // TODO(chanseok): can become "@Before setUp()" once we remove the managed SDK debug feature flag. private void createPreferenceArea() { shell = shellResource.getShell(); area = new CloudSdkPreferenceArea(cloudSdkManager); diff --git a/plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/ConfigurationFileUtils.java b/plugins/com.google.cloud.tools.eclipse.test.util/src/com/google/cloud/tools/eclipse/test/util/project/ConfigurationFileUtils.java similarity index 97% rename from plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/ConfigurationFileUtils.java rename to plugins/com.google.cloud.tools.eclipse.test.util/src/com/google/cloud/tools/eclipse/test/util/project/ConfigurationFileUtils.java index 9ceeef2c49..15e7b75966 100644 --- a/plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/ui/navigator/ConfigurationFileUtils.java +++ b/plugins/com.google.cloud.tools.eclipse.test.util/src/com/google/cloud/tools/eclipse/test/util/project/ConfigurationFileUtils.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.cloud.tools.eclipse.appengine.facets.ui.navigator; +package com.google.cloud.tools.eclipse.test.util.project; import com.google.cloud.tools.eclipse.appengine.facets.WebProjectUtil; import com.google.common.base.Strings; diff --git a/plugins/com.google.cloud.tools.eclipse.test.util/src/com/google/cloud/tools/eclipse/test/util/project/TestProjectCreator.java b/plugins/com.google.cloud.tools.eclipse.test.util/src/com/google/cloud/tools/eclipse/test/util/project/TestProjectCreator.java index facd78627c..512eab0aa1 100644 --- a/plugins/com.google.cloud.tools.eclipse.test.util/src/com/google/cloud/tools/eclipse/test/util/project/TestProjectCreator.java +++ b/plugins/com.google.cloud.tools.eclipse.test.util/src/com/google/cloud/tools/eclipse/test/util/project/TestProjectCreator.java @@ -25,9 +25,6 @@ import com.google.cloud.tools.eclipse.util.ClasspathUtil; import com.google.common.base.Preconditions; import com.google.common.base.Strings; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -170,7 +167,7 @@ private void addContainerPathToRawClasspath() throws JavaModelException { private void addFacets() throws CoreException { if (makeFaceted) { - facetedProject = ProjectFacetsManager.create(getProject(), true, null); + facetedProject = ProjectFacetsManager.create(project, true, null); } if (projectFacetVersions.isEmpty()) { return; @@ -184,7 +181,7 @@ private void addFacets() throws CoreException { if (facetedProject.hasProjectFacet(AppEngineStandardFacet.FACET)) { // App Engine runtime is added via a Job, so wait. - ProjectUtils.waitForProjects(getProject()); + ProjectUtils.waitForProjects(project); } if (facetedProject.hasProjectFacet(JavaFacet.FACET)) { @@ -193,15 +190,12 @@ private void addFacets() throws CoreException { } } - private void setAppEngineServiceId(String serviceId) throws CoreException { + private void setAppEngineServiceId(String serviceId) { IFile appEngineWebXml = AppEngineConfigurationUtil.findConfigurationFile( getProject(), new Path("appengine-web.xml")); assertTrue("Project should have AppEngine Standard facet", appEngineWebXml.exists()); - String contents = "\n" - + "" + serviceId + "\n\n"; - InputStream in = new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8)); - appEngineWebXml.setContents(in, IFile.FORCE, null); + ConfigurationFileUtils.createAppEngineWebXml(project, serviceId); } }