org.sonatype.nexus.repository.storage.Asset Java Examples

The following examples show how to use org.sonatype.nexus.repository.storage.Asset. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComponentComponentTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testReadAsset() {
  Asset asset = mock(Asset.class);
  Bucket bucket = mock(Bucket.class);
  EntityId bucketId = mock(EntityId.class);
  EntityMetadata entityMetadata = mock(EntityMetadata.class);
  when(asset.getEntityMetadata()).thenReturn(entityMetadata);
  when(asset.bucketId()).thenReturn(bucketId);
  when(asset.attributes()).thenReturn(new NestedAttributesMap("attributes", new HashMap<>()));
  when(entityMetadata.getId()).thenReturn(new DetachedEntityId("someid"));
  when(contentPermissionChecker.isPermitted(anyString(),any(), eq(BreadActions.BROWSE), any())).thenReturn(true);

  when(browseService.getAssetById(new DetachedEntityId("someid"), repository)).thenReturn(asset);
  when(bucketStore.getById(bucketId)).thenReturn(bucket);
  when(bucket.getRepositoryName()).thenReturn("testRepositoryName");
  AssetXO assetXO = underTest.readAsset("someid", "testRepositoryName");

  assertThat(assetXO, is(notNullValue()));
  assertThat(assetXO.getId(), is("someid"));
  assertThat(assetXO.getRepositoryName(), is("testRepositoryName"));
  assertThat(assetXO.getContainingRepositoryName(), is("testRepositoryName"));
}
 
Example #2
Source File: GolangDataAccess.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Save an asset and create blob.
 *
 * @return blob content
 */
@TransactionalStoreBlob
public Content maybeCreateAndSaveAsset(final Repository repository,
                                       final String assetPath,
                                       final AssetKind assetKind,
                                       final TempBlob tempBlob,
                                       final Payload payload) throws IOException
{
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(repository);

  Asset asset = findAsset(tx, bucket, assetPath);
  if (asset == null) {
    asset = tx.createAsset(bucket, repository.getFormat());
    asset.name(assetPath);
    asset.formatAttributes().set(P_ASSET_KIND, assetKind.name());
  }
  return saveAsset(tx, asset, tempBlob, payload);
}
 
Example #3
Source File: RUploadHandler.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException {
  final AssetUpload assetUpload = upload.getAssetUploads().get(0);
  final PartPayload payload = assetUpload.getPayload();
  final Map<String, String> fields = assetUpload.getFields();
  final String uploadPath = removeInitialSlashFromPath(fields.get(PATH_ID));
  final String assetPath = buildPath(uploadPath, payload.getName());

  ensurePermitted(repository.getName(), RFormat.NAME, assetPath, Collections.emptyMap());
  validateArchiveUploadPath(assetPath);

  try {
    UnitOfWork.begin(repository.facet(StorageFacet.class).txSupplier());
    Asset asset = repository.facet(RHostedFacet.class).upload(assetPath, payload);
    return new UploadResponse(asset);
  }
  finally {
    UnitOfWork.end();
  }
}
 
Example #4
Source File: OrientNpmProxyFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalTouchMetadata
protected Content getDistTags(final NpmPackageId packageId) {
  checkNotNull(packageId);
  StorageTx tx = UnitOfWork.currentTx();
  Asset packageRootAsset = NpmFacetUtils.findPackageRootAsset(tx, tx.findBucket(getRepository()), packageId);
  if (packageRootAsset != null) {
    try {
      final NestedAttributesMap attributesMap = NpmFacetUtils.loadPackageRoot(tx, packageRootAsset);
      final NestedAttributesMap distTags = attributesMap.child(DIST_TAGS);
      return NpmFacetUtils.distTagsToContent(distTags);
    }
    catch (IOException e) {
      log.error("Unable to read packageRoot {}", packageId.id(), e);
    }
  }
  return null;
}
 
Example #5
Source File: HelmHostedFacetImpl.java    From nexus-repository-helm with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalStoreBlob
public Asset upload(String path, TempBlob tempBlob, Payload payload, AssetKind assetKind) throws IOException {
  checkNotNull(path);
  checkNotNull(tempBlob);
  if (assetKind != HELM_PACKAGE && assetKind != HELM_PROVENANCE) {
    throw new IllegalArgumentException("Unsupported assetKind: " + assetKind);
  }

  StorageTx tx = UnitOfWork.currentTx();
  InputStream inputStream = tempBlob.get();
  HelmAttributes attributes = helmAttributeParser.getAttributes(assetKind, inputStream);
  final Asset asset =
      helmFacet.findOrCreateAsset(tx, path, assetKind, attributes);
  helmFacet.saveAsset(tx, asset, tempBlob, payload);
  return asset;
}
 
Example #6
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Saves the package root JSON content by persisting content into root asset's blob. It also removes some transient
 * fields from JSON document.
 */
static void savePackageRoot(final StorageTx tx,
                            final Asset packageRootAsset,
                            final NestedAttributesMap packageRoot) throws IOException
{
  packageRoot.remove(NpmMetadataUtils.META_ID);
  packageRoot.remove("_attachments");
  packageRootAsset.formatAttributes().set(
      NpmAttributes.P_NPM_LAST_MODIFIED, NpmMetadataUtils.maintainTime(packageRoot).toDate()
  );
  storeContent(
      tx,
      packageRootAsset,
      new StreamCopier<Supplier<InputStream>>(
          outputStream -> serialize(new OutputStreamWriter(outputStream, UTF_8), packageRoot),
          inputStream -> () -> inputStream).read(),
      AssetKind.PACKAGE_ROOT
  );
  tx.saveAsset(packageRootAsset);
}
 
Example #7
Source File: RawUploadHandlerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void testNormalizePath(String directory, String file, String expectedPath) throws IOException {
  reset(rawFacet);
  ComponentUpload component = new ComponentUpload();

  component.getFields().put("directory", directory);

  AssetUpload asset = new AssetUpload();
  asset.getFields().put("filename", file);
  asset.setPayload(jarPayload);
  component.getAssetUploads().add(asset);

  when(assetPayload.componentId()).thenReturn(new DetachedEntityId("foo"));
  when(attributesMap.get(Asset.class)).thenReturn(assetPayload);
  when(content.getAttributes()).thenReturn(attributesMap);
  when(rawFacet.put(any(), any())).thenReturn(content);
  underTest.handle(repository, component);

  ArgumentCaptor<String> pathCapture = ArgumentCaptor.forClass(String.class);
  verify(rawFacet).put(pathCapture.capture(), any(PartPayload.class));

  String path = pathCapture.getValue();
  assertNotNull(path);
  assertThat(path, is(expectedPath));
}
 
Example #8
Source File: OrientNpmHostedFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreMetadata
@Override
public void deleteDistTags(final NpmPackageId packageId, final String tag, final Payload payload) throws IOException
{
  checkNotNull(packageId);
  checkNotNull(tag);
  log.debug("Deleting distTags: {}", packageId);

  if ("latest".equals(tag)) {
    throw new IOException("Unable to delete latest");
  }

  StorageTx tx = UnitOfWork.currentTx();
  Asset packageRootAsset = findPackageRootAsset(tx, tx.findBucket(getRepository()), packageId);
  if (packageRootAsset == null) {
    return;
  }

  try {
    NpmFacetUtils.deleteDistTags(tx, packageRootAsset, tag);
  }
  catch (IOException e) {
    log.info("Unable to obtain dist-tags for {}", packageId.id(), e);
  }
}
 
Example #9
Source File: AssetXOBuilderTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() {
  Map<String,Object> checksum = Maps.newHashMap(ImmutableMap.of(HashAlgorithm.SHA1.name(), "87acec17cd9dcd20a716cc2cf67417b71c8a7016"));

  when(assetOne.name()).thenReturn("nameOne");
  when(assetOne.getEntityMetadata()).thenReturn(assetOneEntityMetadata);
  when(assetOne.attributes()).thenReturn(new NestedAttributesMap(Asset.CHECKSUM, checksum));

  when(assetOneORID.toString()).thenReturn("assetOneORID");

  when(assetOneEntityMetadata.getId()).thenReturn(assetOneEntityId);
  when(assetOneEntityId.getValue()).thenReturn("assetOne");

  when(repository.getName()).thenReturn("maven-releases");
  when(repository.getUrl()).thenReturn("http://localhost:8081/repository/maven-releases");
  when(repository.getFormat()).thenReturn(new Format("maven2") {});
}
 
Example #10
Source File: OrientNpmHostedFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Asset putPackage(final Map<String, Object> packageJson, final TempBlob tempBlob) throws IOException {
  checkNotNull(packageJson);
  checkNotNull(tempBlob);

  log.debug("Storing package: {}", packageJson);

  checkNotNull(packageJson.get(NpmAttributes.P_NAME), "Uploaded package is invalid, or is missing package.json");

  NestedAttributesMap metadata = createFullPackageMetadata(
      new NestedAttributesMap("metadata", packageJson),
      getRepository().getName(),
      tempBlob.getHashes().get(HashAlgorithm.SHA1).toString(),
      null,
      extractAlwaysPackageVersion);

  NpmPackageId packageId = NpmPackageId.parse((String) metadata.get(NpmAttributes.P_NAME));

  return putPackage(packageId, metadata, tempBlob);
}
 
Example #11
Source File: OrientComponentAssetTestHelper.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean assetWithComponentExists(
    final Repository repository,
    final String path,
    final String group,
    final String name,
    final String version)
{
  return findAssetByName(repository, path)
      .map(Asset::componentId)
      .flatMap(componentId -> {
        try (StorageTx tx = repository.facet(StorageFacet.class).txSupplier().get()) {
          tx.begin();
          return Optional.ofNullable(tx.findComponent(componentId));
        }
      })
      .filter(component -> group == null || Objects.equals(component.group(), group))
      .filter(component -> Objects.equals(component.name(), name))
      .filter(component -> Objects.equals(component.version(), version))
      .isPresent();
}
 
Example #12
Source File: BrowseNodeEntityAdapterTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void createEntities(final ODatabaseDocumentTx db) {
  bucket = new Bucket();
  bucket.setRepositoryName(REPOSITORY_NAME);
  bucket.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>()));
  bucketEntityAdapter.addEntity(db, bucket);

  component = new DefaultComponent();
  component.bucketId(EntityHelper.id(bucket));
  component.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>()));
  component.format(FORMAT_NAME);
  component.group("org").name("foo").version("1.0");
  componentEntityAdapter.addEntity(db, component);

  asset = new Asset();
  asset.bucketId(EntityHelper.id(bucket));
  asset.componentId(EntityHelper.id(component));
  asset.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>()));
  asset.format(FORMAT_NAME);
  asset.name("/org/foo/1.0/foo-1.0.jar");
  assetEntityAdapter.addEntity(db, asset);
}
 
Example #13
Source File: CocoapodsProxyFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalTouchMetadata
public void setCacheInfo(final Content content, final CacheInfo cacheInfo) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();

  Asset asset = Content.findAsset(tx, tx.findBucket(getRepository()), content);
  if (asset == null) {
    log.debug(
        "Attempting to set cache info for non-existent Cocoapods asset {}",
        content.getAttributes().require(Asset.class)
    );
    return;
  }

  log.debug("Updating cacheInfo of {} to {}", asset, cacheInfo);
  CacheInfo.applyToAsset(asset, cacheInfo);
  tx.saveAsset(asset);
}
 
Example #14
Source File: OrientPyPiHostedFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalStoreBlob
@Nullable
public Content getRootIndex() {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());

  Asset asset = findAsset(tx, bucket, INDEX_PATH_PREFIX);
  if (asset == null) {
    try {
      return createAndSaveRootIndex(bucket);
    }
    catch (IOException e) {
      log.error("Unable to create root index for repository: {}", getRepository().getName(), e);
      return null;
    }
  }

  return toContent(asset, tx.requireBlob(asset.requireBlobRef()));
}
 
Example #15
Source File: MavenProxyFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalTouchMetadata
protected void indicateVerified(final Context context, final Content content, final CacheInfo cacheInfo)
    throws IOException
{
  final StorageTx tx = UnitOfWork.currentTx();
  final Bucket bucket = tx.findBucket(getRepository());
  final MavenPath path = mavenPath(context);

  // by EntityId
  Asset asset = Content.findAsset(tx, bucket, content);
  if (asset == null) {
    // by format coordinates
    asset = findAsset(tx, bucket, path);
  }
  if (asset == null) {
    log.debug("Attempting to set cache info for non-existent maven asset {}", path.getPath());
    return;
  }

  log.debug("Updating cacheInfo of {} to {}", path.getPath(), cacheInfo);
  CacheInfo.applyToAsset(asset, cacheInfo);
  tx.saveAsset(asset);
}
 
Example #16
Source File: AptRestoreFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalStoreBlob
public Content restore(final AssetBlob assetBlob, final String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Asset asset;
  AptFacet aptFacet = facet(AptFacet.class);
  if (isDebPackageContentType(path)) {
    ControlFile controlFile = AptPackageParser.getDebControlFile(assetBlob.getBlob());
    asset = aptFacet.findOrCreateDebAsset(tx, path, new PackageInfo(controlFile));
  }
  else {
    asset = aptFacet.findOrCreateMetadataAsset(tx, path);
  }

  tx.attachBlob(asset, assetBlob);
  Content.applyToAsset(asset, Content.maintainLastModified(asset, new AttributesMap()));
  tx.saveAsset(asset);
  return FacetHelper.toContent(asset, assetBlob.getBlob());
}
 
Example #17
Source File: CocoapodsFacetImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void shouldStorePodAssetAndComponent() throws IOException {
  when(storageTx.findAssetWithProperty(any(), any(), eq(bucket))).thenReturn(null);
  when(storageTx.findComponents(any(), any())).thenReturn(Collections.emptyList());
  component = spy(new DefaultComponent());
  when(storageTx.createComponent(any(), any())).thenReturn(component);
  asset = spy(new Asset());
  configAttributeMap();
  when(storageTx.createAsset(any(), eq(component))).thenReturn(asset);

  cocoapodsFacet.getOrCreateAsset(PATH, content, true);

  verify(storageTx, times(1)).createAsset(bucket, component);
  verify(storageTx, times(1)).saveAsset(asset);
  verify(storageTx, times(1)).createComponent(bucket, format);
  verify(storageTx, times(1)).saveComponent(component);

  assertEquals(PATH, asset.name());
  assertEquals(NAME, component.name());
  assertEquals(VERSION, component.version());
}
 
Example #18
Source File: CocoapodsBrowseNodeGeneratorTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void shouldRemoveRestParametersFromAssetName() {
  final String assetName = "assetName?param=value";
  final String assetViewName = "assetName";
  final String assetPath = "path/to/" + assetName;
  final String componentGroup = "testGroup";
  final String componentName = "testComponentName";
  final String componentVersion = "testVersion";

  Component component = createComponent(componentName, componentGroup, componentVersion);
  Asset asset = createAsset(assetPath);

  List<BrowsePaths> pathsAssetWithComponent = generator.computeAssetPaths(asset, component);
  List<BrowsePaths> pathsAsset = generator.computeAssetPaths(asset, component);

  assertPaths(asList("pods", componentGroup, componentName, componentVersion, assetViewName), pathsAsset, false);
  assertPaths(asList("pods", componentGroup, componentName, componentVersion, assetViewName), pathsAssetWithComponent, false);
}
 
Example #19
Source File: NpmRepairPackageRootComponent.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private String calculateIntegrity(final Asset asset, final Blob blob, final String algorithm) {
  try {
    HashCode hash;
    if (algorithm.equalsIgnoreCase(SHA1.name())) {
      hash = hash(SHA1, blob.getInputStream());
    }
    else {
      hash = hash(SHA512, blob.getInputStream());
    }

    return algorithm + "-" + Base64.getEncoder().encodeToString(hash.asBytes());
  }
  catch (IOException e) {
    log.error("Failed to calculate hash for asset {}", asset.name(), e);
  }
  return "";
}
 
Example #20
Source File: ConanProxyFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalTouchBlob
@Nullable
protected String getUrlForConanManifest(final ConanCoords coords) {
  String downloadUrlsAssetPath = OrientConanProxyHelper.getProxyAssetPath(coords, DOWNLOAD_URL);
  StorageTx tx = UnitOfWork.currentTx();

  Asset downloadUrlAsset = findAsset(tx, tx.findBucket(getRepository()), downloadUrlsAssetPath);
  if (downloadUrlAsset == null) {
    // NEXUS-22735. Looks like it was search request. So let's look up conanmanifest url from digest
    String digestAssetPath = OrientConanProxyHelper.getProxyAssetPath(coords, DIGEST);
    Asset digest = findAsset(tx, tx.findBucket(getRepository()), digestAssetPath);
    if (digest == null) {
      throw new IllegalStateException("DIGEST not found");
    }
    return conanUrlIndexer.findUrl(tx.requireBlob(digest.blobRef()).getInputStream(), CONAN_MANIFEST.getFilename());
  }
  return conanUrlIndexer.findUrl(tx.requireBlob(downloadUrlAsset.blobRef()).getInputStream(), CONAN_MANIFEST.getFilename());
}
 
Example #21
Source File: RepositoryBrowseResource.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private String getListItemPath(final Repository repository,
                               final BrowseNode browseNode,
                               final Asset asset)
{
  final String listItemPath;

  if (asset == null) {
    listItemPath = escapeHelper.uri(browseNode.getName()) + "/";
  }
  else {
    listItemPath = repository.getUrl() + "/" +
        Stream.of(asset.name().split("/"))
            .map(escapeHelper::uri)
            .collect(Collectors.joining("/"));
  }

  return listItemPath;
}
 
Example #22
Source File: OrientRebuildBrowseNodeServiceTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Asset createMockAsset(final String id, final String componentId) {
  Asset asset = mock(Asset.class);
  when(asset.getEntityMetadata()).thenReturn(mock(EntityMetadata.class));

  EntityId entityId = new DetachedEntityId(id);
  when(asset.getEntityMetadata().getId()).thenReturn(entityId);

  if (componentId != null) {
    EntityId componentEntityId = new DetachedEntityId(componentId);
    when(asset.componentId()).thenReturn(componentEntityId);
  }

  return asset;
}
 
Example #23
Source File: AssetPathBrowseNodeGeneratorTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void computeComponentPathsWithComponent() {
  Component component = createComponent("component", "group", "1.0.0");
  Asset asset = createAsset("asset/path/foo");

  List<BrowsePaths> paths = generator.computeComponentPaths(asset, component);

  assertPaths(asList("asset", "path", "foo"), paths);
}
 
Example #24
Source File: AssetPathBrowseNodeGeneratorTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void computeAssetPathsWithComponent() {
  Component component = createComponent("component", "group", "1.0.0");
  Asset asset = createAsset("asset/path/foo");

  List<BrowsePaths> paths = generator.computeAssetPaths(asset, component);

  assertPaths(asList("asset", "path", "foo"), paths);
}
 
Example #25
Source File: RFacetUtils.java    From nexus-repository-r with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Browse all assets in bucket by asset kind
 *
 * @return {@link Iterable} of assets or empty one
 */
public static Iterable<Asset> browseAllAssetsByKind(final StorageTx tx,
                                                    final Bucket bucket,
                                                    final AssetKind assetKind)
{
  final Query query = builder()
      .where(P_ATTRIBUTES + "." + RFormat.NAME + "." + P_ASSET_KIND)
      .eq(assetKind.name())
      .build();
  return tx.browseAssets(query, bucket);
}
 
Example #26
Source File: RestoreMetadataTask.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
protected void integrityCheckFailedHandler(final Asset asset) {
  Bucket bucket = bucketStore.getById(asset.bucketId());
  Repository repository = repositoryManager.get(bucket.getRepositoryName());

  log.debug("Removing asset {} from repository {}, blob integrity check failed", asset.name(), repository.getName());

  boolean dryRun = getConfiguration().getBoolean(DRY_RUN, false);
  if (!dryRun) {
    maintenanceService.deleteAsset(repository, asset);
  }
}
 
Example #27
Source File: RepairMetadataComponent.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
protected void doRepairRepositoryWith(final Repository repository,
                                      final BiFunction<Repository, Iterable<Asset>, String> function)
{
  String lastId = BEGINNING_ID;

  while (lastId != null) {
    try {
      lastId = processBatchWith(repository, lastId, function);
    }
    catch (Exception e) {
      propagateIfPossible(e, RuntimeException.class);
      throw new RuntimeException(e);
    }
  }
}
 
Example #28
Source File: P2ProxyIT.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void retrieveCompositeArtifactsJarFromProxyWhenRemoteOnline() throws Exception {
  assertThat(status(proxyClient.get(COMPOSITE_ARTIFACTS_JAR)), is(HttpStatus.OK));

  final Asset asset = findAsset(proxyRepo, COMPOSITE_ARTIFACTS_JAR);
  assertThat(asset.name(), is(equalTo(COMPOSITE_ARTIFACTS_JAR)));
  assertThat(asset.format(), is(equalTo(FORMAT_NAME)));
}
 
Example #29
Source File: ComposerProxyIT.java    From nexus-repository-composer with Eclipse Public License 1.0 5 votes vote down vote up
public void retrieveListJSONFromProxyWhenRemoteOnline() throws Exception {
  assertThat(status(proxyClient.get(VALID_LIST_URL)), is(HttpStatus.OK));

  final Asset asset = findAsset(proxyRepo, FILE_LIST);
  assertThat(asset.name(), is(equalTo(FILE_LIST)));
  assertThat(asset.contentType(), is(equalTo(MIME_TYPE_JSON)));
  assertThat(asset.format(), is(equalTo(FORMAT_NAME)));
}
 
Example #30
Source File: RepositoryResourceTestSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
Asset getMockedAsset(String name, String idValue) {
  AssetMocks assetMocks = new AssetMocks();
  MockitoAnnotations.initMocks(assetMocks);

  when(assetMocks.asset.name()).thenReturn(name);
  when(assetMocks.asset.getEntityMetadata()).thenReturn(assetMocks.assetEntityMetadata);
  NestedAttributesMap attributes = new NestedAttributesMap("attributes", ImmutableMap.of(Asset.CHECKSUM, testChecksum));
  when(assetMocks.asset.attributes()).thenReturn(attributes);

  when(assetMocks.assetEntityMetadata.getId()).thenReturn(assetMocks.assetEntityId);
  when(assetMocks.assetEntityId.getValue()).thenReturn(idValue);

  return assetMocks.asset;
}