ItemAttributesResource extends AbstractResourceStoreContentPlexusResource { @VisibleForTesting static void applyTo(final AttributesDTO attributes, final Attributes proxyAttributes) { for (AttributeDTO attribute : attributes) { String key = attribute.getKey(); checkArgument(!key.startsWith(SYSTEM_ATTR_PREFIX), "Can not override system attribute: %s", key); proxyAttributes.put(key, attribute.getValue()); } } ItemAttributesResource(); @Override String getResourceUri(); @Override AttributesDTO getPayloadInstance(); @Override boolean acceptsUpload(); @Override PathProtectionDescriptor getResourceProtection(); @Override void configureXStream(final XStream xstream); @Override Object get(Context context, Request request, Response response, Variant variant); @Override Object put(Context context, Request request, Response response, Object payload); @Override void delete(Context context, Request request, Response response); static final String SYSTEM_ATTR_PREFIX; }
@Test(expected = IllegalArgumentException.class) public void applyTo_canNotOverrideSystemAttribute() throws Exception { AttributesDTO attributes = new AttributesDTO(); attributes.getAttributes().add(new AttributeDTO(ItemAttributesResource.SYSTEM_ATTR_PREFIX + "foo", "bar")); Attributes target = mock(Attributes.class); ItemAttributesResource.applyTo(attributes, target); verifyNoMoreInteractions(target); }