use of io.fabric8.openshift.api.model.Project 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));
}
use of io.fabric8.openshift.api.model.Project 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));
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class EnvVarHandlerTest method envVarHandlerWithoutNameTest.
@Test
public void envVarHandlerWithoutNameTest() {
// Environment Variable without name in Config
EnvVar var1 = new EnvVarBuilder().withName(null).withValue("OK").build();
env.clear();
env.put(null, var1.getValue());
EnvVarHandler envVarHandler = new EnvVarHandler(project);
new Expectations() {
{
externalEnvVarHandler.getExportedEnvironmentVariables(project, env);
ret.put(null, "OK");
result = ret;
}
};
List<EnvVar> envVars = envVarHandler.getEnvironmentVariables(env);
assertNotNull(envVars);
assertEquals(1, envVars.size());
assertTrue(!envVars.contains(var1));
assertEquals("KUBERNETES_NAMESPACE", envVars.get(0).getName());
assertTrue(envVars.contains(var4));
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class EnvVarHandlerTest method emptyEnvVarHandlerTest.
@Test
public void emptyEnvVarHandlerTest() {
// Empty Environment Variable in Config
EnvVarHandler envVarHandler = new EnvVarHandler(project);
env.clear();
new Expectations() {
{
externalEnvVarHandler.getExportedEnvironmentVariables(project, env);
ret.putAll(env);
result = ret;
}
};
List<EnvVar> envVars = envVarHandler.getEnvironmentVariables(env);
assertNotNull(envVars);
assertEquals(1, envVars.size());
assertEquals("KUBERNETES_NAMESPACE", envVars.get(0).getName());
assertTrue(envVars.contains(var4));
}
use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class JobHandlerTest method jobHandlerTest.
@Test
public void jobHandlerTest() {
ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
JobHandler jobHandler = new JobHandler(podTemplateHandler);
ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").controllerName("testing").withServiceAccount("test-account").volumes(volumes1).build();
Job job = jobHandler.getJob(config, images);
// Assertion
assertNotNull(job.getSpec());
assertNotNull(job.getMetadata());
assertNotNull(job.getSpec().getTemplate());
assertEquals("testing", job.getMetadata().getName());
assertEquals("test-account", job.getSpec().getTemplate().getSpec().getServiceAccountName());
assertFalse(job.getSpec().getTemplate().getSpec().getVolumes().isEmpty());
assertEquals("test", job.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
assertEquals("/test/path", job.getSpec().getTemplate().getSpec().getVolumes().get(0).getHostPath().getPath());
assertNotNull(job.getSpec().getTemplate().getSpec().getContainers());
}
Aggregations