org.sonatype.nexus.repository.http.HttpStatus Java Examples

The following examples show how to use org.sonatype.nexus.repository.http.HttpStatus. 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: ProxyHandlerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testBypassHttpErrorExceptionPropagatesCodeWithMessageWithHeader() throws Exception {
  final int httpStatus = HttpStatus.FORBIDDEN;
  final String errorMessage = "Error Message";
  final String headerName = "Header Name";
  final String headerValue = "Header Value";

  ListMultimap<String, String> headers = ArrayListMultimap.create();
  headers.put(headerName, headerValue);
  BypassHttpErrorException bypassException = new BypassHttpErrorException(httpStatus, errorMessage, headers);

  when(request.getAction()).thenReturn(HttpMethods.GET);
  doThrow(bypassException).when(proxyFacet).get(context);

  Response response = underTest.handle(context);

  assertStatusCode(response, httpStatus);
  assertStatusMessage(response, errorMessage);
  assertThat(response.getHeaders().get(headerName), is(headerValue));
}
 
Example #2
Source File: ConanProxyIT.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void retrieveDownloadUrlsFromNonPackageRoute() throws Exception {
  HttpResponse response = proxyClient.getHttpResponse(PATH_DOWNLOAD_URLS_WITHOUT_PACKAGES);
  assertThat(status(response), is(HttpStatus.OK));

  HttpEntity entity = response.getEntity();
  String download_urls = EntityUtils.toString(entity);
  JsonObject obj = new JsonParser().parse(download_urls).getAsJsonObject();

  assertThat(obj.get(FILE_MANIFEST).getAsString(),
      is("http://localhost:10000/repository/conan-test-proxy-online/conans/vthiery/jsonformoderncpp/3.7.0/stable/conanmanifest.txt"));
  assertThat(obj.get("conanfile.py").getAsString(),
      is("http://localhost:10000/repository/conan-test-proxy-online/conans/vthiery/jsonformoderncpp/3.7.0/stable/conanfile.py"));

  final Asset asset = findAsset(proxyRepo, PATH_DOWNLOAD_URLS_WITHOUT_PACKAGES);
  assertThat(asset.format(), is(ConanFormat.NAME));
  assertThat(asset.name(), is(PATH_DOWNLOAD_URLS_WITHOUT_PACKAGES));
  assertThat(asset.contentType(), is(ContentTypes.TEXT_PLAIN));
}
 
Example #3
Source File: NpmSearchGroupHandlerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testSkipResultWithBadResponse() throws Exception {
  when(status1.getCode()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR);

  Response response = underTest.doGet(context, dispatchedRepositories);

  assertThat(response.getStatus().getCode(), is(OK));
  assertThat(response.getPayload(), not(nullValue()));
  try (InputStream in = response.getPayload().openInputStream()) {
    assertThat(CharStreams.toString(new InputStreamReader(in, UTF_8)), is("response"));
  }

  ArgumentCaptor<NpmSearchResponse> searchResponseCaptor = ArgumentCaptor.forClass(NpmSearchResponse.class);
  verify(npmSearchResponseMapper).writeString(searchResponseCaptor.capture());

  NpmSearchResponse searchResponse = searchResponseCaptor.getValue();
  assertThat(searchResponse.getTotal(), is(1));
  assertThat(searchResponse.getObjects(), hasSize(1));
  assertThat(searchResponse.getObjects(), contains(npmSearchResponseObject2));
}
 
Example #4
Source File: ConanProxyIT.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void checkComponentRemovedWhenAssetRemoved() throws IOException {
  HttpResponse response = proxyClient.getHttpResponse(PATH_MANIFEST);
  assertThat(status(response), is(HttpStatus.OK));

  String assetPath = PATH_MANIFEST;

  Asset asset = findAsset(proxyRepo, assetPath);
  Component component = findComponent(proxyRepo, LIBRARY_NAME);
  assertThat(component.name(), is(equalTo(LIBRARY_NAME)));
  assertThat(component.version(), is(equalTo(LIBRARY_VERSION)));
  assertThat(component.group(), is(equalTo(LIBRARY_VENDOR)));

  ComponentMaintenance maintenanceFacet = proxyRepo.facet(ComponentMaintenance.class);
  maintenanceFacet.deleteAsset(asset.getEntityMetadata().getId());

  asset = findAsset(proxyRepo, assetPath);
  assertThat(asset, is(equalTo(null)));
  component = findComponent(proxyRepo, LIBRARY_NAME);
  assertThat(component, is(equalTo(null)));
}
 
Example #5
Source File: RawHostedIT.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void canDisallowDelete() throws Exception {
  rawClient = rawClient(repos.createRawHosted(HOSTED_REPO + "-no-delete"));

  HttpEntity testEntity = new FileEntity(resolveTestFile(TEST_CONTENT), TEXT_PLAIN);

  HttpResponse response = rawClient.put(TEST_CONTENT, testEntity);
  MatcherAssert.assertThat(response.getStatusLine().getStatusCode(), Matchers.is(HttpStatus.CREATED));

  Configuration hostedConfig = repositoryManager.get(HOSTED_REPO + "-no-delete").getConfiguration().copy();
  hostedConfig.attributes(STORAGE).set(WRITE_POLICY, DENY);
  repositoryManager.update(hostedConfig);

  response = rawClient.delete(TEST_CONTENT);
  MatcherAssert.assertThat(response.getStatusLine().getStatusCode(), Matchers.is(HttpStatus.BAD_REQUEST));
  assertThat(response.getStatusLine().getReasonPhrase(), Matchers.containsString("cannot be deleted"));
}
 
Example #6
Source File: P2ProxyIT.java    From nexus-repository-p2 with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void checkCache() throws Exception {
  assertThat(status(proxyClient.get(FEATURE_TEST_PATH)), is(HttpStatus.OK));

  // fetch in cache and stop remote
  Asset asset = findAsset(proxyRepo, FEATURE_TEST_PATH);
  assertThat(asset.name(), is(equalTo(FEATURE_TEST_PATH)));
  assertThat(asset.format(), is(equalTo(FORMAT_NAME)));
  server.stop();

  // verify that fetch from cache works
  assertThat(status(proxyClient.get(FEATURE_TEST_PATH)), is(HttpStatus.OK));
  asset = findAsset(proxyRepo, FEATURE_TEST_PATH);
  assertThat(asset.name(), is(equalTo(FEATURE_TEST_PATH)));
  assertThat(asset.format(), is(equalTo(FORMAT_NAME)));
}
 
Example #7
Source File: RawRestoreBlobIT.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void verifyMetadataRestored(final Runnable metadataLossSimulation) throws Exception {
  metadataLossSimulation.run();

  testHelper.runRestoreMetadataTask();

  testHelper.assertComponentInRepository(hostedRepository, TEST_CONTENT);
  testHelper.assertComponentInRepository(proxyRepository, TEST_CONTENT);

  testHelper.assertAssetMatchesBlob(hostedRepository, TEST_CONTENT);
  testHelper.assertAssetMatchesBlob(proxyRepository, TEST_CONTENT);

  testHelper.assertAssetAssociatedWithComponent(hostedRepository, TEST_CONTENT, TEST_CONTENT);
  testHelper.assertAssetAssociatedWithComponent(proxyRepository, TEST_CONTENT, TEST_CONTENT);

  assertThat(hostedClient.get(TEST_CONTENT).getStatusLine().getStatusCode(), is(HttpStatus.OK));
  assertThat(proxyClient.get(TEST_CONTENT).getStatusLine().getStatusCode(), is(HttpStatus.OK));
}
 
Example #8
Source File: ConanProxySearchIT.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void search() throws Exception {
  HttpResponse response = proxyClient.getHttpResponse(PATH_SEARCH);
  assertThat(status(response), is(HttpStatus.OK));

  HttpEntity entity = response.getEntity();
  String actualJson = EntityUtils.toString(entity);
  assertThat(actualJson, is(MOCK_SEARCH_REMOTE_RESPONSE));

  Header contentType = response.getEntity().getContentType();
  String mimeType = contentType.getValue();
  assertThat(mimeType, is(ContentTypes.APPLICATION_JSON));

  Asset conanManifestAsset = findAsset(proxyRepo, PATH_MANIFEST);
  assertThat(conanManifestAsset, nullValue());

  Asset downloadUrlsAsset = findAsset(proxyRepo, PATH_DOWNLOAD_URLS);
  assertThat(downloadUrlsAsset, nullValue());

  Asset digestAsset = findAsset(proxyRepo, PATH_DIGEST);
  assertThat(digestAsset, nullValue());
}
 
Example #9
Source File: ConanProxySearchIT.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void patternSearch() throws Exception {
  HttpResponse response = proxyClient.getHttpResponse(PATH_PATTERN_SEARCH);
  assertThat(status(response), is(HttpStatus.OK));

  HttpEntity entity = response.getEntity();
  String actualJson = EntityUtils.toString(entity);
  assertThat(actualJson, is(MOCK_PATTERN_SEARCH_REMOTE_RESPONSE));

  Header contentType = response.getEntity().getContentType();
  String mimeType = contentType.getValue();
  assertThat(mimeType, is(ContentTypes.APPLICATION_JSON));

  Asset conanManifestAsset = findAsset(proxyRepo, PATH_MANIFEST);
  assertThat(conanManifestAsset, nullValue());

  Asset downloadUrlsAsset = findAsset(proxyRepo, PATH_DOWNLOAD_URLS);
  assertThat(downloadUrlsAsset, nullValue());

  Asset digestAsset = findAsset(proxyRepo, PATH_DIGEST);
  assertThat(digestAsset, nullValue());
}
 
Example #10
Source File: RRestoreBlobIT.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
private void verifyMetadataRestored(final Runnable metadataLossSimulation) throws Exception {
  metadataLossSimulation.run();

  testHelper.runRestoreMetadataTask();

  testHelper.assertComponentInRepository(hostedRepository, AGRICOLAE_131_TARGZ.packageName);
  testHelper.assertComponentInRepository(proxyRepository, AGRICOLAE_131_TARGZ.packageName);

  testHelper.assertAssetMatchesBlob(hostedRepository, AGRICOLAE_131_TARGZ.fullPath);
  testHelper.assertAssetMatchesBlob(proxyRepository, AGRICOLAE_131_TARGZ.fullPath);

  testHelper.assertAssetAssociatedWithComponent(hostedRepository, AGRICOLAE_131_TARGZ.packageName,
      AGRICOLAE_131_TARGZ.fullPath);
  testHelper.assertAssetAssociatedWithComponent(proxyRepository, AGRICOLAE_131_TARGZ.packageName,
      AGRICOLAE_131_TARGZ.fullPath);

  assertThat(hostedClient.get(AGRICOLAE_131_TARGZ.fullPath).getStatusLine().getStatusCode(), is(HttpStatus.OK));
  assertThat(proxyClient.get(AGRICOLAE_131_TARGZ.fullPath).getStatusLine().getStatusCode(), is(HttpStatus.OK));
}
 
Example #11
Source File: HelmRestoreBlobIT.java    From nexus-repository-helm with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());
  hostedRepository = repos.createHelmHosted(HOSTED_REPO_NAME);
  hostedClient = createHelmClient(hostedRepository);

  proxyServer = Server.withPort(0)
      .serve("/" + MONGO_PATH_FULL_728_TARGZ)
      .withBehaviours(file(testData.resolveFile(MONGO_PKG_FILE_NAME_728_TGZ)))
      .start();

  proxyRepository = repos.createHelmProxy(PROXY_REPO_NAME, "http://localhost:" + proxyServer.getPort() + "/");
  proxyClient = createHelmClient(proxyRepository);

  assertThat(hostedClient.put(MONGO_PATH_FULL_728_TARGZ,
      fileToHttpEntity(MONGO_PKG_FILE_NAME_728_TGZ)).getStatusLine().getStatusCode(), is(HttpStatus.OK));
  assertThat(proxyClient.fetch(MONGO_PATH_FULL_728_TARGZ, CONTENT_TYPE_TGZ).getStatusLine().getStatusCode(), is(HttpStatus.OK));
}
 
Example #12
Source File: HelmRestoreBlobIT.java    From nexus-repository-helm with Eclipse Public License 1.0 6 votes vote down vote up
private void verifyMetadataRestored(final Runnable metadataLossSimulation) throws Exception {
  metadataLossSimulation.run();

  testHelper.runRestoreMetadataTask();

  testHelper.assertComponentInRepository(hostedRepository, MONGO_PKG_NAME);
  testHelper.assertComponentInRepository(proxyRepository, MONGO_PKG_NAME);

  testHelper.assertAssetMatchesBlob(hostedRepository, MONGO_PATH_FULL_728_TARGZ);
  testHelper.assertAssetMatchesBlob(proxyRepository, MONGO_PATH_FULL_728_TARGZ);

  testHelper.assertAssetAssociatedWithComponent(hostedRepository, MONGO_PKG_NAME, MONGO_PATH_FULL_728_TARGZ);
  testHelper.assertAssetAssociatedWithComponent(proxyRepository, MONGO_PKG_NAME, MONGO_PATH_FULL_728_TARGZ);

  assertThat(hostedClient.get(MONGO_PATH_FULL_728_TARGZ).getStatusLine().getStatusCode(), is(HttpStatus.OK));
  assertThat(proxyClient.get(MONGO_PATH_FULL_728_TARGZ).getStatusLine().getStatusCode(), is(HttpStatus.OK));
}
 
Example #13
Source File: OrientPyPiIndexGroupHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private String mergeResponses(final String name,
                              final AssetKind assetKind,
                              final Map<Repository, Response> remoteResponses) throws IOException
{
  Map<String, PyPiLink> results = new TreeMap<>();
  for (Entry<Repository, Response> entry : remoteResponses.entrySet()) {
    Response response = entry.getValue();
    if (response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null) {
      processResults(response, results);
    }
  }

  if (INDEX.equals(assetKind)) {
    return PyPiIndexUtils.buildIndexPage(templateHelper, name, results.values());
  }
  else {
    return PyPiIndexUtils.buildRootIndexPage(templateHelper, results.values());
  }
}
 
Example #14
Source File: RRestoreBlobIT.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());
  hostedRepository = repos.createRHosted(HOSTED_REPO_NAME);
  hostedClient = createRClient(hostedRepository);

  proxyServer = Server.withPort(0)
      .serve("/" + AGRICOLAE_131_TARGZ.fullPath)
      .withBehaviours(file(testData.resolveFile(AGRICOLAE_131_TARGZ.filename)))
      .start();

  proxyRepository = repos.createRProxy(PROXY_REPO_NAME, "http://localhost:" + proxyServer.getPort() + "/");
  proxyClient = createRClient(proxyRepository);

  assertThat(hostedClient.put(AGRICOLAE_131_TARGZ.fullPath,
      fileToHttpEntity(AGRICOLAE_131_TARGZ.filename)).getStatusLine().getStatusCode(), is(HttpStatus.OK));
  assertThat(proxyClient.fetch(AGRICOLAE_131_TARGZ.fullPath).getStatusLine().getStatusCode(), is(HttpStatus.OK));
}
 
Example #15
Source File: PackagesGroupHandler.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Response doGet(@Nonnull final Context context,
                         @Nonnull final GroupHandler.DispatchedRepositories dispatched)
    throws Exception
{
  GroupFacet groupFacet = context.getRepository().facet(GroupFacet.class);
  Map<Repository, Response> responses = getAll(context, groupFacet.members(), dispatched);
  List<Response> successfulResponses = responses.values().stream()
      .filter(response -> response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null)
      .collect(Collectors.toList());
  if (successfulResponses.isEmpty()) {
    return notFoundResponse(context);
  }
  if (successfulResponses.size() == 1) {
    return successfulResponses.get(0);
  }

  List<List<Map<String, String>>> parts = successfulResponses.stream().map(this::parseResponse).collect(
      Collectors.toList());
  List<Map<String, String>> merged = RPackagesUtils.merge(parts);

  return HttpResponses.ok(RPackagesUtils.buildPackages(merged));
}
 
Example #16
Source File: IndexHtmlForwardHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  String path = context.getRequest().getPath();

  // sanity, to ensure we don't corrupt the path
  if (!path.endsWith("/")) {
    path = path + "/";
  }

  for (String file : INDEX_FILES) {
    Response response = forward(context, path + file);
    // return response if it was successful or an error which was not not found
    if (response.getStatus().isSuccessful() || response.getStatus().getCode() != HttpStatus.NOT_FOUND) {
      return response;
    }
    // otherwise try next index file
  }

  // or there is no such file, give up not found
  return HttpResponses.notFound(context.getRequest().getPath());
}
 
Example #17
Source File: ConanProxyIT.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void retrieveInfoWhenRemoteOnline() throws Exception {
  // Conan client gets conanmanifest.txt file to examine conanifo.txt file hash
  HttpResponse response = proxyClient.getHttpResponse(PATH_MANIFEST);
  assertThat(status(response), is(HttpStatus.OK));
  // Conan client gets conanifo.txt file
  assertThat(status(proxyClient.getHttpResponse(PATH_INFO)), is(HttpStatus.OK));

  final Asset asset = findAsset(proxyRepo, PATH_INFO);
  assertThat(asset.format(), is(ConanFormat.NAME));
  assertThat(asset.name(), is(PATH_INFO));
  assertThat(asset.contentType(), is(ContentTypes.TEXT_PLAIN));
}
 
Example #18
Source File: RawMavenSiteIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void deploySimpleSite() throws Exception {
  runMavenSite();

  final HttpResponse index = client.get(INDEX_HTML);

  assertThat(status(index), is(HttpStatus.OK));
  assertThat(asString(index), containsString("About testproject"));
}
 
Example #19
Source File: RawITSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
protected void uploadAndDownload(RawClient rawClient, String file) throws Exception {
  final File testFile = resolveTestFile(file);
  final int response = rawClient.put(file, ContentType.TEXT_PLAIN, testFile);
  assertThat(response, is(HttpStatus.CREATED));

  assertThat(bytes(rawClient.get(file)), is(Files.toByteArray(testFile)));

  assertThat(status(rawClient.delete(file)), is(HttpStatus.NO_CONTENT));

  assertThat("content should be deleted", status(rawClient.get(file)), is(HttpStatus.NOT_FOUND));
}
 
Example #20
Source File: RawRestoreBlobIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  hostedRepository = repos.createRawHosted(HOSTED_REPO_NAME);
  hostedClient = rawClient(hostedRepository);

  proxyServer = Server.withPort(0).start();
  proxyServer.serve("/" + TEST_CONTENT).withBehaviours(resolveFile(TEST_CONTENT));

  proxyRepository = repos.createRawProxy(PROXY_REPO_NAME, "http://localhost:" + proxyServer.getPort() + "/");
  proxyClient = rawClient(proxyRepository);

  File testFile = resolveTestFile(TEST_CONTENT);
  assertThat(hostedClient.put(TEST_CONTENT, TEXT_PLAIN, testFile), is(HttpStatus.CREATED));
  assertThat(proxyClient.get(TEST_CONTENT).getStatusLine().getStatusCode(), is(HttpStatus.OK));
}
 
Example #21
Source File: ConanProxyIT.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void retrieveManifestWhenRemoteOnline() throws Exception {
  HttpResponse response = proxyClient.getHttpResponse(PATH_MANIFEST);

  assertThat(status(response), is(HttpStatus.OK));

  final Asset asset = findAsset(proxyRepo, PATH_MANIFEST);
  assertThat(asset.format(), is(ConanFormat.NAME));
  assertThat(asset.name(), is(PATH_MANIFEST));
  assertThat(asset.contentType(), is(ContentTypes.TEXT_PLAIN));
}
 
Example #22
Source File: ConanProxyIT.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void retrievePackageWhenRemoteOnline() throws Exception {
  HttpResponse response = proxyClient.getHttpResponse(PATH_TGZ_PACKAGE);
  assertThat(status(response), is(HttpStatus.OK));

  Asset asset = findAsset(proxyRepo, PATH_TGZ_PACKAGE);
  assertThat(asset.format(), is(ConanFormat.NAME));
  assertThat(asset.name(), is(PATH_TGZ_PACKAGE));
  assertThat(asset.contentType(), is(ContentTypes.APPLICATION_GZIP));
}
 
Example #23
Source File: HelmContentHostedIT.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void fetchTgzPackageFile() throws Exception {
  HttpResponse httpResponse = client.fetch(MONGO_PKG_FILE_NAME_600_TGZ, CONTENT_TYPE_TGZ);

  assertThat(status(httpResponse), is(HttpStatus.OK));
  assertThat(bytes(httpResponse), is(Files.toByteArray(testData.resolveFile(MONGO_PKG_FILE_NAME_600_TGZ))));
}
 
Example #24
Source File: RawMavenSiteIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void mkcolMethodNotAllowed() throws Exception {
  runMavenSite();

  final HttpResponse index = client.mkcol(INDEX_HTML);

  assertThat(status(index), is(HttpStatus.METHOD_NOT_ALLOWED));
}
 
Example #25
Source File: FormatHighAvailabilitySupportHandlerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void responseIsBadRequest_IfNexusIsClusteredAndFormatIsNotClustered() throws Exception {
  when(highAvailabilitySupportChecker.isSupported(FORMAT_NAME)).thenReturn(false);
  final Response response = handlerUnderTest.handle(context);
  verify(highAvailabilitySupportChecker).isSupported(FORMAT_NAME);
  assertThat(response.getStatus().getCode(), is(HttpStatus.BAD_REQUEST));
}
 
Example #26
Source File: FormatHighAvailabilitySupportHandlerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void responseIsOk_IfNexusIsNotClusteredAndFormatIsNotClustered() throws Exception {
  when(highAvailabilitySupportChecker.isSupported(FORMAT_NAME)).thenReturn(true);
  final Response response = handlerUnderTest.handle(context);
  verify(highAvailabilitySupportChecker).isSupported(FORMAT_NAME);
  assertThat(response.getStatus().getCode(), is(HttpStatus.OK));
}
 
Example #27
Source File: RawProxyIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void fetchFromRemote() throws Exception {
  final File testFile = resolveTestFile(TEST_CONTENT);
  hostedClient.put(TEST_PATH, ContentType.TEXT_PLAIN, testFile);

  HttpResponse httpResponse = proxyClient.get(TEST_PATH);

  assertThat(status(httpResponse), is(HttpStatus.OK));
  assertThat(bytes(httpResponse), is(Files.toByteArray(testFile)));
}
 
Example #28
Source File: RawHostedIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canDisallowRedeploy() throws Exception {
  rawClient = rawClient(repos.createRawHosted(HOSTED_REPO + "-no-redeploy", ALLOW_ONCE));

  HttpEntity testEntity = new FileEntity(resolveTestFile(TEST_CONTENT), TEXT_PLAIN);

  HttpResponse response = rawClient.put(TEST_CONTENT, testEntity);
  MatcherAssert.assertThat(response.getStatusLine().getStatusCode(), Matchers.is(HttpStatus.CREATED));

  response = rawClient.put(TEST_CONTENT, testEntity);
  MatcherAssert.assertThat(response.getStatusLine().getStatusCode(), Matchers.is(HttpStatus.BAD_REQUEST));
  assertThat(response.getStatusLine().getReasonPhrase(), Matchers.containsString("cannot be updated"));
}
 
Example #29
Source File: RawProxyOfHostedIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void notFoundCaches404() throws Exception {
  // Ask for a nonexistent file
  proxyClient.get(TEST_PATH);

  // Put the file in the hosted repo
  hostedClient.put(TEST_PATH, ContentType.TEXT_PLAIN, resolveTestFile(TEST_CONTENT));

  // The NFC should ensure we still see the 404
  assertThat(status(proxyClient.get(TEST_PATH)), is(HttpStatus.NOT_FOUND));
}
 
Example #30
Source File: ConanProxyIT.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void retrieveDigest() throws Exception {
  HttpResponse response = proxyClient.getHttpResponse(PATH_DIGEST);
  assertThat(status(response), is(HttpStatus.OK));
  HttpEntity entity = response.getEntity();
  String digest = EntityUtils.toString(entity);
  JsonObject obj = new JsonParser().parse(digest).getAsJsonObject();
  assertThat(obj.get(FILE_MANIFEST).getAsString(), is(NXRM_CONAN_PROXY_REPO_PATH + PATH_MANIFEST));

  final Asset asset = findAsset(proxyRepo, PATH_DIGEST);
  assertThat(asset.format(), is(ConanFormat.NAME));
  assertThat(asset.name(), is(PATH_DIGEST));
  assertThat(asset.contentType(), is(ContentTypes.APPLICATION_JSON));
}