Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.
Merged
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
11 changes: 11 additions & 0 deletions dev/org.eclipse.codewind.openapi.ui.test/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
3 changes: 3 additions & 0 deletions dev/org.eclipse.codewind.openapi.ui.test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.class
/bin
/build
28 changes: 28 additions & 0 deletions dev/org.eclipse.codewind.openapi.ui.test/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.codewind.openapi.ui.test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
17 changes: 17 additions & 0 deletions dev/org.eclipse.codewind.openapi.ui.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: OpenAPI UI Test Plugin
Bundle-SymbolicName: org.eclipse.codewind.openapi.ui.test
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.codewind.openapi.ui.test.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.swtbot.eclipse.finder,
org.eclipse.swtbot.junit4_x,
org.junit,
org.eclipse.ui.ide,
org.eclipse.core.resources,
org.eclipse.codewind.openapi.test
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: org.eclipse.codewind.openapi.ui.test
Bundle-ActivationPolicy: lazy
4 changes: 4 additions & 0 deletions dev/org.eclipse.codewind.openapi.ui.test/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.codewind.openapi.ui.test;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

public class Activator extends AbstractUIPlugin {

// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.codewind.openapi.ui.test"; //$NON-NLS-1$

// The shared instance
private static Activator plugin;

/**
* The constructor
*/
public Activator() {
}

@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}

@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}

/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.codewind.openapi.ui.test;

import org.eclipse.codewind.openapi.ui.test.menus.ContextMenuTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({
ContextMenuTest.class
})
public class AllUiTests {

public AllUiTests() {
// Empty
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*******************************************************************************
* Copyright (c) 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.codewind.openapi.ui.test;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Stack;
import java.util.StringTokenizer;

import org.eclipse.codewind.openapi.test.Constants;
import org.eclipse.codewind.openapi.test.util.TestUtilities;
import org.eclipse.codewind.openapi.ui.test.menus.utils.UITestUtilities;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBotTestCase;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;

public class BaseTestCase extends SWTBotTestCase {

protected SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot();

protected IProject testProject;
protected IFile definitionFile;

// Configurable options to test and should be overridden
protected String newProjectName = "TestProject";
protected String sourceDefinition = Constants.PETSTORE_30;
protected String targetDefinitionInProject = "petstore.yaml";

public BaseTestCase() {
// Empty
}

protected void createGeneralProject(String projectName) {
try {
this.testProject = TestUtilities.createGeneralProject(projectName);
} catch (CoreException e) {
fail();
}
assertNotNull("Project creation", this.testProject);
assertEquals("Test project name", projectName, this.testProject.getName());
}

/**
*
* @param sourceFile - source OpenAPI definition in the test plugin resources folder
* @param destinationFile - path of target OpenAPI definition in the test project but excludes
* the project name
*/
protected void copyDefinitionToProject(String sourceFile, String destinationFile) {
try {
this.definitionFile = TestUtilities.copyDefinitionToProject(sourceFile, destinationFile, this.testProject);
assertTrue("Copied file exists in workspace", this.definitionFile.exists());
assertEquals("Definition is in the test project", this.testProject, this.definitionFile.getProject());
} catch (CoreException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (FileNotFoundException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}

protected void setup() {
createGeneralProject(this.newProjectName);
copyDefinitionToProject(this.sourceDefinition, this.targetDefinitionInProject);
}

protected void doTestInProjectExplorer(boolean openApiMenuShouldAppear) {
SWTBotView view = UITestUtilities.getProjectExplorerView();
StringTokenizer token = new StringTokenizer(targetDefinitionInProject, "/");
Stack<String> pathSegments = new Stack<String>();
while (token.hasMoreElements()) {
pathSegments.add(0, token.nextToken());
}
verifyContextMenu(openApiMenuShouldAppear, view, newProjectName, pathSegments);
}

// Accept first child node of root node
protected void verifyContextMenu(boolean expectedOpenApiMenuExists, SWTBotView view, String rootNode, Stack<String> pathSegments) {
SWTBotTreeItem targetTreeItem = UITestUtilities.findTreeItem(rootNode, view, pathSegments);
verifyContextMenu(expectedOpenApiMenuExists, targetTreeItem);
}

// Accept a path to the child node relative to the root node
protected void verifyContextMenu(boolean expectedOpenApiMenuExists, SWTBotView view, String rootNode, String childNode) {
SWTBotTreeItem targetTreeItem = UITestUtilities.findTreeItem(rootNode, view, childNode);
verifyContextMenu(expectedOpenApiMenuExists, targetTreeItem);
}

private void verifyContextMenu(boolean expectedOpenApiMenuExists, SWTBotTreeItem targetTreeItem) {
assertNotNull("The test file should be in the project and the tree node exists", targetTreeItem);
try {
SWTBotMenu contextMenu = targetTreeItem.contextMenu(UIConstants.MENU_OPENAPI_GENERATE);
if (expectedOpenApiMenuExists) {
assertNotNull("OpenAPI Generate menu should exist", contextMenu);
List<String> cascadeMenuItems = contextMenu.menuItems();
for (String s: cascadeMenuItems) {
System.out.println(s);
}
assertTrue("There should be three menu actions", cascadeMenuItems.size() == 3);
assertTrue("Client API stub... menu exists", cascadeMenuItems.get(0).equals(UIConstants.MENU_GEN_CLIENT));
assertTrue("Server API stub... menu exists", cascadeMenuItems.get(1).equals(UIConstants.MENU_GEN_SERVER));
assertTrue("HTML documentation...", cascadeMenuItems.get(2).equals(UIConstants.MENU_HTML));
}
} catch (Exception e) {
if (!expectedOpenApiMenuExists) {
assertTrue("OpenAPI Generate menu should not be available on non-OpenAPI 3.0 documents", e instanceof WidgetNotFoundException);
return;
}
throw e; // Fail test if test otherwise
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.codewind.openapi.ui.test;

public class UIConstants {

public UIConstants() {
// Empty
}

// The following four strings are hard coded into the org.eclipse.codewind.openapi.ui plugin.properties
public static String MENU_OPENAPI_GENERATE = "OpenAPI Generate";
public static String MENU_GEN_CLIENT = "Client API stub...";
public static String MENU_GEN_SERVER = "Server API stub...";
public static String MENU_HTML = "HTML documentation...";
}
Loading