diff options
author | Jim Hahn <jrh3@att.com> | 2019-04-13 09:05:13 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-04-14 16:43:51 -0400 |
commit | c8d0a3d8b7df3b09ce3405f1192754fdef7026d3 (patch) | |
tree | 27651921942e65b243f0d4110592b759d7afd2d8 /models-base/src/test/java | |
parent | c38fcf1a16f0d6bfdf2d80efa64a94ae68d80f03 (diff) |
Add prefix matching for policy version
Re-introduced regular expressions to match policy version
so that the policy version found in the metadata, which is just
the major number, can be matched with a policy's version, which
is of the form, major.minor.patch.
Simplified equals() test, as we already know "text!=null".
Added filterPrefixPred() and modified policy filter to use it when
matching versions, as it is simpler to use when matching a version
prefix.
Also added tests to PfObjectFilterTest to test each of the XxxPred()
methods.
Change-Id: I0734873f701a539e883fe25b8eecfdde60cc8b6d
Issue-ID: POLICY-1542
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-base/src/test/java')
-rw-r--r-- | models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java index 686342111..291a7d402 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +27,9 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; - +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Predicate; import org.junit.Test; import org.onap.policy.models.base.testconcepts.DummyPfObject; @@ -100,5 +103,51 @@ public class PfObjectFilterTest { latestVersionList.remove(1); List<DummyPfObject> newestVersionList = dof.latestVersionFilter(latestVersionList); assertEquals(latestVersionList, newestVersionList); + + MyFilter filter = new MyFilter(); + + assertEquals(true, filter.filterString(null, "Hello")); + + DummyPfObject doNullVersion = new DummyPfObject(); + do5.setName("bbbbb"); + + assertEquals(false, filter(filter::filterStringPred, DummyPfObject::getVersion, doNullVersion, "1.0.0")); + assertEquals(false, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, "1")); + assertEquals(false, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, "2.0.0")); + assertEquals(true, filter(filter::filterStringPred, DummyPfObject::getVersion, doNullVersion, null)); + assertEquals(true, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, null)); + assertEquals(true, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, "1.0.0")); + + assertEquals(false, filter(filter::filterPrefixPred, DummyPfObject::getVersion, doNullVersion, "1.")); + assertEquals(false, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.1")); + assertEquals(false, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.1")); + assertEquals(false, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "2")); + assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, doNullVersion, null)); + assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, null)); + assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.")); + assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.0.")); + assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.0.0")); + + assertEquals(false, filter(filter::filterRegexpPred, DummyPfObject::getVersion, doNullVersion, "1[.].*")); + assertEquals(false, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "2[.].*")); + assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, doNullVersion, null)); + assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, null)); + assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1[.].*")); + assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1[.]0[.].*")); + assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1[.]0[.]0")); + assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1....")); + } + + private boolean filter(BiFunction<String, Function<DummyPfObject, String>, Predicate<DummyPfObject>> predMaker, + Function<DummyPfObject, String> extractor, DummyPfObject dpo, String text) { + Predicate<DummyPfObject> pred = predMaker.apply(text, extractor); + return pred.test(dpo); + } + + private static class MyFilter implements PfObjectFilter<DummyPfObject> { + @Override + public List<DummyPfObject> filter(List<DummyPfObject> originalList) { + return null; + } } } |