-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Added an ability to list namespace available to ws creation
Signed-off-by: Sergii Leshchenko <[email protected]>
- Loading branch information
1 parent
ddad8bf
commit e35533f
Showing
3 changed files
with
93 additions
and
0 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
79 changes: 79 additions & 0 deletions
79
...se/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceServiceTest.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,79 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.workspace.infrastructure.kubernetes.api.server; | ||
|
||
import static com.jayway.restassured.RestAssured.given; | ||
import static java.util.Collections.singletonList; | ||
import static org.everrest.assured.JettyHttpServer.ADMIN_USER_NAME; | ||
import static org.everrest.assured.JettyHttpServer.ADMIN_USER_PASSWORD; | ||
import static org.everrest.assured.JettyHttpServer.SECURE_PATH; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.jayway.restassured.response.Response; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.eclipse.che.api.core.rest.CheJsonProvider; | ||
import org.eclipse.che.dto.server.DtoFactory; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.server.impls.KubernetesNamespaceMetaImpl; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.dto.KubernetesNamespaceMetaDto; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespaceFactory; | ||
import org.everrest.assured.EverrestJetty; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.testng.MockitoTestNGListener; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Tests for {@link KubernetesNamespaceService} | ||
* | ||
* @author Sergii Leshchenko | ||
*/ | ||
@Listeners(value = {EverrestJetty.class, MockitoTestNGListener.class}) | ||
public class KubernetesNamespaceServiceTest { | ||
|
||
@SuppressWarnings("unused") // is declared for deploying by everrest-assured | ||
private CheJsonProvider jsonProvider = new CheJsonProvider(Collections.emptySet()); | ||
|
||
@Mock private KubernetesNamespaceFactory namespaceFactory; | ||
|
||
@InjectMocks private KubernetesNamespaceService service; | ||
|
||
@Test | ||
public void shouldReturnNamespaces() throws Exception { | ||
KubernetesNamespaceMetaImpl namespaceMeta = | ||
new KubernetesNamespaceMetaImpl( | ||
"ws-namespace", ImmutableMap.of("phase", "active", "default", "true")); | ||
when(namespaceFactory.list()).thenReturn(singletonList(namespaceMeta)); | ||
|
||
final Response response = | ||
given() | ||
.auth() | ||
.basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) | ||
.when() | ||
.get(SECURE_PATH + "/kubernetes/namespace"); | ||
|
||
assertEquals(response.getStatusCode(), 200); | ||
List<KubernetesNamespaceMetaDto> namespaces = | ||
unwrapDtoList(response, KubernetesNamespaceMetaDto.class); | ||
assertEquals(namespaces.size(), 1); | ||
assertEquals(new KubernetesNamespaceMetaImpl(namespaces.get(0)), namespaceMeta); | ||
verify(namespaceFactory).list(); | ||
} | ||
|
||
private static <T> List<T> unwrapDtoList(Response response, Class<T> dtoClass) { | ||
return DtoFactory.getInstance().createListDtoFromJson(response.body().print(), dtoClass); | ||
} | ||
} |