@Test public void testContextAttribute() { URI testUri = URI.create("lol:wut"); when(mockContext.getResourceValues(testUri)).thenReturn(new String[]{"foo:bar"}); EvaluationResult eval = test.getResourceAttribute(URI.create(StringAttribute.identifier), testUri, null); // call again to test cache test.getResourceAttribute(URI.create(StringAttribute.identifier), testUri, null); verify(mockContext, times(1)).getResourceValues(testUri); verify(mockFinder, times(0)).findAttribute(any(URI.class), any(URI.class), any(URI.class), any(URI.class), any(EvaluationCtx.class), any(Integer.class)); assertEquals("foo:bar", eval.getAttributeValue().getValue()); }
values = null; } else { values = context.getResourceValues(attributeId);
values = null; } else { values = context.getResourceValues(attributeId);
@Test public void testModuleAttribute() { URI testUri = URI.create("lol:wut"); when(mockFinder.findAttribute( any(URI.class), eq(testUri), any(URI.class), any(URI.class), any(EvaluationCtx.class), eq(AttributeDesignator.RESOURCE_TARGET))) .thenReturn(new EvaluationResult(StringAttribute.getInstance("foo:bar"))); EvaluationResult eval = test.getResourceAttribute(URI.create(StringAttribute.identifier), testUri, null); test.getResourceAttribute(URI.create(StringAttribute.identifier), testUri, null); verify(mockContext, times(2)).getResourceValues(testUri); verify(mockFinder, times(2)).findAttribute(any(URI.class), any(URI.class), any(URI.class), any(URI.class), any(EvaluationCtx.class), any(Integer.class)); assertEquals("foo:bar", eval.getAttributeValue().getValue()); } // Supports legacy test runners
/** * A "copy constructor" that creates a writable context from one that might * be read-only. */ public JournalEntryContext(Context source) { password = source.getPassword(); noOp = source.getNoOp(); now = source.now(); for (Iterator<URI> keys = source.environmentAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(environmentAttributes, key, source .getEnvironmentValues(key)); } for (Iterator<String> keys = source.subjectAttributes(); keys.hasNext();) { String key = keys.next(); storeInMap(subjectAttributes, key, source.getSubjectValues(key)); } for (Iterator<URI> keys = source.actionAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(actionAttributes, key, source.getActionValues(key)); } for (Iterator<URI> keys = source.resourceAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(resourceAttributes, key, source.getResourceValues(key)); } }
break; case AttributeDesignator.RESOURCE_TARGET: values = context.getResourceValues(id); break; case AttributeDesignator.ACTION_TARGET:
break; case AttributeDesignator.RESOURCE_TARGET: values = context.getResourceValues(id); break; case AttributeDesignator.ACTION_TARGET:
/** * A "copy constructor" that creates a writable context from one that might * be read-only. */ public JournalEntryContext(Context source) { password = source.getPassword(); noOp = source.getNoOp(); now = source.now(); for (Iterator<URI> keys = source.environmentAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(environmentAttributes, key, source .getEnvironmentValues(key)); } for (Iterator<String> keys = source.subjectAttributes(); keys.hasNext();) { String key = keys.next(); storeInMap(subjectAttributes, key, source.getSubjectValues(key)); } for (Iterator<URI> keys = source.actionAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(actionAttributes, key, source.getActionValues(key)); } for (Iterator<URI> keys = source.resourceAttributes(); keys.hasNext();) { URI key = keys.next(); storeInMap(resourceAttributes, key, source.getResourceValues(key)); } }