qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject [1/5] qpid-broker-j git commit: QPID-8083: [System Tests] [REST/HTTP] Eliminate GroupProvider rest tests
Date Mon, 19 Feb 2018 07:53:17 GMT
Repository: qpid-broker-j
Updated Branches:
  refs/heads/master d85f421c6 -> 3aad3e3d3


QPID-8083: [System Tests] [REST/HTTP] Eliminate GroupProvider rest tests


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/dbe3ca73
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/dbe3ca73
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/dbe3ca73

Branch: refs/heads/master
Commit: dbe3ca730da5cf27db5e21645996e6f2f5ea6d93
Parents: d85f421
Author: Keith Wall <kwall@apache.org>
Authored: Sat Feb 17 10:55:23 2018 +0000
Committer: Keith Wall <kwall@apache.org>
Committed: Mon Feb 19 07:52:31 2018 +0000

----------------------------------------------------------------------
 broker-core/pom.xml                             |   5 +
 .../adapter/FileBasedGroupProviderImplTest.java | 250 +++++++++++-
 .../systest/rest/GroupProviderRestTest.java     | 387 -------------------
 .../apache/qpid/systest/rest/GroupRestTest.java | 153 --------
 4 files changed, 246 insertions(+), 549 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/dbe3ca73/broker-core/pom.xml
----------------------------------------------------------------------
diff --git a/broker-core/pom.xml b/broker-core/pom.xml
index 431c1e2..f737909 100644
--- a/broker-core/pom.xml
+++ b/broker-core/pom.xml
@@ -95,6 +95,11 @@
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.hamcrest</groupId>
+      <artifactId>hamcrest-library</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
    
   <build>

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/dbe3ca73/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileBasedGroupProviderImplTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileBasedGroupProviderImplTest.java
b/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileBasedGroupProviderImplTest.java
index fd0766a..6f6e4d3 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileBasedGroupProviderImplTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileBasedGroupProviderImplTest.java
@@ -20,27 +20,48 @@
  */
 package org.apache.qpid.server.model.adapter;
 
+import static org.apache.qpid.server.model.adapter.FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.io.File;
+import java.io.FileOutputStream;
+import java.security.Principal;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.UUID;
+import java.util.Properties;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import com.google.common.collect.Sets;
 
 import org.apache.qpid.server.configuration.IllegalConfigurationException;
 import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor;
 import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.model.AuthenticationProvider;
 import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.BrokerModel;
+import org.apache.qpid.server.model.ConfiguredObjectFactory;
+import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl;
+import org.apache.qpid.server.model.Group;
+import org.apache.qpid.server.model.GroupMember;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.Model;
 import org.apache.qpid.test.utils.QpidTestCase;
 import org.apache.qpid.test.utils.TestFileUtils;
 
 public class FileBasedGroupProviderImplTest extends QpidTestCase
 {
     private TaskExecutor _taskExecutor;
-    private Broker _broker;
+    private Broker<?> _broker;
     private File _groupFile;
+    private ConfiguredObjectFactory _objectFactory;
 
     @Override
     public void setUp() throws Exception
@@ -48,12 +69,13 @@ public class FileBasedGroupProviderImplTest extends QpidTestCase
         super.setUp();
         _taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
 
+        final Model model = BrokerModel.getInstance();
+        _objectFactory = new ConfiguredObjectFactoryImpl(model);
+
         _broker = mock(Broker.class);
         when(_broker.getTaskExecutor()).thenReturn(_taskExecutor);
         when(_broker.getChildExecutor()).thenReturn(_taskExecutor);
-        when(_broker.getModel()).thenReturn(BrokerModel.getInstance());
-        when(_broker.getId()).thenReturn(UUID.randomUUID());
-        when(_broker.getCategoryClass()).thenReturn(Broker.class);
+        when(_broker.getModel()).thenReturn(model);
     }
 
     @Override
@@ -80,13 +102,13 @@ public class FileBasedGroupProviderImplTest extends QpidTestCase
 
         String groupsFile = _groupFile.getAbsolutePath() + File.separator + "groups";
         assertFalse("File should not exist", new File(groupsFile).exists());
+        attributes.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
         attributes.put(FileBasedGroupProvider.PATH, groupsFile);
         attributes.put(FileBasedGroupProvider.NAME, getTestName());
 
-        FileBasedGroupProviderImpl groupsProvider = new FileBasedGroupProviderImpl(attributes,
_broker);
         try
         {
-            groupsProvider.create();
+            _objectFactory.create(GroupProvider.class, attributes, _broker);
             fail("Exception is expected on validation of groups provider with invalid path");
         } catch (IllegalConfigurationException e)
         {
@@ -99,13 +121,13 @@ public class FileBasedGroupProviderImplTest extends QpidTestCase
         _groupFile = TestFileUtils.createTempFile(this, "groups", "=blah");
         Map<String, Object> attributes = new HashMap<>();
         String groupsFile = _groupFile.getAbsolutePath();
+        attributes.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
         attributes.put(FileBasedGroupProvider.PATH, groupsFile);
         attributes.put(FileBasedGroupProvider.NAME, getTestName());
 
-        FileBasedGroupProviderImpl groupsProvider = new FileBasedGroupProviderImpl(attributes,
_broker);
         try
         {
-            groupsProvider.create();
+            _objectFactory.create(GroupProvider.class, attributes, _broker);
             fail("Exception is expected on validation of groups provider with invalid group
file");
         }
         catch (IllegalConfigurationException e)
@@ -114,4 +136,214 @@ public class FileBasedGroupProviderImplTest extends QpidTestCase
         }
     }
 
+    public void testExistingGroupFile() throws Exception
+    {
+        Map<String, Set<String>> input = new HashMap<>();
+        input.put("super", Sets.newHashSet("root"));
+
+        _groupFile = createTemporaryGroupFile(input);
+
+        Map<String, Object> providerAttrs = new HashMap<>();
+        String groupsFile = _groupFile.getAbsolutePath();
+        providerAttrs.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
+        providerAttrs.put(FileBasedGroupProvider.PATH, groupsFile);
+        providerAttrs.put(FileBasedGroupProvider.NAME, getTestName());
+
+        @SuppressWarnings("unchecked")
+        GroupProvider<?> provider = _objectFactory.create(GroupProvider.class, providerAttrs,
_broker);
+
+        Set<Principal> adminGroups = provider.getGroupPrincipalsForUser(() -> "root");
+        assertThat("root has unexpected group membership",
+                   adminGroups.stream().map(Principal::getName).collect(Collectors.toSet()),
+                   containsInAnyOrder("super"));
+
+        Collection<Group> groups = provider.getChildren(Group.class);
+        assertThat(groups.size(), is(equalTo(1)));
+        Group<?> superGroup = groups.iterator().next();
+        assertThat(superGroup.getName(), is(equalTo("super")));
+
+        Collection<GroupMember> members = superGroup.getChildren(GroupMember.class);
+        assertThat(members.size(), is(equalTo(1)));
+        GroupMember rootMember = members.iterator().next();
+        assertThat(rootMember.getName(), is(equalTo("root")));
+    }
+
+    public void testAddGroupAndMember() throws Exception
+    {
+        _groupFile = createTemporaryGroupFile(Collections.emptyMap());
+
+        Map<String, Object> providerAttrs = new HashMap<>();
+        String groupsFile = _groupFile.getAbsolutePath();
+        providerAttrs.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
+        providerAttrs.put(FileBasedGroupProvider.PATH, groupsFile);
+        providerAttrs.put(FileBasedGroupProvider.NAME, getTestName());
+
+        @SuppressWarnings("unchecked")
+        GroupProvider<?> provider = _objectFactory.create(GroupProvider.class, providerAttrs,
_broker);
+
+        assertThat(provider.getChildren(Group.class).size(), is(equalTo(0)));
+
+        final Map<String, Object> groupAttrs = Collections.singletonMap(Group.NAME,
"supers");
+        Group superGroup = provider.createChild(Group.class, groupAttrs);
+        assertThat(superGroup.getName(), is(equalTo("supers")));
+
+        final Map<String, Object> memberAttrs = Collections.singletonMap(GroupMember.NAME,
"root");
+        GroupMember rootMember = (GroupMember) superGroup.createChild(GroupMember.class,
memberAttrs);
+        assertThat(rootMember.getName(), is(equalTo("root")));
+    }
+
+    public void testRemoveGroupAndMember() throws Exception
+    {
+        Map<String, Set<String>> input = new HashMap<>();
+        input.put("supers", Sets.newHashSet( "root"));
+        input.put("operators", Sets.newHashSet("operator", "root"));
+
+        _groupFile = createTemporaryGroupFile(input);
+
+        Map<String, Object> providerAttrs = new HashMap<>();
+        String groupsFile = _groupFile.getAbsolutePath();
+        providerAttrs.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
+        providerAttrs.put(FileBasedGroupProvider.PATH, groupsFile);
+        providerAttrs.put(FileBasedGroupProvider.NAME, getTestName());
+
+        @SuppressWarnings("unchecked")
+        GroupProvider<?> provider = _objectFactory.create(GroupProvider.class, providerAttrs,
_broker);
+
+        assertThat(provider.getChildren(Group.class).size(), is(equalTo(2)));
+
+        Group operators = provider.getChildByName(Group.class, "operators");
+        GroupMember rootMember = (GroupMember) operators.getChildByName(GroupMember.class,
"root");
+        rootMember.delete();
+
+        assertThat(operators.getChildren(GroupMember.class).size(), is(equalTo(1)));
+        Group supers = provider.getChildByName(Group.class, "supers");
+        assertThat(supers.getChildren(GroupMember.class).size(), is(equalTo(1)));
+
+        operators.delete();
+        assertThat(provider.getChildren(Group.class).size(), is(equalTo(1)));
+    }
+
+    public void testGroupAndMemberDurability() throws Exception
+    {
+        _groupFile = createTemporaryGroupFile(Collections.emptyMap());
+
+        Map<String, Object> providerAttrs = new HashMap<>();
+        String groupsFile = _groupFile.getAbsolutePath();
+        providerAttrs.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
+        providerAttrs.put(FileBasedGroupProvider.PATH, groupsFile);
+        providerAttrs.put(FileBasedGroupProvider.NAME, getTestName());
+
+        {
+            @SuppressWarnings("unchecked")
+            final GroupProvider<?> provider = _objectFactory.create(GroupProvider.class,
providerAttrs, _broker);
+            assertThat(provider.getChildren(Group.class).size(), is(equalTo(0)));
+
+            final Map<String, Object> groupAttrs = Collections.singletonMap(Group.NAME,
"group");
+            final Group group = provider.createChild(Group.class, groupAttrs);
+
+            final Map<String, Object> memberAttrs = Collections.singletonMap(GroupMember.NAME,
"user");
+            group.createChild(GroupMember.class, memberAttrs);
+
+            provider.close();
+        }
+
+        {
+            @SuppressWarnings("unchecked")
+            final GroupProvider<?> provider = _objectFactory.create(GroupProvider.class,
providerAttrs, _broker);
+            assertThat(provider.getChildren(Group.class).size(), is(equalTo(1)));
+
+            final Group group = provider.getChildByName(Group.class, "group");
+            assertThat(group.getChildren(GroupMember.class).size(), is(equalTo(1)));
+            final GroupMember member = (GroupMember) group.getChildByName(GroupMember.class,
"user");
+
+            member.delete();
+            provider.close();
+        }
+
+        {
+            @SuppressWarnings("unchecked")
+            final GroupProvider<?> provider = _objectFactory.create(GroupProvider.class,
providerAttrs, _broker);
+            final Group group = provider.getChildByName(Group.class, "group");
+            assertThat(group.getChildren(GroupMember.class).size(), is(equalTo(0)));
+
+            group.delete();
+            provider.close();
+        }
+
+        {
+            @SuppressWarnings("unchecked")
+            final GroupProvider<?> provider = _objectFactory.create(GroupProvider.class,
providerAttrs, _broker);
+            assertThat(provider.getChildren(Group.class).size(), is(equalTo(0)));
+            provider.close();
+        }
+    }
+
+    public void testProvideDelete() throws Exception
+    {
+        _groupFile = createTemporaryGroupFile(Collections.emptyMap());
+
+        Map<String, Object> providerAttrs = new HashMap<>();
+        String groupsFile = _groupFile.getAbsolutePath();
+        providerAttrs.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
+        providerAttrs.put(FileBasedGroupProvider.PATH, groupsFile);
+        providerAttrs.put(FileBasedGroupProvider.NAME, getTestName());
+
+        @SuppressWarnings("unchecked")
+        final GroupProvider<?> provider = _objectFactory.create(GroupProvider.class,
providerAttrs, _broker);
+
+        provider.delete();
+        assertThat(_groupFile.exists(), is(equalTo(false)));
+    }
+
+    public void testSharingUnderlyingFileDisallowed() throws Exception
+    {
+        _groupFile = createTemporaryGroupFile(Collections.emptyMap());
+        String groupsFile = _groupFile.getAbsolutePath();
+
+        Map<String, Object> providerAttrs1 = new HashMap<>();
+        providerAttrs1.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
+        providerAttrs1.put(FileBasedGroupProvider.PATH, groupsFile);
+        providerAttrs1.put(FileBasedGroupProvider.NAME, getTestName() + "1");
+
+        @SuppressWarnings("unchecked")
+        GroupProvider<?> provider = _objectFactory.create(GroupProvider.class, providerAttrs1,
_broker);
+
+        when(_broker.getChildren(GroupProvider.class)).thenReturn(Collections.singletonList(provider));
+        try
+        {
+
+            Map<String, Object> providerAttrs2 = new HashMap<>();
+            providerAttrs2.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
+            providerAttrs2.put(FileBasedGroupProvider.PATH, groupsFile);
+            providerAttrs2.put(FileBasedGroupProvider.NAME, getTestName() + "2");
+
+            _objectFactory.create(GroupProvider.class, providerAttrs2, _broker);
+            fail("Exception not thrown");
+        }
+        catch (IllegalConfigurationException e)
+        {
+            // PASS
+        }
+    }
+
+    private File createTemporaryGroupFile(Map<String, Set<String>> groups) throws
Exception
+    {
+        File groupFile = File.createTempFile("group", "grp");
+        groupFile.deleteOnExit();
+
+        Properties props = new Properties();
+
+        Map<String, String> m = groups.entrySet()
+                                      .stream()
+                                      .collect(Collectors.toMap(e -> e.getKey() + ".users",
+                                                                e -> e.getValue()
+                                                                      .stream()
+                                                                      .collect(Collectors.joining(","))));
+        props.putAll(m);
+        try(final FileOutputStream out = new FileOutputStream(groupFile))
+        {
+            props.store(out, "test group file");
+        }
+        return groupFile;
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/dbe3ca73/systests/src/test/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java
b/systests/src/test/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java
deleted file mode 100644
index 9bb9c6d..0000000
--- a/systests/src/test/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java
+++ /dev/null
@@ -1,387 +0,0 @@
-/*
- *
- * 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.qpid.systest.rest;
-
-import static org.apache.qpid.server.management.plugin.servlet.rest.AbstractServlet.SC_UNPROCESSABLE_ENTITY;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.qpid.server.model.BrokerModel;
-import org.apache.qpid.server.model.ConfiguredObject;
-import org.apache.qpid.server.model.Group;
-import org.apache.qpid.server.model.GroupProvider;
-import org.apache.qpid.server.model.LifetimePolicy;
-import org.apache.qpid.server.model.State;
-import org.apache.qpid.server.model.SystemConfig;
-import org.apache.qpid.server.model.adapter.FileBasedGroupProvider;
-import org.apache.qpid.server.model.adapter.FileBasedGroupProviderImpl;
-import org.apache.qpid.test.utils.TestBrokerConfiguration;
-import org.apache.qpid.test.utils.TestFileUtils;
-
-public class GroupProviderRestTest extends QpidRestTestCase
-{
-    private static final String FILE_GROUP_MANAGER = TestBrokerConfiguration.ENTRY_NAME_GROUP_FILE;
-    private File _groupFile;
-
-    @Override
-    public void setUp() throws Exception
-    {
-        _groupFile = createTemporaryGroupFile();
-
-        getDefaultBrokerConfiguration().addGroupFileConfiguration(_groupFile.getAbsolutePath());
-
-        super.setUp();
-    }
-
-    @Override
-    public void tearDown() throws Exception
-    {
-        super.tearDown();
-
-        if (_groupFile != null)
-        {
-            if (_groupFile.exists())
-            {
-                _groupFile.delete();
-            }
-        }
-    }
-
-    public void testGet() throws Exception
-    {
-        List<Map<String, Object>> providerDetails = getRestTestHelper().getJsonAsList("groupprovider");
-        assertNotNull("Providers details cannot be null", providerDetails);
-        assertEquals("Unexpected number of providers", 1, providerDetails.size());
-        for (Map<String, Object> provider : providerDetails)
-        {
-            assertProvider(FILE_GROUP_MANAGER, FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE,
provider);
-            Map<String, Object> data = getRestTestHelper().getJsonAsMap("groupprovider/"
-                                                                        + provider.get(GroupProvider.NAME));
-            assertNotNull("Cannot load data for " + provider.get(GroupProvider.NAME), data);
-            assertProvider(FILE_GROUP_MANAGER, FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE,
data);
-        }
-    }
-
-    public void testCreateNewGroup() throws Exception
-    {
-        String groupName = "newGroup";
-
-        Map<String, Object> data =
-                getRestTestHelper().getJsonAsMap("groupprovider/" + FILE_GROUP_MANAGER +
"?depth=1");
-        assertNotNull("Cannot load data for provider", data);
-
-        getRestTestHelper().assertNumberOfGroups(data, 1);
-
-        getRestTestHelper().createGroup(groupName, FILE_GROUP_MANAGER);
-        data = getRestTestHelper().getJsonAsMap("groupprovider/" + FILE_GROUP_MANAGER + "?depth=1");
-        assertNotNull("Cannot load data for provider", data);
-
-        getRestTestHelper().assertNumberOfGroups(data, 2);
-    }
-
-    public void testRemoveGroup() throws Exception
-    {
-        String groupName = "myGroup";
-
-        Map<String, Object> data =
-                getRestTestHelper().getJsonAsMap("groupprovider/" + FILE_GROUP_MANAGER +
"?depth=1");
-        assertNotNull("Cannot load data for provider", data);
-
-        getRestTestHelper().assertNumberOfGroups(data, 1);
-
-        getRestTestHelper().removeGroup(groupName, FILE_GROUP_MANAGER);
-
-        data = getRestTestHelper().getJsonAsMap("groupprovider/" + FILE_GROUP_MANAGER + "?depth=1");
-        assertNotNull("Cannot load data for provider", data);
-
-        getRestTestHelper().assertNumberOfGroups(data, 0);
-    }
-
-    public void testCreateNewFileGroupProviderFromExistingGroupFile() throws Exception
-    {
-        String[] groupMemberNames = {"test1","test2"};
-        File groupFile = TestFileUtils.createTempFile(this, ".groups", "testusers.users="
+ groupMemberNames[0] + "," + groupMemberNames[1]);
-        try
-        {
-            String providerName = getTestName();
-            Map<String, Object> attributes = new HashMap<String, Object>();
-            attributes.put(GroupProvider.NAME, providerName);
-            attributes.put(GroupProvider.TYPE, FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE);
-            attributes.put(FileBasedGroupProvider.PATH, groupFile.getAbsolutePath());
-
-            int responseCode = getRestTestHelper().submitRequest("groupprovider/" + providerName,
"PUT", attributes);
-            assertEquals("Group provider was not created", 201, responseCode);
-
-            Map<String, Object> data = getRestTestHelper().getJsonAsMap("groupprovider/"
+ providerName + "?depth=2");
-            assertProvider(providerName, FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE,
data);
-            assertEquals("Unexpected name", providerName, data.get(GroupProvider.NAME));
-            assertEquals("Unexpected path", groupFile.getAbsolutePath(), data.get(FileBasedGroupProvider.PATH));
-
-            @SuppressWarnings("unchecked")
-            List<Map<String, Object>> groups = (List<Map<String, Object>>)
data.get("groups");
-            assertEquals("Unexpected group size", 1, groups.size());
-            Map<String, Object> group = groups.get(0);
-            assertEquals("Unexpected group name", "testusers",group.get("name"));
-
-            @SuppressWarnings("unchecked")
-            List<Map<String, Object>> groupMemberList = (List<Map<String,
Object>>) group.get("groupmembers");
-            assertEquals("Unexpected group members size", 2, groupMemberList.size());
-
-            for (String memberName : groupMemberNames)
-            {
-                boolean found = false;
-                for (Map<String, Object> memberData : groupMemberList)
-                {
-                    Object name = memberData.get("name");
-                    if (memberName.equals(name))
-                    {
-                        found = true;
-                        break;
-                    }
-                }
-                assertTrue("Cannot find group member " + memberName + " in " + groupMemberList
, found);
-            }
-        }
-        finally
-        {
-            groupFile.delete();
-        }
-    }
-
-    public void testCreationOfNewFileGroupProviderFailsWhenPathIsMissed() throws Exception
-    {
-        String providerName = getTestName();
-        Map<String, Object> attributes = new HashMap<String, Object>();
-        attributes.put(GroupProvider.NAME, providerName);
-        attributes.put(GroupProvider.TYPE, FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE);
-
-        int responseCode = getRestTestHelper().submitRequest("groupprovider/" + providerName,
"PUT", attributes);
-        assertEquals("Group provider was created", SC_UNPROCESSABLE_ENTITY, responseCode);
-    }
-
-    public void testCreateNewFileGroupProviderFromNonExistingGroupFile() throws Exception
-    {
-        File groupFile = new File(TMP_FOLDER + File.separator + getTestName() + File.separator
+ "groups");
-        assertFalse("Group file should not exist", groupFile.exists());
-        try
-        {
-            String providerName = getTestName();
-            Map<String, Object> attributes = new HashMap<String, Object>();
-            attributes.put(GroupProvider.NAME, providerName);
-            attributes.put(GroupProvider.TYPE, FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE);
-            attributes.put(FileBasedGroupProvider.PATH, groupFile.getAbsolutePath());
-
-            int responseCode = getRestTestHelper().submitRequest("groupprovider/" + providerName,
"PUT", attributes);
-            assertEquals("Group provider was not created", 201, responseCode);
-
-            Map<String, Object> data = getRestTestHelper().getJsonAsMap("groupprovider/"
+ providerName);
-            assertEquals("Unexpected name", providerName, data.get(GroupProvider.NAME));
-            assertEquals("Unexpected path", groupFile.getAbsolutePath(), data.get(FileBasedGroupProvider.PATH));
-
-            @SuppressWarnings("unchecked")
-            List<Map<String, Object>> groups = (List<Map<String, Object>>)
data.get("groups");
-            assertNull("Unexpected groups", groups);
-
-            assertTrue("Group file has not been created", groupFile.exists());
-        }
-        finally
-        {
-            groupFile.delete();
-            groupFile.getParentFile().delete();
-        }
-    }
-
-    public void testCreateNewFileGroupProviderForTheSameGroupFileFails() throws Exception
-    {
-        File groupFile = TestFileUtils.createTempFile(this, ".groups", "testusers.users=test1,test2");
-        String providerName = getTestName();
-        try
-        {
-            Map<String, Object> attributes = new HashMap<String, Object>();
-            attributes.put(GroupProvider.NAME, providerName);
-            attributes.put(GroupProvider.TYPE, FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE);
-            attributes.put(FileBasedGroupProvider.PATH, groupFile.getAbsolutePath());
-
-            int responseCode = getRestTestHelper().submitRequest("groupprovider/" + providerName,
"PUT", attributes);
-            assertEquals("Group provider was not created", 201, responseCode);
-
-            attributes.put(GroupProvider.NAME, providerName + 2);
-            responseCode = getRestTestHelper().submitRequest("groupprovider/" + providerName
+ 2, "PUT", attributes);
-            assertEquals("Group provider for the same group file was created", SC_UNPROCESSABLE_ENTITY,
responseCode);
-        }
-        finally
-        {
-            groupFile.delete();
-        }
-    }
-
-    public void testDeleteGroupProvider() throws Exception
-    {
-        File groupFile = TestFileUtils.createTempFile(this, ".groups", "testusers.users=test1,test2");
-        String providerName = getTestName();
-        try
-        {
-            Map<String, Object> attributes = new HashMap<String, Object>();
-            attributes.put(GroupProvider.NAME, providerName);
-            attributes.put(GroupProvider.TYPE, FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE);
-            attributes.put(FileBasedGroupProvider.PATH, groupFile.getAbsolutePath());
-
-            int responseCode = getRestTestHelper().submitRequest("groupprovider/" + providerName,
"PUT", attributes);
-            assertEquals("Expected to fail because we can have only one password provider",
201, responseCode);
-
-            responseCode = getRestTestHelper().submitRequest("groupprovider/" + providerName
, "DELETE");
-            assertEquals("Group provider was not deleted", 200, responseCode);
-
-            getRestTestHelper().submitRequest("groupprovider/" + providerName, "GET", HttpServletResponse.SC_NOT_FOUND);
-        }
-        finally
-        {
-            groupFile.delete();
-        }
-    }
-
-    public void testUpdateGroupProviderAttributesFails() throws Exception
-    {
-        File groupFile = TestFileUtils.createTempFile(this, ".groups", "testusers.users=test1,test2");
-        String providerName = getTestName();
-        try
-        {
-            Map<String, Object> attributes = new HashMap<String, Object>();
-            attributes.put(GroupProvider.NAME, providerName);
-            attributes.put(GroupProvider.TYPE, FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE);
-            attributes.put(FileBasedGroupProvider.PATH, groupFile.getAbsolutePath());
-
-            int responseCode = getRestTestHelper().submitRequest("groupprovider/" + providerName,
"PUT", attributes);
-            assertEquals("Password provider should be created successfully", 201, responseCode);
-
-            File newGroupFile = TestFileUtils.createTempFile(this, ".groups");
-            try
-            {
-                attributes.put(FileBasedGroupProvider.PATH, newGroupFile.getAbsolutePath());
-
-                responseCode = getRestTestHelper().submitRequest("groupprovider/" + providerName,
"PUT", attributes);
-                assertEquals("Changing of group file is unsupported at the moment", SC_UNPROCESSABLE_ENTITY,
responseCode);
-            }
-            finally
-            {
-                newGroupFile.delete();
-            }
-        }
-        finally
-        {
-            groupFile.delete();
-        }
-    }
-
-    public void testRemovalOfGroupProviderInErrorStateUsingManagementMode() throws Exception
-    {
-        stopDefaultBroker();
-
-        File file = new File(TMP_FOLDER, getTestName());
-        if (file.exists())
-        {
-            file.delete();
-        }
-        assertFalse("Group file should not exist", file.exists());
-
-        TestBrokerConfiguration config = getDefaultBrokerConfiguration();
-        config.removeObjectConfiguration(GroupProvider.class, TestBrokerConfiguration.ENTRY_NAME_GROUP_FILE);
-        UUID id = config.addGroupFileConfiguration(file.getAbsolutePath());
-        config.setSaved(false);
-        startDefaultBroker(true);
-
-        getRestTestHelper().setUsernameAndPassword(SystemConfig.MANAGEMENT_MODE_USER_NAME,
MANAGEMENT_MODE_PASSWORD);
-
-        Map<String, Object> groupProvider =
-                getRestTestHelper().getJsonAsMap("groupprovider/" + TestBrokerConfiguration.ENTRY_NAME_GROUP_FILE);
-        assertEquals("Unexpected id", id.toString(), groupProvider.get(GroupProvider.ID));
-        assertEquals("Unexpected path", file.getAbsolutePath() , groupProvider.get(FileBasedGroupProvider.PATH));
-        assertEquals("Unexpected state", State.ERRORED.name() , groupProvider.get(GroupProvider.STATE));
-
-        int status = getRestTestHelper().submitRequest("groupprovider/" + TestBrokerConfiguration.ENTRY_NAME_GROUP_FILE,
"DELETE");
-        assertEquals("ACL was not deleted", 200, status);
-        getRestTestHelper().submitRequest("groupprovider/" + TestBrokerConfiguration.ENTRY_NAME_GROUP_FILE,
-                "GET", HttpServletResponse.SC_NOT_FOUND);
-    }
-
-    private void assertProvider(String name, String type, Map<String, Object> provider)
throws IOException
-    {
-        Asserts.assertAttributesPresent(provider, BrokerModel.getInstance().getTypeRegistry().getAttributeNames(
-                GroupProvider.class),
-                ConfiguredObject.TYPE,
-                ConfiguredObject.CREATED_BY,
-                ConfiguredObject.CREATED_TIME,
-                ConfiguredObject.LAST_UPDATED_BY,
-                ConfiguredObject.LAST_UPDATED_TIME,
-                ConfiguredObject.DESCRIPTION,
-                ConfiguredObject.CONTEXT,
-                ConfiguredObject.DESIRED_STATE);
-        assertEquals("Unexpected value of provider attribute " + GroupProvider.STATE, State.ACTIVE.name(),
-                provider.get(GroupProvider.STATE));
-        assertEquals("Unexpected value of provider attribute " + GroupProvider.LIFETIME_POLICY,
-                LifetimePolicy.PERMANENT.name(), provider.get(GroupProvider.LIFETIME_POLICY));
-        assertEquals("Unexpected value of provider attribute " + GroupProvider.DURABLE, Boolean.TRUE,
-                provider.get(GroupProvider.DURABLE));
-        assertEquals("Unexpected value of provider attribute " + GroupProvider.TYPE, type,
-                provider.get(GroupProvider.TYPE));
-
-        assertEquals("Unexpected value of provider attribute " + GroupProvider.NAME, name,
-                (String) provider.get(GroupProvider.NAME));
-
-        @SuppressWarnings("unchecked")
-        List<Map<String, Object>> groups = getRestTestHelper().getJsonAsList("group/"
+ name);
-        assertNotNull("Groups were not found", groups);
-        assertEquals("Unexpected number of groups", 1, groups.size());
-        for (Map<String, Object> group : groups)
-        {
-
-            final String groupName = (String) group.get(Group.NAME);
-            assertNotNull("Attribute " + Group.NAME, groupName);
-
-            assertNotNull("Attribute " + Group.ID, group.get(Group.ID));
-        }
-    }
-
-    private File createTemporaryGroupFile() throws Exception
-    {
-        File groupFile = File.createTempFile("group", "grp");
-        groupFile.deleteOnExit();
-
-        Properties props = new Properties();
-        props.put("myGroup.users", "guest");
-
-        try(final FileOutputStream out = new FileOutputStream(groupFile))
-        {
-            props.store(out, "test group file");
-        }
-
-        return groupFile;
-    }
-}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/dbe3ca73/systests/src/test/java/org/apache/qpid/systest/rest/GroupRestTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/systest/rest/GroupRestTest.java b/systests/src/test/java/org/apache/qpid/systest/rest/GroupRestTest.java
deleted file mode 100644
index 5e54e2d..0000000
--- a/systests/src/test/java/org/apache/qpid/systest/rest/GroupRestTest.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- *
- * 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.qpid.systest.rest;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.qpid.server.model.GroupMember;
-import org.apache.qpid.test.utils.TestBrokerConfiguration;
-
-public class GroupRestTest extends QpidRestTestCase
-{
-    private static final String GROUP_NAME = "myGroup";
-    private static final String FILE_GROUP_MANAGER = TestBrokerConfiguration.ENTRY_NAME_GROUP_FILE;
-    private static final String EXISTING_MEMBER = "user1";
-    private static final String NEW_MEMBER = "user2";
-
-    private File _groupFile;
-
-    @Override
-    public void setUp() throws Exception
-    {
-        _groupFile = createTemporaryGroupFile();
-
-        getDefaultBrokerConfiguration().addGroupFileConfiguration(_groupFile.getAbsolutePath());
-
-        super.setUp();
-    }
-
-    @Override
-    public void tearDown() throws Exception
-    {
-        super.tearDown();
-
-        if (_groupFile != null)
-        {
-            if (_groupFile.exists())
-            {
-                _groupFile.delete();
-            }
-        }
-    }
-
-    public void testGet() throws Exception
-    {
-        Map<String, Object> group =
-                getRestTestHelper().getJsonAsMap("group/" + FILE_GROUP_MANAGER + "/myGroup?depth=1");
-        List<Map<String, Object>> groupmembers = (List<Map<String, Object>>)
group.get("groupmembers");
-        assertEquals(1, groupmembers.size());
-
-        Map<String, Object> member1 = groupmembers.get(0);
-        assertEquals(EXISTING_MEMBER, (String)member1.get(GroupMember.NAME));
-    }
-
-    public void testCreateNewMemberByPutUsingMemberURI() throws Exception
-    {
-        Map<String, Object> group =
-                getRestTestHelper().getJsonAsMap("group/" + FILE_GROUP_MANAGER + "/myGroup?depth=1");
-        getRestTestHelper().assertNumberOfGroupMembers(group, 1);
-
-        String url = "groupmember/" + FILE_GROUP_MANAGER + "/"+ GROUP_NAME + "/" +  NEW_MEMBER;
-        getRestTestHelper().submitRequest(url, "PUT", Collections.<String, Object>emptyMap(),
HttpServletResponse.SC_CREATED);
-
-        Map<String, Object> member = getRestTestHelper().getJsonAsMap(url);
-        assertEquals("Unexpected group name", NEW_MEMBER, member.get(GroupMember.NAME));
-    }
-
-    public void testCreateNewMemberByPostUsingParentURI() throws Exception
-    {
-        Map<String, Object> group =
-                getRestTestHelper().getJsonAsMap("group/" + FILE_GROUP_MANAGER + "/myGroup?depth=1");
-        getRestTestHelper().assertNumberOfGroupMembers(group, 1);
-
-        String url = "groupmember/" + FILE_GROUP_MANAGER + "/"+ GROUP_NAME;
-        Map<String, Object> data = Collections.<String, Object>singletonMap("name",
NEW_MEMBER);
-        getRestTestHelper().submitRequest(url, "POST", data, HttpServletResponse.SC_CREATED);
-
-        Map<String, Object> member = getRestTestHelper().getJsonAsMap(url + "/" + NEW_MEMBER);
-        assertEquals("Unexpected group name", NEW_MEMBER, member.get(GroupMember.NAME));
-
-        // verify that second creation request fails
-        getRestTestHelper().submitRequest(url, "POST", data, HttpServletResponse.SC_CONFLICT);
-    }
-
-    public void testCreateNewMemberByPutUsingParentURI() throws Exception
-    {
-        Map<String, Object> group =
-                getRestTestHelper().getJsonAsMap("group/" + FILE_GROUP_MANAGER + "/myGroup?depth=1");
-        getRestTestHelper().assertNumberOfGroupMembers(group, 1);
-
-        String url = "groupmember/" + FILE_GROUP_MANAGER + "/"+ GROUP_NAME;
-        Map<String, Object> data = Collections.<String, Object>singletonMap("name",
NEW_MEMBER);
-        getRestTestHelper().submitRequest(url, "PUT", data, HttpServletResponse.SC_CREATED);
-
-        Map<String, Object> member = getRestTestHelper().getJsonAsMap(url + "/" + NEW_MEMBER);
-        assertEquals("Unexpected group name", NEW_MEMBER, member.get(GroupMember.NAME));
-
-        // verify that second creation request fails
-        getRestTestHelper().submitRequest(url, "PUT", data, HttpServletResponse.SC_CONFLICT);
-    }
-
-    public void testRemoveMemberFromGroup() throws Exception
-    {
-        Map<String, Object> group =
-                getRestTestHelper().getJsonAsMap("group/" + FILE_GROUP_MANAGER + "/myGroup?depth=1");
-        getRestTestHelper().assertNumberOfGroupMembers(group, 1);
-
-        getRestTestHelper().removeMemberFromGroup(FILE_GROUP_MANAGER, GROUP_NAME, EXISTING_MEMBER);
-
-        group = getRestTestHelper().getJsonAsMap("group/" + FILE_GROUP_MANAGER + "/myGroup");
-        getRestTestHelper().assertNumberOfGroupMembers(group, 0);
-    }
-
-    private File createTemporaryGroupFile() throws Exception
-    {
-        File groupFile = File.createTempFile("group", "grp");
-        groupFile.deleteOnExit();
-
-        Properties props = new Properties();
-        props.put(GROUP_NAME + ".users", EXISTING_MEMBER);
-
-        try(final FileOutputStream out = new FileOutputStream(groupFile))
-        {
-            props.store(out, "test group file");
-        }
-
-        return groupFile;
-    }
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message