@Test public void should_throw_an_exception_when_the_asset_has_empty_locations() { MockFilterConfig filterConfig = new MockFilterConfig(); context = new Context(filterConfig); request = new MockHttpServletRequest(); request.setContextPath("/context"); request.setAttribute(WebConstants.DANDELION_CONTEXT_ATTRIBUTE, context); assetMapper = new AssetMapper(context, request); exception.expect(DandelionException.class); exception .expectMessage("No location is configured for the asset 'asset-name' (js, v1.0.0). Please add at least one location in the corresponding JSON file."); AssetStorageUnit asu = new AssetStorageUnit(); asu.setName("asset-name"); asu.setType(AssetType.js); asu.setVersion("1.0.0"); asu.setLocations(Collections.<String, String> emptyMap()); assetMapper.mapToAsset(asu); }
public Asset mapToAsset(AssetStorageUnit asu) { Asset asset = new Asset(asu); LOG.trace("Resolving location for the asset {}", asset.toLog()); String locationKey = getLocationKey(asu); asset.setConfigLocationKey(locationKey); AssetLocator assetLocator = AssetUtils.getAssetLocator(asset, context); String location = assetLocator.getLocation(asu, request); LOG.trace("Locator '{}' will be applied on the asset {}.", assetLocator.getClass().getSimpleName(), asu.toLog()); asset.setProcessedConfigLocation(location); asset.setConfigLocation(asu.getLocations().get(locationKey)); asset.setGeneratorUid(asu.getGeneratorUid()); asset.setStorageKey(AssetUtils.generateStorageKey(asset, request)); if (asset.isNotVendor()) { if (context.getConfiguration().isAssetMinificationEnabled()) { asset = this.context.getProcessorManager().process(asset, request); } else if (context.getConfiguration().isAssetAutoVersioningEnabled() || assetLocator.isCachingForced()) { String contents = assetLocator.getContent(asset, request); this.context.getAssetStorage().put(asset.getStorageKey(), new StorageEntry(asset, contents)); } } asset.setName(getName(asu, location)); asset.setType(getType(asu, location)); asset.setVersion(getVersion(asset)); asset.setFinalLocation(getFinalLocation(asset, assetLocator)); return asset; }
AssetMapper { public Asset mapToAsset(AssetStorageUnit asu) { Asset asset = new Asset(asu); LOG.trace("Resolving location for the asset {}", asset.toLog()); String locationKey = getLocationKey(asu); asset.setConfigLocationKey(locationKey); AssetLocator assetLocator = AssetUtils.getAssetLocator(asset, context); String location = assetLocator.getLocation(asu, request); LOG.trace("Locator '{}' will be applied on the asset {}.", assetLocator.getClass().getSimpleName(), asu.toLog()); asset.setProcessedConfigLocation(location); asset.setConfigLocation(asu.getLocations().get(locationKey)); asset.setGeneratorUid(asu.getGeneratorUid()); asset.setStorageKey(AssetUtils.generateStorageKey(asset, request)); if (asset.isNotVendor()) { if (context.getConfiguration().isAssetMinificationEnabled()) { asset = this.context.getProcessorManager().process(asset, request); } else if (context.getConfiguration().isAssetAutoVersioningEnabled() || assetLocator.isCachingForced()) { String contents = assetLocator.getContent(asset, request); this.context.getAssetStorage().put(asset.getStorageKey(), new StorageEntry(asset, contents)); } } asset.setName(getName(asu, location)); asset.setType(getType(asu, location)); asset.setVersion(getVersion(asset)); asset.setFinalLocation(getFinalLocation(asset, assetLocator)); return asset; } }
AssetMapper { public Asset mapToAsset(AssetStorageUnit asu) { Asset asset = new Asset(asu); LOG.trace("Resolving location for the asset {}", asset.toLog()); String locationKey = getLocationKey(asu); asset.setConfigLocationKey(locationKey); AssetLocator assetLocator = AssetUtils.getAssetLocator(asset, context); String location = assetLocator.getLocation(asu, request); LOG.trace("Locator '{}' will be applied on the asset {}.", assetLocator.getClass().getSimpleName(), asu.toLog()); asset.setProcessedConfigLocation(location); asset.setConfigLocation(asu.getLocations().get(locationKey)); asset.setGeneratorUid(asu.getGeneratorUid()); asset.setStorageKey(AssetUtils.generateStorageKey(asset, request)); if (asset.isNotVendor()) { if (context.getConfiguration().isAssetMinificationEnabled()) { asset = this.context.getProcessorManager().process(asset, request); } else if (context.getConfiguration().isAssetAutoVersioningEnabled() || assetLocator.isCachingForced()) { String contents = assetLocator.getContent(asset, request); this.context.getAssetStorage().put(asset.getStorageKey(), new StorageEntry(asset, contents)); } } asset.setName(getName(asu, location)); asset.setType(getType(asu, location)); asset.setVersion(getVersion(asset)); asset.setFinalLocation(getFinalLocation(asset, assetLocator)); return asset; } AssetMapper(Context context, HttpServletRequest request); }
AssetMapper { public Asset mapToAsset(AssetStorageUnit asu) { Asset asset = new Asset(asu); LOG.trace("Resolving location for the asset {}", asset.toLog()); String locationKey = getLocationKey(asu); asset.setConfigLocationKey(locationKey); AssetLocator assetLocator = AssetUtils.getAssetLocator(asset, context); String location = assetLocator.getLocation(asu, request); LOG.trace("Locator '{}' will be applied on the asset {}.", assetLocator.getClass().getSimpleName(), asu.toLog()); asset.setProcessedConfigLocation(location); asset.setConfigLocation(asu.getLocations().get(locationKey)); asset.setGeneratorUid(asu.getGeneratorUid()); asset.setStorageKey(AssetUtils.generateStorageKey(asset, request)); if (asset.isNotVendor()) { if (context.getConfiguration().isAssetMinificationEnabled()) { asset = this.context.getProcessorManager().process(asset, request); } else if (context.getConfiguration().isAssetAutoVersioningEnabled() || assetLocator.isCachingForced()) { String contents = assetLocator.getContent(asset, request); this.context.getAssetStorage().put(asset.getStorageKey(), new StorageEntry(asset, contents)); } } asset.setName(getName(asu, location)); asset.setType(getType(asu, location)); asset.setVersion(getVersion(asset)); asset.setFinalLocation(getFinalLocation(asset, assetLocator)); return asset; } AssetMapper(Context context, HttpServletRequest request); Set<Asset> mapToAssets(Set<AssetStorageUnit> asus); Asset mapToAsset(AssetStorageUnit asu); }
AssetMapper { public Asset mapToAsset(AssetStorageUnit asu) { Asset asset = new Asset(asu); LOG.trace("Resolving location for the asset {}", asset.toLog()); String locationKey = getLocationKey(asu); asset.setConfigLocationKey(locationKey); AssetLocator assetLocator = AssetUtils.getAssetLocator(asset, context); String location = assetLocator.getLocation(asu, request); LOG.trace("Locator '{}' will be applied on the asset {}.", assetLocator.getClass().getSimpleName(), asu.toLog()); asset.setProcessedConfigLocation(location); asset.setConfigLocation(asu.getLocations().get(locationKey)); asset.setGeneratorUid(asu.getGeneratorUid()); asset.setStorageKey(AssetUtils.generateStorageKey(asset, request)); if (asset.isNotVendor()) { if (context.getConfiguration().isAssetMinificationEnabled()) { asset = this.context.getProcessorManager().process(asset, request); } else if (context.getConfiguration().isAssetAutoVersioningEnabled() || assetLocator.isCachingForced()) { String contents = assetLocator.getContent(asset, request); this.context.getAssetStorage().put(asset.getStorageKey(), new StorageEntry(asset, contents)); } } asset.setName(getName(asu, location)); asset.setType(getType(asu, location)); asset.setVersion(getVersion(asset)); asset.setFinalLocation(getFinalLocation(asset, assetLocator)); return asset; } AssetMapper(Context context, HttpServletRequest request); Set<Asset> mapToAssets(Set<AssetStorageUnit> asus); Asset mapToAsset(AssetStorageUnit asu);  }