Search in sources :

Example 11 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class EnricherManagerTest method createDefaultResources.

@Test
public void createDefaultResources() {
    new Expectations() {

        {
            context.getConfig();
            result = new ProcessorConfig(Arrays.asList("fmp-controller"), null, null);
            context.getImages();
            result = new ImageConfiguration.Builder().alias("img1").name("img1").build();
        }
    };
    EnricherManager manager = new EnricherManager(null, context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    manager.createDefaultResources(builder);
    assertTrue(builder.build().getItems().size() > 0);
}
Also used : Expectations(mockit.Expectations) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 12 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromConfig.

/**
 * The main class is determined via config in a non-fat-jar deployment
 * @throws MojoExecutionException
 */
@Test
public void testMainClassDeterminationFromConfig() throws MojoExecutionException {
    new MockBuild();
    new MockProcessorConfig("the.main.ClassName");
    new MockMavenProject();
    final GeneratorContext generatorContext = new GeneratorContext.Builder().project(new MavenProject()).config(new ProcessorConfig()).strategy(OpenShiftBuildStrategy.docker).logger(log).build();
    JavaExecGenerator generator = new JavaExecGenerator(generatorContext);
    final List<ImageConfiguration> images = new ArrayList<ImageConfiguration>();
    List<ImageConfiguration> customized = generator.customize(images, false);
    assertEquals("1 images returned", (long) 1, (long) customized.size());
    ImageConfiguration imageConfig = customized.get(0);
    assertEquals("Image name", "TheImageName", imageConfig.getName());
    assertEquals("Main Class set as environment variable", "the.main.ClassName", imageConfig.getBuildConfiguration().getEnv().get(JavaExecGenerator.JAVA_MAIN_CLASS_ENV_VAR));
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 13 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromDetectionOnNonFatJar.

/**
 * The main class is determined via main class detection in a non-fat-jar deployment
 * @throws MojoExecutionException
 */
@Test
public void testMainClassDeterminationFromDetectionOnNonFatJar() throws MojoExecutionException {
    new MockBuild();
    new MockProcessorConfig(null);
    new MockMavenProject();
    new MockFatJarDetector(false);
    new MockClassUtils();
    final GeneratorContext generatorContext = new GeneratorContext.Builder().project(new MavenProject()).config(new ProcessorConfig()).strategy(OpenShiftBuildStrategy.docker).logger(log).build();
    JavaExecGenerator generator = new JavaExecGenerator(generatorContext);
    final List<ImageConfiguration> images = new ArrayList<ImageConfiguration>();
    List<ImageConfiguration> customized = generator.customize(images, false);
    assertEquals("1 images returned", (long) 1, (long) customized.size());
    ImageConfiguration imageConfig = customized.get(0);
    assertEquals("Image name", "TheImageName", imageConfig.getName());
    assertEquals("Main Class set as environment variable", "the.detected.MainClass", imageConfig.getBuildConfiguration().getEnv().get(JavaExecGenerator.JAVA_MAIN_CLASS_ENV_VAR));
}
Also used : ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) MavenProject(org.apache.maven.project.MavenProject) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Test(org.junit.Test)

Example 14 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromFatJar.

/**
 * The main class is determined as the Main-Class of a fat jar
 * @throws MojoExecutionException
 */
@Test
public void testMainClassDeterminationFromFatJar() throws MojoExecutionException {
    new MockBuild();
    new MockProcessorConfig(null);
    new MockMavenProject();
    new MockFatJarDetector(true);
    new MockJavaExecGenerator();
    final GeneratorContext generatorContext = new GeneratorContext.Builder().project(new MavenProject()).config(new ProcessorConfig()).strategy(OpenShiftBuildStrategy.docker).logger(log).build();
    JavaExecGenerator generator = new JavaExecGenerator(generatorContext);
    final List<ImageConfiguration> images = new ArrayList<ImageConfiguration>();
    List<ImageConfiguration> customized = generator.customize(images, false);
    assertEquals("1 images returned", (long) 1, (long) customized.size());
    ImageConfiguration imageConfig = customized.get(0);
    assertEquals("Image name", "TheImageName", imageConfig.getName());
    assertNull("Main Class is NOT set as environment variable#", imageConfig.getBuildConfiguration().getEnv().get(JavaExecGenerator.JAVA_MAIN_CLASS_ENV_VAR));
}
Also used : ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) MavenProject(org.apache.maven.project.MavenProject) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Test(org.junit.Test)

Example 15 with ProcessorConfig

use of io.fabric8.maven.core.config.ProcessorConfig in project fabric8-maven-plugin by fabric8io.

the class AutoTLSEnricherTest method testSecretName.

@Test
public void testSecretName() throws Exception {
    final SecretNameTestConfig[] data = new SecretNameTestConfig[] { new SecretNameTestConfig(PlatformMode.kubernetes, null, null), new SecretNameTestConfig(PlatformMode.openshift, null, "projectA-tls"), new SecretNameTestConfig(PlatformMode.openshift, "custom-secret", "custom-secret") };
    for (final SecretNameTestConfig tc : data) {
        final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(AutoTLSEnricher.ENRICHER_NAME, new TreeMap(Collections.singletonMap(AutoTLSEnricher.Config.tlsSecretName.name(), tc.tlsSecretNameConfig))));
        final Properties projectProps = new Properties();
        projectProps.put(PlatformMode.FABRIC8_EFFECTIVE_PLATFORM_MODE, tc.mode.name());
        // Setup mock behaviour
        new Expectations() {

            {
                project.getProperties();
                result = projectProps;
                project.getArtifactId();
                result = "projectA";
                minTimes = 0;
                context.getProject();
                result = project;
                context.getConfig();
                result = config;
            }
        };
        AutoTLSEnricher enricher = new AutoTLSEnricher(context);
        Map<String, String> annotations = enricher.getAnnotations(Kind.SERVICE);
        if (tc.mode == PlatformMode.kubernetes) {
            assertNull(annotations);
            continue;
        }
        assertEquals(1, annotations.size());
        assertEquals(tc.tlsSecretName, annotations.get(AutoTLSEnricher.AUTOTLS_ANNOTATION_KEY));
    }
}
Also used : Expectations(mockit.Expectations) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Aggregations

ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)27 Test (org.junit.Test)21 Expectations (mockit.Expectations)17 TreeMap (java.util.TreeMap)10 Probe (io.fabric8.kubernetes.api.model.Probe)7 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)4 ArrayList (java.util.ArrayList)3 MavenProject (org.apache.maven.project.MavenProject)3 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)2 Logger (io.fabric8.maven.docker.util.Logger)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 PodTemplate (io.fabric8.kubernetes.api.model.PodTemplate)1 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)1 PlatformMode (io.fabric8.maven.core.config.PlatformMode)1 Profile (io.fabric8.maven.core.config.Profile)1 Generator (io.fabric8.maven.generator.api.Generator)1 Watcher (io.fabric8.maven.watcher.api.Watcher)1