Search in sources :

Example 6 with MultivaluedMapImpl

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

the class ConsumerContentOverrideResourceTest method setUp.

@Before
public void setUp() {
    ConsumerType ctype = new ConsumerType("test-consumer-type");
    ctype.setId("test-ctype");
    consumer = new Consumer("test-consumer", "test-user", new Owner("Test Owner"), ctype);
    MultivaluedMap<String, String> mvm = new MultivaluedMapImpl<>();
    mvm.add("consumer_uuid", consumer.getUuid());
    context = mock(UriInfo.class);
    when(context.getPathParameters()).thenReturn(mvm);
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(overrideRules.canOverrideForConsumer(any(String.class))).thenReturn(true);
    i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    contentOverrideValidator = new ContentOverrideValidator(i18n, overrideRules);
    resource = new ConsumerContentOverrideResource(consumerContentOverrideCurator, consumerCurator, contentOverrideValidator, i18n);
    when(principal.canAccess(any(Object.class), any(SubResource.class), any(Access.class))).thenReturn(true);
}
Also used : SubResource(org.candlepin.auth.SubResource) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) Access(org.candlepin.auth.Access) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) ContentOverrideValidator(org.candlepin.util.ContentOverrideValidator) ConsumerType(org.candlepin.model.ConsumerType) UriInfo(javax.ws.rs.core.UriInfo) Before(org.junit.Before)

Example 7 with MultivaluedMapImpl

use of org.jboss.resteasy.specimpl.MultivaluedMapImpl in project robozonky by RoboZonky.

the class AbstractCommonFilterTest method userAgent.

@Test
void userAgent() throws URISyntaxException {
    final MultivaluedMap<String, Object> map = new MultivaluedMapImpl<>();
    final ClientRequestContext ctx = mock(ClientRequestContext.class);
    when(ctx.getUri()).thenReturn(new URI("http://localhost/"));
    when(ctx.getHeaders()).thenReturn(map);
    getTestedFilter().filter(ctx);
    assertThat(map.get("User-Agent").get(0)).isEqualTo(Defaults.ROBOZONKY_USER_AGENT);
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 8 with MultivaluedMapImpl

use of org.jboss.resteasy.specimpl.MultivaluedMapImpl in project robozonky by RoboZonky.

the class RoboZonkyFilterTest method response.

@Test
void response() throws IOException {
    final String key = UUID.randomUUID().toString();
    final String key2 = UUID.randomUUID().toString();
    final String value = UUID.randomUUID().toString();
    final MultivaluedMap<String, String> map = new MultivaluedMapImpl<>();
    map.add(key, value);
    map.addAll(key2, Collections.emptyList());
    final ClientRequestContext ctx = mock(ClientRequestContext.class);
    final ClientResponseContext ctx2 = mock(ClientResponseContext.class);
    when(ctx2.getHeaders()).thenReturn(map);
    when(ctx2.getStatusInfo()).thenReturn(mock(Response.StatusType.class));
    final RoboZonkyFilter filter = new RoboZonkyFilter();
    filter.filter(ctx, ctx2);
    assertSoftly(softly -> {
        softly.assertThat(filter.getLastResponseHeader(key)).contains(value);
        softly.assertThat(filter.getLastResponseHeader(key2)).isEmpty();
    });
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) ClientResponseContext(javax.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 9 with MultivaluedMapImpl

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

the class OwnerResourceTest method testImportManifestAsyncSuccess.

@Test
public void testImportManifestAsyncSuccess() 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);
    JobDetail job = mock(JobDetail.class);
    when(input.getParts()).thenReturn(parts);
    when(part.getHeaders()).thenReturn(mm);
    when(part.getBody(any(GenericType.class))).thenReturn(archive);
    when(manifestManager.importManifestAsync(eq(owner), any(File.class), eq("test_file.zip"), any(ConflictOverrides.class))).thenReturn(job);
    JobDetail response = thisOwnerResource.importManifestAsync(owner.getKey(), new String[] {}, input);
    assertNotNull(response);
    assertEquals(job, response);
    verify(manifestManager, never()).importManifest(eq(owner), any(File.class), any(String.class), any(ConflictOverrides.class));
}
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) JobDetail(org.quartz.JobDetail) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) EventSink(org.candlepin.audit.EventSink) File(java.io.File) Test(org.junit.Test)

Example 10 with MultivaluedMapImpl

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

the class ActivationKeyContentOverrideResourceTest method setUp.

@Before
public void setUp() throws URISyntaxException {
    key = new ActivationKey("actkey", owner);
    key.setId("keyid");
    MultivaluedMap<String, String> mvm = new MultivaluedMapImpl<>();
    mvm.add("activation_key_id", key.getId());
    when(context.getPathParameters()).thenReturn(mvm);
    akcor = new ActivationKeyContentOverrideResource(activationKeyContentOverrideCurator, akc, contentOverrideValidator, i18n);
    when(akc.verifyAndLookupKey(eq(key.getId()))).thenReturn(key);
    when(principal.canAccess(any(Object.class), any(SubResource.class), any(Access.class))).thenReturn(true);
}
Also used : SubResource(org.candlepin.auth.SubResource) Access(org.candlepin.auth.Access) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Before(org.junit.Before)

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