Search in sources :

Example 66 with Service

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project java-monitoring by googleapis.

the class ServiceMonitoringServiceClientTest method getServiceTest.

@Test
public void getServiceTest() throws Exception {
    Service expectedResponse = Service.newBuilder().setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()).setDisplayName("displayName1714148973").setTelemetry(Service.Telemetry.newBuilder().build()).putAllUserLabels(new HashMap<String, String>()).build();
    mockServiceMonitoringService.addResponse(expectedResponse);
    ServiceName name = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]");
    Service actualResponse = client.getService(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetServiceRequest actualRequest = ((GetServiceRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ServiceName(com.google.monitoring.v3.ServiceName) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) GetServiceRequest(com.google.monitoring.v3.GetServiceRequest) Test(org.junit.Test)

Example 67 with Service

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project java-monitoring by googleapis.

the class ServiceMonitoringServiceClientTest method createServiceExceptionTest4.

@Test
public void createServiceExceptionTest4() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockServiceMonitoringService.addException(exception);
    try {
        String parent = "parent-995424086";
        Service service = Service.newBuilder().build();
        client.createService(parent, service);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) Test(org.junit.Test)

Example 68 with Service

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project java-monitoring by googleapis.

the class ServiceMonitoringServiceClientTest method listServicesTest.

@Test
public void listServicesTest() throws Exception {
    Service responsesElement = Service.newBuilder().build();
    ListServicesResponse expectedResponse = ListServicesResponse.newBuilder().setNextPageToken("").addAllServices(Arrays.asList(responsesElement)).build();
    mockServiceMonitoringService.addResponse(expectedResponse);
    FolderName parent = FolderName.of("[FOLDER]");
    ListServicesPagedResponse pagedListResponse = client.listServices(parent);
    List<Service> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListServicesRequest actualRequest = ((ListServicesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListServicesRequest(com.google.monitoring.v3.ListServicesRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ListServicesResponse(com.google.monitoring.v3.ListServicesResponse) ListServicesPagedResponse(com.google.cloud.monitoring.v3.ServiceMonitoringServiceClient.ListServicesPagedResponse) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) FolderName(com.google.monitoring.v3.FolderName) Test(org.junit.Test)

Example 69 with Service

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project java-monitoring by googleapis.

the class ServiceMonitoringServiceClientTest method createServiceExceptionTest.

@Test
public void createServiceExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockServiceMonitoringService.addException(exception);
    try {
        FolderName parent = FolderName.of("[FOLDER]");
        Service service = Service.newBuilder().build();
        client.createService(parent, service);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Service(com.google.monitoring.v3.Service) MockGrpcService(com.google.api.gax.grpc.testing.MockGrpcService) FolderName(com.google.monitoring.v3.FolderName) Test(org.junit.Test)

Example 70 with Service

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project yakc by manusa.

the class AuthIT method retrieveSecretForServiceAccount.

private Secret retrieveSecretForServiceAccount() throws IOException {
    final ServiceAccount sa = KC.create(CoreV1Api.class).listNamespacedServiceAccount(NAMESPACE).stream().findFirst().orElseThrow(() -> new AssertionError("No Service Account found"));
    final String secretName = sa.getSecrets() == null ? null : sa.getSecrets().stream().findFirst().map(ObjectReference::getName).orElse(null);
    if (secretName != null) {
        return KC.create(CoreV1Api.class).listNamespacedSecret(NAMESPACE).stream().filter(s -> s.getType().equals("kubernetes.io/service-account-token")).filter(s -> s.getMetadata().getName().equals(secretName)).findAny().orElseThrow(() -> new AssertionError(String.format("Secret %s doesn't exist", secretName)));
    } else {
        // https://kubernetes.io/docs/concepts/configuration/secret/#service-account-token-secrets
        final Secret serviceAccountTokenSecret = Secret.builder().metadata(ObjectMeta.builder().name(sa.getMetadata().getName() + "-token").putInAnnotations("kubernetes.io/service-account.name", sa.getMetadata().getName()).build()).type("kubernetes.io/service-account-token").putInStringData("token", "my-secret-token").build();
        return KC.create(CoreV1Api.class).createNamespacedSecret(NAMESPACE, serviceAccountTokenSecret).get();
    }
}
Also used : Node(com.marcnuri.yakc.model.io.k8s.api.core.v1.Node) KC(com.marcnuri.yakc.KubernetesClientExtension.KC) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceAccount(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceAccount) IOException(java.io.IOException) Secret(com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret) Test(org.junit.jupiter.api.Test) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api) ObjectMeta(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta) Configuration(com.marcnuri.yakc.config.Configuration) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) ObjectReference(com.marcnuri.yakc.model.io.k8s.api.core.v1.ObjectReference) Secret(com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret) ServiceAccount(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceAccount) ObjectReference(com.marcnuri.yakc.model.io.k8s.api.core.v1.ObjectReference)

Aggregations

Test (org.junit.jupiter.api.Test)34 Service (io.fabric8.knative.serving.v1.Service)28 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)22 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)22 CoreException (org.eclipse.core.runtime.CoreException)18 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)16 Service (com.google.monitoring.v3.Service)16 IOException (java.io.IOException)16 Test (org.junit.Test)16 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 AbstractMessage (com.google.protobuf.AbstractMessage)11 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)11 ProdBuildResults (io.quarkus.test.ProdBuildResults)11 ProdModeTestResults (io.quarkus.test.ProdModeTestResults)11 QuarkusProdModeTest (io.quarkus.test.QuarkusProdModeTest)11 Path (java.nio.file.Path)11 ArrayList (java.util.ArrayList)11 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)11 List (java.util.List)10 DisplayName (org.junit.jupiter.api.DisplayName)10