You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2017/08/17 14:30:14 UTC

[22/27] karaf git commit: Extract response data. Improve assertions

Extract response data. Improve assertions


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/b57bceae
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/b57bceae
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/b57bceae

Branch: refs/heads/model_features
Commit: b57bceae1855e610e3941c73b1b1260bea264c0d
Parents: db2bf32
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Wed Aug 16 18:01:20 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Wed Aug 16 18:01:20 2017 +0200

----------------------------------------------------------------------
 .../modules/syncope/SyncopeLoginModuleTest.java | 131 +++----------------
 .../jaas/modules/syncope/syncope1Response.xml   |  70 ++++++++++
 .../jaas/modules/syncope/syncope2Response.json  |  55 ++++++++
 3 files changed, 146 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/b57bceae/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModuleTest.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModuleTest.java b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModuleTest.java
index 560879a..1156585 100644
--- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModuleTest.java
+++ b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/syncope/SyncopeLoginModuleTest.java
@@ -16,131 +16,42 @@
  */
 package org.apache.karaf.jaas.modules.syncope;
 
-import org.junit.Test;
-import org.junit.Assert;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.junit.Assert.assertThat;
 
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.List;
+import java.util.stream.Collectors;
+
+import org.junit.Test;
 
 public class SyncopeLoginModuleTest {
 
     @Test
     public void testRolesExtractionSyncope1() throws Exception {
-        String syncopeResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
-                "<user>\n" +
-                "    <attributes>\n" +
-                "        <attribute>\n" +
-                "            <readonly>false</readonly>\n" +
-                "            <schema>cool</schema>\n" +
-                "            <value>false</value>\n" +
-                "        </attribute>\n" +
-                "        <attribute>\n" +
-                "            <readonly>false</readonly>\n" +
-                "            <schema>email</schema>\n" +
-                "            <value>karaf@example.net</value>\n" +
-                "        </attribute>\n" +
-                "        <attribute>\n" +
-                "            <readonly>false</readonly>\n" +
-                "            <schema>fullname</schema>\n" +
-                "            <value>karaf</value>\n" +
-                "        </attribute>\n" +
-                "        <attribute>\n" +
-                "            <readonly>false</readonly>\n" +
-                "            <schema>gender</schema>\n" +
-                "            <value>M</value>\n" +
-                "        </attribute>\n" +
-                "        <attribute>\n" +
-                "            <readonly>false</readonly>\n" +
-                "            <schema>surname</schema>\n" +
-                "            <value>karaf</value>\n" +
-                "        </attribute>\n" +
-                "        <attribute>\n" +
-                "            <readonly>false</readonly>\n" +
-                "            <schema>userId</schema>\n" +
-                "            <value>karaf@example.net</value>\n" +
-                "        </attribute>\n" +
-                "    </attributes>\n" +
-                "    <derivedAttributes/>\n" +
-                "    <id>100</id>\n" +
-                "    <propagationStatuses/>\n" +
-                "    <resources/>\n" +
-                "    <virtualAttributes/>\n" +
-                "    <creationDate>2014-08-12T18:37:09.202+02:00</creationDate>\n" +
-                "    <failedLogins>0</failedLogins>\n" +
-                "    <lastLoginDate>2014-08-13T09:38:02.204+02:00</lastLoginDate>\n" +
-                "    <memberships>\n" +
-                "        <membership>\n" +
-                "            <attributes/>\n" +
-                "            <derivedAttributes/>\n" +
-                "            <id>100</id>\n" +
-                "            <propagationStatuses/>\n" +
-                "            <resources/>\n" +
-                "            <virtualAttributes/>\n" +
-                "            <resources/>\n" +
-                "            <roleId>100</roleId>\n" +
-                "            <roleName>admin</roleName>\n" +
-                "        </membership>\n" +
-                "        <membership>\n" +
-                "            <attributes/>\n" +
-                "            <derivedAttributes/>\n" +
-                "            <id>101</id>\n" +
-                "            <propagationStatuses/>\n" +
-                "            <resources/>\n" +
-                "            <virtualAttributes/>\n" +
-                "            <resources/>\n" +
-                "            <roleId>101</roleId>\n" +
-                "            <roleName>another</roleName>\n" +
-                "        </membership>\n" +
-                "    </memberships>\n" +
-                "    <password>36460D3A3C1E27C0DB2AF23344475EE712DD3C9D</password>\n" +
-                "    <status>active</status>\n" +
-                "    <username>karaf</username>\n" +
-                "</user>\n";
+        String syncopeResponse = read("syncope1Response.xml");
         SyncopeLoginModule syncopeLoginModule = new SyncopeLoginModule();
         List<String> roles = syncopeLoginModule.extractingRolesSyncope1(syncopeResponse);
-        Assert.assertEquals(2, roles.size());
-        Assert.assertEquals("admin", roles.get(0));
-        Assert.assertEquals("another", roles.get(1));
+        assertThat(roles, containsInAnyOrder("admin", "another"));
     }
 
     @Test
     public void testRolesExtractionSyncope2() throws Exception {
-        String syncopeResponse = "{\n" + "\n"
-                + "   \"@class\":\"org.apache.syncope.common.lib.to.UserTO\",\n" + "\n"
-                + "   \"creator\":\"admin\",\n" + "\n"
-                + "   \"creationDate\":\"2017-07-31T08:36:41.000+0000\",\n" + "\n"
-                + "   \"lastModifier\":\"admin\",\n" + "\n"
-                + "   \"lastChangeDate\":\"2017-08-01T08:46:19.236+0000\",\n" + "\n"
-                + "   \"key\":\"e5a131b0-eb66-4115-a131-b0eb66511579\",\n" + "\n"
-                + "   \"type\":\"USER\",\n" + "\n" + "   \"realm\":\"/karaf\",\n" + "\n"
-                + "   \"status\":\"created\",\n" + "\n" + "   \"password\":null,\n" + "\n"
-                + "   \"token\":null,\n" + "\n" + "   \"tokenExpireTime\":null,\n" + "\n"
-                + "   \"username\":\"karaf\",\n" + "\n"
-                + "   \"lastLoginDate\":\"2017-08-01T08:46:19.224+0000\",\n" + "\n"
-                + "   \"changePwdDate\":null,\n" + "\n" + "   \"failedLogins\":0,\n" + "\n"
-                + "   \"securityQuestion\":null,\n" + "\n" + "   \"securityAnswer\":null,\n" + "\n"
-                + "   \"mustChangePassword\":false,\n" + "\n" + "   \"auxClasses\":[\n" + "\n"
-                + " \n" + "\n" + "   ],\n" + "\n" + "   \"plainAttrs\":[\n" + "\n" + " \n" + "\n"
-                + "   ],\n" + "\n" + "   \"derAttrs\":[\n" + "\n" + " \n" + "\n" + "   ],\n" + "\n"
-                + "   \"virAttrs\":[\n" + "\n" + " \n" + "\n" + "   ],\n" + "\n"
-                + "   \"resources\":[\n" + "\n" + " \n" + "\n" + "   ],\n" + "\n"
-                + "   \"roles\":[\n" + "\n" + "      \"admin\", \"another\"\n" + "\n" + "   ],\n" +
-                "\n"
-                + "   \"dynRoles\":[\n" + "\n" + "      \"admin\"\n" + "\n" + "   ],\n" + "\n"
-                + "   \"relationships\":[\n" + "\n" + " \n" + "\n" + "   ],\n" + "\n"
-                + "   \"memberships\":[\n" + "\n" + "      {\n" + "\n"
-                + "         \"type\":\"Membership\",\n" + "\n"
-                + "         \"rightType\":\"GROUP\",\n" + "\n"
-                + "         \"rightKey\":\"3847aa78-3202-4d8f-87aa-7832026d8fba\",\n" + "\n"
-                + "         \"groupName\":\"manager\",\n" + "\n" + "         \"plainAttrs\":[\n"
-                + "\n" + " \n" + "\n" + "         ],\n" + "\n" + "         \"derAttrs\":[\n" + "\n"
-                + " \n" + "\n" + "         ],\n" + "\n" + "         \"virAttrs\":[\n" + "\n" + " \n"
-                + "\n" + "         ]\n" + "\n" + "      }\n" + "\n" + "   ],\n" + "\n"
-                + "   \"dynGroups\":[\n" + "\n" + " \n" + "\n" + "   ]\n" + "\n" + "}";
+        String syncopeResponse = read("syncope2Response.json");
         SyncopeLoginModule syncopeLoginModule = new SyncopeLoginModule();
         List<String> roles = syncopeLoginModule.extractingRolesSyncope2(syncopeResponse);
-        Assert.assertEquals(2, roles.size());
-        Assert.assertEquals("admin", roles.get(0));
-        Assert.assertEquals("another", roles.get(1));
+        assertThat(roles, containsInAnyOrder("admin", "another"));
+    }
+
+    private String read(String resourceName) throws URISyntaxException, IOException {
+        URI response = this.getClass().getResource(resourceName).toURI();
+        return Files.lines(Paths.get(response), Charset.forName("UTF-8"))
+            .collect(Collectors.joining("\n"));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/b57bceae/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/syncope/syncope1Response.xml
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/syncope/syncope1Response.xml b/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/syncope/syncope1Response.xml
new file mode 100644
index 0000000..105ec10
--- /dev/null
+++ b/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/syncope/syncope1Response.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<user>
+    <attributes>
+        <attribute>
+            <readonly>false</readonly>
+            <schema>cool</schema>
+            <value>false</value>
+        </attribute>
+        <attribute>
+            <readonly>false</readonly>
+            <schema>email</schema>
+            <value>karaf@example.net</value>
+        </attribute>
+        <attribute>
+            <readonly>false</readonly>
+            <schema>fullname</schema>
+            <value>karaf</value>
+        </attribute>
+        <attribute>
+            <readonly>false</readonly>
+            <schema>gender</schema>
+            <value>M</value>
+        </attribute>
+        <attribute>
+            <readonly>false</readonly>
+            <schema>surname</schema>
+            <value>karaf</value>
+        </attribute>
+        <attribute>
+            <readonly>false</readonly>
+            <schema>userId</schema>
+            <value>karaf@example.net</value>
+        </attribute>
+    </attributes>
+    <derivedAttributes/>
+    <id>100</id>
+    <propagationStatuses/>
+    <resources/>
+    <virtualAttributes/>
+    <creationDate>2014-08-12T18:37:09.202+02:00</creationDate>
+    <failedLogins>0</failedLogins>
+    <lastLoginDate>2014-08-13T09:38:02.204+02:00</lastLoginDate>
+    <memberships>
+        <membership>
+            <attributes/>
+            <derivedAttributes/>
+            <id>100</id>
+            <propagationStatuses/>
+            <resources/>
+            <virtualAttributes/>
+            <resources/>
+            <roleId>100</roleId>
+            <roleName>admin</roleName>
+        </membership>
+        <membership>
+            <attributes/>
+            <derivedAttributes/>
+            <id>101</id>
+            <propagationStatuses/>
+            <resources/>
+            <virtualAttributes/>
+            <resources/>
+            <roleId>101</roleId>
+            <roleName>another</roleName>
+        </membership>
+    </memberships>
+    <password>36460D3A3C1E27C0DB2AF23344475EE712DD3C9D</password>
+    <status>active</status>
+    <username>karaf</username>
+</user>

http://git-wip-us.apache.org/repos/asf/karaf/blob/b57bceae/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/syncope/syncope2Response.json
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/syncope/syncope2Response.json b/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/syncope/syncope2Response.json
new file mode 100644
index 0000000..8a803f2
--- /dev/null
+++ b/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/syncope/syncope2Response.json
@@ -0,0 +1,55 @@
+{
+   "@class":"org.apache.syncope.common.lib.to.UserTO",
+   "creator":"admin",
+   "creationDate":"2017-07-31T08:36:41.000+0000",
+   "lastModifier":"admin",
+   "lastChangeDate":"2017-08-01T08:46:19.236+0000",
+   "key":"e5a131b0-eb66-4115-a131-b0eb66511579",
+   "type":"USER",
+   "realm":"/karaf",
+   "status":"created",
+   "password":null,
+   "token":null,
+   "tokenExpireTime":null,
+   "username":"karaf",
+   "lastLoginDate":"2017-08-01T08:46:19.224+0000",
+   "changePwdDate":null,
+   "failedLogins":0,
+   "securityQuestion":null,
+   "securityAnswer":null,
+   "mustChangePassword":false,
+   "auxClasses":[
+   ],
+   "plainAttrs":[
+   ],
+   "derAttrs":[
+   ],
+   "virAttrs":[
+   ],
+   "resources":[
+   ],
+   "roles":[
+      "admin", "another"
+   ],
+   "dynRoles":[
+      "admin"
+   ],
+   "relationships":[
+   ],
+   "memberships":[
+      {
+         "type":"Membership",
+         "rightType":"GROUP",
+         "rightKey":"3847aa78-3202-4d8f-87aa-7832026d8fba",
+         "groupName":"manager",
+         "plainAttrs":[
+         ],
+         "derAttrs":[
+         ],
+         "virAttrs":[
+         ]
+      }
+   ],
+   "dynGroups":[
+   ]
+}