-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test : Update SpringBoot integration tests for layered jar
+ Remove spring boot dependencies from dependencyManagement in parent pom. Spring boot projects would not use spring-boot.version property explicitly in poms + Add ZeroConfigFatJarK8sITCase to verify kubernetes maven plugin workflow in case of spring boot projects that don't generate a layered jar Signed-off-by: Rohan Kumar <[email protected]>
- Loading branch information
1 parent
1a0cb99
commit 24add42
Showing
18 changed files
with
400 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...java/org/eclipse/jkube/integrationtests/springboot/zeroconfigfatjar/ZeroConfigFatJar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.integrationtests.springboot.zeroconfigfatjar; | ||
|
||
import io.fabric8.junit.jupiter.api.KubernetesTest; | ||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import org.eclipse.jkube.integrationtests.JKubeCase; | ||
import org.eclipse.jkube.integrationtests.maven.MavenCase; | ||
|
||
import static org.eclipse.jkube.integrationtests.assertions.PodAssertion.awaitPod; | ||
import static org.eclipse.jkube.integrationtests.assertions.ServiceAssertion.awaitService; | ||
import static org.hamcrest.Matchers.hasSize; | ||
|
||
@KubernetesTest(createEphemeralNamespace = false) | ||
public class ZeroConfigFatJar implements JKubeCase, MavenCase { | ||
private static final String PROJECT_ZERO_CONFIG_FATJAR = "projects-to-be-tested/maven/spring/zero-config-fatjar"; | ||
|
||
private static KubernetesClient kubernetesClient; | ||
|
||
@Override | ||
public KubernetesClient getKubernetesClient() { | ||
return kubernetesClient; | ||
} | ||
|
||
@Override | ||
public String getProject() { | ||
return PROJECT_ZERO_CONFIG_FATJAR; | ||
} | ||
|
||
@Override | ||
public String getApplication() { | ||
return "spring-boot-zero-config-fatjar"; | ||
} | ||
|
||
final Pod assertThatShouldApplyResources() throws Exception { | ||
final Pod pod = awaitPod(this) | ||
.logContains("Started ZeroConfigFatJarApplication in", 40) | ||
.getKubernetesResource(); | ||
awaitService(this, pod.getMetadata().getNamespace()) | ||
.assertPorts(hasSize(1)) | ||
.assertPort("http", 8080, false); | ||
return pod; | ||
} | ||
} |
139 changes: 139 additions & 0 deletions
139
...eclipse/jkube/integrationtests/springboot/zeroconfigfatjar/ZeroConfigFatJarK8sITCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.integrationtests.springboot.zeroconfigfatjar; | ||
|
||
import io.fabric8.kubernetes.api.model.Pod; | ||
import org.apache.maven.shared.invoker.InvocationResult; | ||
import org.eclipse.jkube.integrationtests.maven.MavenInvocationResult; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.junit.jupiter.api.parallel.ResourceLock; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import static org.eclipse.jkube.integrationtests.Locks.CLUSTER_RESOURCE_INTENSIVE; | ||
import static org.eclipse.jkube.integrationtests.Tags.KUBERNETES; | ||
import static org.eclipse.jkube.integrationtests.assertions.DeploymentAssertion.awaitDeployment; | ||
import static org.eclipse.jkube.integrationtests.assertions.DockerAssertion.assertImageWasRecentlyBuilt; | ||
import static org.eclipse.jkube.integrationtests.assertions.InvocationResultAssertion.assertInvocation; | ||
import static org.eclipse.jkube.integrationtests.assertions.JKubeAssertions.assertJKube; | ||
import static org.eclipse.jkube.integrationtests.assertions.KubernetesListAssertion.assertListResource; | ||
import static org.eclipse.jkube.integrationtests.assertions.YamlAssertion.yaml; | ||
import static org.eclipse.jkube.integrationtests.docker.DockerUtils.getImageHistory; | ||
import static org.eclipse.jkube.integrationtests.docker.DockerUtils.listImageFiles; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.allOf; | ||
import static org.hamcrest.Matchers.anEmptyMap; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.hasItems; | ||
import static org.hamcrest.Matchers.hasProperty; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.stringContainsInOrder; | ||
import static org.junit.jupiter.api.parallel.ResourceAccessMode.READ_WRITE; | ||
|
||
@Tag(KUBERNETES) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
class ZeroConfigFatJarK8sITCase extends ZeroConfigFatJar { | ||
@Test | ||
@Order(1) | ||
@DisplayName("k8s:build, should create fat jar image") | ||
void k8sBuild() throws Exception { | ||
// When | ||
final InvocationResult invocationResult = maven("k8s:build"); | ||
// Then | ||
assertInvocation(invocationResult); | ||
assertImageWasRecentlyBuilt("integration-tests", "spring-boot-zero-config-fatjar"); | ||
final List<String> imageFiles = listImageFiles("integration-tests/spring-boot-zero-config-fatjar", "/deployments"); | ||
assertThat(imageFiles, hasItem("/deployments/data")); | ||
assertThat(imageFiles, hasItem("/deployments/spring-boot-zero-config-fatjar-0.0.0-SNAPSHOT.jar")); | ||
final List<String> imageHistory = getImageHistory(String.format("%s/%s", "integration-tests", getApplication())); | ||
long dirCopyLayers = imageHistory.stream() | ||
.filter(l -> l.contains("COPY dir:")) | ||
.count(); | ||
assertThat(dirCopyLayers, equalTo(1L)); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
@DisplayName("k8s:resource, should create manifests") | ||
void k8sResource() throws Exception { | ||
// When | ||
final InvocationResult invocationResult = maven("k8s:resource"); | ||
// Then | ||
assertInvocation(invocationResult); | ||
final File metaInfDirectory = new File( | ||
String.format("../%s/target/classes/META-INF", getProject())); | ||
assertThat(metaInfDirectory.exists(), equalTo(true)); | ||
assertListResource(new File(metaInfDirectory, "jkube/kubernetes.yml")); | ||
assertThat(new File(metaInfDirectory, "jkube/kubernetes/spring-boot-zero-config-fatjar-deployment.yml"), yaml(not(anEmptyMap()))); | ||
assertThat(new File(metaInfDirectory, "jkube/kubernetes/spring-boot-zero-config-fatjar-service.yml"), yaml(not(anEmptyMap()))); | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
@ResourceLock(value = CLUSTER_RESOURCE_INTENSIVE, mode = READ_WRITE) | ||
@DisplayName("k8s:apply, should deploy pod and service") | ||
@SuppressWarnings("unchecked") | ||
void k8sApply() throws Exception { | ||
// When | ||
final InvocationResult invocationResult = maven("k8s:apply"); | ||
// Then | ||
assertInvocation(invocationResult); | ||
final Pod pod = assertThatShouldApplyResources(); | ||
awaitDeployment(this, pod.getMetadata().getNamespace()) | ||
.assertReplicas(equalTo(1)) | ||
.assertContainers(hasSize(1)) | ||
.assertContainers(hasItems(allOf( | ||
hasProperty("image", equalTo("integration-tests/spring-boot-zero-config-fatjar:latest")), | ||
hasProperty("name", equalTo("spring-boot")), | ||
hasProperty("ports", hasSize(3)), | ||
hasProperty("ports", hasItems(allOf( | ||
hasProperty("name", equalTo("http")), | ||
hasProperty("containerPort", equalTo(8080)) | ||
))) | ||
))); | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
@DisplayName("k8s:log, should retrieve log") | ||
void k8sLog() throws Exception { | ||
// When | ||
final MavenInvocationResult invocationResult = maven("k8s:log", properties("jkube.log.follow", "false")); | ||
// Then | ||
assertInvocation(invocationResult); | ||
assertThat(invocationResult.getStdOut(), | ||
stringContainsInOrder("Tomcat started on port(s): 8080", "Started ZeroConfigFatJarApplication in", "seconds")); | ||
} | ||
|
||
@Test | ||
@Order(5) | ||
@DisplayName("k8s:undeploy, should delete all applied resources") | ||
void k8sUndeploy() throws Exception { | ||
// When | ||
final InvocationResult invocationResult = maven("k8s:undeploy"); | ||
// Then | ||
assertInvocation(invocationResult); | ||
assertJKube(this) | ||
.assertThatShouldDeleteAllAppliedResources() | ||
.assertDeploymentDeleted(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.