diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/predicates/TrafficControllerPoolPredicates.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/predicates/TrafficControllerPoolPredicates.java new file mode 100644 index 0000000000..89067ab839 --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/predicates/TrafficControllerPoolPredicates.java @@ -0,0 +1,100 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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 org.jclouds.ultradns.ws.predicates; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.ultradns.ws.domain.TrafficControllerPool; +import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord; + +import com.google.common.base.Predicate; + +/** + * Predicates handy when working with TrafficControllerPool Types + * + * @author Adrian Cole + */ +public class TrafficControllerPoolPredicates { + + /** + * evaluates to true if the input {@link TrafficControllerPool} exists + * with {@link TrafficControllerPool#getId() id} corresponding to the + * {@code id} parameter. + * + * @param id + * the {@link TrafficControllerPool#getId() id} of the + * desired pool record + */ + public static Predicate idEqualTo(String id) { + return new IdEqualToPredicate(id); + } + + private static final class IdEqualToPredicate implements Predicate { + private final String id; + + public IdEqualToPredicate(String id) { + this.id = checkNotNull(id, "id"); + } + + @Override + public boolean apply(TrafficControllerPool input) { + if (input == null) + return false; + return id.equals(input.getId()); + } + + @Override + public String toString() { + return "IdEqualTo(" + id + ")"; + } + } + + /** + * evaluates to true if the input {@link TrafficControllerPoolRecord} exists + * with {@link TrafficControllerPoolRecord#getId() id} corresponding to the + * {@code recordId} parameter. + * + * @param recordId + * the {@link TrafficControllerPoolRecord#getId() id} of the + * desired pool record + */ + public static Predicate recordIdEqualTo(String recordId) { + return new RecordIdEqualToPredicate(recordId); + } + + private static final class RecordIdEqualToPredicate implements Predicate { + private final String id; + + public RecordIdEqualToPredicate(String id) { + this.id = checkNotNull(id, "recordId"); + } + + @Override + public boolean apply(TrafficControllerPoolRecord input) { + if (input == null) + return false; + return id.equals(input.getId()); + } + + @Override + public String toString() { + return "RecordIdEqualTo(" + id + ")"; + } + } +} diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/predicates/TrafficControllerPoolPredicatesTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/predicates/TrafficControllerPoolPredicatesTest.java new file mode 100644 index 0000000000..0ffadd663a --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/predicates/TrafficControllerPoolPredicatesTest.java @@ -0,0 +1,76 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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 org.jclouds.ultradns.ws.predicates; + +import static org.jclouds.ultradns.ws.predicates.TrafficControllerPoolPredicates.idEqualTo; +import static org.jclouds.ultradns.ws.predicates.TrafficControllerPoolPredicates.recordIdEqualTo; + +import org.jclouds.ultradns.ws.domain.TrafficControllerPool; +import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord; +import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord.Status; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "TrafficControllerPoolPredicatesTest") +public class TrafficControllerPoolPredicatesTest { + TrafficControllerPool pool = TrafficControllerPool.builder() + .zoneId("0000000000000001") + .id("000000000000002") + .name("us-west-1c.discovery.jclouds.org.") + .dname("us-west-1c.discovery.jclouds.org.") + .statusCode(1) + .failOverEnabled(true) + .probingEnabled(true).build(); + + @Test + public void testIdEqualToWhenEqual() { + assert idEqualTo("000000000000002").apply(pool); + } + + @Test + public void testIdEqualToWhenNotEqual() { + assert !idEqualTo("000000000000003").apply(pool); + } + + TrafficControllerPoolRecord record = TrafficControllerPoolRecord.builder() + .id("0000000000000001") + .poolId("0000000000000001") + .pointsTo("canary.jclouds.org.") + .weight(2) + .priority(2) + .type("CNAME") + .forceAnswer("Normal") + .probingEnabled(true) + .status(Status.OK) + .serving(true) + .description("canary app").build(); + + @Test + public void testRecordIdEqualToWhenEqual() { + assert recordIdEqualTo("0000000000000001").apply(record); + } + + @Test + public void testRecordIdEqualToWhenNotEqual() { + assert !recordIdEqualTo("0000000000000002").apply(record); + } +}