-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2125 from rohanKanojia/pr/issue2124
- Loading branch information
Showing
4 changed files
with
278 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...t/java/io/fabric8/kubernetes/client/dsl/internal/RawCustomResourceOperationsImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.kubernetes.client.dsl.internal; | ||
|
||
import io.fabric8.kubernetes.client.Config; | ||
import io.fabric8.kubernetes.client.ConfigBuilder; | ||
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext; | ||
import io.fabric8.kubernetes.client.utils.Utils; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.OkHttpClient; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.net.MalformedURLException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class RawCustomResourceOperationsImplTest { | ||
private OkHttpClient mockClient; | ||
private Config config; | ||
private CustomResourceDefinitionContext customResourceDefinitionContext; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
this.mockClient = Mockito.mock(OkHttpClient.class, Mockito.RETURNS_DEEP_STUBS); | ||
this.config = new ConfigBuilder().withMasterUrl("https://localhost:8443/").build(); | ||
this.customResourceDefinitionContext = new CustomResourceDefinitionContext.Builder() | ||
.withGroup("test.fabric8.io") | ||
.withName("hellos.test.fabric8.io") | ||
.withPlural("hellos") | ||
.withScope("Namespaced") | ||
.withVersion("v1alpha1") | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void testFetchWatchUrlWithNamespace() throws MalformedURLException { | ||
// Given | ||
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext); | ||
|
||
// When | ||
HttpUrl url = rawCustomResourceOperations.fetchWatchUrl("test", null, null, null); | ||
|
||
// Then | ||
assertEquals("https://localhost:8443/apis/test.fabric8.io/v1alpha1/namespaces/test/hellos?watch=true", url.url().toString()); | ||
} | ||
|
||
@Test | ||
public void testFetchWatchUrlWithNamespaceAndName() throws MalformedURLException { | ||
// Given | ||
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext); | ||
|
||
// When | ||
HttpUrl url = rawCustomResourceOperations.fetchWatchUrl("test", "example-resource", null, null); | ||
|
||
// Then | ||
assertEquals("https://localhost:8443/apis/test.fabric8.io/v1alpha1/namespaces/test/hellos?fieldSelector=metadata.name%3Dexample-resource&watch=true", url.url().toString()); | ||
} | ||
|
||
@Test | ||
public void testFetchWatchUrlWithNamespaceAndNameAndResourceVersion() throws MalformedURLException { | ||
// Given | ||
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext); | ||
|
||
// When | ||
HttpUrl url = rawCustomResourceOperations.fetchWatchUrl("test", "example-resource", null, "100069"); | ||
|
||
// Then | ||
assertEquals("https://localhost:8443/apis/test.fabric8.io/v1alpha1/namespaces/test/hellos?fieldSelector=metadata.name%3Dexample-resource&resourceVersion=100069&watch=true", url.url().toString()); | ||
} | ||
|
||
@Test | ||
public void testFetchWatchUrlWithoutAnything() throws MalformedURLException { | ||
// Given | ||
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext); | ||
|
||
// When | ||
HttpUrl url = rawCustomResourceOperations.fetchWatchUrl(null, null, null, null); | ||
|
||
// Then | ||
assertEquals("https://localhost:8443/apis/test.fabric8.io/v1alpha1/hellos?watch=true", url.url().toString()); | ||
} | ||
|
||
@Test | ||
public void testFetchWatchUrlWithLabels() throws MalformedURLException { | ||
// Given | ||
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext); | ||
|
||
// When | ||
Map<String, String> labels = new HashMap<>(); | ||
labels.put("foo", "bar"); | ||
labels.put("foo1", "bar1"); | ||
|
||
HttpUrl url = rawCustomResourceOperations.fetchWatchUrl(null, null, labels, null); | ||
|
||
// Then | ||
assertEquals("https://localhost:8443/apis/test.fabric8.io/v1alpha1/hellos?labelSelector=" + Utils.toUrlEncoded("foo=bar") + "," + Utils.toUrlEncoded("foo1=bar1") + "&watch=true", url.url().toString()); | ||
} | ||
|
||
@Test | ||
public void testFetchWatchUrlWithLabelsWithNamespace() throws MalformedURLException { | ||
// Given | ||
RawCustomResourceOperationsImpl rawCustomResourceOperations = new RawCustomResourceOperationsImpl(mockClient, config, customResourceDefinitionContext); | ||
|
||
// When | ||
Map<String, String> labels = new HashMap<>(); | ||
labels.put("foo", "bar"); | ||
labels.put("foo1", "bar1"); | ||
|
||
HttpUrl url = rawCustomResourceOperations.fetchWatchUrl("test", null, labels, null); | ||
|
||
// Then | ||
assertEquals("https://localhost:8443/apis/test.fabric8.io/v1alpha1/namespaces/test/hellos?labelSelector=" + Utils.toUrlEncoded("foo=bar") + "," + Utils.toUrlEncoded("foo1=bar1") + "&watch=true", url.url().toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters