org.jboss.forge.addon.ui.controller.CommandController Java Examples
The following examples show how to use
org.jboss.forge.addon.ui.controller.CommandController.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WindupCommandTest.java From windup with Eclipse Public License 1.0 | 6 votes |
private void setupController(CommandController controller, File inputFile, File outputFile) throws Exception { controller.initialize(); Assert.assertTrue(controller.isEnabled()); controller.setValueFor(InputPathOption.NAME, Collections.singletonList(inputFile)); // FORGE-2524 final Object value = controller.getValueFor(InputPathOption.NAME); Assume.assumeTrue(value instanceof Collection); Assume.assumeTrue(((Collection) value).iterator().hasNext()); Assume.assumeTrue(((Collection) value).iterator().next() instanceof File); Assume.assumeTrue(((Collection) value).iterator().next().equals(inputFile)); if (outputFile != null) { controller.setValueFor(OutputPathOption.NAME, outputFile); } controller.setValueFor(TargetOption.NAME, Collections.singletonList("eap")); Assert.assertTrue(controller.canExecute()); controller.setValueFor("packages", "org.jboss"); Assert.assertTrue(controller.canExecute()); }
Example #2
Source File: SetupCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 6 votes |
@Test public void checkCommandMetadata() throws Exception { try (CommandController controller = uiTestHarness.createCommandController(SetupCommand.class, project.getRoot())) { controller.initialize(); // Checks the command metadata assertTrue(controller.getCommand() instanceof SetupCommand); UICommandMetadata metadata = controller.getMetadata(); assertEquals("Thorntail: Setup", metadata.getName()); assertEquals("Thorntail", metadata.getCategory().getName()); assertNull(metadata.getCategory().getSubCategory()); assertEquals(3, controller.getInputs().size()); assertFalse(controller.hasInput("dummy")); assertTrue(controller.hasInput("httpPort")); assertTrue(controller.hasInput("contextPath")); assertTrue(controller.hasInput("portOffset")); } }
Example #3
Source File: CommandsResource.java From fabric8-forge with Apache License 2.0 | 6 votes |
@Override @GET @Path("/commandInput/{name}/{namespace}/{projectName}/{path: .*}") @Produces(MediaType.APPLICATION_JSON) public Response getCommandInput(@PathParam("name") final String name, @PathParam("namespace") String namespace, @PathParam("projectName") String projectName, @PathParam("path") String resourcePath) throws Exception { return withUIContext(namespace, projectName, resourcePath, false, new RestUIFunction<Response>() { @Override public Response apply(RestUIContext context) throws Exception { CommandInputDTO answer = null; UICommand command = getCommandByName(context, name); if (command != null) { CommandController controller = createController(context, command); answer = UICommands.createCommandInputDTO(context, command, controller); } if (answer != null) { return Response.ok(answer).build(); } else { return Response.status(Status.NOT_FOUND).build(); } } }); }
Example #4
Source File: CommandsResource.java From fabric8-forge with Apache License 2.0 | 6 votes |
protected void configureAttributeMaps(UserDetails userDetails, CommandController controller, ExecutionRequest executionRequest) { Map<Object, Object> attributeMap = controller.getContext().getAttributeMap(); if (userDetails != null) { attributeMap.put("gitUser", userDetails.getUser()); attributeMap.put("gitPassword", userDetails.getPassword()); attributeMap.put("gitAuthorEmail", userDetails.getEmail()); attributeMap.put("gitAddress", userDetails.getAddress()); attributeMap.put("gitUrl", userDetails.getAddress()); attributeMap.put("localGitUrl", userDetails.getInternalAddress()); attributeMap.put("gitBranch", userDetails.getBranch()); attributeMap.put("projectName", executionRequest.getProjectName()); attributeMap.put("buildName", executionRequest.getProjectName()); attributeMap.put("namespace", executionRequest.getNamespace()); attributeMap.put("jenkinsfilesFolder", projectFileSystem.getJenkinsfilesLibraryFolder()); projectFileSystem.asyncCloneOrPullJenkinsWorkflows(userDetails); } }
Example #5
Source File: NewNodeXmlTest.java From fabric8-forge with Apache License 2.0 | 6 votes |
protected List<ContextDto> getRoutesXml(Project project) throws Exception { CommandController command = testHarness.createCommandController(CamelGetRoutesXmlCommand.class, project.getRoot()); command.initialize(); command.setValueFor("format", "JSON"); Result result = command.execute(); assertFalse("Should not fail", result instanceof Failed); String message = result.getMessage(); System.out.println(); System.out.println(); System.out.println("JSON: " + message); System.out.println(); List<ContextDto> answer = NodeDtos.parseContexts(message); System.out.println(); System.out.println(); List<NodeDto> nodeList = NodeDtos.toNodeList(answer); for (NodeDto node : nodeList) { System.out.println(node.getLabel()); } System.out.println(); return answer; }
Example #6
Source File: NewNodeXmlTest.java From fabric8-forge with Apache License 2.0 | 6 votes |
protected void setNodeValue(String key, CommandController command) { Object value = key; SelectComponent nodeInput = (SelectComponent) command.getInput("node"); Iterable<NodeDto> valueChoices = nodeInput.getValueChoices(); NodeDto found = NodeDtos.findNodeByKey(valueChoices, key); if (found != null) { value = found; System.out.println("Found node " + value); } else { System.out.println("Failed to find node with key '" + key + "' in the node choices: " + nodeInput.getValueChoices()); } command.setValueFor("node", value); System.out.println("Set value of node " + value + " currently has " + nodeInput.getValue()); if (nodeInput.getValue() == null) { command.setValueFor("node", key); System.out.println("Set value of node " + value + " currently has " + nodeInput.getValue()); } }
Example #7
Source File: NewComponentInstanceTest.java From fabric8-forge with Apache License 2.0 | 6 votes |
@Test public void testSomething() throws Exception { File tempDir = OperatingSystemUtils.createTempDir(); try { Project project = projectFactory.createTempProject(); Assert.assertNotNull("Should have created a project", project); CommandController command = testHarness.createCommandController(CamelSetupCommand.class, project.getRoot()); command.initialize(); command.setValueFor("kind", "camel-spring"); Result result = command.execute(); Assert.assertFalse("Should setup Camel in the project", result instanceof Failed); command = testHarness.createCommandController(CamelGetComponentsCommand.class, project.getRoot()); command.initialize(); result = command.execute(); Assert.assertFalse("Should not fail", result instanceof Failed); String message = result.getMessage(); System.out.println(message); } finally { tempDir.delete(); } }
Example #8
Source File: NewNodeXmlTest.java From fabric8-forge with Apache License 2.0 | 6 votes |
protected void testDeleteRoute(Project project) throws Exception { String key = "_camelContext1/cbr-route/_choice1/_when1/_to1"; CommandController command = testHarness.createCommandController(CamelDeleteNodeXmlCommand.class, project.getRoot()); command.initialize(); command.setValueFor("xml", "META-INF/spring/camel-context.xml"); setNodeValue(key, command); assertValidAndExecutes(command); List<ContextDto> contexts = getRoutesXml(project); assertFalse("Should have loaded a camelContext", contexts.isEmpty()); assertNoNodeWithKey(contexts, key); assertNodeWithKey(contexts, NEW_ROUTE_KEY); }
Example #9
Source File: WindupCommandTest.java From windup with Eclipse Public License 1.0 | 5 votes |
@Test public void testNewMigration() throws Exception { Assert.assertNotNull(uiTestHarness); try (CommandController controller = uiTestHarness.createCommandController(WindupCommand.class)) { File inputFile = File.createTempFile("windupwizardtest", ".jar"); inputFile.deleteOnExit(); try (InputStream iStream = getClass().getResourceAsStream("/test.jar")) { try (OutputStream oStream = new FileOutputStream(inputFile)) { IOUtils.copy(iStream, oStream); } } File reportPath = new File(inputFile.getAbsoluteFile() + "_output"); try { reportPath.mkdirs(); setupController(controller, inputFile, reportPath); Result result = controller.execute(); final String msg = "controller.execute() 'Failed': " + result.getMessage(); Assert.assertFalse(msg, result instanceof Failed); } finally { inputFile.delete(); FileUtils.deleteDirectory(reportPath); } } }
Example #10
Source File: CreateTestClassCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 5 votes |
@Test public void checkCommandMetadata() throws Exception { try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class, project.getRoot())) { controller.initialize(); UICommandMetadata metadata = controller.getMetadata(); assertThat(controller.getCommand(), is(instanceOf(CreateTestClassCommand.class))); assertThat(metadata.getName(), is("Thorntail: New Test")); assertThat(metadata.getCategory().getName(), is("Thorntail")); assertThat(metadata.getCategory().getSubCategory(), is(nullValue())); } }
Example #11
Source File: SetupCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 5 votes |
@Test public void testThorntailSetupWithZeroParameters() throws Exception { try (CommandController controller = uiTestHarness.createCommandController(SetupCommand.class, project.getRoot())) { controller.initialize(); controller.setValueFor("httpPort", 0); controller.setValueFor("portOffset", 0); Assert.assertTrue(controller.isValid()); final AtomicBoolean flag = new AtomicBoolean(); controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener() { @Override public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { if (result.getMessage().equals("Thorntail is now set up! Enjoy!")) { flag.set(true); } } }); controller.execute(); Assert.assertTrue(flag.get()); ThorntailFacet facet = project.getFacet(ThorntailFacet.class); Assert.assertTrue(facet.isInstalled()); MavenPluginAdapter thorntailPlugin = (MavenPluginAdapter) project.getFacet(MavenPluginFacet.class) .getEffectivePlugin(ThorntailFacet.PLUGIN_COORDINATE); Assert.assertEquals("thorntail-maven-plugin", thorntailPlugin.getCoordinate().getArtifactId()); Assert.assertEquals(1, thorntailPlugin.getExecutions().size()); Assert.assertEquals(0, thorntailPlugin.getConfig().listConfigurationElements().size()); } }
Example #12
Source File: SetupCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 5 votes |
@Test public void testThorntailSetupWithNullParameters() throws Exception { try (CommandController controller = uiTestHarness.createCommandController(SetupCommand.class, project.getRoot())) { controller.initialize(); controller.setValueFor("httpPort", null); controller.setValueFor("contextPath", null); controller.setValueFor("portOffset", null); Assert.assertTrue(controller.isValid()); final AtomicBoolean flag = new AtomicBoolean(); controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener() { @Override public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { if (result.getMessage().equals("Thorntail is now set up! Enjoy!")) { flag.set(true); } } }); controller.execute(); Assert.assertTrue(flag.get()); ThorntailFacet facet = project.getFacet(ThorntailFacet.class); Assert.assertTrue(facet.isInstalled()); MavenPluginAdapter thorntailPlugin = (MavenPluginAdapter) project.getFacet(MavenPluginFacet.class) .getEffectivePlugin(ThorntailFacet.PLUGIN_COORDINATE); Assert.assertEquals("thorntail-maven-plugin", thorntailPlugin.getCoordinate().getArtifactId()); Assert.assertEquals(1, thorntailPlugin.getExecutions().size()); Assert.assertEquals(0, thorntailPlugin.getConfig().listConfigurationElements().size()); } }
Example #13
Source File: ProjectGenerator.java From fabric8-forge with Apache License 2.0 | 5 votes |
protected static WizardCommandController assertWizardController(CommandController controller) { if (controller instanceof WizardCommandController) { return (WizardCommandController) controller; } else { fail("controller is not a wizard! " + controller.getClass()); return null; } }
Example #14
Source File: SetupCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 5 votes |
@Test public void testThorntailSetup() throws Exception { try (CommandController controller = uiTestHarness.createCommandController(SetupCommand.class, project.getRoot())) { controller.initialize(); Assert.assertTrue(controller.isValid()); final AtomicBoolean flag = new AtomicBoolean(); controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener() { @Override public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { if (result.getMessage().equals("Thorntail is now set up! Enjoy!")) { flag.set(true); } } }); controller.execute(); Assert.assertTrue(flag.get()); ThorntailFacet facet = project.getFacet(ThorntailFacet.class); Assert.assertTrue(facet.isInstalled()); MavenPluginAdapter thorntailPlugin = (MavenPluginAdapter) project.getFacet(MavenPluginFacet.class) .getEffectivePlugin(ThorntailFacet.PLUGIN_COORDINATE); Assert.assertEquals("thorntail-maven-plugin", thorntailPlugin.getCoordinate().getArtifactId()); Assert.assertEquals(1, thorntailPlugin.getExecutions().size()); Assert.assertEquals(0, thorntailPlugin.getConfig().listConfigurationElements().size()); } }
Example #15
Source File: NewNodeXmlTest.java From fabric8-forge with Apache License 2.0 | 5 votes |
protected static void assertValidAndExecutes(CommandController command) throws Exception { List<UIMessage> validate = command.validate(); for (UIMessage uiMessage : validate) { System.out.println("Invalid value of input: " + uiMessage.getSource().getName() + " message: " + uiMessage.getDescription()); } Result result = command.execute(); String message = result.getMessage(); assertFalse("Should not fail: " + message, result instanceof Failed); System.out.println(message); }
Example #16
Source File: WindupUpdateRulesetCommandTest.java From windup with Eclipse Public License 1.0 | 5 votes |
@Test @Ignore("Command can't be used currently as there's no way to run it from the UI." + " I'm leaving it here in case we needed the command again (maybe from a GUI?).") public void testUpdateRulesetCommand() throws Exception { // Extract the windup zip to a temp dir. File tempDir = OperatingSystemUtils.createTempDir(); ZipUtil.unzipFromClassResource(WindupUpdateRulesetCommandTest.class, TEST_OLD_WINDUP, tempDir); // This may cause FileNotFound in Furnace if it's already running. System.setProperty("windup.home", new File(tempDir, "windup-old-ruleset").getAbsolutePath()); try (CommandController controller = uiTestHarness.createCommandController(WindupUpdateRulesetCommand.class)) { boolean rulesetNeedUpdate = updater.rulesetsNeedUpdate(true); Assert.assertTrue("Rulesets should need an update.", rulesetNeedUpdate); controller.initialize(); Assert.assertTrue(controller.isEnabled()); Result result = controller.execute(); Assert.assertFalse(result instanceof Failed); rulesetNeedUpdate = updater.rulesetsNeedUpdate(true); Assert.assertFalse(rulesetNeedUpdate); } finally { FileUtils.deleteDirectory(tempDir); System.getProperties().remove("windup.home"); } }
Example #17
Source File: CommandsResource.java From fabric8-forge with Apache License 2.0 | 5 votes |
protected CommandController createController(RestUIContext context, UICommand command) throws Exception { RestUIRuntime runtime = new RestUIRuntime(); CommandController controller = commandControllerFactory.createController(context, runtime, command); controller.initialize(); return controller; }
Example #18
Source File: UICommands.java From fabric8-forge with Apache License 2.0 | 5 votes |
public static ValidationResult createValidationResult(RestUIContext context, CommandController controller, List<UIMessage> messages) { boolean valid = controller.isValid(); boolean canExecute = controller.canExecute(); RestUIProvider provider = context.getProvider(); String out = provider.getOut(); String err = provider.getErr(); return new ValidationResult(toDtoList(messages), valid, canExecute, out, err); }
Example #19
Source File: UICommands.java From fabric8-forge with Apache License 2.0 | 5 votes |
public static void populateController(Map<String, Object> requestedInputs, CommandController controller, ConverterFactory converterFactory) { if (requestedInputs != null) { Map<String, InputComponent<?, ?>> inputs = controller.getInputs(); Set<String> inputKeys = new HashSet<>(inputs.keySet()); inputKeys.retainAll(requestedInputs.keySet()); Set<Map.Entry<String, InputComponent<?, ?>>> entries = inputs.entrySet(); for (Map.Entry<String, InputComponent<?, ?>> entry : entries) { String key = entry.getKey(); Object value = requestedInputs.get(key); controller.setValueFor(key, Proxies.unwrap(value)); } } }
Example #20
Source File: UICommands.java From fabric8-forge with Apache License 2.0 | 5 votes |
public static CommandInputDTO createCommandInputDTO(RestUIContext context, UICommand command, CommandController controller) throws Exception { CommandInfoDTO info = createCommandInfoDTO(context, command); CommandInputDTO inputInfo = new CommandInputDTO(info); Map<String, InputComponent<?, ?>> inputs = controller.getInputs(); if (inputs != null) { Set<Map.Entry<String, InputComponent<?, ?>>> entries = inputs.entrySet(); for (Map.Entry<String, InputComponent<?, ?>> entry : entries) { String key = entry.getKey(); InputComponent<?, ?> input = entry.getValue(); PropertyDTO dto = UICommands.createInputDTO(context, input); inputInfo.addProperty(key, dto); } } return inputInfo; }
Example #21
Source File: ProjectGenerator.java From fabric8-forge with Apache License 2.0 | 5 votes |
protected void useCommand(RestUIContext context, String commandName, boolean shouldExecute) { try { UICommand command = commandFactory.getCommandByName(context, commandName); if (command == null) { LOG.warn("No such command! '" + commandName + "'"); return; } CommandController controller = commandControllerFactory.createController(context, runtime, command); if (controller == null) { LOG.warn("No such controller! '" + commandName + "'"); return; } controller.initialize(); WizardCommandController wizardCommandController = assertWizardController(controller); Map<String, InputComponent<?, ?>> inputs = controller.getInputs(); Set<Map.Entry<String, InputComponent<?, ?>>> entries = inputs.entrySet(); for (Map.Entry<String, InputComponent<?, ?>> entry : entries) { String key = entry.getKey(); InputComponent component = entry.getValue(); Object value = InputComponents.getValueFor(component); Object completions = null; UICompleter<?> completer = InputComponents.getCompleterFor(component); if (completer != null) { completions = completer.getCompletionProposals(context, component, ""); } LOG.info(key + " = " + component + " value: " + value + " completions: " + completions); } validate(controller); wizardCommandController = wizardCommandController.next(); if (shouldExecute) { Result result = controller.execute(); printResult(result); } } catch (Exception e) { LOG.error("Failed to create the " + commandName + " controller! " + e, e); } }
Example #22
Source File: WindupCommandTest.java From windup with Eclipse Public License 1.0 | 4 votes |
@Test public void testOverwriteConfirmation() throws Exception { String overwritePromptMessage = "Overwrite all contents of .*\\?"; // Sets the overwrite response flag to false uiTestHarness.getPromptResults().put(overwritePromptMessage, "false"); try (CommandController controller = uiTestHarness.createCommandController(WindupCommand.class)) { File inputFile = File.createTempFile("windupwizardtest", "jar"); inputFile.deleteOnExit(); try (InputStream iStream = getClass().getResourceAsStream("/test.jar")) { try (OutputStream oStream = new FileOutputStream(inputFile)) { IOUtils.copy(iStream, oStream); } } File reportPath = new File(inputFile.getAbsoluteFile() + "_output"); try { reportPath.mkdirs(); File newFileInOutputPath = new File(reportPath, "forceoverwriteprompt"); // make sure that at least one file is in the output newFileInOutputPath.createNewFile(); setupController(controller, inputFile, reportPath); Result result = controller.execute(); // make sure that it failed to run (since the user's response to the overwrite question is false) Assert.assertTrue(result instanceof Failed); Assert.assertTrue(result.getMessage().contains("overwrite not specified")); } finally { inputFile.delete(); FileUtils.deleteDirectory(reportPath); } } }
Example #23
Source File: SetupCommandTest.java From thorntail-addon with Eclipse Public License 1.0 | 4 votes |
@Test public void testThorntailSetupWithParameters() throws Exception { try (CommandController controller = uiTestHarness.createCommandController(SetupCommand.class, project.getRoot())) { controller.initialize(); controller.setValueFor("httpPort", 4242); controller.setValueFor("contextPath", "root"); controller.setValueFor("portOffset", 42); Assert.assertTrue(controller.isValid()); final AtomicBoolean flag = new AtomicBoolean(); controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener() { @Override public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result) { if (result.getMessage().equals("Thorntail is now set up! Enjoy!")) { flag.set(true); } } }); controller.execute(); Assert.assertTrue(flag.get()); ThorntailFacet facet = project.getFacet(ThorntailFacet.class); Assert.assertTrue(facet.isInstalled()); MavenPluginAdapter thorntailPlugin = (MavenPluginAdapter) project.getFacet(MavenPluginFacet.class) .getEffectivePlugin(ThorntailFacet.PLUGIN_COORDINATE); Assert.assertEquals("thorntail-maven-plugin", thorntailPlugin.getCoordinate().getArtifactId()); Assert.assertEquals(1, thorntailPlugin.getExecutions().size()); Configuration config = thorntailPlugin.getConfig(); ConfigurationElement configurationProps = config.getConfigurationElement("properties"); Assert.assertEquals(3, configurationProps.getChildren().size()); Assert.assertEquals("4242", configurationProps.getChildByName("swarm.http.port").getText()); Assert.assertEquals("root", configurationProps.getChildByName("swarm.context.path").getText()); Assert.assertEquals("42", configurationProps.getChildByName("swarm.port.offset").getText()); } }
Example #24
Source File: WindupCommandTest.java From windup with Eclipse Public License 1.0 | 4 votes |
@Test public void testOutputDirCannotBeParentOfInputDir() throws Exception { try (CommandController controller = uiTestHarness.createCommandController(WindupCommand.class)) { File tempDir = OperatingSystemUtils.createTempDir(); File inputFile = File.createTempFile("windupwizardtest", ".jar", tempDir); inputFile.deleteOnExit(); try (InputStream iStream = getClass().getResourceAsStream("/test.jar")) { try (OutputStream oStream = new FileOutputStream(inputFile)) { IOUtils.copy(iStream, oStream); } } try { controller.initialize(); Assert.assertTrue(controller.isEnabled()); controller.setValueFor(TargetOption.NAME, Collections.singletonList("eap")); controller.setValueFor(InputPathOption.NAME, Collections.singletonList(inputFile)); Assert.assertTrue(controller.canExecute()); controller.setValueFor(OutputPathOption.NAME, tempDir); Assert.assertFalse(controller.canExecute()); List<UIMessage> messages = controller.validate(); boolean validationFound = false; for (UIMessage message : messages) { if (message.getDescription().equals("Output path must not be a parent of input path.")) { validationFound = true; break; } } Assert.assertTrue(validationFound); controller.setValueFor(OutputPathOption.NAME, null); Assert.assertTrue(controller.canExecute()); controller.setValueFor(OverwriteOption.NAME, true); } finally { FileUtils.deleteDirectory(tempDir); } } }
Example #25
Source File: WindupCommandTest.java From windup with Eclipse Public License 1.0 | 4 votes |
@Test public void testOutputDefaultValue() throws Exception { Assert.assertNotNull(uiTestHarness); try (CommandController controller = uiTestHarness.createCommandController(WindupCommand.class)) { File inputFile = File.createTempFile("windupwizardtest", ".jar"); inputFile.deleteOnExit(); try (InputStream iStream = getClass().getResourceAsStream("/test.jar")) { try (OutputStream oStream = new FileOutputStream(inputFile)) { IOUtils.copy(iStream, oStream); } } try { setupController(controller, inputFile, null); Result result = controller.execute(); Object outputDir = controller.getValueFor("output"); Assert.assertTrue("The output should be a folder", DirectoryResource.class.isAssignableFrom(outputDir.getClass())); Assert.assertTrue("The output should be created inside the .report folder by default", ((DirectoryResource) outputDir).getName().endsWith(".report")); ArrayList<File> inputDirs = (ArrayList<File>) controller.getValueFor("input"); Assert.assertEquals(1, inputDirs.size()); File inputDirParent = inputDirs.get(0).getParentFile(); File child = new File(inputDirParent, ((DirectoryResource) outputDir).getName()); Assert.assertTrue("The output should be created near the ${input} folder by default", child.exists()); Assert.assertTrue("The output should be created near the ${input} folder by default", child.isDirectory()); final String msg = "controller.execute() 'Failed': " + result.getMessage(); Assert.assertFalse(msg, result instanceof Failed); } finally { inputFile.delete(); } } }
Example #26
Source File: WindupCommandTest.java From windup with Eclipse Public License 1.0 | 4 votes |
@Test public void testUserRulesDirMigration() throws Exception { Assert.assertNotNull(uiTestHarness); try (CommandController controller = uiTestHarness.createCommandController(WindupCommand.class)) { File outputFile = File.createTempFile("windupwizardtest", ".jar"); outputFile.deleteOnExit(); try (InputStream iStream = getClass().getResourceAsStream("/test.jar")) { try (OutputStream oStream = new FileOutputStream(outputFile)) { IOUtils.copy(iStream, oStream); } } File reportPath = new File(outputFile.getAbsoluteFile() + "_output"); try { reportPath.mkdirs(); setupController(controller, outputFile, reportPath); File userRulesDir = FileUtils.getTempDirectory().toPath().resolve("Windup") .resolve("windupcommanduserrules_" + RandomStringUtils.randomAlphanumeric(6)).toFile(); userRulesDir.mkdirs(); controller.setValueFor(UserRulesDirectoryOption.NAME, Collections.singletonList(userRulesDir)); Result result = controller.execute(); final String msg = "controller.execute() 'Failed': " + result.getMessage(); Assert.assertFalse(msg, result instanceof Failed); WindupConfiguration windupConfiguration = (WindupConfiguration) controller.getContext() .getAttributeMap() .get(WindupConfiguration.class); List<File> resultUserSpecifiedRulesDirs = windupConfiguration.getOptionValue(UserRulesDirectoryOption.NAME); Assert.assertEquals(1, resultUserSpecifiedRulesDirs.size()); Iterable<Path> allRulesPaths = windupConfiguration.getAllUserRulesDirectories(); Path expectedUserHomeRulesDir = PathUtil.getUserRulesDir(); Path expectedWindupHomeRulesDir = PathUtil.getWindupRulesDir(); boolean foundUserSpecifiedPath = false; boolean foundUserHomeDirRulesPath = false; boolean foundWindupHomeDirRulesPath = false; int totalFound = 0; for (Path rulesPath : allRulesPaths) { totalFound++; if (rulesPath.equals(userRulesDir.toPath())) { foundUserSpecifiedPath = true; } if (rulesPath.equals(expectedUserHomeRulesDir)) { foundUserHomeDirRulesPath = true; } if (rulesPath.equals(expectedWindupHomeRulesDir)) { foundWindupHomeDirRulesPath = true; } } Assert.assertTrue(foundUserSpecifiedPath); Assert.assertTrue(foundUserHomeDirRulesPath); Assert.assertTrue(foundWindupHomeDirRulesPath); Assert.assertEquals(3, totalFound); } finally { outputFile.delete(); FileUtils.deleteDirectory(reportPath); } } }
Example #27
Source File: WindupCommandTest.java From windup with Eclipse Public License 1.0 | 4 votes |
@Test public void testDuplicateUserRulesDirMigration() throws Exception { Assert.assertNotNull(uiTestHarness); try (CommandController controller = uiTestHarness.createCommandController(WindupCommand.class)) { File outputFile = File.createTempFile("windupwizardtest", ".jar"); outputFile.deleteOnExit(); try (InputStream iStream = getClass().getResourceAsStream("/test.jar")) { try (OutputStream oStream = new FileOutputStream(outputFile)) { IOUtils.copy(iStream, oStream); } } File reportPath = new File(outputFile.getAbsoluteFile() + "_output"); try { reportPath.mkdirs(); setupController(controller, outputFile, reportPath); Path expectedUserHomeRulesDir = PathUtil.getUserRulesDir(); expectedUserHomeRulesDir.toFile().mkdirs(); controller.setValueFor(UserRulesDirectoryOption.NAME, Collections.singletonList(expectedUserHomeRulesDir.toFile())); Result result = controller.execute(); final String msg = "controller.execute() 'Failed': " + result.getMessage(); Assert.assertFalse(msg, result instanceof Failed); WindupConfiguration windupConfiguration = (WindupConfiguration) controller.getContext() .getAttributeMap() .get(WindupConfiguration.class); Collection<File> resultUserSpecifiedRulesDirs = windupConfiguration.getOptionValue(UserRulesDirectoryOption.NAME); Assert.assertEquals(expectedUserHomeRulesDir.toFile(), resultUserSpecifiedRulesDirs.iterator().next()); Iterable<Path> allRulesPaths = windupConfiguration.getAllUserRulesDirectories(); Path expectedWindupHomeRulesDir = PathUtil.getWindupRulesDir(); boolean foundUserHomeDirRulesPath = false; boolean foundWindupHomeDirRulesPath = false; int totalFound = 0; for (Path rulesPath : allRulesPaths) { totalFound++; if (rulesPath.equals(expectedUserHomeRulesDir)) { foundUserHomeDirRulesPath = true; } if (rulesPath.equals(expectedWindupHomeRulesDir)) { foundWindupHomeDirRulesPath = true; } } Assert.assertTrue(foundUserHomeDirRulesPath); Assert.assertTrue(foundWindupHomeDirRulesPath); Assert.assertEquals(2, totalFound); } finally { outputFile.delete(); FileUtils.deleteDirectory(reportPath); } } }
Example #28
Source File: WindupCommandTest.java From windup with Eclipse Public License 1.0 | 4 votes |
@Test public void testUserIgnoreDirMigration() throws Exception { Assert.assertNotNull(uiTestHarness); try (CommandController controller = uiTestHarness.createCommandController(WindupCommand.class)) { File outputFile = File.createTempFile("windupwizardtest", ".jar"); outputFile.deleteOnExit(); File inputIgnoreFile = File.createTempFile("generated-windup-ignore", ".txt"); inputIgnoreFile.deleteOnExit(); try (InputStream iStream = getClass().getResourceAsStream("/test.jar")) { try (OutputStream oStream = new FileOutputStream(outputFile)) { IOUtils.copy(iStream, oStream); } } try (InputStream iStream = getClass().getResourceAsStream(TEST_IGNORE_FILE)) { try (OutputStream oStream = new FileOutputStream(inputIgnoreFile)) { IOUtils.copy(iStream, oStream); } } File reportPath = new File(outputFile.getAbsoluteFile() + "_output"); try { reportPath.mkdirs(); setupController(controller, outputFile, reportPath); controller.setValueFor(UserIgnorePathOption.NAME, inputIgnoreFile); Result result = controller.execute(); final String msg = "controller.execute() 'Failed': " + result.getMessage(); Assert.assertFalse(msg, result instanceof Failed); WindupConfiguration windupConfiguration = (WindupConfiguration) controller.getContext() .getAttributeMap() .get(WindupConfiguration.class); File resultIgnoreFile = windupConfiguration.getOptionValue(UserIgnorePathOption.NAME); Assert.assertEquals(inputIgnoreFile, resultIgnoreFile); Iterable<Path> allIgnoreDirectories = windupConfiguration.getAllIgnoreDirectories(); Path expectedUserHomeIgnoreDir = PathUtil.getUserIgnoreDir(); Path expectedWindupHomeIgnoreDir = PathUtil.getWindupIgnoreDir(); boolean foundUserSpecifiedPath = false; boolean foundUserHomeDirIgnorePath = false; boolean foundWindupHomeDirIgnorePath = false; int totalFound = 0; for (Path rulesPath : allIgnoreDirectories) { totalFound++; if (rulesPath.equals(resultIgnoreFile.toPath())) { foundUserSpecifiedPath = true; } if (rulesPath.equals(expectedUserHomeIgnoreDir)) { foundUserHomeDirIgnorePath = true; } if (rulesPath.equals(expectedWindupHomeIgnoreDir)) { foundWindupHomeDirIgnorePath = true; } } Assert.assertTrue(foundUserSpecifiedPath); Assert.assertTrue(foundUserHomeDirIgnorePath); Assert.assertTrue(foundWindupHomeDirIgnorePath); Assert.assertEquals(3, totalFound); GraphContext context = (GraphContext) controller.getContext().getAttributeMap().get(GraphContext.class); GraphService<FileModel> service = new GraphService<>(context.load(), FileModel.class); Iterable<FileModel> findAll = service.findAll(); boolean notEmpty = false; for (FileModel fileModel : findAll) { notEmpty = true; if (!(fileModel instanceof IgnoredFileModel) && (fileModel.getFileName().contains("META-INF"))) { Assert.fail("The file " + fileModel.getFileName() + " should be ignored"); } } Assert.assertTrue("There should be some file models present in the graph", notEmpty); } finally { outputFile.delete(); FileUtils.deleteDirectory(reportPath); } } }
Example #29
Source File: WindupCommandRuleFilteringTest.java From windup with Eclipse Public License 1.0 | 4 votes |
private void setupAndRun(Set<String> includeTags, Set<String> excludeTags, Set<String> sources, Set<String> targets) throws Exception { Assert.assertNotNull(uiTestHarness); this.tag1SourceGlassfishRuleProvider.executed = false; this.tag1SourceGlassfishTargetFooRuleProvider.executed = false; this.tag2SourceGlassfishTargetJBossRuleProvider.executed = false; this.tag3SourceOrionServerRuleProvider.executed = false; try (CommandController controller = uiTestHarness.createCommandController(WindupCommand.class)) { File outputFile = File.createTempFile("windupwizardtest", ".jar"); outputFile.deleteOnExit(); File inputFile = File.createTempFile("windupwizardtest", ".jar"); inputFile.deleteOnExit(); try (InputStream iStream = getClass().getResourceAsStream("/test.jar")) { try (OutputStream oStream = new FileOutputStream(outputFile)) { IOUtils.copy(iStream, oStream); } } File reportPath = new File(inputFile.getAbsoluteFile() + "_output"); try { reportPath.mkdirs(); controller.initialize(); Assert.assertTrue(controller.isEnabled()); //controller.setValueFor(InputPathOption.NAME, inputFile); controller.setValueFor(InputPathOption.NAME, Collections.singletonList(inputFile)); // FORGE-2524 Object valueFor = controller.getValueFor(InputPathOption.NAME);/// controller.setValueFor(OutputPathOption.NAME, outputFile); if (includeTags != null) { controller.setValueFor(IncludeTagsOption.NAME, includeTags); } if (excludeTags != null) { controller.setValueFor(ExcludeTagsOption.NAME, excludeTags); } if (sources != null) { controller.setValueFor(SourceOption.NAME, sources); } if (targets != null) { controller.setValueFor(TargetOption.NAME, targets); } Assert.assertTrue(controller.canExecute()); Result result = controller.execute(); final String msg = "controller.execute() 'Failed': " + result.getMessage(); Assert.assertFalse(msg, result instanceof Failed); } finally { inputFile.delete(); FileUtils.deleteDirectory(reportPath); } } }
Example #30
Source File: WindupUpdateDistributionCommandTest.java From windup with Eclipse Public License 1.0 | 4 votes |
@Test @Ignore("Completely broken now. New Furnace doesn't deal well with setting windup.home like this.") public void testUpdateDistributionCommand() throws Exception { // Unzip the rulesets from a .zip in resources. File tempDir = OperatingSystemUtils.createTempDir(); tempDir.deleteOnExit(); File extractedPath = new File(tempDir, "extracted-rulesets"); ZipUtil.unzipFromClassResource(getClass(), WindupUpdateDistributionCommandTest.TEST_RULESET_ZIP, extractedPath); String windupDir = extractedPath + "/windup-old-ruleset"; System.setProperty(PathUtil.WINDUP_RULESETS_DIR_SYSPROP, windupDir); File addonsDir = new File(windupDir, "addons"); addonsDir.mkdirs(); String currentUiVersion = getInstalledAddonVersion(addon.getRepository().getRootDirectory().getPath(), WINDUP_UI_ADDON_NAME); installOldAddonVersion(currentUiVersion); // changeUiAddonVersion(addon.getRepository().getRootDirectory(), // currentUiVersion); waitForOldWindupUIAddon(furnace); boolean rulesetNeedUpdate = updater.rulesetsNeedUpdate(true); Assert.assertTrue(rulesetNeedUpdate); try (CommandController controller = uiTestHarness.createCommandController("Windup Update Distribution")) { try { controller.initialize(); Assert.assertTrue(controller.isEnabled()); // Actually runs the command. Result result = controller.execute(); Assert.assertFalse("Windup Update Distribution command should suceed, but it failed.", result instanceof Failed); rulesetNeedUpdate = updater.rulesetsNeedUpdate(true); Assert.assertFalse("Ruleset should have already been updated to the latest version and as such should not need another update.", rulesetNeedUpdate); checkWindupDirectory(windupDir); } finally { FileUtils.deleteDirectory(tempDir); } } }