Search in sources :

Example 1 with MultivaluedMapImpl

use of org.jboss.resteasy.specimpl.MultivaluedMapImpl in project microservice_framework by CJSCommonPlatform.

the class DefaultRestProcessorTest method headersWithUserId.

private static ResteasyHttpHeaders headersWithUserId(final String userId) {
    final ResteasyHttpHeaders headers;
    final MultivaluedMapImpl<String, String> requestHeaders = new MultivaluedMapImpl<>();
    requestHeaders.add(HeaderConstants.USER_ID, userId);
    headers = new ResteasyHttpHeaders(requestHeaders);
    return headers;
}
Also used : MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Matchers.anyString(org.mockito.Matchers.anyString) ResteasyHttpHeaders(org.jboss.resteasy.specimpl.ResteasyHttpHeaders)

Example 2 with MultivaluedMapImpl

use of org.jboss.resteasy.specimpl.MultivaluedMapImpl in project candlepin by candlepin.

the class LinkHeaderResponseFilterTest method testAddsUnchangingQueryParameters.

@Test
public void testAddsUnchangingQueryParameters() {
    MultivaluedMap<String, String> map = new MultivaluedMapImpl<>();
    map.add("baz", "qu=ux");
    UriBuilder bu = UriBuilder.fromUri("https://localhost:8443/candlepin/resource");
    URI returned = interceptor.addUnchangingQueryParams(bu, map).build();
    assertEquals(URI.create("https://localhost:8443/candlepin/resource?baz=qu%3Dux"), returned);
}
Also used : MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.Test)

Example 3 with MultivaluedMapImpl

use of org.jboss.resteasy.specimpl.MultivaluedMapImpl in project candlepin by candlepin.

the class LinkHeaderResponseFilterTest method testDoesNotAddChangingQueryParameters.

@Test
public void testDoesNotAddChangingQueryParameters() {
    MultivaluedMap<String, String> map = new MultivaluedMapImpl<>();
    map.add("page", "10");
    UriBuilder bu = UriBuilder.fromUri("https://localhost:8443/candlepin/resource");
    URI returned = interceptor.addUnchangingQueryParams(bu, map).build();
    assertEquals(URI.create("https://localhost:8443/candlepin/resource"), returned);
}
Also used : MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.Test)

Example 4 with MultivaluedMapImpl

use of org.jboss.resteasy.specimpl.MultivaluedMapImpl in project candlepin by candlepin.

the class OwnerResourceTest method testImportManifestFailure.

@Test
public void testImportManifestFailure() throws IOException, ImporterException {
    ManifestManager manifestManager = mock(ManifestManager.class);
    EventSink es = mock(EventSink.class);
    OwnerResource thisOwnerResource = new OwnerResource(ownerCurator, productCurator, null, null, i18n, es, eventFactory, null, null, manifestManager, null, null, null, null, importRecordCurator, null, null, null, null, null, null, null, contentOverrideValidator, serviceLevelValidator, null, null, null, null, null, this.modelTranslator);
    MultipartInput input = mock(MultipartInput.class);
    InputPart part = mock(InputPart.class);
    File archive = mock(File.class);
    List<InputPart> parts = new ArrayList<>();
    parts.add(part);
    MultivaluedMap<String, String> mm = new MultivaluedMapImpl<>();
    List<String> contDis = new ArrayList<>();
    contDis.add("form-data; name=\"upload\"; filename=\"test_file.zip\"");
    mm.put("Content-Disposition", contDis);
    when(input.getParts()).thenReturn(parts);
    when(part.getHeaders()).thenReturn(mm);
    when(part.getBody(any(GenericType.class))).thenReturn(archive);
    ImporterException expectedException = new ImporterException("Bad import");
    when(manifestManager.importManifest(eq(owner), any(File.class), any(String.class), any(ConflictOverrides.class))).thenThrow(expectedException);
    try {
        thisOwnerResource.importManifest(owner.getKey(), new String[] {}, input);
        fail("Expected IseException was not thrown");
    } catch (IseException ise) {
    // expected, so we catch and go on.
    }
    verify(manifestManager).recordImportFailure(eq(owner), eq(expectedException), eq("test_file.zip"));
}
Also used : ImporterException(org.candlepin.sync.ImporterException) ConflictOverrides(org.candlepin.sync.ConflictOverrides) GenericType(org.jboss.resteasy.util.GenericType) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) ArrayList(java.util.ArrayList) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Matchers.anyString(org.mockito.Matchers.anyString) ManifestManager(org.candlepin.controller.ManifestManager) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) IseException(org.candlepin.common.exceptions.IseException) EventSink(org.candlepin.audit.EventSink) File(java.io.File) Test(org.junit.Test)

Example 5 with MultivaluedMapImpl

use of org.jboss.resteasy.specimpl.MultivaluedMapImpl in project candlepin by candlepin.

the class OwnerResourceTest method testImportManifestSynchronousSuccess.

@Test
public void testImportManifestSynchronousSuccess() throws IOException, ImporterException {
    ManifestManager manifestManager = mock(ManifestManager.class);
    EventSink es = mock(EventSink.class);
    OwnerResource thisOwnerResource = new OwnerResource(ownerCurator, productCurator, null, null, i18n, es, eventFactory, null, null, manifestManager, null, null, null, null, importRecordCurator, null, null, null, null, null, null, null, contentOverrideValidator, serviceLevelValidator, null, null, null, null, null, this.modelTranslator);
    MultipartInput input = mock(MultipartInput.class);
    InputPart part = mock(InputPart.class);
    File archive = mock(File.class);
    List<InputPart> parts = new ArrayList<>();
    parts.add(part);
    MultivaluedMap<String, String> mm = new MultivaluedMapImpl<>();
    List<String> contDis = new ArrayList<>();
    contDis.add("form-data; name=\"upload\"; filename=\"test_file.zip\"");
    mm.put("Content-Disposition", contDis);
    when(input.getParts()).thenReturn(parts);
    when(part.getHeaders()).thenReturn(mm);
    when(part.getBody(any(GenericType.class))).thenReturn(archive);
    ImportRecord ir = new ImportRecord(owner);
    when(manifestManager.importManifest(eq(owner), any(File.class), eq("test_file.zip"), any(ConflictOverrides.class))).thenReturn(ir);
    ImportRecord response = thisOwnerResource.importManifest(owner.getKey(), new String[] {}, input);
    assertNotNull(response);
    assertEquals(ir, response);
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) GenericType(org.jboss.resteasy.util.GenericType) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) ArrayList(java.util.ArrayList) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Matchers.anyString(org.mockito.Matchers.anyString) ManifestManager(org.candlepin.controller.ManifestManager) ImportRecord(org.candlepin.model.ImportRecord) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) EventSink(org.candlepin.audit.EventSink) File(java.io.File) Test(org.junit.Test)

Aggregations

MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)10 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)4 File (java.io.File)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 EventSink (org.candlepin.audit.EventSink)3 ManifestManager (org.candlepin.controller.ManifestManager)3 ConflictOverrides (org.candlepin.sync.ConflictOverrides)3 InputPart (org.jboss.resteasy.plugins.providers.multipart.InputPart)3 MultipartInput (org.jboss.resteasy.plugins.providers.multipart.MultipartInput)3 GenericType (org.jboss.resteasy.util.GenericType)3 ClientRequestContext (javax.ws.rs.client.ClientRequestContext)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 Access (org.candlepin.auth.Access)2 SubResource (org.candlepin.auth.SubResource)2 Before (org.junit.Before)2 Test (org.junit.jupiter.api.Test)2 ClientResponseContext (javax.ws.rs.client.ClientResponseContext)1 UriInfo (javax.ws.rs.core.UriInfo)1