Java Code Examples for org.sonatype.nexus.common.app.BaseUrlHolder#set()

The following examples show how to use org.sonatype.nexus.common.app.BaseUrlHolder#set() . 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: ViewServletTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  defaultResponseSender = spy(new DefaultHttpResponseSender());

  when(descriptionRenderer.renderHtml(any(Description.class))).thenReturn("HTML");
  when(descriptionRenderer.renderJson(any(Description.class))).thenReturn("JSON");

  underTest = spy(new ViewServlet(mock(RepositoryManager.class),
      new HttpResponseSenderSelector(Collections.<String, HttpResponseSender>emptyMap(), defaultResponseSender),
      mock(DescriptionHelper.class),
      descriptionRenderer, true
  ));

  when(request.getPath()).thenReturn("/test");

  parameters = new Parameters();
  when(request.getParameters()).thenReturn(parameters);

  BaseUrlHolder.set("http://placebo");
}
 
Example 2
Source File: MavenTestHelper.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private String url(final Repository repo, final String path) {
  boolean reset = false;
  if (!BaseUrlHolder.isSet()) {
    reset = true;
    BaseUrlHolder.set(nexusUrl.toString());
  }
  String repoPath = path.startsWith("/") ? path : '/' + path;
  try {
    return String.format("%s%s", repo.getUrl(), repoPath);
  }
  finally {
    if (reset) {
      BaseUrlHolder.unset();
    }
  }
}
 
Example 3
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 4
Source File: NpmPackageRootMetadataUtilsTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void createFullPackageMetadataImpl(final BiFunction<String, String, String> function, String packageJsonFilename) throws URISyntaxException, IOException {
  try {
    assertThat(BaseUrlHolder.isSet(), is(false));
    BaseUrlHolder.set("http://localhost:8080/");

    File packageJsonFile = new File(NpmPackageRootMetadataUtilsTest.class.getResource(packageJsonFilename).toURI());
    File archive = tempFolderRule.newFile();
    Map<String, Object> packageJson = new NpmPackageParser()
        .parsePackageJson(() -> ArchiveUtils.pack(archive, packageJsonFile, "package/package.json"));

    NestedAttributesMap packageMetadata = NpmPackageRootMetadataUtils
        .createFullPackageMetadata(new NestedAttributesMap("metadata", packageJson),
            "npm-hosted",
            "abcd",
            repository,
            function);

    assertPackageMetadata(packageMetadata);
  }
  finally {
    BaseUrlHolder.unset();
  }
}
 
Example 5
Source File: CleanupTaskConanProxyIT.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());
  testData.addDirectory(NexusPaxExamSupport.resolveBaseFile("target/it-resources/conan"));
  testData.addDirectory(NexusPaxExamSupport.resolveBaseFile("target/test-classes/conan"));

  server = Server.withPort(0)
      .serve("/" + JSON_FOR_MODERN_CPP_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(DOWNLOAD_URLS_FILE_NAME)))
      .serve("/" + LIB_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(LIB_DOWNLOAD_URLS_FILE_NAME)))
      .start();

  proxyRepo = repos.createConanProxy(testName.getMethodName(), server.getUrl().toExternalForm());
  URL repositoryUrl = repositoryBaseUrl(proxyRepo);
  proxyClient = new ConanClient(
      clientBuilder(repositoryUrl).build(),
      clientContext(),
      repositoryUrl.toURI()
  );
  proxyClient.get(JSON_FOR_MODERN_CPP_URL);
}
 
Example 6
Source File: RHostedIT.java    From nexus-repository-r with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());
  repository = repos.createRHosted("r-hosted-test");
  client = createRClient(repository);
  uploadPackages(AGRICOLAE_121_TARGZ, AGRICOLAE_131_TGZ);
}
 
Example 7
Source File: NpmStreamingObjectMapperTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void verify_TarballUrl_Manipulation_Of_Json_While_Streaming_Out() throws IOException {
  String nxrmUrl = "http://localhost:8080/";
  String remoteUrl = "https://registry.npmjs.org";
  String distTarballPath = "\"dist\":{\"tarball\":\"";
  String packageId = "array-first";
  String packagePath = "/" + packageId + "/-/" + packageId;

  // these are not the complete tarball urls but are unique enough to identify that it was changed
  String normDistTarball = distTarballPath + nxrmUrl + "repository/" + REPO_NAME + packagePath;
  String remoteDistTarball = distTarballPath + remoteUrl + packagePath;

  assertThat(BaseUrlHolder.isSet(), is(false));

  BaseUrlHolder.set(nxrmUrl);

  try (InputStream packageRoot = getResource("streaming-payload-manipulate-while-streaming-out.json");
       InputStream packageRoot2 = getResource("streaming-payload-manipulate-while-streaming-out.json")) {

    String original = IOUtils.toString(packageRoot);

    assertThat(original, containsString(remoteDistTarball));
    assertThat(original, not(containsString(normDistTarball)));

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    new NpmStreamingObjectMapper(singletonList(rewriteTarballUrlMatcher(REPO_NAME, packageId)))
        .readAndWrite(packageRoot2, outputStream);

    String streamed = outputStream.toString();
    assertThat(streamed, not(containsString(remoteDistTarball)));
    assertThat(streamed, containsString(normDistTarball));
  }
}
 
Example 8
Source File: CondaClientITSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This initialize method will add the conda resources test data directory and create the {@link #condaCli}.
 */
@Before
public void onInitializeClientIT() throws Exception {
  addTestDataDirectory("target/it-resources/conda");
  BaseUrlHolder.set(this.nexusUrl.toString());
  condaCli = new CondaCommandLineITSupport(createTestConfig());
}
 
Example 9
Source File: ConanProxySearchIT.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());

  server = Server
      .withPort(CONAN_REMOTE_PORT)

      // we should make sure that proxy will not use download_urls
      .serve("/" + PATH_DOWNLOAD_URLS)
      .withBehaviours(Behaviours.error(501))

      .serve("/" + PATH_PATTERN_SEARCH)
      .withBehaviours(Behaviours.content(MOCK_PATTERN_SEARCH_REMOTE_RESPONSE, ContentTypes.APPLICATION_JSON))

      .serve("/" + PATH_SEARCH)
      .withBehaviours(Behaviours.content(MOCK_SEARCH_REMOTE_RESPONSE, ContentTypes.APPLICATION_JSON))

      .serve("/" + PATH_DIGEST)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_DIGEST)))

      .serve("/" + PATH_MANIFEST)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_MANIFEST)))

      .start();

  proxyRepo = repos.createConanProxy(NXRM_CONAN_PROXY_REPO_NAME, server.getUrl().toExternalForm());
  proxyClient = conanClient(proxyRepo);
}
 
Example 10
Source File: RaptureWebResourceBundleTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() {
  BaseUrlHolder.set("http://baseurl/");

  when(httpServletRequest.getParameter("debug")).thenReturn("false");

  underTest =
      new RaptureWebResourceBundle(applicationVersion, Providers.of(httpServletRequest), Providers.of(stateComponent),
          templateHelper, asList(new UiPluginDescriptorImpl()),
          asList(new ExtJsUiPluginDescriptorImpl("test-1"), new ExtJsUiPluginDescriptorImpl("test-2")));
}
 
Example 11
Source File: HelmProxyIT.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());
  server = Server.withPort(0)
      .serve("/*").withBehaviours(error(200))
      .serve("/" + MONGO_PKG_FILE_NAME_600_TGZ).withBehaviours(file(testData.resolveFile(MONGO_PKG_FILE_NAME_600_TGZ)))
      .serve("/" + YAML_FILE_NAME).withBehaviours(file(testData.resolveFile(YAML_FILE_NAME)))
      .start();
  repository = repos.createHelmProxy("helm-proxy-test", server.getUrl().toExternalForm());
  client = helmClient(repository);
}
 
Example 12
Source File: HelmContentProxyIT.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());
  server = Server.withPort(0)
      .serve("/*").withBehaviours(error(200))
      .serve("/" + MONGO_PKG_FILE_NAME_600_TGZ)
      .withBehaviours(file(testData.resolveFile(MONGO_PKG_FILE_NAME_600_TGZ)))
      .serve("/" + YAML_FILE_NAME).withBehaviours(file(testData.resolveFile(YAML_FILE_NAME)))
      .start();
  repository = repos.createHelmProxy("helm-proxy-test", server.getUrl().toExternalForm());
  client = helmClient(repository);
}
 
Example 13
Source File: RepositoryAuditor.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Map<String, Object> createFullAttributes(final Repository repository) {
  boolean baseUrlAbsent = !BaseUrlHolder.isSet();
  try {
    if (baseUrlAbsent) {
      BaseUrlHolder.set(""); // use empty base URL placeholder during conversion to avoid log-spam
    }

    AbstractApiRepository apiObject = convert(repository);

    ObjectWriter writer = mapper.writerFor(apiObject.getClass());

    String json = writer.writeValueAsString(apiObject);

    return mapper.readerFor(new TypeReference<Map<String, Object>>()
    {
    }).readValue(json);
  }
  catch (Exception e) {
    log.error("Failed to convert repo object falling back to simple", e);
    return createSimple(repository);
  }
  finally {
    if (baseUrlAbsent) {
      BaseUrlHolder.unset();
    }
  }
}
 
Example 14
Source File: CleanupTaskP2ProxyIT.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());
  testData.addDirectory(NexusPaxExamSupport.resolveBaseFile("target/test-classes/p2"));
  server = Server.withPort(0)
      .serve("/" + VALID_PACKAGE_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(PACKAGE_NAME)))
      .serve("/" + VALID_HELP_PACKAGE_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(HELP_PACKAGE_NAME)))
      .start();

  proxyRepo = repos.createP2Proxy(testName.getMethodName(), server.getUrl().toExternalForm());
  proxyClient = p2Client(proxyRepo);
  deployArtifacts(VALID_HELP_PACKAGE_URL);
}
 
Example 15
Source File: P2RepositoriesApiResourceIT.java    From nexus-repository-p2 with Eclipse Public License 1.0 4 votes vote down vote up
@Before
public void before() {
  BaseUrlHolder.set(this.nexusUrl.toString());
}
 
Example 16
Source File: RResourceIT.java    From nexus-repository-r with Eclipse Public License 1.0 4 votes vote down vote up
@Before
public void before() {
  BaseUrlHolder.set(this.nexusUrl.toString());
  repos.createRHosted(MEMBER_NAME);
}
 
Example 17
Source File: SimpleApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Before
public void setup() {
  underTest = new SimpleApiRepositoryAdapter(routingRuleStore);
  BaseUrlHolder.set("http://nexus-url");
}
 
Example 18
Source File: AptApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Before
public void setup() {
  underTest = new AptApiRepositoryAdapter(routingRuleStore);
  BaseUrlHolder.set("http://nexus-url");
}
 
Example 19
Source File: HelmHostedIT.java    From nexus-repository-helm with Eclipse Public License 1.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());
  repository = repos.createHelmHosted("helm-hosted-test");
  client = createHelmClient(repository);
}
 
Example 20
Source File: MavenApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Before
public void setup() {
  underTest = new MavenApiRepositoryAdapter(routingRuleStore);
  BaseUrlHolder.set("http://nexus-url");
}