/**
 * 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.mock;

import io.fabric8.kubernetes.api.model.PodBuilder;
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import org.junit.Rule;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;


public class PodCrudTest {

  @Rule
  public KubernetesServer server = new KubernetesServer(true, true);

  @Test
  public void testCrud() {
    KubernetesClient client = server.getClient();

    client.pods().inNamespace("ns1").create(new PodBuilder().withNewMetadata().withName("pod1").endMetadata().build());
    client.pods().inNamespace("ns1").create(new PodBuilder().withNewMetadata().withName("pod2").endMetadata().build());
    client.pods().inNamespace("ns2").create(new PodBuilder().withNewMetadata().withName("pod3").endMetadata().build());

    PodList podList = client.pods().list();
    assertNotNull(podList);
    assertEquals(0, podList.getItems().size());

    podList = client.pods().inNamespace("ns1").list();
    assertNotNull(podList);
    assertEquals(2, podList.getItems().size());

    podList = client.pods().inAnyNamespace().list();
    assertNotNull(podList);
    assertEquals(3, podList.getItems().size());

    client.pods().inNamespace("ns1").withName("pod1").delete();
    podList = client.pods().inNamespace("ns1").list();
    assertNotNull(podList);
    assertEquals(1, podList.getItems().size());

    podList = client.pods().inAnyNamespace().list();
    assertNotNull(podList);
    assertEquals(2, podList.getItems().size());
  }
}

@@ -644,16 +644,60 @@
 .mock;%0A%0A
+import io.fabric8.kubernetes.api.model.Pod;%0A
 import i
@@ -735,24 +735,24 @@
 PodBuilder;%0A
-
 import io.fa
@@ -954,16 +954,47 @@
 .Test;%0A%0A
+import java.util.Collections;%0A%0A
 import s
@@ -1278,48 +1278,19 @@
     
-client.pods().inNamespace(%22ns1%22).create(
+Pod pod1 = 
 new 
@@ -1337,16 +1337,52 @@
 %22pod1%22).
+addToLabels(%22testKey%22, %22testValue%22).
 endMetad
@@ -1398,55 +1398,151 @@
 ld()
-)
 ;%0A    
-client.pods().inNamespace(%22ns1%22).create(
+Pod pod2 = new PodBuilder().withNewMetadata().withName(%22pod2%22).addToLabels(%22testKey%22, %22testValue%22).endMetadata().build();%0A    Pod pod3 = 
 new 
@@ -1585,17 +1585,17 @@
 ame(%22pod
-2
+3
 %22).endMe
@@ -1610,18 +1610,18 @@
 .build()
-)
 ;
+%0A
 %0A    cli
@@ -1646,17 +1646,17 @@
 pace(%22ns
-2
+1
 %22).creat
@@ -1661,81 +1661,114 @@
 ate(
-new PodBuilder().withNewMetadata().withName(%22pod3%22).endMetadata().build()
+pod1);%0A    client.pods().inNamespace(%22ns1%22).create(pod2);%0A    client.pods().inNamespace(%22ns2%22).create(pod3
 );%0A%0A
@@ -2419,32 +2419,32 @@
 tNull(podList);%0A
-
     assertEquals
@@ -2474,15 +2474,482 @@
 size());
+%0A%0A    // test listing with labels%0A    podList = client.pods().inAnyNamespace().withLabels(Collections.singletonMap(%22testKey%22, %22testValue%22)).list();%0A    assertNotNull(podList);%0A    assertEquals(2, podList.getItems().size());%0A%0A    // test update%0A//    pod2 = client.pods().inNamespace(%22ns1%22).withName(%22pod2%22).edit()%0A//      .editMetadata().withName(%22pod1234%22).endMetadata().done();%0A//    assertNotNull(pod1);%0A//    assertEquals(pod1.getMetadata().getName(), %22pod1234%22);
 %0A  %7D%0A%7D%0A

Fix #923 Improved PodCrudTest