use of io.fabric8.utils.Block in project fabric8 by fabric8io.
the class Example method main.
public static void main(String[] args) {
try {
final KubernetesClient client = new DefaultKubernetesClient();
assertThat(client).pods().runningStatus().hasSize(6);
assertThat(client).pods().runningStatus().filterLabel("provider", "fabric8").assertSize().isGreaterThan(0);
assertThat(client.services().inNamespace("default").withName("fabric8").get().getMetadata()).name().isEqualTo("fabric8");
Map<String, String> consoleLabels = new HashMap<>();
consoleLabels.put("component", "console");
consoleLabels.put("provider", "fabric8");
assertThat(client).podsForService("fabric8").runningStatus().extracting("metadata").extracting("labels").contains(consoleLabels);
assertThat(client).podsForService("fabric8").runningStatus().hasSize(1).extracting("metadata").extracting("labels").contains(consoleLabels);
assertThat(client).podsForService("fabric8").logs().doesNotContainText("Exception", "Error");
assertThat(client).pods().logs().doesNotContainText("Exception", "Error");
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
try {
assertThat(client.services().inNamespace("default").withName("doesNotExist").get().getMetadata()).name().isEqualTo("fabric8-console-controller");
} catch (KubernetesClientException e) {
if (e.getCode() != 404) {
throw e;
} else {
throw new AssertionError(e);
}
}
}
});
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
try {
assertThat(client).pods().runningStatus().filterLabel("component", "doesNotExist").hasSize(1);
} catch (KubernetesClientException e) {
if (e.getCode() != 404) {
throw e;
} else {
throw new AssertionError(e);
}
}
}
});
System.out.println("Done!");
} catch (Throwable e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
}
use of io.fabric8.utils.Block in project fabric8 by fabric8io.
the class ExampleTest method testNullNavigationOnPod.
@Test
public void testNullNavigationOnPod() throws Exception {
final Pod pod = new Pod();
pod.setMetadata(null);
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
assertThat(pod).metadata().name().isEqualTo("cheese");
}
});
}
use of io.fabric8.utils.Block in project fabric8 by fabric8io.
the class ExampleTest method testNavigationListAssertions.
@Test
public void testNavigationListAssertions() throws Exception {
final String id1 = "abc";
final String id2 = "def";
Map<String, String> labels1 = new HashMap<>();
labels1.put("foo", "bar");
Map<String, String> labels2 = new HashMap<>();
labels2.put("whatnot", "cheese");
final Pod pod1 = new Pod();
pod1.setMetadata(new ObjectMeta());
pod1.getMetadata().setName(id1);
pod1.getMetadata().setLabels(labels1);
final Pod pod2 = new Pod();
pod2.setMetadata(new ObjectMeta());
pod2.getMetadata().setName(id2);
pod2.getMetadata().setLabels(labels2);
final PodList emptyPodList = new PodList();
final PodList podList = new PodList();
podList.setItems(new ArrayList<Pod>(Arrays.asList(pod1, pod2)));
assertThat(emptyPodList).describedAs("emptyPodList").items().isEmpty();
assertThat(podList).describedAs("podListWith2Items").items().first().metadata().name().isEqualTo(id1);
assertThat(podList).describedAs("podListWith2Items").items().last().metadata().name().isEqualTo(id2);
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
assertThat(podList).describedAs("podListWith2Items").items().item(-1).isNotNull();
}
});
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
assertThat(podList).describedAs("podListWith2Items").items().item(2).isNotNull();
}
});
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
assertThat(podList).describedAs("podListWith2Items").items().first().metadata().name().isEqualTo("shouldNotMatch");
}
});
}
use of io.fabric8.utils.Block in project fabric8 by fabric8io.
the class ExampleTest method testNullNavigationOnRC.
@Test
public void testNullNavigationOnRC() throws Exception {
final ReplicationController rc = new ReplicationController();
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
assertThat(rc).spec().template().spec().containers().first().image().isEqualTo("someDockerImageName");
}
});
}
use of io.fabric8.utils.Block in project fabric8 by fabric8io.
the class ExampleTest method testJsonArrayOperation.
@Test
public void testJsonArrayOperation() throws Exception {
final JSONArrayAssert dumpAllThreads = assertThat(client).jsonArrayOperation("java.lang:type=Threading", "dumpAllThreads", true, true);
dumpAllThreads.assertSize().isGreaterThan(1);
int size = dumpAllThreads.get().size();
for (int i = 0; i < size; i++) {
JSONObjectAssert object = dumpAllThreads.assertJSONObject(i);
object.isNotNull();
object.assertString("threadName").isNotEmpty();
}
// lets try access an invalid array
final int badIndex = size + 100;
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
dumpAllThreads.assertJSONObject(badIndex);
}
});
}
Aggregations