Search in sources :

Example 6 with JavaProject

use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.

the class GradleUtilTest method extractProperties_whenBothSystemAndGradlePropertyProvided_thenSystemPropertyShouldHaveMorePrecedence.

@Test
public void extractProperties_whenBothSystemAndGradlePropertyProvided_thenSystemPropertyShouldHaveMorePrecedence() {
    // Given
    final Map<String, Object> gradleProperties = new HashMap<>();
    gradleProperties.put("foo.property", "gradlevalue");
    System.setProperty("foo.property", "systemvalue");
    when(project.getProperties()).thenAnswer(i -> gradleProperties);
    // When
    final JavaProject result = convertGradleProject(project);
    // Then
    assertThat(result.getProperties()).hasFieldOrPropertyWithValue("foo.property", null).hasEntrySatisfying("foo.property", e -> assertThat(e).isEqualTo("systemvalue"));
    System.clearProperty("foo.property");
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 7 with JavaProject

use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.

the class GradleUtilTest method findClassesOutputDirectory_withNotFoundSourceSet_shouldReturnDefault.

@Test
public void findClassesOutputDirectory_withNotFoundSourceSet_shouldReturnDefault() {
    // Given
    when(javaPlugin.getSourceSets().getByName("main")).thenThrow(new UnknownDomainObjectException("Not found"));
    // When
    final JavaProject result = convertGradleProject(project);
    // Then
    assertThat(result.getOutputDirectory()).isEqualTo(folder.getRoot().toPath().resolve("build").resolve("classes").resolve("java").resolve("main").toFile());
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) UnknownDomainObjectException(org.gradle.api.UnknownDomainObjectException) Test(org.junit.Test)

Example 8 with JavaProject

use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.

the class GradleUtilTest method findArtifact_withExistentFile_shouldReturnValidArtifact.

@Test
public void findArtifact_withExistentFile_shouldReturnValidArtifact() throws IOException {
    // Given
    final Configuration c = mock(Configuration.class, RETURNS_DEEP_STUBS);
    when(c.getAllDependencies().stream()).thenAnswer(i -> Stream.empty());
    when(c.getOutgoing().getArtifacts().getFiles().getFiles()).thenReturn(Stream.of(folder.newFile("final-artifact.jar")).collect(Collectors.toSet()));
    projectConfigurations.add(c);
    // When
    final JavaProject result = convertGradleProject(project);
    // Then
    assertThat(result.getArtifact()).isNotNull().hasName("final-artifact.jar");
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) Configuration(org.gradle.api.artifacts.Configuration) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) Test(org.junit.Test)

Example 9 with JavaProject

use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.

the class GradleUtilTest method findArtifact_withMultipleExistentFiles_shouldReturnArtifactWithLargestSize.

@Test
public void findArtifact_withMultipleExistentFiles_shouldReturnArtifactWithLargestSize() throws IOException {
    // Given
    final Configuration c = mock(Configuration.class, RETURNS_DEEP_STUBS);
    File jar1 = folder.newFile("final-artifact.jar");
    Files.write(jar1.toPath(), "FatJar".getBytes());
    File jar2 = folder.newFile("final-artifact-plain.jar");
    when(c.getAllDependencies().stream()).thenAnswer(i -> Stream.empty());
    when(c.getOutgoing().getArtifacts().getFiles().getFiles()).thenReturn(Stream.of(jar2, jar1).collect(Collectors.toSet()));
    projectConfigurations.add(c);
    // When
    final JavaProject result = convertGradleProject(project);
    // Then
    assertThat(result.getArtifact()).isNotNull().hasName("final-artifact.jar");
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) Configuration(org.gradle.api.artifacts.Configuration) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) File(java.io.File) Test(org.junit.Test)

Example 10 with JavaProject

use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.

the class GradleUtilTest method extractDependencies_withMultipleAndDuplicateDependencies_shouldReturnValidDependencies.

@Test
public void extractDependencies_withMultipleAndDuplicateDependencies_shouldReturnValidDependencies() {
    // Given
    final Function<String[], Configuration> mockConfiguration = configurationDependencyMock();
    projectConfigurations.add(mockConfiguration.apply(new String[] { "api", "com.example", "artifact", null }));
    projectConfigurations.add(mockConfiguration.apply(new String[] { "implementation", "com.example.sub", "duplicate-artifact", "1.33.7" }));
    projectConfigurations.add(mockConfiguration.apply(new String[] { "implementation", "com.example.sub", "duplicate-artifact", "1.33.7" }));
    projectConfigurations.add(mockConfiguration.apply(new String[] { "implementation", "com.example", "other.artifact", "1.0.0" }));
    projectConfigurations.add(mockConfiguration.apply(new String[] { "implementation", "com.example", "other.artifact", "1.1.0" }));
    projectConfigurations.add(mockConfiguration.apply(new String[] { "testImplementation", "com.example", "other.artifact", "1.1.0" }));
    // When
    final JavaProject result = convertGradleProject(project);
    // Then
    assertThat(result.getDependencies()).hasSize(5).satisfies(l -> assertThat(l).first().extracting("file").hasFieldOrPropertyWithValue("name", "artifact.jar")).extracting("groupId", "artifactId", "version", "scope").containsExactlyInAnyOrder(tuple("com.example", "artifact", null, "compile"), tuple("com.example.sub", "duplicate-artifact", "1.33.7", "compile"), tuple("com.example", "other.artifact", "1.0.0", "compile"), tuple("com.example", "other.artifact", "1.1.0", "compile"), tuple("com.example", "other.artifact", "1.1.0", "test"));
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) Configuration(org.gradle.api.artifacts.Configuration) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) Test(org.junit.Test)

Aggregations

JavaProject (org.eclipse.jkube.kit.common.JavaProject)52 Test (org.junit.Test)43 File (java.io.File)16 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)9 DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)9 Expectations (mockit.Expectations)9 HashMap (java.util.HashMap)7 Properties (java.util.Properties)6 Configuration (org.gradle.api.artifacts.Configuration)6 DeprecatableConfiguration (org.gradle.internal.deprecation.DeprecatableConfiguration)6 IOException (java.io.IOException)5 Collections (java.util.Collections)4 List (java.util.List)4 MavenProject (org.apache.maven.project.MavenProject)4 Plugin (org.eclipse.jkube.kit.common.Plugin)4 JKubeEnricherContext (org.eclipse.jkube.kit.enricher.api.JKubeEnricherContext)4 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang3.StringUtils)3