Search in sources :

Example 1 with JavaProject

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

the class AssemblyManagerTest method testEnsureThatArtifactFileIsSetWithEverythingNull.

@Test
public void testEnsureThatArtifactFileIsSetWithEverythingNull() throws IOException {
    // Given
    JavaProject project = JavaProject.builder().build();
    // When
    final File artifactFile = assemblyManager.ensureThatArtifactFileIsSet(project);
    // Then
    assertThat(artifactFile).isNull();
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) File(java.io.File) Test(org.junit.Test)

Example 2 with JavaProject

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

the class WildflyJARHealthCheckEnricher method isAvailable.

private boolean isAvailable() {
    if (isProbeEnforced()) {
        return true;
    }
    JavaProject project = ((JKubeEnricherContext) getContext()).getProject();
    Plugin plugin = JKubeProjectUtil.getPlugin(project, BOOTABLE_JAR_GROUP_ID, BOOTABLE_JAR_ARTIFACT_ID);
    if (plugin == null) {
        return false;
    }
    Map<String, Object> config = plugin.getConfiguration();
    return config.containsKey("cloud");
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) JKubeEnricherContext(org.eclipse.jkube.kit.enricher.api.JKubeEnricherContext) Plugin(org.eclipse.jkube.kit.common.Plugin)

Example 3 with JavaProject

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

the class GradleUtilTest method findArtifact_withMultipleArchiveFiles_shouldReturnJavaArchiveOnly.

@Test
public void findArtifact_withMultipleArchiveFiles_shouldReturnJavaArchiveOnly() throws IOException {
    // Given
    final Configuration c = mock(Configuration.class, RETURNS_DEEP_STUBS);
    File jar1 = folder.newFile("final-artifact.jar");
    File jar2 = folder.newFile("final-artifact.tar");
    File jar3 = folder.newFile("final-artifact.zip");
    when(c.getAllDependencies().stream()).thenAnswer(i -> Stream.empty());
    when(c.getOutgoing().getArtifacts().getFiles().getFiles()).thenReturn(Stream.of(jar1, jar2, jar3).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 4 with JavaProject

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

the class GradleUtilTest method extractProperties_withComplexMap_shouldReturnValidProperties.

@Test
public void extractProperties_withComplexMap_shouldReturnValidProperties() {
    // Given
    final Map<String, Object> complexProperties = new HashMap<>();
    when(project.getProperties()).thenAnswer(i -> complexProperties);
    complexProperties.put("property.1", "test");
    complexProperties.put("property.ignored", null);
    complexProperties.put("object", Collections.singletonMap("field1", 1));
    // When
    final JavaProject result = convertGradleProject(project);
    // Then
    assertThat(result.getProperties()).isNotEmpty().hasFieldOrPropertyWithValue("object.field1", 1).hasFieldOrPropertyWithValue("property.1", null).hasEntrySatisfying("property.1", e -> assertThat(e).isEqualTo("test"));
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with JavaProject

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

the class GradleUtilTest method convertGradleProject_withConcurrentConfigurationModifications_shouldReturnValidProject.

/**
 * Some plugins might modify the ConfigurationContainer collection while we traverse it.
 *
 * This test ensures that no ConcurrentModificationException are thrown because we clone the ConfigurationContainer
 * into an ArrayList.
 */
@Test
public void convertGradleProject_withConcurrentConfigurationModifications_shouldReturnValidProject() {
    // Given
    final Configuration mockConfiguration = mock(Configuration.class, RETURNS_DEEP_STUBS);
    projectConfigurations.add(mockConfiguration);
    final Answer<Set<?>> concurrentModificationAnswer = i -> {
        projectConfigurations.remove(mockConfiguration);
        projectConfigurations.add(mockConfiguration);
        return Collections.emptySet();
    };
    when(mockConfiguration.isCanBeResolved()).thenReturn(true);
    when(mockConfiguration.getOutgoing().getArtifacts().getFiles().getFiles()).thenAnswer(concurrentModificationAnswer);
    when(mockConfiguration.getIncoming().getResolutionResult().getAllDependencies()).thenAnswer(concurrentModificationAnswer);
    when(mockConfiguration.getIncoming().getResolutionResult().getRoot().getDependencies()).thenAnswer(concurrentModificationAnswer);
    // When
    final JavaProject result = convertGradleProject(project);
    // Then
    assertThat(result).isNotNull();
}
Also used : DefaultProvider(org.gradle.api.internal.provider.DefaultProvider) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Function(java.util.function.Function) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Configuration(org.gradle.api.artifacts.Configuration) Answer(org.mockito.stubbing.Answer) GradleUtil.convertGradleProject(org.eclipse.jkube.gradle.plugin.GradleUtil.convertGradleProject) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) Map(java.util.Map) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) UnknownDomainObjectException(org.gradle.api.UnknownDomainObjectException) JavaProject(org.eclipse.jkube.kit.common.JavaProject) Before(org.junit.Before) Files(java.nio.file.Files) Project(org.gradle.api.Project) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Assertions.tuple(org.assertj.core.api.Assertions.tuple) GradleUtil.canBeResolved(org.eclipse.jkube.gradle.plugin.GradleUtil.canBeResolved) DefaultPluginContainer(org.gradle.api.internal.plugins.DefaultPluginContainer) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) File(java.io.File) Objects(java.util.Objects) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) List(java.util.List) Stream(java.util.stream.Stream) Rule(org.junit.Rule) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult) Collections(java.util.Collections) Dependency(org.gradle.api.artifacts.Dependency) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) TemporaryFolder(org.junit.rules.TemporaryFolder) Mockito.mock(org.mockito.Mockito.mock) JavaProject(org.eclipse.jkube.kit.common.JavaProject) HashSet(java.util.HashSet) Set(java.util.Set) 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