repo-reorg-2020: moved sts4-relevant spring-ide bundles from https://github.com/spring-projects/spring-ide/releases/tag/REPO-REORG-2020 into sts4 repo
This commit is contained in:
@@ -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>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.springframework.ide.eclipse.boot.refactoring.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>
|
||||
@@ -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
|
||||
@@ -0,0 +1,60 @@
|
||||
eclipse.preferences.version=1
|
||||
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
|
||||
sp_cleanup.add_default_serial_version_id=true
|
||||
sp_cleanup.add_generated_serial_version_id=false
|
||||
sp_cleanup.add_missing_annotations=false
|
||||
sp_cleanup.add_missing_deprecated_annotations=true
|
||||
sp_cleanup.add_missing_methods=false
|
||||
sp_cleanup.add_missing_nls_tags=false
|
||||
sp_cleanup.add_missing_override_annotations=true
|
||||
sp_cleanup.add_missing_override_annotations_interface_methods=true
|
||||
sp_cleanup.add_serial_version_id=false
|
||||
sp_cleanup.always_use_blocks=true
|
||||
sp_cleanup.always_use_parentheses_in_expressions=false
|
||||
sp_cleanup.always_use_this_for_non_static_field_access=false
|
||||
sp_cleanup.always_use_this_for_non_static_method_access=false
|
||||
sp_cleanup.convert_functional_interfaces=false
|
||||
sp_cleanup.convert_to_enhanced_for_loop=false
|
||||
sp_cleanup.correct_indentation=false
|
||||
sp_cleanup.format_source_code=false
|
||||
sp_cleanup.format_source_code_changes_only=false
|
||||
sp_cleanup.insert_inferred_type_arguments=false
|
||||
sp_cleanup.make_local_variable_final=true
|
||||
sp_cleanup.make_parameters_final=false
|
||||
sp_cleanup.make_private_fields_final=true
|
||||
sp_cleanup.make_type_abstract_if_missing_method=false
|
||||
sp_cleanup.make_variable_declarations_final=false
|
||||
sp_cleanup.never_use_blocks=false
|
||||
sp_cleanup.never_use_parentheses_in_expressions=true
|
||||
sp_cleanup.on_save_use_additional_actions=true
|
||||
sp_cleanup.organize_imports=false
|
||||
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
|
||||
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
|
||||
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
|
||||
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
|
||||
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
|
||||
sp_cleanup.remove_private_constructors=true
|
||||
sp_cleanup.remove_redundant_type_arguments=true
|
||||
sp_cleanup.remove_trailing_whitespaces=true
|
||||
sp_cleanup.remove_trailing_whitespaces_all=true
|
||||
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
|
||||
sp_cleanup.remove_unnecessary_casts=false
|
||||
sp_cleanup.remove_unnecessary_nls_tags=false
|
||||
sp_cleanup.remove_unused_imports=false
|
||||
sp_cleanup.remove_unused_local_variables=false
|
||||
sp_cleanup.remove_unused_private_fields=true
|
||||
sp_cleanup.remove_unused_private_members=false
|
||||
sp_cleanup.remove_unused_private_methods=true
|
||||
sp_cleanup.remove_unused_private_types=true
|
||||
sp_cleanup.sort_members=false
|
||||
sp_cleanup.sort_members_all=false
|
||||
sp_cleanup.use_anonymous_class_creation=false
|
||||
sp_cleanup.use_blocks=false
|
||||
sp_cleanup.use_blocks_only_for_return_and_throw=false
|
||||
sp_cleanup.use_lambda=true
|
||||
sp_cleanup.use_parentheses_in_expressions=false
|
||||
sp_cleanup.use_this_for_non_static_field_access=false
|
||||
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
|
||||
sp_cleanup.use_this_for_non_static_method_access=false
|
||||
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
|
||||
sp_cleanup.use_type_arguments=false
|
||||
@@ -0,0 +1,36 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Test
|
||||
Fragment-Host: org.springframework.ide.eclipse.boot.refactoring;bundle-version="3.7.3"
|
||||
Bundle-SymbolicName: org.springframework.ide.eclipse.boot.refactoring.test
|
||||
Bundle-Version: 4.8.1.qualifier
|
||||
Bundle-Vendor: Pivotal Inc
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
org.junit,
|
||||
org.eclipse.core.resources,
|
||||
org.springsource.ide.eclipse.commons.tests.util,
|
||||
org.apache.commons.io,
|
||||
org.eclipse.debug.core,
|
||||
org.eclipse.jdt.core,
|
||||
org.springsource.ide.eclipse.commons.livexp,
|
||||
org.springsource.ide.eclipse.commons.frameworks.core,
|
||||
org.springsource.ide.eclipse.commons.frameworks.test.util,
|
||||
org.springframework.ide.eclipse.boot.launch,
|
||||
org.eclipse.jdt.launching,
|
||||
org.eclipse.debug.ui,
|
||||
org.mockito;bundle-version="[1.9.5,1.9.6)",
|
||||
org.springframework.ide.eclipse.boot,
|
||||
org.eclipse.core.expressions,
|
||||
org.springframework.ide.eclipse.boot.test,
|
||||
com.google.guava;bundle-version="15.0.0",
|
||||
org.eclipse.ui,
|
||||
org.eclipse.equinox.security,
|
||||
org.reactivestreams.reactive-streams;bundle-version="1.0.2",
|
||||
io.projectreactor.reactor-core;bundle-version="[3.3.1,3.3.2)",
|
||||
org.apache.commons.lang,
|
||||
javax.ws.rs;bundle-version="2.0.1",
|
||||
org.eclipse.osgi,
|
||||
org.hamcrest;bundle-version="[1.1.0,1.2.0)"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ActivationPolicy: lazy
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot.ide</groupId>
|
||||
<artifactId>org.springframework.boot.ide</artifactId>
|
||||
<version>4.8.1-SNAPSHOT</version>
|
||||
<relativePath>../../eclipse-distribution/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>org.springframework.ide.eclipse</groupId>
|
||||
<artifactId>org.springframework.ide.eclipse.boot.refactoring.test</artifactId>
|
||||
<packaging>eclipse-test-plugin</packaging>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>tycho-surefire-plugin</artifactId>
|
||||
<version>${tycho-version}</version>
|
||||
<configuration>
|
||||
<useUIHarness>true</useUIHarness>
|
||||
<forkedProcessTimeoutInSeconds>7200</forkedProcessTimeoutInSeconds>
|
||||
<testSuite>org.springframework.ide.eclipse.boot.refactoring.test</testSuite>
|
||||
<testClass>org.springframework.ide.eclipse.boot.refactoring.test.ConvertPropertiesToYamlTest</testClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>target-platform-configuration</artifactId>
|
||||
<version>${tycho-version}</version>
|
||||
<configuration>
|
||||
<dependency-resolution>
|
||||
<extraRequirements>
|
||||
<requirement>
|
||||
<type>eclipse-feature</type>
|
||||
<id>org.eclipse.m2e.feature</id>
|
||||
<versionRange>0.0.0</versionRange>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<type>eclipse-plugin</type>
|
||||
<id>org.eclipse.equinox.event</id>
|
||||
<versionRange>0.0.0</versionRange>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<type>eclipse-plugin</type>
|
||||
<id>org.apache.felix.scr</id>
|
||||
<versionRange>0.0.0</versionRange>
|
||||
</requirement>
|
||||
</extraRequirements>
|
||||
</dependency-resolution>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,342 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Spring IDE Developers
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Spring IDE Developers - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.eclipse.boot.refactoring.test;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springsource.ide.eclipse.commons.tests.util.StsTestCase.assertContains;
|
||||
import static org.springsource.ide.eclipse.commons.tests.util.StsTestCase.createFile;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
||||
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.eclipse.boot.refactoring.ConvertPropertiesToYamlRefactoring;
|
||||
import org.springframework.ide.eclipse.boot.test.BootProjectTestHarness;
|
||||
import org.springsource.ide.eclipse.commons.frameworks.core.util.IOUtil;
|
||||
import org.springsource.ide.eclipse.commons.tests.util.StsTestUtil;
|
||||
|
||||
public class ConvertPropertiesToYamlTest {
|
||||
|
||||
public interface Checker<T> {
|
||||
void check(T it) throws Exception;
|
||||
}
|
||||
|
||||
BootProjectTestHarness projects = new BootProjectTestHarness(getWorkspace());
|
||||
|
||||
protected IWorkspace getWorkspace() {
|
||||
return ResourcesPlugin.getWorkspace();
|
||||
}
|
||||
|
||||
@Before public void setup() throws Exception {
|
||||
StsTestUtil.deleteAllProjects();
|
||||
}
|
||||
|
||||
@Test public void fileIsInTheWay() throws Exception {
|
||||
IProject project = projects.createBootProject("fileIsInTheWay");
|
||||
createFile(project, "src/main/resources/application.yml", "someting: already-in-here");
|
||||
IFile propsFile = project.getFile("src/main/resources/application.properties");
|
||||
assertTrue(propsFile.exists());
|
||||
ConvertPropertiesToYamlRefactoring refactoring = new ConvertPropertiesToYamlRefactoring(propsFile);
|
||||
|
||||
RefactoringStatus status = refactoring.checkInitialConditions(new NullProgressMonitor());
|
||||
assertStatus(status, RefactoringStatus.FATAL, "'/fileIsInTheWay/src/main/resources/application.yml' already exists");
|
||||
}
|
||||
|
||||
@Test public void hasComments() throws Exception {
|
||||
IProject project = projects.createBootProject("hasComments");
|
||||
do_hasComments_test(project, "#comment");
|
||||
do_hasComments_test(project, "!comment");
|
||||
do_hasComments_test(project, " \t!comment");
|
||||
ConvertPropertiesToYamlRefactoring refactoring = do_hasComments_test(project, " #!comment");
|
||||
|
||||
perform(refactoring); //Despite the warning, the refactoring should be executable.
|
||||
assertFalse(project.getFile("src/main/resources/application.properties").exists());
|
||||
assertFile(project, "src/main/resources/application.yml",
|
||||
"other:\n" +
|
||||
" property: othervalue\n" +
|
||||
"some:\n" +
|
||||
" property: somevalue\n"
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void almostHasComments() throws Exception {
|
||||
do_conversionTest(
|
||||
"my.hello=Good morning!\n" +
|
||||
"my.goodbye=See ya # later\n"
|
||||
, // ==>
|
||||
"my:\n" +
|
||||
" goodbye: 'See ya # later'\n" +
|
||||
" hello: Good morning!\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test public void conversionWithListItems() throws Exception {
|
||||
do_conversionTest(
|
||||
"some.thing[0].a=first-a\n" +
|
||||
"some.thing[0].b=first-b\n" +
|
||||
"some.thing[1].a=second-a\n" +
|
||||
"some.thing[1].b=second-b\n"
|
||||
, // ==>
|
||||
"some:\n" +
|
||||
" thing:\n" +
|
||||
" - a: first-a\n" +
|
||||
" b: first-b\n" +
|
||||
" - a: second-a\n" +
|
||||
" b: second-b\n"
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void simpleConversion() throws Exception {
|
||||
do_conversionTest(
|
||||
"some.thing=vvvv\n" +
|
||||
"some.other.thing=blah\n"
|
||||
, // ==>
|
||||
"some:\n" +
|
||||
" other:\n" +
|
||||
" thing: blah\n" +
|
||||
" thing: vvvv\n"
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void nonStringyValueConversion() throws Exception {
|
||||
//See: https://www.pivotaltracker.com/story/show/154181583
|
||||
//Test that we do not add unnecessary quotes around certain types of values.
|
||||
do_conversionTest(
|
||||
"exponated=123.4E-12\n" +
|
||||
"server.port=8888\n" +
|
||||
"foobar.enabled=true\n" +
|
||||
"foobar.nice=false\n" +
|
||||
"fractional=0.78\n" +
|
||||
"largenumber=989898989898989898989898989898989898989898989898989898989898\n" +
|
||||
"longfractional=-0.989898989898989898989898989898989898989898989898989898989898\n"
|
||||
, // ==>
|
||||
"exponated: '123.4E-12'\n" + //quotes are added because conversion to number changes the string value
|
||||
"foobar:\n" +
|
||||
" enabled: true\n" +
|
||||
" nice: false\n" +
|
||||
"fractional: 0.78\n" +
|
||||
"largenumber: 989898989898989898989898989898989898989898989898989898989898\n" +
|
||||
"longfractional: -0.989898989898989898989898989898989898989898989898989898989898\n" +
|
||||
"server:\n" +
|
||||
" port: 8888\n"
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void emptyFileConversion() throws Exception {
|
||||
do_conversionTest(
|
||||
""
|
||||
, // ==>
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void unusualName() throws Exception {
|
||||
IProject project = projects.createProject("unusualName");
|
||||
IFile input = createFile(project, "no-extension",
|
||||
"server.port: 6789"
|
||||
);
|
||||
ConvertPropertiesToYamlRefactoring refactoring = new ConvertPropertiesToYamlRefactoring(input);
|
||||
assertOkStatus(refactoring.checkAllConditions(new NullProgressMonitor()));
|
||||
perform(refactoring);
|
||||
assertEquals(
|
||||
"server:\n" +
|
||||
" port: 6789\n"
|
||||
,
|
||||
IOUtil.toString(project.getFile("no-extension.yml").getContents())
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void nonExistentInput() throws Exception {
|
||||
IProject project = projects.createProject("nonExistentInput");
|
||||
IFile input = project.getFile("doesnotexist.properties");
|
||||
ConvertPropertiesToYamlRefactoring refactoring = new ConvertPropertiesToYamlRefactoring(input);
|
||||
assertStatus(refactoring.checkInitialConditions(new NullProgressMonitor()),
|
||||
RefactoringStatus.FATAL, "is not accessible");
|
||||
}
|
||||
|
||||
@Test public void multipleAssignmentProblem() throws Exception {
|
||||
do_conversionTest(
|
||||
"some.property=something\n" +
|
||||
"some.property=something-else"
|
||||
, // ==>
|
||||
"some:\n" +
|
||||
" property:\n" +
|
||||
" - something\n" +
|
||||
" - something-else\n"
|
||||
, (status) -> {
|
||||
assertStatus(status, RefactoringStatus.WARNING, "Multiple values [something, something-else] assigned to 'some.property'.");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void scalarAndMapConflict() throws Exception {
|
||||
do_conversionTest(
|
||||
"some.property=a-scalar\n" +
|
||||
"some.property.sub=sub-value"
|
||||
,
|
||||
"some:\n" +
|
||||
" property:\n" +
|
||||
" sub: sub-value\n"
|
||||
, (status) -> {
|
||||
assertStatus(status, RefactoringStatus.ERROR, "Direct assignment 'some.property=a-scalar' can not be combined with sub-property assignment 'some.property.sub...'");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void scalarAndSequenceConflict() throws Exception {
|
||||
do_conversionTest(
|
||||
"some.property=a-scalar\n" +
|
||||
"some.property[0]=zero\n" +
|
||||
"some.property[1]=one\n"
|
||||
,
|
||||
"some:\n" +
|
||||
" property:\n" +
|
||||
" - zero\n" +
|
||||
" - one\n"
|
||||
, (status) -> {
|
||||
assertStatus(status, RefactoringStatus.ERROR, "Direct assignment 'some.property=a-scalar' can not be combined with sequence assignment 'some.property[0]...'");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void mapAndSequenceConflict() throws Exception {
|
||||
do_conversionTest(
|
||||
"some.property.abc=val1\n" +
|
||||
"some.property.def=val2\n" +
|
||||
"some.property[0]=zero\n" +
|
||||
"some.property[1]=one\n"
|
||||
,
|
||||
"some:\n" +
|
||||
" property:\n" +
|
||||
" '0': zero\n" +
|
||||
" '1': one\n" +
|
||||
" abc: val1\n" +
|
||||
" def: val2\n"
|
||||
, (status) -> {
|
||||
assertStatus(status, RefactoringStatus.WARNING, "'some.property' has some entries that look like list items and others that look like map entries");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void scalarAndMapAndSequenceConflict() throws Exception {
|
||||
do_conversionTest(
|
||||
"some.property=a-scalar\n" +
|
||||
"some.property.abc=val1\n" +
|
||||
"some.property.def=val2\n" +
|
||||
"some.property[0]=zero\n" +
|
||||
"some.property[1]=one\n"
|
||||
,
|
||||
"some:\n" +
|
||||
" property:\n" +
|
||||
" '0': zero\n" +
|
||||
" '1': one\n" +
|
||||
" abc: val1\n" +
|
||||
" def: val2\n"
|
||||
, (status) -> {
|
||||
assertStatus(status, RefactoringStatus.ERROR, "Direct assignment 'some.property=a-scalar' can not be combined with sub-property assignment 'some.property.abc...'. ");
|
||||
assertStatus(status, RefactoringStatus.ERROR, "'some.property' has some entries that look like list items and others that look like map entries");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void do_conversionTest(String input, String expectedOutput) throws Exception {
|
||||
do_conversionTest(input, expectedOutput, (status) -> {
|
||||
assertEquals(RefactoringStatus.OK, status.getSeverity());
|
||||
});
|
||||
}
|
||||
|
||||
private void do_conversionTest(String input, String expectedOutput, Checker<RefactoringStatus> statusChecker) throws Exception {
|
||||
IProject project = projects.createProject("conversionTestProject");
|
||||
IFile propertiesFile = createFile(project, "application.properties", input);
|
||||
IFile yamlFile = project.getFile("application.yml");
|
||||
assertTrue(propertiesFile.exists());
|
||||
assertFalse(yamlFile.exists());
|
||||
|
||||
ConvertPropertiesToYamlRefactoring refactoring = new ConvertPropertiesToYamlRefactoring(propertiesFile);
|
||||
statusChecker.check(refactoring.checkAllConditions(new NullProgressMonitor()));
|
||||
perform(refactoring);
|
||||
|
||||
assertFalse(propertiesFile.exists());
|
||||
assertTrue(yamlFile.exists());
|
||||
|
||||
assertEquals(expectedOutput, IOUtil.toString(yamlFile.getContents()));
|
||||
}
|
||||
|
||||
private void assertFile(IProject project, String path, String expectedContents) throws Exception {
|
||||
IFile file = project.getFile(path);
|
||||
assertTrue(file.getFullPath().toString(), file.exists());
|
||||
assertEquals(expectedContents, IOUtil.toString(file.getContents()));
|
||||
}
|
||||
|
||||
private void perform(ConvertPropertiesToYamlRefactoring refactoring) throws Exception {
|
||||
Change change = refactoring.createChange(new NullProgressMonitor());
|
||||
IWorkspace workspace = getWorkspace();
|
||||
CompletableFuture<Void> result = new CompletableFuture<>();
|
||||
Job job = new Job(refactoring.getName()) {
|
||||
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
workspace.run(new PerformChangeOperation(change), monitor);
|
||||
result.complete(null);
|
||||
} catch (Throwable e) {
|
||||
result.completeExceptionally(e);
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
};
|
||||
job.setRule(workspace.getRuleFactory().buildRule());
|
||||
job.schedule();
|
||||
result.get();
|
||||
}
|
||||
|
||||
private ConvertPropertiesToYamlRefactoring do_hasComments_test(IProject project, String comment) throws Exception {
|
||||
IFile propsFile = createFile(project, "src/main/resources/application.properties",
|
||||
"some.property=somevalue\n"+
|
||||
comment +"\n" +
|
||||
"other.property=othervalue"
|
||||
);
|
||||
ConvertPropertiesToYamlRefactoring refactoring = new ConvertPropertiesToYamlRefactoring(propsFile);
|
||||
assertOkStatus(refactoring.checkInitialConditions(new NullProgressMonitor()));
|
||||
assertStatus(refactoring.checkFinalConditions(new NullProgressMonitor()), RefactoringStatus.WARNING, "has comments, which will be lost");
|
||||
return refactoring;
|
||||
}
|
||||
|
||||
private void assertOkStatus(RefactoringStatus s) {
|
||||
assertEquals(RefactoringStatus.OK, s.getSeverity());
|
||||
}
|
||||
|
||||
private void assertStatus(RefactoringStatus status, int expectedSeverity, String expectedMessageFragment) {
|
||||
assertEquals(expectedSeverity, status.getSeverity());
|
||||
StringBuilder allMessages = new StringBuilder();
|
||||
for (RefactoringStatusEntry entry : status.getEntries()) {
|
||||
allMessages.append(entry.getMessage());
|
||||
allMessages.append("\n-------------\n");
|
||||
}
|
||||
assertContains(expectedMessageFragment, allMessages.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user