io.fabric8.kubernetes.assertions.HasMetadatasAssert Maven / Gradle / Ivy
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.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.ListAssert;
import org.assertj.core.api.filter.Filters;
import org.assertj.core.util.Lists;
import java.util.List;
/**
*/
public abstract class HasMetadatasAssert extends ListAssert {
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 R first() {
assertSize().isGreaterThan(0);
return get().get(0);
}
/**
* Asserts that this collection has at least one element and returns the last one
*/
public R last() {
assertSize().isGreaterThan(0);
List list = get();
return 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));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy