Return-Path: X-Original-To: apmail-deltaspike-users-archive@www.apache.org Delivered-To: apmail-deltaspike-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A47F118ECF for ; Fri, 12 Feb 2016 03:53:46 +0000 (UTC) Received: (qmail 28248 invoked by uid 500); 12 Feb 2016 03:53:41 -0000 Delivered-To: apmail-deltaspike-users-archive@deltaspike.apache.org Received: (qmail 28212 invoked by uid 500); 12 Feb 2016 03:53:41 -0000 Mailing-List: contact users-help@deltaspike.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@deltaspike.apache.org Delivered-To: mailing list users@deltaspike.apache.org Received: (qmail 28200 invoked by uid 99); 12 Feb 2016 03:53:40 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Feb 2016 03:53:40 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 533D21A0468 for ; Fri, 12 Feb 2016 03:53:40 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.429 X-Spam-Level: * X-Spam-Status: No, score=1.429 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id o2h3h_MfIVpE for ; Fri, 12 Feb 2016 03:53:38 +0000 (UTC) Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 012AF31ADE for ; Fri, 12 Feb 2016 03:53:38 +0000 (UTC) Received: by mail-wm0-f49.google.com with SMTP id p63so3511113wmp.1 for ; Thu, 11 Feb 2016 19:53:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=aSFUKJrjFqrtro5pjZ1+BqrZwvY75vcAy4iXR8tNksM=; b=sOVEwu2xvE9hTKFk0JR/CDp5zEz5LiqCiZqmBZXoR85brrUmq+IoIwRAuGURH44rpi thZqtkrCPmq+FJm0pu6iM0QSsMXZuMRhUrvF2h6bhOQQgmOfFJb99LK5X8nOhds+opJF fRJOb5u10B6vxA3kz67t9NyexlIAfn2QlZsW2+RL9G5QCcFHOX4gXKHjJUKsDnjZSdEh 2cIdCl7mI0NzQeRlCeK6y4Xy7a86FRQA3nd2biJrGgzZo0xAysxMdNd8YdfuwU8IrlQ1 wwJFuXcTiCvOF31ZbAUdG99UyYMBQJLLILSt0JXLkU8n8RI760gSjmXFDBbBk3Jrf3gP SZAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=aSFUKJrjFqrtro5pjZ1+BqrZwvY75vcAy4iXR8tNksM=; b=EQnp4qWj8DaxB5Rc/810u1ROQzJwHnJR4xrmN+8LZtnxK3d2+pn/2OHohiUJCU/R7t B7a7vOIV1D57sT5Qt5exTvnZoyluQuuZqj2qFMZLW3Msivdx1fjKwGbncHKQQ0dxhcMo e6/qyXXS/tZPmSm4exvidTfkr1s7muBsitcK2QWVm5Uh5ik/B2A2je5ABNH74eszHH1s oORbgEsdLBO+mnLzHPna/d7rpwjTzEwQY8vCI8hVv/xLdN7yRkYQY4L0poB0KXI7o3M1 62f3ApvujW81v21orH3yyj4fRoLK80gaenWSc+VSXGFsnCoyXeeUgEoIyy8asYUfwIUw Auug== X-Gm-Message-State: AG10YOTtt1J6VWPLusVXyolTumYrNH3PgaP1brh33eRzLlbgECzmFGIfcieCNCdE8VmG5w1gPn6Pnw/njMW3ZA== X-Received: by 10.28.30.198 with SMTP id e189mr449226wme.60.1455249217576; Thu, 11 Feb 2016 19:53:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.136.145 with HTTP; Thu, 11 Feb 2016 19:53:18 -0800 (PST) In-Reply-To: References: From: Karl Pietrzak Date: Thu, 11 Feb 2016 22:53:18 -0500 Message-ID: Subject: Re: how to test different java.security.Principal's To: users@deltaspike.apache.org Content-Type: multipart/alternative; boundary=001a114b33deac65a2052b8a9c76 --001a114b33deac65a2052b8a9c76 Content-Type: text/plain; charset=UTF-8 I'm not sure how to use my custom CDI qualifiers to achieve my goal. Care to send a blog post or a link to an example? I guess one of the confounding problems might be a test executing in Maven has two bean archives: - target/classes - target/test-classes So whatever solution needs to recognize that target/classes might have its own bean.xml (for production). Do I need an @Alternative or something? Thanks! Any tips would be greatly appreciated. On Wed, Feb 10, 2016 at 9:24 AM, Gerhard Petracek < gerhard.petracek@gmail.com> wrote: > hi, > > you can use your own cdi-qualifier/s or you can use just one (central) > producer which has at least one parameter of type > javax.enterprise.inject.spi.InjectionPoint. > (InjectionPoint allows to get information about the target > -> you can produce dependent-scoped instances e.g. based on the target > test-class). > > regards, > gerhard > > > > 2016-02-10 14:27 GMT+01:00 Karl Pietrzak : > > > Thanks to Java EE 7, or maybe even before it, you can inject a > > java.security.Principal > > . > > > > This is awesome, and I'd love to use this functionality to unit test my > > code with my own Principal's. > > > > Something like: > > > > @Dependent > > > > @RunWith(CdiTestRunner.*class*) > > > > *public* *class* AliceUnitTest { > > > > @Produces > > > > *public* Principal customPrincipal() { > > > > *return* *new* CustomPrincipal("alice@example.com"); > > > > } > > > > @Inject > > > > Principal principal; > > > > > > @Test > > > > *public* *void* injection() { > > > > *assertThat*(principal.getName(), *is*("alice@example.com")); > > > > } > > > > @Dependent > > > > @RunWith(CdiTestRunner.*class*) > > > > *public* *class* BobUnitTest { > > > > @Produces > > > > *public* Principal customPrincipal() { > > > > *return* *new* CustomPrincipal("bob@example.com"); > > > > } > > > > > > @Inject > > > > Principal principal; > > > > > > @Test > > > > *public* *void* injection() { > > > > *assertThat*(principal.getName(), *is*("bob@example.com")); > > > > } > > > > > > } > > > > > > This results in "WELD-001409: Ambiguous dependencies for type Principal > > with qualifiers @Default" and "WELD-001318: Cannot resolve an ambiguous > > dependency between: ". > > > > I think I tried every different scope and bean-discovery-mode. Is this > > supported at all? > > > > Code available at > > > > > https://github.com/The-Alchemist/javaeetesting/tree/testing-different-principals/deltaspike > > > > Any tips would be greatly appreciated. :) > > > > -- > > Karl > > > -- Karl --001a114b33deac65a2052b8a9c76--