+ assertEquals(1, getCount(newEntry));
+ }
+
+ private long getCount(Dbao newEntry) throws PIPException {
+ responses = new LinkedList<>(Arrays.asList(resp1, resp2, resp3));
+ attributes = new LinkedList<>(
+ Arrays.asList(newEntry.getActor(), newEntry.getOperation(), newEntry.getTarget()));
+
+ PIPResponse result = pipEngine.getAttributes(pipRequest, pipFinder);
+
+ Attribute attr = result.getAttributes().iterator().next();
+ AttributeValue<?> value = attr.getValues().iterator().next();
+
+ return ((Number) value.getValue()).longValue();
+ }
+
+ @Test
+ public void testStringToChronoUnit() throws PIPException {
+ // not configured yet
+ Dbao newEntry = createEntry("cl-foobar-1", "vnf-1", "SUCCESS");
+ assertEquals(-1, getCount(newEntry));
+
+ // now configure it
+ pipEngine.configure("issuer", properties);
+
+ String[] units = {"second", "minute", "hour", "day", "week", "month", "year"};
+
+ for (String unit : units) {
+ when(pipRequest.getIssuer()).thenReturn("urn:org:onap:xacml:guard:tw:1:" + unit);
+
+ /*
+ * It would be better to use assertEquals below, but the test DB doesn't
+ * support week, month, or year.
+ */
+
+ // should run without throwing an exception
+ getCount(newEntry);
+ }
+
+ // invalid time unit
+ when(pipRequest.getIssuer()).thenReturn("urn:org:onap:xacml:guard:tw:1:invalid");
+ assertEquals(-1, getCount(newEntry));