Package org.sonatype.nexus.proxy.item

Examples of org.sonatype.nexus.proxy.item.StorageFileItem


  protected void testCreateEventWithPomFile(
      Class<? extends RepositoryItemEvent> eventClass) throws Exception {
    ArtifactUsageEventInspector eventInspector = new ArtifactUsageEventInspector();
    ArtifactUsageCalculator calculator = mock(ArtifactUsageCalculator.class);
    eventInspector.setArtifactUsageCalculator(calculator);
    StorageFileItem item = mock(StorageFileItem.class);
    when(item.getPath()).thenReturn("some.pom");
    RepositoryItemEvent event = mock(eventClass);
    when(event.getItem()).thenReturn(item);

    eventInspector.inspect(event);
View Full Code Here


  public void testRemoteEventWithPomFile() throws Exception {
    ArtifactUsageEventInspector eventInspector = new ArtifactUsageEventInspector();
    ArtifactUsageCalculator calculator = mock(ArtifactUsageCalculator.class);
    eventInspector.setArtifactUsageCalculator(calculator);
    StorageFileItem item = mock(StorageFileItem.class);
    when(item.getPath()).thenReturn("some.pom");
    RepositoryItemEvent event = mock(RepositoryItemEventDelete.class);
    when(event.getItem()).thenReturn(item);

    eventInspector.inspect(event);
View Full Code Here

  protected void testEventWithJarFile(
      Class<? extends RepositoryItemEvent> eventClass) throws Exception {
    ArtifactUsageEventInspector eventInspector = new ArtifactUsageEventInspector();
    ArtifactUsageCalculator calculator = mock(ArtifactUsageCalculator.class);
    eventInspector.setArtifactUsageCalculator(calculator);
    StorageFileItem item = mock(StorageFileItem.class);
    when(item.getPath()).thenReturn("some.jar");
    RepositoryItemEvent event = mock(eventClass);
    when(event.getItem()).thenReturn(item);

    eventInspector.inspect(event);
View Full Code Here

    return (DefaultArtifactUsageCalculator) this
        .lookup(ArtifactUsageCalculator.class);
  }

  public void testGetGavFromSimplePom() throws Exception {
    StorageFileItem pomFileItem = getMockStorageFileItem("src/test/remote-repo/test/artifactusage/simple-artifact/1.0/simple-artifact-1.0.pom");

    GAV artifact = ((DefaultArtifactUsageCalculator) this
        .lookup(ArtifactUsageCalculator.class))
        .getArtifactForStorageItem(pomFileItem);
    assertNotNull(artifact);
View Full Code Here

    assertEquals("simple-artifact", artifact.getArtifactId());
    assertEquals("1.0", artifact.getVersion());
  }

  public void testGetGavFromPomWithParent() throws Exception {
    StorageFileItem pomFileItem = getMockStorageFileItem("src/test/remote-repo/test/artifactusage/artifact-with-parent/1.0/artifact-with-parent-1.0.pom");

    GAV artifact = ((DefaultArtifactUsageCalculator) this
        .lookup(ArtifactUsageCalculator.class))
        .getArtifactForStorageItem(pomFileItem);
    assertNotNull(artifact);
View Full Code Here

    assertEquals("1.9.1", artifact.getVersion());

  }

  public void testGetGavFromPomWithProperties() throws Exception {
    StorageFileItem pomFileItem = getMockStorageFileItem("src/test/remote-repo/test/artifactusage/artifact-with-properties/1.0/artifact-with-properties-1.0.pom");

    GAV artifact = ((DefaultArtifactUsageCalculator) this
        .lookup(ArtifactUsageCalculator.class))
        .getArtifactForStorageItem(pomFileItem);
    assertNotNull(artifact);
View Full Code Here

  StorageFileItem getMockStorageFileItem(String path) throws IOException {
    InputStream input = new FileInputStream(path);
    RepositoryItemUid itemUid = Mockito.mock(RepositoryItemUid.class);
    Mockito.when(itemUid.getPath()).thenReturn(path);

    StorageFileItem pomFileItem = Mockito.mock(StorageFileItem.class);
    Mockito.when(pomFileItem.getRepositoryItemUid()).thenReturn(itemUid);
    Mockito.when(pomFileItem.getInputStream()).thenReturn(input);
    Mockito.when(pomFileItem.getModified()).thenReturn(
        System.currentTimeMillis());
    return pomFileItem;
  }
View Full Code Here

   * @return last discovery status.
   */
  public DiscoveryStatus read()
      throws IOException
  {
    final StorageFileItem file = getFileItem();
    if (file == null) {
      return null;
    }

    final Properties props = new Properties();
    try (final InputStream inputStream = file.getInputStream()) {
      props.load(inputStream);
      final DStatus lastDiscoveryStatus = DStatus.valueOf(props.getProperty(LAST_DISCOVERY_STATUS_KEY));
      final String lastDiscoveryStrategy = props.getProperty(LAST_DISCOVERY_STRATEGY_KEY, "unknown");
      final String lastDiscoveryMessage = props.getProperty(LAST_DISCOVERY_MESSAGE_KEY, "");
      final long lastDiscoveryTimestamp =
View Full Code Here

      }
      catch (IOException e) {
        throw new LocalStorageException("Could not get the content from the ContentLocator!", e);
      }

      StorageFileItem storedFile = (StorageFileItem) retrieveItem(false, request);

      String sha1Hash = storedFile.getRepositoryItemAttributes().get(DigestCalculatingInspector.DIGEST_SHA1_KEY);

      String md5Hash = storedFile.getRepositoryItemAttributes().get(DigestCalculatingInspector.DIGEST_MD5_KEY);

      if (!StringUtils.isEmpty(sha1Hash)) {
        request.setRequestPath(storedFile.getPath() + ".sha1");

        storeItem(false, new DefaultStorageFileItem(this, request, true, true, new StringContentLocator(
            sha1Hash)));
      }

      if (!StringUtils.isEmpty(md5Hash)) {
        request.setRequestPath(storedFile.getPath() + ".md5");

        storeItem(false, new DefaultStorageFileItem(this, request, true, true, new StringContentLocator(
            md5Hash)));
      }
    }
View Full Code Here

      }
      catch (IOException e) {
        throw new LocalStorageException("Could not get the content from the ContentLocator!", e);
      }

      StorageFileItem storedFile = (StorageFileItem) retrieveItem(fromTask, new ResourceStoreRequest(item));

      ResourceStoreRequest req = new ResourceStoreRequest(storedFile);

      String sha1Hash = storedFile.getRepositoryItemAttributes().get(DigestCalculatingInspector.DIGEST_SHA1_KEY);

      String md5Hash = storedFile.getRepositoryItemAttributes().get(DigestCalculatingInspector.DIGEST_MD5_KEY);

      if (!StringUtils.isEmpty(sha1Hash)) {
        req.setRequestPath(item.getPath() + ".sha1");

        storeItem(fromTask, new DefaultStorageFileItem(this, req, true, true, new StringContentLocator(
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.item.StorageFileItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.