Search in sources :

Example 1 with KubernetesType

use of io.kubernetes.client.common.KubernetesType in project java by kubernetes-client.

the class YamlTest method testLoadAllFile.

@Test
public void testLoadAllFile() throws Exception {
    List<Object> list = Yaml.loadAll(new File(TEST_YAML_FILE_PATH));
    List<KubernetesType> k8ObjectList = new ArrayList<>();
    for (Object object : list) {
        String type = object.getClass().getSimpleName();
        if (type.equals("V1Service")) {
            V1Service svc = (V1Service) object;
            assertEquals("v1", svc.getApiVersion());
            assertEquals("Service", svc.getKind());
            assertEquals("mock", svc.getMetadata().getName());
            k8ObjectList.add(svc);
        } else if (type.equals("V1Deployment")) {
            V1Deployment deploy = (V1Deployment) object;
            assertEquals("apps/v1", deploy.getApiVersion());
            assertEquals("Deployment", deploy.getKind());
            assertEquals("helloworld", deploy.getMetadata().getName());
            k8ObjectList.add(deploy);
        } else if (type.equals("V1Secret")) {
            V1Secret secret = (V1Secret) object;
            assertEquals("Secret", secret.getKind());
            assertEquals("secret", secret.getMetadata().getName());
            assertEquals("Opaque", secret.getType());
            assertEquals("hello", new String(secret.getData().get("secret-data"), UTF_8));
            k8ObjectList.add(secret);
        } else {
            throw new Exception("some thing wrong happened");
        }
    }
    String result = Yaml.dumpAll(k8ObjectList.iterator());
    String expected = Resources.toString(EXPECTED_YAML_FILE, UTF_8).replace("\r\n", "\n");
    assertThat(result, equalTo(expected));
}
Also used : V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) KubernetesType(io.kubernetes.client.common.KubernetesType) ArrayList(java.util.ArrayList) V1Service(io.kubernetes.client.openapi.models.V1Service) File(java.io.File) V1Secret(io.kubernetes.client.openapi.models.V1Secret) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

KubernetesType (io.kubernetes.client.common.KubernetesType)1 V1Deployment (io.kubernetes.client.openapi.models.V1Deployment)1 V1Secret (io.kubernetes.client.openapi.models.V1Secret)1 V1Service (io.kubernetes.client.openapi.models.V1Service)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1