org.sonatype.nexus.repository.types.GroupType Java Examples

The following examples show how to use org.sonatype.nexus.repository.types.GroupType. 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: RestoreMetadataTask.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void blobStoreIntegrityCheck(final boolean integrityCheck, final String blobStoreId) {
  if (!integrityCheck) {
    log.warn("Integrity check operation not selected");
    return;
  }

  BlobStore blobStore = blobStoreManager.get(blobStoreId);

  if (blobStore == null) {
    log.error("Unable to find blob store '{}' in the blob store manager", blobStoreId);
    return;
  }

  StreamSupport.stream(repositoryManager.browseForBlobStore(blobStoreId).spliterator(), false)
      .filter(r -> !(r.getType() instanceof GroupType))
      .forEach(repository -> integrityCheckStrategies
          .getOrDefault(repository.getFormat().getValue(), defaultIntegrityCheckStrategy)
          .check(repository, blobStore, this::isCanceled, this::integrityCheckFailedHandler)
      );
}
 
Example #2
Source File: BrowseServiceImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Inject
public BrowseServiceImpl(@Named(GroupType.NAME) final Type groupType,
                         final ComponentEntityAdapter componentEntityAdapter,
                         final VariableResolverAdapterManager variableResolverAdapterManager,
                         final ContentPermissionChecker contentPermissionChecker,
                         final AssetEntityAdapter assetEntityAdapter,
                         final BrowseAssetIterableFactory browseAssetIterableFactory,
                         final BrowseAssetsSqlBuilder browseAssetsSqlBuilder,
                         final BrowseComponentsSqlBuilder browseComponentsSqlBuilder,
                         final BucketStore bucketStore,
                         final RepositoryManager repositoryManager)
{
  this.groupType = checkNotNull(groupType);
  this.componentEntityAdapter = checkNotNull(componentEntityAdapter);
  this.variableResolverAdapterManager = checkNotNull(variableResolverAdapterManager);
  this.contentPermissionChecker = checkNotNull(contentPermissionChecker);
  this.assetEntityAdapter = checkNotNull(assetEntityAdapter);
  this.browseAssetIterableFactory = checkNotNull(browseAssetIterableFactory);
  this.browseAssetsSqlBuilder = checkNotNull(browseAssetsSqlBuilder);
  this.browseComponentsSqlBuilder = checkNotNull(browseComponentsSqlBuilder);
  this.bucketStore = checkNotNull(bucketStore);
  this.repositoryManager = checkNotNull(repositoryManager);
}
 
Example #3
Source File: BrowseServiceImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() {
  results = asList(assetOne, assetTwo);

  when(queryOptions.getContentAuth()).thenReturn(true);

  when(assetOneORID.toString()).thenReturn("assetOne");
  when(componentOneORID.toString()).thenReturn("componentOne");

  when(mavenReleases.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(mavenReleases.getName()).thenReturn("releases");
  when(mavenReleases.getFormat()).thenReturn(format);
  when(format.getValue()).thenReturn("maven2");

  when(storageFacet.txSupplier()).thenReturn(txSupplier);
  when(txSupplier.get()).thenReturn(storageTx);

  browseAssetsSqlBuilder = new BrowseAssetsSqlBuilder(assetEntityAdapter);
  browseComponentsSqlBuilder = new BrowseComponentsSqlBuilder(componentEntityAdapter);

  underTest = spy(new BrowseServiceImpl(new GroupType(), componentEntityAdapter, variableResolverAdapterManager,
      contentPermissionChecker, assetEntityAdapter, browseAssetIterableFactory, browseAssetsSqlBuilder,
      browseComponentsSqlBuilder, bucketStore, repositoryManager));
}
 
Example #4
Source File: SimpleApiRepositoryAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AbstractApiRepository adapt(final Repository repository) {
  boolean online = repository.getConfiguration().isOnline();
  String name = repository.getName();
  String format = repository.getFormat().toString();
  String url = repository.getUrl();

  switch (repository.getType().toString()) {
    case GroupType.NAME:
      return new SimpleApiGroupRepository(name, format, url, online, getStorageAttributes(repository),
          getGroupAttributes(repository));
    case HostedType.NAME:
      return new SimpleApiHostedRepository(name, format, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository));
    case ProxyType.NAME:
      return new SimpleApiProxyRepository(name, format, url, online, getStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), getProxyAttributes(repository),
          getNegativeCacheAttributes(repository), getHttpClientAttributes(repository),
          getRoutingRuleName(repository));
    default:
      return null;
  }
}
 
Example #5
Source File: BrowseServiceImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGetAssetById_withEntityId_groupRepository() {
  EntityId assetId = new DetachedEntityId(assetOneORID.toString());
  EntityId bucketId = mock(EntityId.class);
  Bucket bucket = mock(Bucket.class);

  when(storageTx.findAsset(assetId)).thenReturn(assetOne);
  when(assetOne.bucketId()).thenReturn(bucketId);
  when(bucketStore.getById(bucketId)).thenReturn(bucket);
  when(bucket.getRepositoryName()).thenReturn("releases");

  Repository groupRepository = mock(Repository.class);
  when(groupRepository.getType()).thenReturn(new GroupType());
  when(groupRepository.getName()).thenReturn("group-repository");
  when(groupRepository.facet(StorageFacet.class)).thenReturn(storageFacet);
  GroupFacet groupFacet = mock(GroupFacet.class);
  when(groupFacet.allMembers()).thenReturn(Arrays.asList(groupRepository, mavenReleases));
  when(groupRepository.facet(GroupFacet.class)).thenReturn(groupFacet);

  when(assetEntityAdapter.readEntity(assetOneDoc)).thenReturn(assetOne);

  assertThat(underTest.getAssetById(assetId, groupRepository), is(assetOne));
  verify(groupFacet).allMembers();
}
 
Example #6
Source File: OrientPyPiGroupFacetTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  AttributesMap attributesMap = new AttributesMap();
  attributesMap.set(CONTENT_LAST_MODIFIED, DateTime.now());

  when(originalContent.getAttributes()).thenReturn(attributesMap);

  underTest = new OrientPyPiGroupFacet(repositoryManager, constraintViolationFactory, new GroupType()) {
    @Override
    public boolean isStale(@Nullable final Content content) {
      return false;
    }
  };

  responses = ImmutableMap.of(repository, response);
}
 
Example #7
Source File: BrowseServiceImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void setupMocksForBrowserComponentAssets(boolean allowAssetOne, boolean allowAssetTwo) {
  Repository groupRepository = mock(Repository.class);
  when(groupRepository.getType()).thenReturn(new GroupType());
  when(groupRepository.getName()).thenReturn("group-repository");
  when(groupRepository.facet(StorageFacet.class)).thenReturn(storageFacet);
  GroupFacet groupFacet = mock(GroupFacet.class);
  when(groupFacet.allMembers()).thenReturn(Arrays.asList(groupRepository, mavenReleases));
  when(groupRepository.facet(GroupFacet.class)).thenReturn(groupFacet);
  when(storageTx.findComponent(new DetachedEntityId(componentOneORID.toString()))).thenReturn(componentOne);
  when(repositoryManager.findContainingGroups(mavenReleases.getName())).thenReturn(Collections.singletonList("group-repository"));
  AssetVariableResolver assetVariableResolver = mock(AssetVariableResolver.class);
  when(variableResolverAdapterManager.get(componentOne.format())).thenReturn(assetVariableResolver);
  VariableSource variableSourceOne = createVariableSource(assetOne);
  VariableSource variableSourceTwo = createVariableSource(assetTwo);
  when(assetVariableResolver.fromAsset(assetOne)).thenReturn(variableSourceOne);
  when(assetVariableResolver.fromAsset(assetTwo)).thenReturn(variableSourceTwo);
  when(storageTx.browseAssets(componentOne)).thenReturn(Arrays.asList(assetOne, assetTwo));
  when(contentPermissionChecker
      .isPermitted(eq(Stream.of(mavenReleases.getName(), "group-repository").collect(Collectors.toSet())), any(),
          any(), eq(variableSourceOne))).thenReturn(allowAssetOne);
  when(contentPermissionChecker
      .isPermitted(eq(Stream.of(mavenReleases.getName(), "group-repository").collect(Collectors.toSet())), any(),
          any(), eq(variableSourceTwo))).thenReturn(allowAssetTwo);
}
 
Example #8
Source File: RepositoryBrowseResourceTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void validateAsset_groupRepository() throws Exception {
  Repository groupRepository = mock(Repository.class);
  when(groupRepository.getType()).thenReturn(new GroupType());
  when(groupRepository.getName()).thenReturn("group-repository");
  when(groupRepository.getFormat()).thenReturn(new Format("format") {});
  when(groupRepository.facet(StorageFacet.class)).thenReturn(storageFacet);
  GroupFacet groupFacet = mock(GroupFacet.class);
  when(groupFacet.allMembers()).thenReturn(Arrays.asList(groupRepository, repository));
  when(groupRepository.optionalFacet(GroupFacet.class)).thenReturn(Optional.of(groupFacet));
  when(repositoryManager.get("group-repository")).thenReturn(groupRepository);

  List<BrowseNode<EntityId>> nodes = asList(browseNode("a.txt", mock(EntityId.class), true));
  when(asset.size()).thenReturn(1024L);
  when(asset.blobUpdated()).thenReturn(new DateTime(0));
  when(asset.name()).thenReturn("a1.txt");
  when(groupRepository.getUrl()).thenReturn("http://foo/bar");
  when(browseNodeStore
      .getByPath(groupRepository.getName(), Collections.emptyList(), configuration.getMaxHtmlNodes()))
      .thenReturn(nodes);

  underTest.getHtml("group-repository", "", uriInfo);

  ArgumentCaptor<TemplateParameters> argument = ArgumentCaptor.forClass(TemplateParameters.class);
  verify(templateHelper).render(any(), argument.capture());

  List<BrowseListItem> listItems = (List<BrowseListItem>) argument.getValue().get().get("listItems");
  assertThat(listItems.size(), is(1));

  BrowseListItem item = listItems.get(0);
  assertThat(item.getName(), is("a.txt"));
  assertThat(item.getSize(), is("1024"));
  assertThat(item.getLastModified(), is(format.format(asset.blobUpdated().toDate())));
  assertThat(item.getResourceUri(), is("http://foo/bar/a1.txt"));
}
 
Example #9
Source File: MavenApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAdapt_groupRepository() throws Exception {
  // No maven specific props so simple smoke test
  Repository repository = createRepository(new GroupType());
  repository.getConfiguration().attributes("group").set("memberNames", Arrays.asList("a", "b"));

  SimpleApiGroupRepository groupRepository = (SimpleApiGroupRepository) underTest.adapt(repository);
  assertRepository(groupRepository, "group", true);
}
 
Example #10
Source File: RestoreMetadataTaskTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testIntegrityCheck_SkipGroupRepositories() throws Exception {
  configuration.setBoolean(RESTORE_BLOBS, false);
  configuration.setBoolean(UNDELETE_BLOBS, false);
  configuration.setBoolean(INTEGRITY_CHECK, true);
  underTest.configure(configuration);

  when(repository.getType()).thenReturn(new GroupType());
  when(repositoryManager.browseForBlobStore(any())).thenReturn(singletonList(repository));

  underTest.execute();

  verifyZeroInteractions(integrityCheckStrategies);
}
 
Example #11
Source File: CleanupServiceImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public CleanupServiceImpl(final RepositoryManager repositoryManager,
                          final CleanupComponentBrowse browseService,
                          final CleanupPolicyStorage cleanupPolicyStorage,
                          final CleanupMethod cleanupMethod,
                          final GroupType groupType,
                          @Named("${nexus.cleanup.retries:-3}") final int cleanupRetryLimit)
{
  this.repositoryManager = checkNotNull(repositoryManager);
  this.browseService = checkNotNull(browseService);
  this.cleanupPolicyStorage = checkNotNull(cleanupPolicyStorage);
  this.cleanupMethod = checkNotNull(cleanupMethod);
  this.groupType = checkNotNull(groupType);
  this.cleanupRetryLimit = cleanupRetryLimit;
}
 
Example #12
Source File: CleanupServiceImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  underTest = new CleanupServiceImpl(repositoryManager, browseService, cleanupPolicyStorage, cleanupMethod,
      new GroupType(), RETRY_LIMIT);

  setupRepository(repository1, POLICY_1_NAME);
  setupRepository(repository2, POLICY_2_NAME);
  setupRepository(repository3, null);

  when(storageFacet.txSupplier()).thenReturn(() -> tx);

  when(repositoryManager.browse()).thenReturn(ImmutableList.of(repository1, repository2));

  when(cleanupPolicyStorage.get(POLICY_1_NAME)).thenReturn(cleanupPolicy1);
  when(cleanupPolicyStorage.get(POLICY_2_NAME)).thenReturn(cleanupPolicy2);

  when(cleanupPolicy1.getCriteria()).thenReturn(ImmutableMap.of(LAST_BLOB_UPDATED_KEY, "1"));
  when(cleanupPolicy2.getCriteria()).thenReturn(ImmutableMap.of(LAST_DOWNLOADED_KEY, "2"));

  when(browseService.browse(cleanupPolicy1, repository1)).thenReturn(ImmutableList.of(component1, component2));
  when(browseService.browse(cleanupPolicy2, repository2)).thenReturn(ImmutableList.of(component3));

  when(cancelledCheck.getAsBoolean()).thenReturn(false);

  when(deletionProgress.isFailed()).thenReturn(false);
  when(cleanupMethod.run(any(), any(), any())).thenReturn(deletionProgress);
}
 
Example #13
Source File: OrientBrowseNodeStoreImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void groupQuery() throws Exception {
  List<String> queryPath = asList("org", "foo");

  when(securityHelper.anyPermitted(any())).thenReturn(true);
  when(repository.getType()).thenReturn(new GroupType());
  when(repository.facet(GroupFacet.class)).thenReturn(groupFacet);
  when(groupFacet.leafMembers()).thenReturn(asList(memberA, memberB, memberC));
  when(repository.optionalFacet(BrowseNodeFacet.class)).thenReturn(Optional.of(browseNodeFacet));
  when(browseNodeFacet.browseNodeIdentity()).thenReturn(browseNodeIdentity());

  when(browseNodeEntityAdapter.getByPath(db, MEMBER_A, queryPath, MAX_NODES, "", emptyMap()))
      .thenReturn(asList(node(MEMBER_A, "com"), node(MEMBER_A, "org")));
  when(browseNodeEntityAdapter.getByPath(db, MEMBER_B, queryPath, MAX_NODES, "", emptyMap()))
      .thenReturn(asList(node(MEMBER_B, "biz"), node(MEMBER_B, "org")));
  when(browseNodeEntityAdapter.getByPath(db, MEMBER_C, queryPath, MAX_NODES, "", emptyMap()))
      .thenReturn(asList(node(MEMBER_C, "com"), node(MEMBER_C, "javax")));

  Iterable<BrowseNode<EntityId>> nodes = underTest.getByPath(REPOSITORY_NAME, queryPath, MAX_NODES);

  // check that duplicate nodes were removed, should follow a 'first-one-wins' approach
  assertThat(nodes, containsInAnyOrder(
      allOf(hasProperty("repositoryName", is(MEMBER_A)), hasProperty("name", is("com"))),
      allOf(hasProperty("repositoryName", is(MEMBER_A)), hasProperty("name", is("org"))),
      allOf(hasProperty("repositoryName", is(MEMBER_B)), hasProperty("name", is("biz"))),
      allOf(hasProperty("repositoryName", is(MEMBER_C)), hasProperty("name", is("javax")))));

  verify(securityHelper).anyPermitted(any(RepositoryViewPermission.class));
  verify(browseNodeEntityAdapter).getByPath(db, MEMBER_A, queryPath, MAX_NODES, "", emptyMap());
  verify(browseNodeEntityAdapter).getByPath(db, MEMBER_B, queryPath, MAX_NODES, "", emptyMap());
  verify(browseNodeEntityAdapter).getByPath(db, MEMBER_C, queryPath, MAX_NODES, "", emptyMap());
  verifyNoMoreInteractions(browseNodeEntityAdapter, securityHelper, selectorManager);
}
 
Example #14
Source File: OrientBrowseNodeStoreImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void groupQueryWithLimit() throws Exception {
  List<String> queryPath = asList("org", "foo");

  when(securityHelper.anyPermitted(any())).thenReturn(true);
  when(repository.getType()).thenReturn(new GroupType());
  when(repository.facet(GroupFacet.class)).thenReturn(groupFacet);
  when(groupFacet.leafMembers()).thenReturn(asList(memberA, memberB, memberC));
  when(repository.optionalFacet(BrowseNodeFacet.class)).thenReturn(Optional.of(browseNodeFacet));
  when(browseNodeFacet.browseNodeIdentity()).thenReturn(browseNodeIdentity());

  when(browseNodeEntityAdapter.getByPath(db, MEMBER_A, queryPath, 1, "", emptyMap()))
      .thenReturn(asList(node(MEMBER_A, "com")));
  when(browseNodeEntityAdapter.getByPath(db, MEMBER_B, queryPath, 1, "", emptyMap()))
      .thenReturn(asList(node(MEMBER_B, "com")));
  when(browseNodeEntityAdapter.getByPath(db, MEMBER_C, queryPath, 1, "", emptyMap()))
      .thenReturn(asList(node(MEMBER_C, "com")));

  Iterable<BrowseNode<EntityId>> nodes = underTest.getByPath(REPOSITORY_NAME, queryPath, 1);

  // check that the limit was correctly applied to the merged results
  assertThat(nodes, containsInAnyOrder(
      allOf(hasProperty("repositoryName", is(MEMBER_A)), hasProperty("name", is("com")))));

  verify(securityHelper).anyPermitted(any(RepositoryViewPermission.class));
  // merging of results should be lazy: only the first member should have been consulted
  verify(browseNodeEntityAdapter).getByPath(db, MEMBER_A, queryPath, 1, "", emptyMap());
  verifyNoMoreInteractions(browseNodeEntityAdapter, securityHelper, selectorManager);
}
 
Example #15
Source File: RResourceIT.java    From nexus-repository-r with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void createGroup() throws Exception {
  AbstractRepositoryApiRequest request = createGroupRequest(true);

  Response response = post(getCreateRepositoryPathUrl(GroupType.NAME), request);
  assertEquals(Status.CREATED.getStatusCode(), response.getStatus());

  repositoryManager.delete(request.getName());
}
 
Example #16
Source File: DatastoreBrowseNodeStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private List<BrowseNode<Integer>> fetchPermittedNodes(final Repository repository,
                                             final long maxNodes,
                                             Function<ContentRepository, Iterable<DatastoreBrowseNode>> findChildren,
                                             Predicate<DatastoreBrowseNode> filterNodePredicate) {
  Stream<DatastoreBrowseNode> nodeStream;
  if (repository.getType() instanceof GroupType) {
    Equivalence<BrowseNode<Integer>> browseNodeIdentity = getIdentity(repository);

    // overlay member results, first-one-wins if there are any nodes with the same name
    nodeStream = members(repository)
        .map(this::getContentRepository)
        .map(findChildren)
        .flatMap(iter -> stream(iter.spliterator(), false))
        .map(browseNodeIdentity::wrap)
        .distinct()
        .map(Wrapper::get);
  }
  else {
    nodeStream = of(repository)
        .map(this::getContentRepository)
        .map(findChildren)
        .flatMap(iter -> stream(iter.spliterator(), false));
  }

  return nodeStream
      .filter(filterNodePredicate)
      .limit(maxNodes)
      .collect(toList());
}
 
Example #17
Source File: GroupFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public GroupFacetImpl(final RepositoryManager repositoryManager,
                      final ConstraintViolationFactory constraintViolationFactory,
                      @Named(GroupType.NAME) final Type groupType)
{
  this.repositoryManager = checkNotNull(repositoryManager);
  this.groupType = checkNotNull(groupType);
  this.constraintViolationFactory = checkNotNull(constraintViolationFactory);
}
 
Example #18
Source File: SimpleApiGroupRepository.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@JsonCreator
public SimpleApiGroupRepository(
    @JsonProperty("name") final String name,
    @JsonProperty("format") final String format,
    @JsonProperty("url") final String url,
    @JsonProperty("online") final Boolean online,
    @JsonProperty("storage") final StorageAttributes storage,
    @JsonProperty("group") final GroupAttributes group)
{
  super(name, format, GroupType.NAME, url, online);
  this.storage = storage;
  this.group = group;
}
 
Example #19
Source File: GroupRepositoryApiRequest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@JsonCreator
public GroupRepositoryApiRequest(
    @JsonProperty("name") final String name,
    @JsonProperty("format") final String format,
    @JsonProperty("online") final Boolean online,
    @JsonProperty("storage") final StorageAttributes storage,
    @JsonProperty("group") final GroupAttributes group)
{
  super(name, format, GroupType.NAME, online);
  this.storage = storage;
  this.group = group;
}
 
Example #20
Source File: RepositoryCacheUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Invalidates the group or proxy caches of the specified repository based on type.
 *
 * This is a no-op for hosted repositories.
 */
public static void invalidateCaches(final Repository repository) {
  checkNotNull(repository);
  if (GroupType.NAME.equals(repository.getType().getValue())) {
    invalidateGroupCaches(repository);
  } else if (ProxyType.NAME.equals(repository.getType().getValue())) {
    invalidateProxyAndNegativeCaches(repository);
  }
}
 
Example #21
Source File: RepositoryCacheUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Invalidates the group caches for given repository.
 */
public static void invalidateGroupCaches(final Repository repository) {
  checkNotNull(repository);
  checkArgument(GroupType.NAME.equals(repository.getType().getValue()));
  GroupFacet groupFacet = repository.facet(GroupFacet.class);
  groupFacet.invalidateGroupCaches();
}
 
Example #22
Source File: RebuildBrowseNodesTaskDescriptor.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public RebuildBrowseNodesTaskDescriptor(final NodeAccess nodeAccess, final GroupType groupType) {
  super(TYPE_ID, RebuildBrowseNodesTask.class, TASK_NAME, VISIBLE, EXPOSED,
      new ItemselectFormField(REPOSITORY_NAME_FIELD_ID, "Repository", "Select the repository(ies) to rebuild browse tree",
          true).withStoreApi("coreui_Repository.readReferencesAddingEntryForAll")
          .withButtons("up", "add", "remove", "down").withFromTitle("Available").withToTitle("Selected")
          .withStoreFilter("type", "!" + groupType.getValue()).withValueAsString(true),
      nodeAccess.isClustered() ? newLimitNodeFormField() : null);
}
 
Example #23
Source File: SimpleApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAdapt_groupRepository() throws Exception {
  Repository repository = createRepository(new GroupType());
  repository.getConfiguration().attributes("group").set("memberNames", Arrays.asList("a", "b"));

  SimpleApiGroupRepository groupRepository = (SimpleApiGroupRepository) underTest.adapt(repository);
  assertRepository(groupRepository, "group", true);
  assertThat(groupRepository.getGroup().getMemberNames(), contains("a", "b"));
  assertThat(groupRepository.getStorage().getStrictContentTypeValidation(), is(true));

  setStorageAttributes(repository, "default", /* non-default */ false, null);
  groupRepository = (SimpleApiGroupRepository) underTest.adapt(repository);
  assertThat(groupRepository.getStorage().getBlobStoreName(), is("default"));
  assertThat(groupRepository.getStorage().getStrictContentTypeValidation(), is(false));
}
 
Example #24
Source File: AuthorizingRepositoryManagerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void rebuildIndexShouldThrowExceptionIfRepositoryTypeIsNotHostedOrProxy() throws Exception {
  when(repository.getType()).thenReturn(new GroupType());
  expectedException.expect(IncompatibleRepositoryException.class);

  authorizingRepositoryManager.rebuildSearchIndex("repository");

  verify(repositoryManager).get(eq("repository"));
  verifyNoMoreInteractions(repositoryManager, repositoryPermissionChecker, taskScheduler);
}
 
Example #25
Source File: AuthorizingRepositoryManagerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void invalidateCacheShouldThrowExceptionIfInsufficientPermissions() throws Exception {
  when(repository.getType()).thenReturn(new GroupType());
  doThrow(new AuthorizationException("User is not permitted."))
      .when(repositoryPermissionChecker)
      .ensureUserCanAdmin(any(), any());
  expectedException.expect(AuthorizationException.class);

  authorizingRepositoryManager.invalidateCache("repository");

  verify(repositoryManager).get(eq("repository"));
  verify(repositoryPermissionChecker).ensureUserCanAdmin(eq(EDIT), eq(repository));
  verifyNoMoreInteractions(repositoryManager, repositoryPermissionChecker, taskScheduler);
}
 
Example #26
Source File: AuthorizingRepositoryManagerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void invalidateCacheGroupRepository() throws Exception {
  when(repository.getType()).thenReturn(new GroupType());
  GroupFacet groupFacet = mock(GroupFacet.class);
  when(repository.facet(GroupFacet.class)).thenReturn(groupFacet);

  authorizingRepositoryManager.invalidateCache("repository");

  verify(repositoryManager).get(eq("repository"));
  verify(repositoryPermissionChecker).ensureUserCanAdmin(eq(EDIT), eq(repository));
  verify(repository).facet(GroupFacet.class);
  verify(groupFacet).invalidateGroupCaches();
  verifyNoMoreInteractions(repositoryManager, repositoryPermissionChecker, groupFacet);
}
 
Example #27
Source File: RemoveSnapshotsTaskTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  configuration = new TaskConfiguration();
  configuration.setId("test");
  configuration.setTypeId("test");
  configuration.setString(RepositoryTaskSupport.REPOSITORY_NAME_FIELD_ID, ALL_REPOSITORIES);

  when(mavenFacet.getVersionPolicy()).thenReturn(VersionPolicy.SNAPSHOT);

  taskUnderTest = new TestRemoveSnapshotsTask(new Maven2Format());
  taskUnderTest.install(repositoryManager, new GroupType());
  taskUnderTest.configure(configuration);
}
 
Example #28
Source File: RRecipeTest.java    From nexus-repository-r with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() {
  when(rFormat.getValue()).thenReturn(R_FORMAT);
  rHostedRecipe = new RHostedRecipe(new HostedType(), rFormat);
  rProxyRecipe = new RProxyRecipe(new ProxyType(), rFormat);
  rGroupRecipe = new RGroupRecipe(new GroupType(), rFormat);
  rHostedRecipe.setHighAvailabilitySupportChecker(highAvailabilitySupportChecker);
  rProxyRecipe.setHighAvailabilitySupportChecker(highAvailabilitySupportChecker);
  rGroupRecipe.setHighAvailabilitySupportChecker(highAvailabilitySupportChecker);
}
 
Example #29
Source File: RResourceIT.java    From nexus-repository-r with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void createGroup_noMembers() throws Exception {
  RGroupRepositoryApiRequest request = createGroupRequest(true);
  request.getGroup().getMemberNames().clear();

  Response response = post(getCreateRepositoryPathUrl(GroupType.NAME), request);
  assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());

  assertNull(repositoryManager.get(GROUP_NAME));
}
 
Example #30
Source File: RResourceIT.java    From nexus-repository-r with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void createGroup_mixedMembersFormat() throws Exception {
  RGroupRepositoryApiRequest request = createGroupRequest(true);
  request.getGroup().getMemberNames().add(HOSTED_NAME);

  Response response = post(getCreateRepositoryPathUrl(GroupType.NAME), request);
  assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());

  assertNull(repositoryManager.get(GROUP_NAME));
}