Search in sources :

Example 46 with Context

use of io.fabric8.kubernetes.api.model.Context in project fabric8-maven-plugin by fabric8io.

the class VertxHealthCheckEnricherTest method testDisabledUsingInvalidPort.

@Test
public void testDisabledUsingInvalidPort() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
    final Properties props = new Properties();
    props.put("vertx.health.port", " none ");
    props.put("vertx.health.path", " /ping ");
    new Expectations() {

        {
            context.getProject().getProperties();
            result = props;
        }
    };
    Probe probe = enricher.getLivenessProbe();
    assertNull(probe);
    probe = enricher.getReadinessProbe();
    assertNull(probe);
}
Also used : Expectations(mockit.Expectations) Properties(java.util.Properties) Probe(io.fabric8.kubernetes.api.model.Probe) Test(org.junit.Test)

Example 47 with Context

use of io.fabric8.kubernetes.api.model.Context in project fabric8-maven-plugin by fabric8io.

the class VertxHealthCheckEnricherTest method testDisabledUsingEmptyPath.

@Test
public void testDisabledUsingEmptyPath() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
    final Properties props = new Properties();
    props.put("vertx.health.path", "");
    new Expectations() {

        {
            context.getProject().getProperties();
            result = props;
        }
    };
    Probe probe = enricher.getLivenessProbe();
    assertNull(probe);
    probe = enricher.getReadinessProbe();
    assertNull(probe);
}
Also used : Expectations(mockit.Expectations) Properties(java.util.Properties) Probe(io.fabric8.kubernetes.api.model.Probe) Test(org.junit.Test)

Example 48 with Context

use of io.fabric8.kubernetes.api.model.Context in project fabric8-maven-plugin by fabric8io.

the class VertxHealthCheckEnricherTest method testLivenessDisabledAndReadinessEnabled.

@Test
public void testLivenessDisabledAndReadinessEnabled() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
    final Properties props = new Properties();
    props.put("vertx.health.readiness.path", "/ping");
    props.put("vertx.health.path", "");
    new Expectations() {

        {
            context.getProject().getProperties();
            result = props;
        }
    };
    Probe probe = enricher.getLivenessProbe();
    assertNull(probe);
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getHttpGet().getPath(), "/ping");
}
Also used : Expectations(mockit.Expectations) Properties(java.util.Properties) Probe(io.fabric8.kubernetes.api.model.Probe) Test(org.junit.Test)

Example 49 with Context

use of io.fabric8.kubernetes.api.model.Context in project fabric8-maven-plugin by fabric8io.

the class DefaultControllerEnricherTest method enrichAndAssert.

protected void enrichAndAssert(int sizeOfObjects, int replicaCount) throws com.fasterxml.jackson.core.JsonProcessingException {
    // Setup a sample docker build configuration
    final BuildImageConfiguration buildConfig = new BuildImageConfiguration.Builder().ports(Arrays.asList("8080")).build();
    final TreeMap controllerConfig = new TreeMap();
    controllerConfig.put("replicaCount", String.valueOf(replicaCount));
    setupExpectations(buildConfig, controllerConfig);
    // Enrich
    DefaultControllerEnricher controllerEnricher = new DefaultControllerEnricher(context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    controllerEnricher.addMissingResources(builder);
    // Validate that the generated resource contains
    KubernetesList list = builder.build();
    assertEquals(sizeOfObjects, list.getItems().size());
    String json = KubernetesResourceUtil.toJson(list.getItems().get(0));
    assertThat(json, JsonPathMatchers.isJson());
    assertThat(json, JsonPathMatchers.hasJsonPath("$.spec.replicas", Matchers.equalTo(replicaCount)));
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) TreeMap(java.util.TreeMap) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 50 with Context

use of io.fabric8.kubernetes.api.model.Context in project fabric8-maven-plugin by fabric8io.

the class MavenProjectEnricherTest method testOldStyleGeneratedResources.

@Test
public void testOldStyleGeneratedResources() {
    final Properties properties = new Properties();
    properties.setProperty("fabric8.enricher.fmp-project.useProjectLabel", "true");
    new Expectations() {

        {
            mavenProject.getProperties();
            result = properties;
        }
    };
    ProjectEnricher projectEnricher = new ProjectEnricher(context);
    KubernetesListBuilder builder = createListWithDeploymentConfig();
    projectEnricher.adapt(builder);
    KubernetesList list = builder.build();
    Map<String, String> labels = list.getItems().get(0).getMetadata().getLabels();
    assertNotNull(labels);
    assertEquals("groupId", labels.get("group"));
    assertEquals("artifactId", labels.get("project"));
    assertEquals("version", labels.get("version"));
    assertNull(labels.get("app"));
    Map<String, String> selectors = projectEnricher.getSelector(Kind.DEPLOYMENT_CONFIG);
    assertEquals("groupId", selectors.get("group"));
    assertEquals("artifactId", selectors.get("project"));
    assertNull(selectors.get("version"));
    assertNull(selectors.get("app"));
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)135 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)58 Async (io.vertx.ext.unit.Async)52 Expectations (mockit.Expectations)34 Probe (io.fabric8.kubernetes.api.model.Probe)33 Reconciliation (io.strimzi.controller.cluster.Reconciliation)24 File (java.io.File)23 Git (org.eclipse.jgit.api.Git)23 GitContext (io.fabric8.api.GitContext)21 IOException (java.io.IOException)21 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)20 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 HashMap (java.util.HashMap)17 LockHandle (io.fabric8.api.LockHandle)15 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)15 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)15 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)15 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 Resource (io.fabric8.kubernetes.client.dsl.Resource)14