Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7176B200BB9 for ; Mon, 7 Nov 2016 17:33:48 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 7004B160AEC; Mon, 7 Nov 2016 16:33:48 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9367C160AE0 for ; Mon, 7 Nov 2016 17:33:47 +0100 (CET) Received: (qmail 17836 invoked by uid 500); 7 Nov 2016 16:33:46 -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 17827 invoked by uid 99); 7 Nov 2016 16:33:46 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Nov 2016 16:33:46 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 5B0FBC86FA for ; Mon, 7 Nov 2016 16:33:46 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.199 X-Spam-Level: X-Spam-Status: No, score=-1.199 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id cQvl1OSpK6gT for ; Mon, 7 Nov 2016 16:33:45 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 1883B5FC7E for ; Mon, 7 Nov 2016 16:33:45 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 0DC26E0224 for ; Mon, 7 Nov 2016 16:33:35 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id C7A083A29A1 for ; Mon, 7 Nov 2016 16:33:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1768548 - in /sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit: CreateUsersTest.java impl/TestUtil.java Date: Mon, 07 Nov 2016 16:33:35 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20161107163335.C7A083A29A1@svn01-us-west.apache.org> archived-at: Mon, 07 Nov 2016 16:33:48 -0000 Author: cziegeler Date: Mon Nov 7 16:33:35 2016 New Revision: 1768548 URL: http://svn.apache.org/viewvc?rev=1768548&view=rev Log: SLING-6219 : Allow to create users with repoinit Added: sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/CreateUsersTest.java (with props) Modified: sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java Added: sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/CreateUsersTest.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/CreateUsersTest.java?rev=1768548&view=auto ============================================================================== --- sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/CreateUsersTest.java (added) +++ sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/CreateUsersTest.java Mon Nov 7 16:33:35 2016 @@ -0,0 +1,98 @@ +/* + * 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 ASF 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.jcr.repoinit; + +import java.util.Random; + +import javax.jcr.RepositoryException; + +import org.apache.sling.jcr.repoinit.impl.TestUtil; +import org.apache.sling.testing.mock.sling.ResourceResolverType; +import org.apache.sling.testing.mock.sling.junit.SlingContext; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** Test the creation and delete of users */ +public class CreateUsersTest { + + @Rule + public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK); + + private static final Random random = new Random(42); + private String namePrefix; + private TestUtil U; + + @Before + public void setup() throws RepositoryException { + U = new TestUtil(context); + namePrefix = "user_" + random.nextInt(); + } + + @Test + public void createDeleteSingleTest() throws Exception { + final String userId = namePrefix + "_cdst"; + U.assertUser("at start of test", userId, false); + U.parseAndExecute("create user " + userId); + U.assertUser("after creating user", userId, true); + U.parseAndExecute("delete user " + userId); + U.assertUser("after deleting user", userId, false); + } + + private String user(int index) { + return namePrefix + "_" + index; + } + + @Test + public void createUserMultipleTimes() throws Exception { + final String username = namePrefix + "_multiple"; + U.assertUser("before test", username, false); + final String input = "create user " + username; + for(int i=0; i < 50; i++) { + U.parseAndExecute(input); + } + U.assertUser("after creating it multiple times", username, true); + } + + @Test + public void createDeleteMultipleTest() throws Exception { + final int n = 50; + + { + final StringBuilder input = new StringBuilder(); + for(int i=0; i < n; i++) { + U.assertUser("at start of test", user(i), false); + input.append("create user ").append(user(i)).append("\n"); + } + U.parseAndExecute(input.toString()); + } + + { + final StringBuilder input = new StringBuilder(); + for(int i=0; i < n; i++) { + U.assertUser("before deleting user", user(i), true); + input.append("delete user ").append(user(i)).append("\n"); + } + U.parseAndExecute(input.toString()); + } + + + for(int i=0; i < n; i++) { + U.assertUser("after deleting users", user(i), false); + } + } +} Propchange: sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/CreateUsersTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/CreateUsersTest.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url Modified: sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java?rev=1768548&r1=1768547&r2=1768548&view=diff ============================================================================== --- sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java (original) +++ sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java Mon Nov 7 16:33:35 2016 @@ -16,8 +16,10 @@ */ package org.apache.sling.jcr.repoinit.impl; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.Reader; @@ -40,18 +42,18 @@ import org.apache.sling.testing.mock.sli /** Test utilities */ public class TestUtil { - + public static final String JCR_PRIMARY_TYPE = "jcr:primaryType"; public final Session adminSession; public final String id; public final String username; - + public TestUtil(SlingContext ctx) { adminSession = ctx.resourceResolver().adaptTo(Session.class); id = UUID.randomUUID().toString(); username = "user_" + id; } - + public List parse(String input) throws RepoInitParsingException { final Reader r = new StringReader(input); try { @@ -61,6 +63,17 @@ public class TestUtil { } } + public void assertUser(String info, String id, boolean expectToExist) throws RepositoryException { + final Authorizable a = UserUtil.getUserManager(adminSession).getAuthorizable(id); + if(!expectToExist) { + assertNull(info + ", expecting Principal to be absent:" + id, a); + } else { + assertNotNull(info + ", expecting Principal to exist:" + id, a); + final User u = (User)a; + assertFalse(info + ", expecting Principal to be a plain user:" + id, u.isSystemUser()); + } + } + public void assertServiceUser(String info, String id, boolean expectToExist) throws RepositoryException { final Authorizable a = UserUtil.getUserManager(adminSession).getAuthorizable(id); if(!expectToExist) { @@ -68,14 +81,14 @@ public class TestUtil { } else { assertNotNull(info + ", expecting Principal to exist:" + id, a); final User u = (User)a; - assertNotNull(info + ", expecting Principal to be a System user:" + id, u.isSystemUser()); + assertTrue(info + ", expecting Principal to be a System user:" + id, u.isSystemUser()); } } - + public void assertNodeExists(String path) throws RepositoryException { assertNodeExists(path, null); } - + public void assertNodeExists(String path, String primaryType) throws RepositoryException { if(!adminSession.nodeExists(path)) { fail("Node does not exist:" + path); @@ -91,31 +104,31 @@ public class TestUtil { } } } - + public void parseAndExecute(String input) throws RepositoryException, RepoInitParsingException { final JcrRepoInitOpsProcessorImpl p = new JcrRepoInitOpsProcessorImpl(); p.apply(adminSession, parse(input)); adminSession.save(); } - + public void cleanupUser() throws RepositoryException, RepoInitParsingException { parseAndExecute("delete service user " + username); assertServiceUser("in cleanupUser()", username, false); } - + public Session loginService(String serviceUsername) throws RepositoryException { final SimpleCredentials cred = new SimpleCredentials(serviceUsername, new char[0]); return adminSession.impersonate(cred); } - + public Session getAdminSession() { return adminSession; } - + public void cleanup() { adminSession.logout(); } - + public String getTestCndStatement(String nsPrefix, String nsURI) throws RepositoryException, RepoInitParsingException { return "register nodetypes\n" + "<<===\n" @@ -123,7 +136,7 @@ public class TestUtil { + "===>>\n" ; } - + public String getTestCND(String nsPrefix, String nsURI) { return "<" + nsPrefix + "='" + nsURI + "'>\n" + "[" + nsPrefix + ":foo] > nt:unstructured\n";