From f0fb5bbf1b6c59a463e5dc34feee437aacf93395 Mon Sep 17 00:00:00 2001 From: Steve Hill Date: Wed, 28 Jun 2023 20:23:08 -0700 Subject: [PATCH] Relocate CreateIndexJelly Rewrite test in java. Issue #4 --- .../jenkins}/CreateIndexJelly.java | 3 +- .../jenkins/CreateIndexJellyTest.java | 134 +++++++++++++++++ .../jenkins/rewrite/CreateIndexJellyTest.kt | 140 ------------------ 3 files changed, 136 insertions(+), 141 deletions(-) rename src/main/java/{net/sghill/jenkins/rewrite => org/openrewrite/jenkins}/CreateIndexJelly.java (97%) create mode 100644 src/test/java/org/openrewrite/jenkins/CreateIndexJellyTest.java delete mode 100644 src/test/kotlin/net/sghill/jenkins/rewrite/CreateIndexJellyTest.kt diff --git a/src/main/java/net/sghill/jenkins/rewrite/CreateIndexJelly.java b/src/main/java/org/openrewrite/jenkins/CreateIndexJelly.java similarity index 97% rename from src/main/java/net/sghill/jenkins/rewrite/CreateIndexJelly.java rename to src/main/java/org/openrewrite/jenkins/CreateIndexJelly.java index 24ad5b1..f91faee 100644 --- a/src/main/java/net/sghill/jenkins/rewrite/CreateIndexJelly.java +++ b/src/main/java/org/openrewrite/jenkins/CreateIndexJelly.java @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.sghill.jenkins.rewrite; +package org.openrewrite.jenkins; +import net.sghill.jenkins.rewrite.Jenkins; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.ScanningRecipe; diff --git a/src/test/java/org/openrewrite/jenkins/CreateIndexJellyTest.java b/src/test/java/org/openrewrite/jenkins/CreateIndexJellyTest.java new file mode 100644 index 0000000..d7169d5 --- /dev/null +++ b/src/test/java/org/openrewrite/jenkins/CreateIndexJellyTest.java @@ -0,0 +1,134 @@ +/* + * Copyright 2023 the original author or authors. + *

+ * 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 + *

+ * https://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 org.openrewrite.jenkins; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.mavenProject; +import static org.openrewrite.java.Assertions.srcMainResources; +import static org.openrewrite.maven.Assertions.pomXml; +import static org.openrewrite.test.SourceSpecs.other; +import static org.openrewrite.test.SourceSpecs.text; + +@Disabled // TODO port to rewrite 8.x +class CreateIndexJellyTest implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + spec.recipe(new CreateIndexJelly()); + } + + @Test + void shouldNoOpIfIndexJellyAlreadyExists() { + rewriteRun(other("peanut butter and...", spec -> + spec.path("src/main/resources/index.jelly"))); + } + + @Test + void shouldCreateIndexJelly() { + rewriteRun(mavenProject("plugin", + pomXml(""" + + + org.jenkins-ci.plugins + plugin + 4.40 + + my-plugin + This is my plugin's description + 0.1 + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """.stripIndent()), + srcMainResources( + text(null, """ + +

+ This is my plugin's description +
+ """.stripIndent(), spec -> spec.path("index.jelly")) + ))); + } + + @Test + void shouldCreateIndexJellyEmptyDescription() { + rewriteRun(mavenProject("plugin", + pomXml(""" + + + org.jenkins-ci.plugins + plugin + 4.40 + + my-plugin + + 0.1 + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """.stripIndent()), + srcMainResources( + text(null, """ + +
+ my-plugin +
+ """.stripIndent(), spec -> spec.path("index.jelly")) + ))); + } + + @Test + void shouldCreateIndexJellyNoDescription() { + rewriteRun(mavenProject("plugin", + pomXml(""" + + + org.jenkins-ci.plugins + plugin + 4.40 + + my-plugin + 0.1 + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """.stripIndent()), + srcMainResources( + text(null, """ + +
+ my-plugin +
+ """.stripIndent(), spec -> spec.path("index.jelly")) + ))); + } +} diff --git a/src/test/kotlin/net/sghill/jenkins/rewrite/CreateIndexJellyTest.kt b/src/test/kotlin/net/sghill/jenkins/rewrite/CreateIndexJellyTest.kt deleted file mode 100644 index c5c687e..0000000 --- a/src/test/kotlin/net/sghill/jenkins/rewrite/CreateIndexJellyTest.kt +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2023 the original author or authors. - *

- * 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 - *

- * https://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 net.sghill.jenkins.rewrite - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.openrewrite.java.Assertions.mavenProject -import org.openrewrite.java.Assertions.srcMainResources -import org.openrewrite.maven.Assertions.pomXml -import org.openrewrite.test.RecipeSpec -import org.openrewrite.test.RewriteTest -import org.openrewrite.test.SourceSpecs.other -import org.openrewrite.test.SourceSpecs.text - -@Disabled // TODO port to rewrite 8 -class CreateIndexJellyTest : RewriteTest { - override fun defaults(spec: RecipeSpec) { - spec.recipe(CreateIndexJelly()) - } - - @Test - fun indexJellyAlreadyExists() = rewriteRun( - other("peanut butter and...") { - spec -> spec.path("src/main/resources/index.jelly") - } - ) - - @Test - fun createIndexJelly() = rewriteRun( - mavenProject("plugin", - pomXml(""" - - - org.jenkins-ci.plugins - plugin - 4.40 - - my-plugin - This is my plugin's description - 0.1 - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - """), - srcMainResources( - text(null, """ - -

- This is my plugin's description -
- """) { - spec -> spec.path("index.jelly") - } - ) - ) - ) - @Test - fun createIndexJellyEmptyDescription() = rewriteRun( - mavenProject("plugin", - pomXml(""" - - - org.jenkins-ci.plugins - plugin - 4.40 - - my-plugin - - 0.1 - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - """), - srcMainResources( - text(null, """ - -
- my-plugin -
- """) { - spec -> spec.path("index.jelly") - } - ) - ) - ) - - @Test - fun createIndexJellyNoDescription() = rewriteRun( - mavenProject("plugin", - pomXml(""" - - - org.jenkins-ci.plugins - plugin - 4.40 - - my-plugin - 0.1 - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - """), - srcMainResources( - text(null, """ - -
- my-plugin -
- """) { - spec -> spec.path("index.jelly") - } - ) - ) - ) -}