io.fabric8.kubernetes.assertions.HasMetadatasAssert Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kubernetes-assertions
Show all versions of kubernetes-assertions
This library provides a bunch of helpful assertj assertions for working with the kubernetes-api.
The newest version!
package io.fabric8.kubernetes.assertions;
import io.fabric8.kubernetes.api.model.HasMetadata;
import org.assertj.core.api.Condition;
import org.assertj.core.api.IntegerAssert;
import org.assertj.core.api.ObjectAssert;
import org.assertj.core.api.filter.Filters;
import org.assertj.core.util.Lists;
import java.util.List;
/**
*
*/
public abstract class HasMetadatasAssert
extends MetadatasListAssert
{
public HasMetadatasAssert(List actual)
{
super(actual);
}
protected abstract AI createListAssert(List list);
protected AI assertThat(Iterable result)
{
List list = Lists.newArrayList(result);
return createListAssert(list);
}
public AI filter(Condition condition)
{
return assertThat((Iterable) Filters.filter(actual).having(condition).get());
}
/**
* Returns an assertion on the size of the list
*/
public IntegerAssert assertSize()
{
return (IntegerAssert) org.assertj.core.api.Assertions.assertThat(get().size()).as("size");
}
/**
* Returns the underlying actual value
*/
public List get()
{
return (List) actual;
}
/**
* Asserts that this collection has at least one element and returns the first one
*/
public ObjectAssert first()
{
assertSize().isGreaterThan(0);
return new ObjectAssert<>(get().get(0));
}
/**
* Asserts that this collection has at least one element and returns the last one
*/
public ObjectAssert last()
{
assertSize().isGreaterThan(0);
List list = get();
return new ObjectAssert<>(list.get(list.size() - 1));
}
/**
* Asserts that this collection has a resource with the given name and return it
*
* @return returns the matching resource
*/
public R hasName(String name)
{
return (R) filterName(name).first();
}
/**
* Filters the resources by name
*/
public AI filterName(String name)
{
return filter((Condition) Conditions.hasName(name));
}
/**
* Filters the resources using the given label key and value
*/
public AI filterLabel(String key, String value)
{
return filter((Condition) Conditions.hasLabel(key, value));
}
/**
* Filters the resources using the given namespace
*/
public AI filterNamespace(String namespace)
{
return filter((Condition) Conditions.hasNamespace(namespace));
}
}