org.sonatype.nexus.repository.Format Java Examples

The following examples show how to use org.sonatype.nexus.repository.Format. 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: CleanupConfigurationValidatorTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  when(configuration.getRepositoryName()).thenReturn(REPO_NAME);
  when(configuration.getAttributes()).thenReturn(attributes);
  when(cleanupAttributes.containsKey(POLICY_NAME_KEY)).thenReturn(true);
  when(cleanupAttributes.get(POLICY_NAME_KEY)).thenReturn(ImmutableSet.of(POLICY_NAME));
  when(attributes.containsKey(CLEANUP_KEY)).thenReturn(true);
  when(attributes.get(CLEANUP_KEY)).thenReturn(cleanupAttributes);
  when(cleanupPolicyStorage.get(POLICY_NAME)).thenReturn(cleanupPolicy);
  when(cleanupPolicy.getFormat()).thenReturn(FORMAT);
  when(constraintFactory.createViolation(anyString(), anyString())).thenReturn(constraintViolation);

  recipes.add(recipe);
  when(repositoryManager.getAllSupportedRecipes()).thenReturn(recipes);
  when(configuration.getRecipeName()).thenReturn(FORMAT + "-" + ProxyType.NAME);
  when(recipe.getType()).thenReturn(new ProxyType());
  when(recipe.getFormat()).thenReturn(new Format(FORMAT){});

  underTest = new CleanupConfigurationValidator(constraintFactory, repositoryManager, cleanupPolicyStorage);
}
 
Example #2
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 #3
Source File: UploadManagerImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() {
  when(handlerA.getDefinition()).thenReturn(uploadA);
  when(handlerB.getDefinition()).thenReturn(uploadB);
  when(handlerA.getValidatingComponentUpload(componentUploadCaptor.capture())).thenReturn(validatingComponentUpload);
  when(handlerB.getValidatingComponentUpload(componentUploadCaptor.capture())).thenReturn(validatingComponentUpload);
  when(validatingComponentUpload.getComponentUpload()).thenAnswer(i -> componentUploadCaptor.getValue());

  when(repository.getFormat()).thenReturn(new Format("a")
  {
  });
  when(repository.getType()).thenReturn(new HostedType());
  when(repository.getConfiguration()).thenReturn(configuration);
  when(configuration.isOnline()).thenReturn(true);

  Map<String, UploadHandler> handlers = new HashMap<>();
  handlers.put("a", handlerA);
  handlers.put("b", handlerB);

  underTest = new UploadManagerImpl(handlers, blobStoreAwareMultipartHelper);
}
 
Example #4
Source File: DeleteFolderServiceImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  when(repository.facet(ComponentMaintenance.class)).thenReturn(componentMaintenance);
  when(repository.getName()).thenReturn("repo");
  when(repository.getFormat()).thenReturn(new Format("maven2") { });
  when(configuration.getMaxNodes()).thenReturn(1);
  when(browseNodeStore.getByPath(repository.getName(), Arrays.asList("com", "sonatype"), 1)).thenReturn(browseNodes);
  when(variableResolverAdapterManager.get("maven2")).thenReturn(assetVariableResolver);
  when(assetVariableResolver.fromAsset(any(Asset.class))).thenReturn(variableSource);
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(storageFacet.txSupplier()).thenReturn(Suppliers.ofInstance(storageTx));
  when(securityHelper.isPermitted(new RepositoryViewPermission(repository, BreadActions.DELETE)))
      .thenReturn(new boolean[]{false});

  service = new DeleteFolderServiceImpl(browseNodeStore, configuration, assetStore, contentPermissionChecker,
      variableResolverAdapterManager, securityHelper);
}
 
Example #5
Source File: RepositoryViewPrivilegeDescriptor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Inject
public RepositoryViewPrivilegeDescriptor(final RepositoryManager repositoryManager, final List<Format> formats) {
  super(TYPE, repositoryManager, formats);
  this.formFields = ImmutableList.of(
      new StringTextFormField(
          P_FORMAT,
          messages.format(),
          messages.formatHelp(),
          FormField.MANDATORY
      ),
      new RepositoryCombobox(
          P_REPOSITORY,
          messages.repository(),
          messages.repositoryHelp(),
          true
      ).includeAnEntryForAllRepositories(),
      new StringTextFormField(
          P_ACTIONS,
          messages.actions(),
          messages.actionsHelp(),
          FormField.MANDATORY
      )
  );
}
 
Example #6
Source File: OrientBrowseNodeManagerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private Asset createAsset(final String assetName, final String assetId, final String format, final EntityId componentId) {
  EntityMetadata entityMetadata = mock(EntityMetadata.class);
  when(entityMetadata.getId()).thenReturn(new DetachedEntityId(assetId));

  Asset asset = mock(Asset.class);
  when(asset.getEntityMetadata()).thenReturn(entityMetadata);
  when(asset.name()).thenReturn(assetName);
  when(asset.format()).thenReturn(format);
  when(asset.blobRef()).thenReturn(mock(BlobRef.class));

  if (componentId != null) {
    when(asset.componentId()).thenReturn(componentId);
  }

  Format fmt = mock(Format.class);
  when(fmt.getValue()).thenReturn(format);
  when(repository.getFormat()).thenReturn(fmt);

  return asset;
}
 
Example #7
Source File: RepositoryAdminPrivilegeDescriptor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Inject
public RepositoryAdminPrivilegeDescriptor(final RepositoryManager repositoryManager, final List<Format> formats) {
  super(TYPE, repositoryManager, formats);
  this.formFields = ImmutableList.of(
      new StringTextFormField(
          P_FORMAT,
          messages.format(),
          messages.formatHelp(),
          FormField.MANDATORY
      ),
      new RepositoryCombobox(
          P_REPOSITORY,
          messages.repository(),
          messages.repositoryHelp(),
          true
      ).includeAnEntryForAllRepositories(),
      new StringTextFormField(
          P_ACTIONS,
          messages.actions(),
          messages.actionsHelp(),
          FormField.MANDATORY
      )
  );
}
 
Example #8
Source File: UploadManagerImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() {
  when(handlerA.getDefinition()).thenReturn(uploadA);
  when(handlerB.getDefinition()).thenReturn(uploadB);
  when(handlerA.getValidatingComponentUpload(componentUploadCaptor.capture())).thenReturn(validatingComponentUpload);
  when(handlerB.getValidatingComponentUpload(componentUploadCaptor.capture())).thenReturn(validatingComponentUpload);
  when(validatingComponentUpload.getComponentUpload()).thenAnswer(i -> componentUploadCaptor.getValue());

  when(repository.getFormat()).thenReturn(new Format("a")
  {
  });
  when(repository.getType()).thenReturn(new HostedType());
  when(repository.getConfiguration()).thenReturn(configuration);
  when(configuration.isOnline()).thenReturn(true);

  Map<String, UploadHandler> handlers = new HashMap<>();
  handlers.put("a", handlerA);
  handlers.put("b", handlerB);

  underTest = new UploadManagerImpl(handlers, blobStoreAwareMultipartHelper,
      Collections.singleton(componentUploadExtension));
}
 
Example #9
Source File: ComponentComponentTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() {
  objectMapper = new ObjectMapper();
  underTest = new ComponentComponent();
  underTest.setRepositoryManager(repositoryManager);
  underTest.setContentPermissionChecker(contentPermissionChecker);
  underTest.setVariableResolverAdapterManager(variableResolverAdapterManager);
  underTest.setMaintenanceService(maintenanceService);
  underTest.setBrowseService(browseService);
  underTest.setSelectorFactory(selectorFactory);
  underTest.setObjectMapper(objectMapper);
  underTest.setComponentFinders(componentFinders);
  underTest.setBucketStore(bucketStore);

  when(repositoryManager.get("testRepositoryName")).thenReturn(repository);
  when(repository.getName()).thenReturn("testRepositoryName");
  when(repository.getFormat()).thenReturn(new Format("testFormat") { });
  when(repository.facet(ComponentMaintenance.class)).thenReturn(componentMaintenance);
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(variableResolverAdapterManager.get("testFormat")).thenReturn(assetVariableResolver);
  when(storageFacet.txSupplier()).thenReturn(Suppliers.ofInstance(storageTx));
  when(componentFinders.get(any(String.class))).thenReturn(defaultComponentFinder);
}
 
Example #10
Source File: RepairMetadataComponentTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void whenFormatDoesNotMatchShouldNotRepair() {
  underTest = new RepairMetadataComponentForTest(repositoryManager, assetEntityAdapter, type, format)
  {
    @Override
    protected void doRepairRepository(final Repository repository) {
      throw new UnsupportedOperationException();
    }
  };

  when(repository.getFormat()).thenReturn(new Format("wrong") { });

  try {
    underTest.repairRepository(repository);
  }
  catch (Exception e) {
    fail("repair should not have been attempted");
  }
}
 
Example #11
Source File: RepairMetadataComponentTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public RepairMetadataComponentForTest(final RepositoryManager repositoryManager,
                                      final AssetEntityAdapter assetEntityAdapter,
                                      final Type type,
                                      final Format format)
{
  super(repositoryManager, assetEntityAdapter, type, format);
}
 
Example #12
Source File: UploadManagerImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testHandle_unsupportedRepositoryFormat() throws IOException {
  when(repository.getFormat()).thenReturn(new Format("c")
  {
  });

  expectExceptionOnUpload(repository, "Uploading components to 'c' repositories is unsupported");
}
 
Example #13
Source File: RepairMetadataComponentTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  type = new HostedType();
  format = new Format("value") { };

  repository = mock(Repository.class);
  when(repository.getFormat()).thenReturn(format);
  when(repository.getType()).thenReturn(type);
}
 
Example #14
Source File: GolangSecurityFacetTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setupConfig() throws Exception {
  when(request.getPath()).thenReturn("/some/path.txt");
  when(request.getAction()).thenReturn(HttpMethods.GET);

  when(repository.getFormat()).thenReturn(new Format("go") { });
  when(repository.getName()).thenReturn("GoSecurityFacetTest");

  golangSecurityFacet = new GolangSecurityFacet(securityContributor,
      variableResolverAdapter, contentPermissionChecker);

  golangSecurityFacet.attach(repository);
}
 
Example #15
Source File: LegacyViewServletTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void mockRepository() {
  when(repositoryManager.get(REPOSITORY_NAME)).thenReturn(repository);
  when(repository.getConfiguration()).thenReturn(configuration);
  when(repository.facet(ViewFacet.class)).thenReturn(viewFacet);
  when(repository.getFormat()).thenReturn(new Format("maven") { });
  when(configuration.isOnline()).thenReturn(true);
}
 
Example #16
Source File: LegacyViewServletTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void sendNotFoundWhenLegacyUrlAndFormatDoesNotMatch() throws Exception {
  when(repository.getFormat()).thenReturn(new Format("yum") { });
  when(request.getPathInfo()).thenReturn("/test-repo/content.txt");
  when(request.getRequestURI()).thenReturn("/content/sites/test-repo/content.txt");

  viewServlet.doService(request, response);
  ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class);
  verify(sender).send(eq(null), responseCaptor.capture(), eq(response));

  assertThat(responseCaptor.getValue().getStatus().getCode(), is(equalTo(NOT_FOUND)));
  assertThat(responseCaptor.getValue().getStatus().getMessage(), is(equalTo(NOT_FOUND_MESSAGE)));
}
 
Example #17
Source File: LegacyViewServletTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void sendNotFoundWhenLegacyUrlAndRepositoryNotFound() throws Exception {
  when(repository.getFormat()).thenReturn(new Format("raw") { });
  when(repositoryManager.get(REPOSITORY_NAME)).thenReturn(null);
  when(request.getPathInfo()).thenReturn("/test-repo/content.txt");
  when(request.getRequestURI()).thenReturn("/content/sites/test-repo/content.txt");

  viewServlet.doService(request, response);
  ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class);
  verify(sender).send(eq(null), responseCaptor.capture(), eq(response));

  assertThat(responseCaptor.getValue().getStatus().getCode(), is(equalTo(404)));
  assertThat(responseCaptor.getValue().getStatus().getMessage(), is(equalTo(NOT_FOUND_MESSAGE)));
}
 
Example #18
Source File: RawSecurityFacetTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setupConfig() throws Exception {
  when(request.getPath()).thenReturn("/some/path.txt");
  when(request.getAction()).thenReturn(HttpMethods.GET);

  when(repository.getFormat()).thenReturn(new Format("raw") { });
  when(repository.getName()).thenReturn("RawSecurityFacetTest");

  rawSecurityFacet = new RawSecurityFacet(securityContributor,
      variableResolverAdapter, contentPermissionChecker);

  rawSecurityFacet.attach(repository);
}
 
Example #19
Source File: NpmRepairPackageRootComponent.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public NpmRepairPackageRootComponent(final RepositoryManager repositoryManager,
                                     final AssetEntityAdapter assetEntityAdapter,
                                     final NpmPackageParser npmPackageParser,
                                     @Named(HostedType.NAME) final Type hostedType,
                                     @Named(NpmFormat.NAME) final Format npmFormat)
{
  super(repositoryManager, assetEntityAdapter, hostedType, npmFormat);
  this.npmPackageParser = checkNotNull(npmPackageParser);
}
 
Example #20
Source File: RebuildMaven2MetadataTask.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public RebuildMaven2MetadataTask(@Named(HostedType.NAME) final Type hostedType,
                                 @Named(Maven2Format.NAME) final Format maven2Format)
{
  this.hostedType = checkNotNull(hostedType);
  this.maven2Format = checkNotNull(maven2Format);
}
 
Example #21
Source File: PurgeMavenUnusedSnapshotsTask.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public PurgeMavenUnusedSnapshotsTask(@Named(GroupType.NAME) final Type groupType,
                                     @Named(HostedType.NAME) final Type hostedType,
                                     @Named(Maven2Format.NAME) final Format maven2Format)
{
  this.groupType = checkNotNull(groupType);
  this.hostedType = checkNotNull(hostedType);
  this.maven2Format = checkNotNull(maven2Format);
}
 
Example #22
Source File: OrientPyPiDeleteLegacyProxyAssetsTaskTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Repository mockRepository(final Format format, final Type type, final Asset... assets) {
  Repository repository = mock(Repository.class);
  when(repository.getFormat()).thenReturn(format);
  when(repository.getType()).thenReturn(type);

  StorageFacet facet = mock(StorageFacet.class);
  when(repository.facet(StorageFacet.class)).thenReturn(facet);

  StorageTx storageTx = mock(StorageTx.class);
  when(facet.txSupplier()).thenReturn(() -> storageTx);

  when(storageTx.browseAssets(any(Bucket.class))).thenReturn(Arrays.asList(assets));

  return repository;
}
 
Example #23
Source File: ComposerContentFacetImpl.java    From nexus-repository-composer with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public ComposerContentFacetImpl(@Named(ComposerFormat.NAME) final Format format,
                                final ComposerFormatAttributesExtractor composerFormatAttributesExtractor)
{
  this.format = checkNotNull(format);
  this.composerFormatAttributesExtractor = checkNotNull(composerFormatAttributesExtractor);
}
 
Example #24
Source File: AptRecipeSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
protected AptRecipeSupport(final HighAvailabilitySupportChecker highAvailabilitySupportChecker,
                           final Type type,
                           final Format format)
{
  super(type, format);
  this.highAvailabilitySupportChecker = highAvailabilitySupportChecker;
}
 
Example #25
Source File: UploadManagerImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testHandle() throws IOException, FileUploadException {
  BlobStoreMultipartForm uploadedForm = new BlobStoreMultipartForm();
  TempBlobFormField field = new TempBlobFormField("asset1", "foo.jar", mock(TempBlob.class));
  uploadedForm.putFile("asset1", field);
  when(blobStoreAwareMultipartHelper.parse(anyObject(), anyObject())).thenReturn(uploadedForm);
  when(handlerA.handle(anyObject(), anyObject())).thenReturn(mock(UploadResponse.class));

  underTest.handle(repository, request);

  verify(handlerA, times(1)).handle(repository, componentUploadCaptor.getValue());
  verify(handlerB, never()).handle(anyObject(), anyObject());

  // Try the other, to be sure!
  reset(handlerA, handlerB);
  when(handlerB.getDefinition()).thenReturn(uploadB);
  when(handlerB.getValidatingComponentUpload(anyObject())).thenReturn(validatingComponentUpload);
  when(handlerB.handle(anyObject(), anyObject())).thenReturn(mock(UploadResponse.class));

  when(repository.getFormat()).thenReturn(new Format("b")
  {
  });

  underTest.handle(repository, request);

  verify(handlerB, times(1)).handle(repository, componentUploadCaptor.getValue());
  verify(handlerA, never()).handle(anyObject(), anyObject());
}
 
Example #26
Source File: UploadManagerImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testHandle() throws IOException, FileUploadException {
  BlobStoreMultipartForm uploadedForm = new BlobStoreMultipartForm();
  TempBlobFormField field = new TempBlobFormField("asset1", "foo.jar", mock(TempBlob.class));
  uploadedForm.putFile("asset1", field);
  when(blobStoreAwareMultipartHelper.parse(anyObject(), anyObject())).thenReturn(uploadedForm);
  when(handlerA.handle(anyObject(), anyObject())).thenReturn(mock(UploadResponse.class));

  underTest.handle(repository, request);

  verify(handlerA, times(1)).handle(repository, componentUploadCaptor.getValue());
  verify(handlerB, never()).handle(anyObject(), anyObject());

  // Try the other, to be sure!
  reset(handlerA, handlerB);
  when(handlerB.getDefinition()).thenReturn(uploadB);
  when(handlerB.getValidatingComponentUpload(anyObject())).thenReturn(validatingComponentUpload);
  when(handlerB.handle(anyObject(), anyObject())).thenReturn(mock(UploadResponse.class));

  when(repository.getFormat()).thenReturn(new Format("b")
  {
  });

  underTest.handle(repository, request);

  verify(handlerB, times(1)).handle(repository, componentUploadCaptor.getValue());
  verify(handlerA, never()).handle(anyObject(), anyObject());
}
 
Example #27
Source File: SimpleApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static Repository createRepository(final Type type) throws Exception {
  Repository repository = new RepositoryImpl(mock(EventManager.class), type, new Format("test-format")
  {
  });
  repository.init(config("my-repo"));
  return repository;
}
 
Example #28
Source File: StorageTxImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Guarded(by = ACTIVE)
public Component createComponent(final Bucket bucket, final Format format) {
  checkNotNull(bucket);
  checkNotNull(format);

  Component component = componentFactory.createComponent();
  component.bucketId(id(bucket));
  component.format(format.toString());
  component.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>()));
  return component;
}
 
Example #29
Source File: CleanupConfigurationValidator.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nullable
@Override
public ConstraintViolation<?> validate(final Configuration configuration) {
  List<CleanupPolicy> cleanupPolicies = getCleanupPolicy(configuration);

  if (!cleanupPolicies.isEmpty()) {
    Optional<Format> format = getConfigurationFormat(configuration);
    if (format.isPresent()) {
      // report on the first one oly allowing
      return validCleanupFormat(configuration.getRepositoryName(), format.get().getValue(), cleanupPolicies.get(0));
    }
  }
  return null;
}
 
Example #30
Source File: RepairMetadataComponent.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public RepairMetadataComponent(final RepositoryManager repositoryManager,
                               final AssetEntityAdapter assetEntityAdapter,
                               final Type type,
                               final Format format)
{
  this.repositoryManager = checkNotNull(repositoryManager);
  this.assetEntityAdapter = checkNotNull(assetEntityAdapter);
  this.type = checkNotNull(type);
  this.format = checkNotNull(format);
}