Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BE921FF40 for ; Mon, 15 Apr 2013 11:56:24 +0000 (UTC) Received: (qmail 11595 invoked by uid 500); 15 Apr 2013 11:56:24 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 11506 invoked by uid 500); 15 Apr 2013 11:56:23 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 11486 invoked by uid 99); 15 Apr 2013 11:56:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Apr 2013 11:56:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Apr 2013 11:56:22 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 13C6423889D5; Mon, 15 Apr 2013 11:56:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1467947 - in /sling/trunk/contrib/extensions/muppet/muppet-sling: pom.xml src/test/java/org/apache/sling/muppet/sling/LoginRuleBuilderTest.java Date: Mon, 15 Apr 2013 11:56:01 -0000 To: commits@sling.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130415115602.13C6423889D5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Mon Apr 15 11:56:01 2013 New Revision: 1467947 URL: http://svn.apache.org/r1467947 Log: SLING-2822 - LoginRuleBuilderTest added Added: sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/LoginRuleBuilderTest.java Modified: sling/trunk/contrib/extensions/muppet/muppet-sling/pom.xml Modified: sling/trunk/contrib/extensions/muppet/muppet-sling/pom.xml URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-sling/pom.xml?rev=1467947&r1=1467946&r2=1467947&view=diff ============================================================================== --- sling/trunk/contrib/extensions/muppet/muppet-sling/pom.xml (original) +++ sling/trunk/contrib/extensions/muppet/muppet-sling/pom.xml Mon Apr 15 11:56:01 2013 @@ -79,6 +79,7 @@ javax.jcr jcr + 2.0 provided @@ -124,5 +125,11 @@ 4.8.1 test + + org.apache.sling + org.apache.sling.commons.testing + 2.0.14 + test + Added: sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/LoginRuleBuilderTest.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/LoginRuleBuilderTest.java?rev=1467947&view=auto ============================================================================== --- sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/LoginRuleBuilderTest.java (added) +++ sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/LoginRuleBuilderTest.java Mon Apr 15 11:56:01 2013 @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The SF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.apache.sling.muppet.sling; + +import static org.junit.Assert.assertEquals; + +import java.lang.reflect.Field; + +import org.apache.sling.commons.testing.jcr.RepositoryProvider; +import org.apache.sling.jcr.api.SlingRepository; +import org.apache.sling.muppet.api.EvaluationResult; +import org.apache.sling.muppet.api.Rule; +import org.apache.sling.muppet.sling.impl.rules.LoginRuleBuilder; +import org.junit.Before; +import org.junit.Test; + +public class LoginRuleBuilderTest { + private LoginRuleBuilder builder; + + @Before + public void setup() throws Exception { + builder = new LoginRuleBuilder(); + final Field f = builder.getClass().getDeclaredField("repository"); + f.setAccessible(true); + final SlingRepository r = RepositoryProvider.instance().getRepository(); + f.set(builder, r); + } + + @Test + public void testAdminLoginSucceeds() { + final Rule r = builder.buildRule("sling", "login", "admin#admin", "LOGIN_OK"); + assertEquals("Expecting admin login to succeed", EvaluationResult.Status.OK, r.execute()); + } + + @Test + public void testAdminBadPasswordFails() { + final Rule r = builder.buildRule("sling", "login", "admin#bad", "OK"); + assertEquals("Expecting admin login to succeed", EvaluationResult.Status.ERROR, r.execute()); + } + + @Test + public void testFooLoginFails() { + final Rule r = builder.buildRule("sling", "login", "foo#bar", "OK"); + assertEquals("Expecting admin login to succeed", EvaluationResult.Status.ERROR, r.execute()); + } +}