use of org.sonatype.nexus.repository.view.Response in project nexus-repository-r by sonatype-nexus-community.
the class PackagesGroupHandlerTest method setupRepository.
// Commented out until GroupHandler.DispactchedRepositories is made public
/* @Test
public void okWhenGetPackagesWithSingleResponse() throws Exception {
Response response = underTest.doGet(context, dispatchedRepositories);
assertThat(response.getStatus().getCode(), is(equalTo(200)));
}
@Test
public void okWhenGetPackagesWithMultipleResponses() throws Exception {
members.add(repository2);
Response response = underTest.doGet(context, dispatchedRepositories);
assertThat(response.getStatus().getCode(), is(equalTo(200)));
}
@Test
public void notFoundWhenNoResponses() throws Exception {
members.clear();
Response response = underTest.doGet(context, dispatchedRepositories);
assertThat(response.getStatus().getCode(), is(equalTo(404)));
}*/
private void setupRepository(final Repository repository) throws Exception {
ViewFacet viewFacet = mock(ViewFacet.class);
Response response = mock(Response.class);
Payload payload = mock(Payload.class);
GroupFacet groupFacet = mock(GroupFacet.class);
when(groupFacet.members()).thenReturn(members);
when(repository.facet(GroupFacet.class)).thenReturn(groupFacet);
when(repository.facet(ViewFacet.class)).thenReturn(viewFacet);
when(viewFacet.dispatch(any(), any())).thenReturn(response);
when(response.getPayload()).thenReturn(payload);
when(payload.openInputStream()).thenReturn(new FileInputStream(packages));
when(response.getStatus()).thenReturn(new Status(true, 200));
}
use of org.sonatype.nexus.repository.view.Response in project nexus-repository-r by sonatype-nexus-community.
the class HostedHandlersTest method assertStatus.
private void assertStatus(final Handler handler, final int status) throws Exception {
Response response = handler.handle(context);
assertThat(response.getStatus().getCode(), is(equalTo(status)));
}
use of org.sonatype.nexus.repository.view.Response in project nexus-repository-r by sonatype-nexus-community.
the class HostedHandlersTest method repositoryUploadFailedWrongExtension.
@Test
public void repositoryUploadFailedWrongExtension() throws Exception {
when(request.getPath()).thenReturn(WRONG_EXTENSION_FULL_PATH_VALUE);
Response response = underTest.putArchive.handle(context);
verify(rHostedFacet, times(0)).upload(WRONG_EXTENSION_FULL_PATH_VALUE, payload);
assertThat(response.getStatus().getCode(), is(equalTo(BAD_REQUEST)));
assertThat(response.getStatus().getMessage(), is(equalTo(NOT_VALID_EXTENSION_ERROR_MESSAGE)));
}
use of org.sonatype.nexus.repository.view.Response in project nexus-repository-r by sonatype-nexus-community.
the class HostedHandlersTest method assertStatus.
private void assertStatus(final Handler handler, final int status) throws Exception {
Response response = handler.handle(context);
assertThat(response.getStatus().getCode(), is(equalTo(status)));
}
use of org.sonatype.nexus.repository.view.Response in project nexus-repository-r by sonatype-nexus-community.
the class PackagesGroupHandler method doGet.
@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));
}
Aggregations