Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add App Engine flex new project wizard #2546

Open
wants to merge 17 commits into
base: chanseok-wip
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import com.google.cloud.tools.eclipse.appengine.newproject.maven.MavenCoordinatesInput;
import com.google.cloud.tools.eclipse.appengine.newproject.maven.MavenCoordinatesWizardUi;
import com.google.cloud.tools.eclipse.test.util.ui.CompositeUtil;
import com.google.cloud.tools.eclipse.test.util.ui.ShellTestResource;
import org.eclipse.jface.wizard.WizardPage;
import com.google.common.base.Predicate;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -34,6 +41,7 @@ public class AppEngineWizardPageTest {
@Rule public ShellTestResource shellResource = new ShellTestResource();

private AppEngineWizardPage page;
private MavenCoordinatesInput mavenCoordinatesInput;

@Before
public void setUp() {
Expand All @@ -42,6 +50,12 @@ public void setUp() {
public void setHelp(Composite container) {
// Do nothing in tests.
}

@Override
protected MavenCoordinatesInput createMavenCoordinatesInput(Composite container) {
mavenCoordinatesInput = new MavenCoordinatesWizardUi(container, SWT.NONE);
return mavenCoordinatesInput;
}
};
page.createControl(shellResource.getShell());
}
Expand All @@ -58,8 +72,8 @@ public void testSuggestPackageName() {

@Test
public void testAutoPackageNameSetterOnGroupIdChange_whitespaceInGroupId() {
Text groupIdField = getFieldWithLabel(page, "Group ID:");
Text javaPackageField = getFieldWithLabel(page, "Java package:");
Text groupIdField = getFieldWithLabel("Group ID:");
Text javaPackageField = getFieldWithLabel("Java package:");

groupIdField.setText(" "); // setText() triggers VerifyEvent.
assertEquals("", javaPackageField.getText());
Expand Down Expand Up @@ -87,8 +101,8 @@ public void testAutoPackageNameSetterOnGroupIdChange_whitespaceInGroupId() {
public void testAutoPackageNameSetterOnGroupIdChange_disbledOnUserChange() {
assertTrue(page.autoGeneratePackageName);

Text groupIdField = getFieldWithLabel(page, "Group ID:");
Text javaPackageField = getFieldWithLabel(page, "Java package:");
Text groupIdField = getFieldWithLabel("Group ID:");
Text javaPackageField = getFieldWithLabel("Java package:");

groupIdField.setText("abc");
assertEquals("abc", javaPackageField.getText());
Expand All @@ -108,8 +122,82 @@ public void testAutoPackageNameSetterOnGroupIdChange_disbledOnUserChange() {
assertEquals("", javaPackageField.getText());
}

private static Text getFieldWithLabel(WizardPage page, String label) {
return CompositeUtil.findControlAfterLabel((Composite) page.getControl(), Text.class, label);
@Test
public void testSetMavenValidationMessage_okWhenDisabled() {
assertFalse(mavenCoordinatesInput.uiEnabled());
assertTrue(page.setMavenValidationMessage());
}

@Test
public void testSetMavenValidationMessage_emptyGroupId() {
enableMavenCoordinatesInput();

assertFalse(page.setMavenValidationMessage());
assertEquals("Provide Maven Group ID.", page.getMessage());
assertNull(page.getErrorMessage());
}

@Test
public void testSetMavenValidationMessage_emptyArtifactId() {
enableMavenCoordinatesInput();
getFieldWithLabel("Group ID:").setText("com.example");

assertFalse(page.setMavenValidationMessage());
assertEquals("Provide Maven Artifact ID.", page.getMessage());
assertNull(page.getErrorMessage());
}

@Test
public void testSetMavenValidationMessage_emptyVersion() {
enableMavenCoordinatesInput();
getFieldWithLabel("Group ID:").setText("com.example");
getFieldWithLabel("Artifact ID:").setText("some-artifact-id");
getFieldWithLabel("Version:").setText("");

assertFalse(page.setMavenValidationMessage());
assertEquals("Provide Maven artifact version.", page.getMessage());
assertNull(page.getErrorMessage());
}

@Test
public void testSetMavenValidationMessage_illegalGroupId() {
enableMavenCoordinatesInput();
getFieldWithLabel("Artifact ID:").setText("some-artifact-id");

getFieldWithLabel("Group ID:").setText("<:#= Illegal ID =#:>");
assertFalse(page.setMavenValidationMessage());
assertEquals("Illegal Maven Group ID: <:#= Illegal ID =#:>", page.getErrorMessage());
}

@Test
public void testSetMavenValidationMessage_illegalArtifactId() {
enableMavenCoordinatesInput();
getFieldWithLabel("Group ID:").setText("com.example");

getFieldWithLabel("Artifact ID:").setText("<:#= Illegal ID =#:>");
assertFalse(page.setMavenValidationMessage());
assertEquals("Illegal Maven Artifact ID: <:#= Illegal ID =#:>", page.getErrorMessage());
}

@Test
public void testMavenValidateMavenSettings_noValidationIfUiDisabled() {
getFieldWithLabel("Group ID:").setText("<:#= Illegal ID =#:>");
assertTrue(page.setMavenValidationMessage());
}

private void enableMavenCoordinatesInput() {
Predicate<Control> isMavenCheckbox = new Predicate<Control>() {
@Override
public boolean apply(Control control) {
return control instanceof Button
&& "Create as Maven project".equals(((Button) control).getText());
}
};
Button asMaven = (Button) CompositeUtil.findControl(shellResource.getShell(), isMavenCheckbox);
new SWTBotCheckBox(asMaven).click();
}

private Text getFieldWithLabel(String label) {
return CompositeUtil.findControlAfterLabel(shellResource.getShell(), Text.class, label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.junit.Assert.assertFalse;

import com.google.cloud.tools.eclipse.appengine.newproject.AppEngineProjectConfig.Template;
import com.google.cloud.tools.eclipse.appengine.ui.AppEngineRuntime;
import com.google.cloud.tools.eclipse.test.util.project.TestProjectCreator;
import com.google.cloud.tools.eclipse.util.Templates;
Expand Down Expand Up @@ -132,7 +133,7 @@ public void testMaterializeAppEngineFlexJarFiles()
config.setUseMaven("my.project.group.id", "my-project-artifact-id", "98.76.54");
config.setServiceName("database-service");

IFile mostImportant = CodeTemplates.materializeFlexJar(project, config, monitor);
IFile mostImportant = CodeTemplates.materializeAppEngineFlexJarFiles(project, config, monitor);

validateFlexJarNonConfigFiles(mostImportant);
validateAppYaml();
Expand All @@ -145,8 +146,9 @@ public void testMaterializeFlexSpringBoot()
AppEngineProjectConfig config = new AppEngineProjectConfig();
config.setUseMaven("my.project.group.id", "my-project-artifact-id", "98.76.54");
config.setServiceName("database-service");
config.setTemplate(Template.SPRING_BOOT);

IFile mostImportant = CodeTemplates.materializeFlexSpringBoot(project, config, monitor);
IFile mostImportant = CodeTemplates.materializeAppEngineFlexJarFiles(project, config, monitor);

validateFlexSpringBootNonConfigFiles(mostImportant);
validateAppYaml();
Expand All @@ -160,7 +162,7 @@ public void testMaterializeAppEngineFlexJarFiles_mainClassSet()
config.setUseMaven("my.project.group.id", "my-project-artifact-id", "98.76.54");
config.setPackageName("com.example");

IFile mostImportant = CodeTemplates.materializeFlexJar(project, config, monitor);
IFile mostImportant = CodeTemplates.materializeAppEngineFlexJarFiles(project, config, monitor);
validateMainClassInPomXml("com.example", mostImportant);
}

Expand All @@ -170,7 +172,7 @@ public void testMaterializeAppEngineFlexJarFiles_defaultPackageMainClassSet()
AppEngineProjectConfig config = new AppEngineProjectConfig();
config.setUseMaven("my.project.group.id", "my-project-artifact-id", "98.76.54");

IFile mostImportant = CodeTemplates.materializeFlexJar(project, config, monitor);
IFile mostImportant = CodeTemplates.materializeAppEngineFlexJarFiles(project, config, monitor);
validateMainClassInPomXml(null /* expectedPackage */, mostImportant);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2017 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.newproject;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.google.cloud.tools.eclipse.test.util.project.ProjectUtils;
import com.google.cloud.tools.eclipse.util.MavenUtils;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.CoreException;
import org.junit.Test;

public abstract class CreateAppEngineJarProjectTest extends CreateAppEngineProjectTest {

@Override
protected String getMostImportantFilename() {
return "HelloAppEngineMain.java";
}

@Test
public void testMavenNatureEnabled() throws InvocationTargetException, CoreException {
config.setUseMaven("my.group.id", "my-artifact-id", "12.34.56");

CreateAppEngineProject creator = newCreateAppEngineProject();
creator.execute(monitor);
ProjectUtils.waitForProjects(project);

assertTrue(project.hasNature(MavenUtils.MAVEN2_NATURE_ID));
assertFalse(project.getFolder("build").exists());
assertOutputDirectory("target/classes");
}
}
Loading