RawContentFacetImpl extends FacetSupport implements RawContentFacet { @Override public Content put(final String path, final Payload content) throws IOException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(content, hashAlgorithms)) { return doPutContent(path, tempBlob, content); } } @Inject  RawContentFacetImpl(final AssetEntityAdapter assetEntityAdapter); @Nullable @Override @TransactionalTouchBlob Content get(final String path); @Override Content put(final String path, final Payload content); @Override @TransactionalStoreBlob Asset put(final String path, final AssetBlob assetBlob, @Nullable final AttributesMap contentAttributes); @TransactionalStoreMetadata Asset getOrCreateAsset(final Repository repository, final String componentName, final String componentGroup,
                                final String assetName); @Override @TransactionalDeleteBlob boolean delete(final String path); @Override @TransactionalTouchMetadata void setCacheInfo(final String path, final Content content, final CacheInfo cacheInfo); @Override @Transactional boolean assetExists(final String name);  }
@Test public void testPutWhenComponentAndAssetExist() { when(tx.findComponentWithProperty(P_NAME, ASSET_NAME, bucket)).thenReturn(component); when(tx.firstAsset(component)).thenReturn(asset); underTest.put(ASSET_NAME, assetBlob, NO_CONTENT_ATTRIBUTES); InOrder inOrder = inOrder(tx, asset); inOrder.verify(tx).attachBlob(asset, assetBlob); inOrder.verify(tx).saveAsset(asset); verify(tx, never()).createComponent(bucket, format); verify(tx, never()).saveComponent(component); verify(tx, never()).createAsset(bucket, component); }
@Test public void testPutWhenComponentAndAssetDoNotExist() { when(tx.findComponentWithProperty(P_NAME, ASSET_NAME, bucket)).thenReturn(null); when(tx.createComponent(bucket, format)).thenReturn(component); when(tx.firstAsset(component)).thenReturn(null); when(tx.createAsset(bucket, component)).thenReturn(asset); underTest.put(ASSET_NAME, assetBlob, NO_CONTENT_ATTRIBUTES); InOrder inOrder = inOrder(tx, component, asset); inOrder.verify(tx).createComponent(bucket, format); inOrder.verify(component).group(GROUP_NAME); inOrder.verify(component).name(ASSET_NAME); inOrder.verify(tx).saveComponent(component); inOrder.verify(tx).createAsset(bucket, component); inOrder.verify(asset).name(ASSET_NAME); inOrder.verify(tx).attachBlob(asset, assetBlob); inOrder.verify(tx).saveAsset(asset); }
@Test public void testPutWhenComponentExistsAndAssetDoesNot() { when(tx.findComponentWithProperty(P_NAME, ASSET_NAME, bucket)).thenReturn(component); when(tx.firstAsset(component)).thenReturn(null); when(tx.createAsset(bucket, component)).thenReturn(asset); underTest.put(ASSET_NAME, assetBlob, NO_CONTENT_ATTRIBUTES); InOrder inOrder = inOrder(tx, asset); inOrder.verify(tx).createAsset(bucket, component); inOrder.verify(asset).name(ASSET_NAME); inOrder.verify(tx).attachBlob(asset, assetBlob); inOrder.verify(tx).saveAsset(asset); verify(tx, never()).createComponent(bucket, format); verify(tx, never()).saveComponent(component); }