Search in sources :

Example 1 with NamedTagEventListBuilder

use of io.fabric8.openshift.api.model.NamedTagEventListBuilder in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildServiceTest method createMockServer.

protected WebServerEventCollector<OpenShiftMockServer> createMockServer(BuildService.BuildServiceConfig config, boolean success, long buildDelay, boolean buildConfigExists, boolean imageStreamExists) {
    OpenShiftMockServer mockServer = new OpenShiftMockServer(false);
    WebServerEventCollector<OpenShiftMockServer> collector = new WebServerEventCollector<>(mockServer);
    BuildConfig bc = new BuildConfigBuilder().withNewMetadata().withName(projectName + config.getS2iBuildNameSuffix()).endMetadata().withNewSpec().endSpec().build();
    ImageStream imageStream = new ImageStreamBuilder().withNewMetadata().withName(projectName).endMetadata().withStatus(new ImageStreamStatusBuilder().addNewTagLike(new NamedTagEventListBuilder().addNewItem().withImage("abcdef0123456789").endItem().build()).endTag().build()).build();
    KubernetesList builds = new KubernetesListBuilder().withItems(new BuildBuilder().withNewMetadata().withName(projectName).endMetadata().build()).withNewMetadata().withResourceVersion("1").endMetadata().build();
    String buildStatus = success ? "Complete" : "Fail";
    Build build = new BuildBuilder().withNewMetadata().withResourceVersion("2").endMetadata().withNewStatus().withPhase(buildStatus).endStatus().build();
    if (!buildConfigExists) {
        mockServer.expect().get().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("build-config-check").andReturn(404, "")).once();
        mockServer.expect().post().withPath("/oapi/v1/namespaces/test/buildconfigs").andReply(collector.record("new-build-config").andReturn(201, bc)).once();
    } else {
        mockServer.expect().patch().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("patch-build-config").andReturn(200, bc)).once();
    }
    mockServer.expect().get().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("build-config-check").andReturn(200, bc)).always();
    if (!imageStreamExists) {
        mockServer.expect().get().withPath("/oapi/v1/namespaces/test/imagestreams/" + projectName).andReturn(404, "").once();
    }
    mockServer.expect().get().withPath("/oapi/v1/namespaces/test/imagestreams/" + projectName).andReturn(200, imageStream).always();
    mockServer.expect().post().withPath("/oapi/v1/namespaces/test/imagestreams").andReturn(201, imageStream).once();
    mockServer.expect().post().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix() + "/instantiatebinary?commit=").andReply(collector.record("pushed").andReturn(201, imageStream)).once();
    mockServer.expect().get().withPath("/oapi/v1/namespaces/test/builds").andReply(collector.record("check-build").andReturn(200, builds)).always();
    mockServer.expect().get().withPath("/oapi/v1/namespaces/test/builds?labelSelector=openshift.io/build-config.name%3D" + projectName + config.getS2iBuildNameSuffix()).andReturn(200, builds).always();
    mockServer.expect().withPath("/oapi/v1/namespaces/test/builds/" + projectName).andReturn(200, build).always();
    mockServer.expect().withPath("/oapi/v1/namespaces/test/builds?fieldSelector=metadata.name%3D" + projectName + "&watch=true").andUpgradeToWebSocket().open().waitFor(buildDelay).andEmit(new WatchEvent(build, "MODIFIED")).done().always();
    return collector;
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageStreamStatusBuilder(io.fabric8.openshift.api.model.ImageStreamStatusBuilder) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) WebServerEventCollector(io.fabric8.maven.core.util.WebServerEventCollector) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) BuildBuilder(io.fabric8.openshift.api.model.BuildBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) Build(io.fabric8.openshift.api.model.Build) NamedTagEventListBuilder(io.fabric8.openshift.api.model.NamedTagEventListBuilder) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) WatchEvent(io.fabric8.kubernetes.api.model.WatchEvent)

Aggregations

KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 WatchEvent (io.fabric8.kubernetes.api.model.WatchEvent)1 WebServerEventCollector (io.fabric8.maven.core.util.WebServerEventCollector)1 Build (io.fabric8.openshift.api.model.Build)1 BuildBuilder (io.fabric8.openshift.api.model.BuildBuilder)1 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)1 BuildConfigBuilder (io.fabric8.openshift.api.model.BuildConfigBuilder)1 ImageStream (io.fabric8.openshift.api.model.ImageStream)1 ImageStreamBuilder (io.fabric8.openshift.api.model.ImageStreamBuilder)1 ImageStreamStatusBuilder (io.fabric8.openshift.api.model.ImageStreamStatusBuilder)1 NamedTagEventListBuilder (io.fabric8.openshift.api.model.NamedTagEventListBuilder)1 OpenShiftMockServer (io.fabric8.openshift.client.server.mock.OpenShiftMockServer)1