org.sonatype.nexus.repository.view.payloads.StringPayload Java Examples

The following examples show how to use org.sonatype.nexus.repository.view.payloads.StringPayload. 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: ComposerJsonProcessor.java    From nexus-repository-composer with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Rewrites the provider JSON so that source entries are removed and dist entries are pointed back to Nexus.
 */
public Payload rewriteProviderJson(final Repository repository, final Payload payload) throws IOException {
  Map<String, Object> json = parseJson(payload);
  if (json.get(PACKAGES_KEY) instanceof Map) {
    Map<String, Object> packagesMap = (Map<String, Object>) json.get(PACKAGES_KEY);
    for (String packageName : packagesMap.keySet()) {
      Map<String, Object> packageVersions = (Map<String, Object>) packagesMap.get(packageName);
      for (String packageVersion : packageVersions.keySet()) {
        // TODO: Make this more robust, right now it makes a lot of assumptions and doesn't deal with bad things well
        Map<String, Object> versionInfo = (Map<String, Object>) packageVersions.get(packageVersion);
        versionInfo.remove(SOURCE_KEY); // TODO: For now don't allow sources, probably should make this configurable?

        Map<String, Object> distInfo = (Map<String, Object>) versionInfo.get(DIST_KEY);
        if (distInfo != null && ZIP_TYPE.equals(distInfo.get(TYPE_KEY))) {
          versionInfo.put(DIST_KEY,
              buildDistInfo(repository, packageName, packageVersion, (String) distInfo.get(REFERENCE_KEY),
                  (String) distInfo.get(SHASUM_KEY), ZIP_TYPE));
        }
      }
    }
  }
  return new StringPayload(mapper.writeValueAsString(json), payload.getContentType());
}
 
Example #2
Source File: HandlerContributorTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void addContributedHandlers() throws Exception {
  final AttributesMap attributes = new AttributesMap();

  final Request request = mock(Request.class);
  final Context context = mock(Context.class);

  when(context.getRequest()).thenReturn(request);
  when(context.getAttributes()).thenReturn(attributes);
  when(context.proceed()).thenReturn(HttpResponses.ok(new Content(new StringPayload("test", "text/plain"))));

  final ContributedHandler handlerA = mock(ContributedHandler.class);
  final ContributedHandler handlerB = mock(ContributedHandler.class);
  final HandlerContributor underTest = new HandlerContributor(asList(handlerA, handlerB));
  final Response response = underTest.handle(context);

  assertThat(response.getStatus().isSuccessful(), is(true));
  assertThat(attributes.get(HandlerContributor.EXTENDED_MARKER), is(Boolean.TRUE));

  // Handle a second time to ensure the contributed handlers aren't injected twice
  underTest.handle(context);

  ArgumentCaptor<ContributedHandler> handlerCaptor = ArgumentCaptor.forClass(ContributedHandler.class);
  verify(context, times(2)).insertHandler(handlerCaptor.capture());
  assertThat(handlerCaptor.getAllValues(), is(asList(handlerB, handlerA))); // Intentionally added in "reverse" order
}
 
Example #3
Source File: MetadataUpdaterTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void replaceWithUnchangedExisting() throws IOException {
  when(mavenFacet.get(mavenPath)).thenReturn(
      new Content(
          new StringPayload("<?xml version=\"1.0\" encoding=\"UTF-8\"?><metadata></metadata>",
              "text/xml")), content);
  UnitOfWork.beginBatch(tx);
  try {
    testSubject.replace(mavenPath, Maven2Metadata.newGroupLevel(DateTime.now(), new ArrayList<Plugin>()));
  }
  finally {
    UnitOfWork.end();
  }
  verify(tx, times(1)).commit();
  verify(mavenFacet, times(1)).get(eq(mavenPath));
  verify(mavenFacet, times(0)).put(eq(mavenPath), any(Payload.class));
}
 
Example #4
Source File: MetadataUpdaterTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void updateWithExisting() throws IOException {
  when(mavenFacet.get(mavenPath)).thenReturn(
      new Content(
          new StringPayload("<?xml version=\"1.0\" encoding=\"UTF-8\"?><metadata><groupId>group</groupId></metadata>",
              "text/xml")), content);
  UnitOfWork.beginBatch(tx);
  try {
    testSubject.update(mavenPath, Maven2Metadata.newGroupLevel(DateTime.now(), new ArrayList<Plugin>()));
  }
  finally {
    UnitOfWork.end();
  }
  verify(tx, times(1)).commit();
  verify(mavenFacet, times(1)).get(eq(mavenPath));
  verify(mavenFacet, times(0)).put(eq(mavenPath), any(Payload.class));
}
 
Example #5
Source File: OrientMetadataUtils.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Writes passed in metadata as XML.
 */
public static void write(final Repository repository, final MavenPath mavenPath, final Metadata metadata)
    throws IOException
{
  MavenFacet mavenFacet = repository.facet(MavenFacet.class);
  final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  MavenModels.writeMetadata(buffer, metadata);
  mavenFacet.put(mavenPath, new BytesPayload(buffer.toByteArray(),
      MavenMimeRulesSource.METADATA_TYPE));
  final Map<HashAlgorithm, HashCode> hashCodes = mavenFacet.get(mavenPath).getAttributes()
      .require(Content.CONTENT_HASH_CODES_MAP, Content.T_CONTENT_HASH_CODES_MAP);
  checkState(hashCodes != null, "hashCodes");
  for (HashType hashType : HashType.values()) {
    MavenPath checksumPath = mavenPath.hash(hashType);
    HashCode hashCode = hashCodes.get(hashType.getHashAlgorithm());
    checkState(hashCode != null, "hashCode: type=%s", hashType);
    mavenFacet.put(checksumPath, new StringPayload(hashCode.toString(), Constants.CHECKSUM_CONTENT_TYPE));
  }
}
 
Example #6
Source File: MavenUploadHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private String generatePom(final Repository repository,
                           final String basePath,
                           final String groupId,
                           final String artifactId,
                           final String version,
                           @Nullable final String packaging)
    throws IOException
{
  log.debug("Generating pom for {} {} {} with packaging {}", groupId, artifactId, version, packaging);

  String pom = mavenPomGenerator.generatePom(groupId, artifactId, version, packaging);

  MavenPath mavenPath = parser.parsePath(basePath + ".pom");

  storeAssetContent(repository, mavenPath, new StringPayload(pom, "text/xml"));

  return mavenPath.getPath();
}
 
Example #7
Source File: OrientPyPiHostedHandlers.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Handle request for search.
 */
public Handler search() {
  return context -> {
    Payload payload = checkNotNull(context.getRequest().getPayload());
    try (InputStream is = payload.openInputStream()) {
      QueryBuilder query = parseSearchRequest(context.getRepository().getName(), is);
      List<PyPiSearchResult> results = new ArrayList<>();
      for (SearchHit hit : searchQueryService.browse(unrestricted(query))) {
        Map<String, Object> source = hit.getSource();
        Map<String, Object> formatAttributes = (Map<String, Object>) source.getOrDefault(
            MetadataNodeEntityAdapter.P_ATTRIBUTES, Collections.emptyMap());
        Map<String, Object> pypiAttributes = (Map<String, Object>) formatAttributes.getOrDefault(PyPiFormat.NAME,
            Collections.emptyMap());
        String name = Strings.nullToEmpty((String) pypiAttributes.get(PyPiAttributes.P_NAME));
        String version = Strings.nullToEmpty((String) pypiAttributes.get(PyPiAttributes.P_VERSION));
        String summary = Strings.nullToEmpty((String) pypiAttributes.get(PyPiAttributes.P_SUMMARY));
        results.add(new PyPiSearchResult(name, version, summary));
      }
      String response = buildSearchResponse(results);
      return HttpResponses.ok(new StringPayload(response, ContentTypes.APPLICATION_XML));
    }
  };
}
 
Example #8
Source File: NpmFacetUtilsTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void mergeDistTagResponse_multipleEntries() throws Exception {
  when(response1.getPayload()).thenReturn(new Content(
      new StringPayload("{\"latest\":\"1.0.2\",\"hello\":\"1.2.3\",\"world\":\"4.5.6\"}", APPLICATION_JSON)));
  when(response2.getPayload())
      .thenReturn(new Content(new StringPayload("{\"latest\":\"1.0.1\",\"world\":\"5.5.5\"}", APPLICATION_JSON)));
  when(response3.getPayload())
      .thenReturn(new Content(new StringPayload("{\"latest\":\"1.0.0\",\"hello\":\"2.2.2\"}", APPLICATION_JSON)));

  final Response mergedResponse = NpmFacetUtils
      .mergeDistTagResponse(ImmutableMap.of(repository1, response1, repository2, response2, repository3, response3));

  final byte[] content = IOUtils.toByteArray(mergedResponse.getPayload().openInputStream());
  final Map<String, String> actual = objectMapper.readValue(content, new TypeReference<Map<String, String>>() { });
  assertThat(actual.get("latest"), containsString("1.0.2"));
  assertThat(actual.get("hello"), containsString("2.2.2"));
  assertThat(actual.get("world"), containsString("5.5.5"));
}
 
Example #9
Source File: NpmSearchGroupHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Response doGet(@Nonnull final Context context,
                         @Nonnull final DispatchedRepositories dispatched)
    throws Exception
{
  checkNotNull(context);
  checkNotNull(dispatched);

  Request request = context.getRequest();
  Parameters parameters = request.getParameters();
  String text = npmSearchParameterExtractor.extractText(parameters);

  NpmSearchResponse response;
  if (text.isEmpty()) {
    response = npmSearchResponseFactory.buildEmptyResponse();
  }
  else {
    response = searchMembers(context, dispatched, parameters);
  }

  String content = npmSearchResponseMapper.writeString(response);
  return HttpResponses.ok(new StringPayload(content, ContentTypes.APPLICATION_JSON));
}
 
Example #10
Source File: ConanProxyFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
private Content putMetadata(final Context context,
                            final Content content,
                            final AssetKind assetKind,
                            final ConanCoords coords)
    throws IOException
{
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (TempBlob tempBlob = storageFacet.createTempBlob(content.openInputStream(), HASH_ALGORITHMS)) {

    if (assetKind == DOWNLOAD_URL || assetKind == DIGEST) {
      Content saveMetadata = doSaveMetadata(tempBlob, content, assetKind, coords);
      return new Content(
          new StringPayload(
              conanUrlIndexer.updateAbsoluteUrls(context, saveMetadata, getRepository()),
              ContentTypes.APPLICATION_JSON)
      );
    }
    return doSaveMetadata(tempBlob, content, assetKind, coords);
  }
}
 
Example #11
Source File: ConanTokenFacetImpl.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Response login(final Context context) {
  String token = conanTokenManager.login();
  if(null != token) {
    return new Response.Builder()
        .status(Status.success(OK))
        .payload(new StringPayload(token, TEXT_PLAIN))
        .build();
  }
  return badCredentials("Bad username or password");
}
 
Example #12
Source File: ComposerJsonProcessor.java    From nexus-repository-composer with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Builds a packages.json file as a {@code Content} instance containing the actual JSON for the given providers.
 */
private Content buildPackagesJson(final Repository repository, final Set<String> names) throws IOException {
  Map<String, Object> packagesJson = new LinkedHashMap<>();
  packagesJson.put(PROVIDERS_URL_KEY, repository.getUrl() + PACKAGE_JSON_PATH);
  packagesJson.put(PROVIDERS_KEY, names.stream()
      .collect(Collectors.toMap((each) -> each, (each) -> singletonMap(SHA256_KEY, null))));
  return new Content(new StringPayload(mapper.writeValueAsString(packagesJson), ContentTypes.APPLICATION_JSON));
}
 
Example #13
Source File: ContentHeadersHandlerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void okResponseNotContent() throws Exception {
  when(context.proceed()).thenReturn(HttpResponses.ok(new StringPayload("test", "text/plain")));
  final Response r = subject.handle(context);
  assertThat(r.getStatus().isSuccessful(), is(true));
  assertThat(r.getHeaders().get(HttpHeaders.LAST_MODIFIED), nullValue());
  assertThat(r.getHeaders().get(HttpHeaders.ETAG), nullValue());
}
 
Example #14
Source File: ContentHeadersHandlerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void okResponseNoExtraData() throws Exception {
  when(context.proceed()).thenReturn(
      HttpResponses.ok(new Content(new StringPayload(payloadString, "text/plain"))));
  final Response r = subject.handle(context);
  assertThat(r.getStatus().isSuccessful(), is(true));
  assertThat(r.getHeaders().get(HttpHeaders.LAST_MODIFIED), nullValue());
  assertThat(r.getHeaders().get(HttpHeaders.ETAG), nullValue());
}
 
Example #15
Source File: ContentHeadersHandlerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void okResponseWithWeakEtag() throws Exception {
  final Content content = new Content(new StringPayload(payloadString, "text/plain"));
  content.getAttributes().set(Content.CONTENT_LAST_MODIFIED, now);
  content.getAttributes().set(Content.CONTENT_ETAG, "W/\"etag\"");
  when(context.proceed()).thenReturn(HttpResponses.ok(content));
  final Response r = subject.handle(context);
  assertThat(r.getStatus().isSuccessful(), is(true));
  assertThat(r.getHeaders().get(HttpHeaders.LAST_MODIFIED), equalTo(DateTimeUtils.formatDateTime(now)));
  assertThat(r.getHeaders().get(HttpHeaders.ETAG), equalTo("W/\"etag\""));
}
 
Example #16
Source File: ContentHeadersHandlerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void okResponse() throws Exception {
  final Content content = new Content(new StringPayload(payloadString, "text/plain"));
  content.getAttributes().set(Content.CONTENT_LAST_MODIFIED, now);
  content.getAttributes().set(Content.CONTENT_ETAG, "etag");
  when(context.proceed()).thenReturn(HttpResponses.ok(content));
  final Response r = subject.handle(context);
  assertThat(r.getStatus().isSuccessful(), is(true));
  assertThat(r.getHeaders().get(HttpHeaders.LAST_MODIFIED), equalTo(DateTimeUtils.formatDateTime(now)));
  assertThat(r.getHeaders().get(HttpHeaders.ETAG), equalTo("\"etag\""));
}
 
Example #17
Source File: BrowseUnsupportedHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  TemplateParameters params = templateHelper.parameters();
  params.set("repository", context.getRepository());

  String html = templateHelper.render(template, params);
  return HttpResponses.ok(new StringPayload(html, "text/html"));
}
 
Example #18
Source File: CocoapodsProxyFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Content transformSpecFile(final Payload payload) throws IOException {
  try (InputStream data = payload.openInputStream()) {
    String specFile = IOUtils.toString(data, Charsets.UTF_8);
    try {
      return new Content(
          new StringPayload(specTransformer.toProxiedSpec(specFile, URI.create(getRepository().getUrl() + "/")),
              "application/json"));
    }
    catch (InvalidSpecFileException e) {
      log.info("Invalid Spec file", e);
      return null;
    }
  }
}
 
Example #19
Source File: MetadataUpdaterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void replaceWithExistingCorrupted() throws IOException {
  when(mavenFacet.get(mavenPath)).thenReturn(
      new Content(new StringPayload("ThisIsNotAnXml", "text/xml")), content);
  UnitOfWork.beginBatch(tx);
  try {
    testSubject.replace(mavenPath, Maven2Metadata.newGroupLevel(DateTime.now(), new ArrayList<Plugin>()));
  }
  finally {
    UnitOfWork.end();
  }
  verify(tx, times(1)).commit();
  verify(mavenFacet, times(2)).get(eq(mavenPath));
  verify(mavenFacet, times(1)).put(eq(mavenPath), any(Payload.class));
}
 
Example #20
Source File: MetadataUpdaterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void updateWithExistingCorrupted() throws IOException {
  when(mavenFacet.get(mavenPath)).thenReturn(
      new Content(new StringPayload("ThisIsNotAnXml", "text/xml")), content);
  UnitOfWork.beginBatch(tx);
  try {
    testSubject.update(mavenPath, Maven2Metadata.newGroupLevel(DateTime.now(), new ArrayList<Plugin>()));
  }
  finally {
    UnitOfWork.end();
  }
  verify(tx, times(1)).commit();
  verify(mavenFacet, times(2)).get(eq(mavenPath));
  verify(mavenFacet, times(1)).put(eq(mavenPath), any(Payload.class));
}
 
Example #21
Source File: CreateIndexFacetImpl.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
private void createIndexYaml() {
  ChartIndex index = new ChartIndex();
  index.setApiVersion(API_VERSION);
  index.setGenerated(new DateTime());
  Repository repository = getRepository();
  HelmContentFacet helmFacet = repository.facet(HelmContentFacet.class);
  helmFacet
      .putIndex(INDEX_YAML, new Content(new StringPayload(yamlParser.getYamlContent(index), INDEX_YAML_CONTENT_TYPE)),
          HELM_INDEX);
}
 
Example #22
Source File: MavenIOUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public static Map<HashType, Payload> hashesToPayloads(final Map<HashAlgorithm, HashCode> hashCodes)
{
  Map<HashType, Payload> payloadByHash = new EnumMap<>(HashType.class);
  for (HashType hashType : HashType.values()) {
    HashCode hashCode = hashCodes.get(hashType.getHashAlgorithm());
    if (hashCode != null) {
      Payload payload = new StringPayload(hashCode.toString(), CHECKSUM_CONTENT_TYPE);
      payloadByHash.put(hashType, payload);
    }
  }
  return payloadByHash;
}
 
Example #23
Source File: NpmWhoamiHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception
{
  User user = securitySystem.currentUser();

  Username username = new Username(user == null ? "anonymous" : user.getUserId());

  StringPayload payload = new StringPayload(objectMapper.writeValueAsString(username), APPLICATION_JSON);

  return HttpResponses.ok(payload);
}
 
Example #24
Source File: DefaultHttpResponseSenderTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void customStatusMessageIsMaintainedWithPayload() throws Exception {
  when(request.getAction()).thenReturn(HttpMethods.GET);

  Payload detailedReason = new StringPayload("Please authenticate and try again", "text/plain");

  Response response = new Response.Builder()
      .status(Status.failure(FORBIDDEN, "You can't see this"))
      .payload(detailedReason).build();

  underTest.send(request, response, httpServletResponse);

  verify(httpServletResponse).setStatus(403, "You can't see this");
}
 
Example #25
Source File: ViewServlet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@VisibleForTesting
Response describe(final Request request, final Response response, final Exception exception, final String flags) {
  final Description description = new Description(ImmutableMap.<String, Object>of(
      "path", request.getPath(),
      "nexusUrl", BaseUrlHolder.get()
  ));
  if (exception != null) {
    descriptionHelper.describeException(description, exception);
  }
  descriptionHelper.describeRequest(description, request);
  if (response != null) {
    descriptionHelper.describeResponse(description, response);
  }

  DescribeType type = DescribeType.parse(flags);
  log.trace("Describe type: {}", type);
  switch (type) {
    case HTML: {
      String html = descriptionRenderer.renderHtml(description);
      return HttpResponses.ok(new StringPayload(html, ContentTypes.TEXT_HTML));
    }
    case JSON: {
      String json = descriptionRenderer.renderJson(description);
      return HttpResponses.ok(new StringPayload(json, ContentTypes.APPLICATION_JSON));
    }
    default:
      throw new RuntimeException("Invalid describe-type: " + type);
  }
}
 
Example #26
Source File: OrientPyPiGroupFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
protected Content buildMergedIndexRoot(final String name, final Supplier<String> lazyMergeResult, boolean save)
    throws IOException
{
  try {
    String html = lazyMergeResult.get();
    Content newContent = new Content(new StringPayload(html, ContentTypes.TEXT_HTML));
    return save ? saveToCache(name, newContent) : newContent;
  }
  catch (UncheckedIOException e) { // NOSONAR: unchecked wrapper, we're only interested in its cause
    throw e.getCause();
  }
}
 
Example #27
Source File: OrientPyPiHostedFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@TransactionalStoreBlob
protected Content storeHtmlPage(final StorageTx tx, final Asset asset, final String indexPage) throws IOException
{
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (TempBlob tempBlob = storageFacet.createTempBlob(new StringPayload(indexPage, TEXT_HTML), HASH_ALGORITHMS)) {
    return saveAsset(tx, asset, tempBlob, TEXT_HTML, null);
  }
}
 
Example #28
Source File: NpmPingHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception
{
  StringPayload payload = new StringPayload("{}", APPLICATION_JSON);
  return HttpResponses.ok(payload);
}
 
Example #29
Source File: NpmFacetUtilsTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void mergeDistTagResponse_reverseOrder() throws Exception {
  when(response1.getPayload()).thenReturn(new Content(new StringPayload("{\"latest\":\"1.0.1\"}", APPLICATION_JSON)));
  when(response2.getPayload()).thenReturn(new Content(new StringPayload("{\"latest\":\"1.0.0\"}", APPLICATION_JSON)));

  final Response mergedResponse = NpmFacetUtils
      .mergeDistTagResponse(ImmutableMap.of(repository1, response1, repository2, response2));

  final byte[] content = IOUtils.toByteArray(mergedResponse.getPayload().openInputStream());
  final Map<String, String> actual = objectMapper.readValue(content, new TypeReference<Map<String, String>>() { });
  assertThat(actual.get("latest"), containsString("1.0.1"));
}
 
Example #30
Source File: NpmFacetUtilsTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void mergeDistTagResponse_multipleEntriesSingleTag() throws Exception {
  when(response1.getPayload()).thenReturn(new Content(new StringPayload("{\"latest\":\"1.0.0\"}", APPLICATION_JSON)));
  when(response2.getPayload()).thenReturn(new Content(new StringPayload("{\"latest\":\"1.0.1\"}", APPLICATION_JSON)));

  final Response mergedResponse = NpmFacetUtils
      .mergeDistTagResponse(ImmutableMap.of(repository1, response1, repository2, response2));

  final byte[] content = IOUtils.toByteArray(mergedResponse.getPayload().openInputStream());
  final Map<String, String> actual = objectMapper.readValue(content, new TypeReference<Map<String, String>>() { });
  assertThat(actual.get("latest"), containsString("1.0.1"));
}