You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2018/06/10 16:06:37 UTC
[1/2] syncope git commit: [SYNCOPE-1270] Adjusting test code
Repository: syncope
Updated Branches:
refs/heads/2_0_X 7e1bd363a -> 49a88b121
refs/heads/master ff597a7d5 -> f57cb3105
[SYNCOPE-1270] Adjusting test code
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/f57cb310
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/f57cb310
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/f57cb310
Branch: refs/heads/master
Commit: f57cb310537d9a907c4aa55484938e02c9361733
Parents: ff597a7
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Sun Jun 10 18:01:20 2018 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Sun Jun 10 18:01:20 2018 +0200
----------------------------------------------------------------------
.../apache/syncope/common/lib/to/MappingTO.java | 2 +-
.../apache/syncope/common/lib/to/OrgUnitTO.java | 2 +-
.../syncope/common/lib/to/OIDCProviderTO.java | 2 +-
.../syncope/common/lib/to/SAML2IdPTO.java | 2 +-
.../apache/syncope/fit/OIDCClientDetector.java | 2 +-
.../syncope/fit/core/OIDCClientITCase.java | 91 +++++++-------------
6 files changed, 38 insertions(+), 63 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/f57cb310/common/lib/src/main/java/org/apache/syncope/common/lib/to/MappingTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/MappingTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/MappingTO.java
index 7e5585a..69500e8 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/MappingTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/MappingTO.java
@@ -49,7 +49,7 @@ public class MappingTO extends AbstractBaseBean implements ItemContainerTO {
@Override
public ItemTO getConnObjectKeyItem() {
- return getItems().stream().filter(ItemTO::isConnObjectKey).findFirst().get();
+ return getItems().stream().filter(item -> item.isConnObjectKey()).findFirst().orElse(null);
}
protected boolean addConnObjectKeyItem(final ItemTO connObjectItem) {
http://git-wip-us.apache.org/repos/asf/syncope/blob/f57cb310/common/lib/src/main/java/org/apache/syncope/common/lib/to/OrgUnitTO.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/to/OrgUnitTO.java b/common/lib/src/main/java/org/apache/syncope/common/lib/to/OrgUnitTO.java
index f7e326b..8c4b8b1 100644
--- a/common/lib/src/main/java/org/apache/syncope/common/lib/to/OrgUnitTO.java
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/to/OrgUnitTO.java
@@ -89,7 +89,7 @@ public class OrgUnitTO extends AbstractBaseBean implements EntityTO, ItemContain
@Override
public ItemTO getConnObjectKeyItem() {
- return getItems().stream().filter(item -> item.isConnObjectKey()).findFirst().get();
+ return getItems().stream().filter(item -> item.isConnObjectKey()).findFirst().orElse(null);
}
protected boolean addConnObjectKeyItem(final ItemTO connObjectItem) {
http://git-wip-us.apache.org/repos/asf/syncope/blob/f57cb310/ext/oidcclient/common-lib/src/main/java/org/apache/syncope/common/lib/to/OIDCProviderTO.java
----------------------------------------------------------------------
diff --git a/ext/oidcclient/common-lib/src/main/java/org/apache/syncope/common/lib/to/OIDCProviderTO.java b/ext/oidcclient/common-lib/src/main/java/org/apache/syncope/common/lib/to/OIDCProviderTO.java
index 7669d22..7a3545f 100644
--- a/ext/oidcclient/common-lib/src/main/java/org/apache/syncope/common/lib/to/OIDCProviderTO.java
+++ b/ext/oidcclient/common-lib/src/main/java/org/apache/syncope/common/lib/to/OIDCProviderTO.java
@@ -195,7 +195,7 @@ public class OIDCProviderTO extends AbstractBaseBean implements EntityTO, ItemCo
@Override
public ItemTO getConnObjectKeyItem() {
- return getItems().stream().filter(ItemTO::isConnObjectKey).findFirst().get();
+ return getItems().stream().filter(item -> item.isConnObjectKey()).findFirst().orElse(null);
}
protected boolean addConnObjectKeyItem(final ItemTO connObjectItem) {
http://git-wip-us.apache.org/repos/asf/syncope/blob/f57cb310/ext/saml2sp/common-lib/src/main/java/org/apache/syncope/common/lib/to/SAML2IdPTO.java
----------------------------------------------------------------------
diff --git a/ext/saml2sp/common-lib/src/main/java/org/apache/syncope/common/lib/to/SAML2IdPTO.java b/ext/saml2sp/common-lib/src/main/java/org/apache/syncope/common/lib/to/SAML2IdPTO.java
index 14fe76f..851ff3a 100644
--- a/ext/saml2sp/common-lib/src/main/java/org/apache/syncope/common/lib/to/SAML2IdPTO.java
+++ b/ext/saml2sp/common-lib/src/main/java/org/apache/syncope/common/lib/to/SAML2IdPTO.java
@@ -156,7 +156,7 @@ public class SAML2IdPTO extends AbstractBaseBean implements EntityTO, ItemContai
@Override
public ItemTO getConnObjectKeyItem() {
- return getItems().stream().filter(item -> item.isConnObjectKey()).findFirst().get();
+ return getItems().stream().filter(item -> item.isConnObjectKey()).findFirst().orElse(null);
}
protected boolean addConnObjectKeyItem(final ItemTO connObjectItem) {
http://git-wip-us.apache.org/repos/asf/syncope/blob/f57cb310/fit/core-reference/src/test/java/org/apache/syncope/fit/OIDCClientDetector.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/OIDCClientDetector.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/OIDCClientDetector.java
index b08342e..b32682a 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/OIDCClientDetector.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/OIDCClientDetector.java
@@ -36,7 +36,7 @@ public class OIDCClientDetector {
try {
new SyncopeClientFactoryBean().
setAddress(AbstractITCase.ADDRESS).
- setContentType(SyncopeClientFactoryBean.ContentType.XML).
+ setContentType(SyncopeClientFactoryBean.ContentType.JSON).
create(new AnonymousAuthenticationHandler(
AbstractITCase.ANONYMOUS_UNAME, AbstractITCase.ANONYMOUS_KEY)).
getService(OIDCProviderService.class).list();
http://git-wip-us.apache.org/repos/asf/syncope/blob/f57cb310/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCClientITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCClientITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCClientITCase.java
index 85def66..1721b9b 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCClientITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCClientITCase.java
@@ -26,18 +26,13 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
import org.apache.syncope.client.lib.AnonymousAuthenticationHandler;
-import org.apache.syncope.client.lib.BasicAuthenticationHandler;
import org.apache.syncope.client.lib.SyncopeClient;
-import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
import org.apache.syncope.common.lib.to.ItemTO;
import org.apache.syncope.common.lib.to.OIDCLoginRequestTO;
import org.apache.syncope.common.lib.to.OIDCProviderTO;
import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.common.rest.api.service.OIDCClientService;
-import org.apache.syncope.common.rest.api.service.OIDCProviderService;
import org.apache.syncope.fit.AbstractITCase;
import org.apache.syncope.fit.OIDCClientDetector;
import org.junit.jupiter.api.AfterAll;
@@ -46,21 +41,6 @@ import org.junit.jupiter.api.Test;
public class OIDCClientITCase extends AbstractITCase {
- private static SyncopeClient anonymous;
-
- private static SyncopeClient admin;
-
- @BeforeAll
- public static void setup() {
- anonymous = new SyncopeClientFactoryBean().
- setAddress(ADDRESS).
- create(new AnonymousAuthenticationHandler(ANONYMOUS_UNAME, ANONYMOUS_KEY));
-
- admin = new SyncopeClientFactoryBean().
- setAddress(ADDRESS).
- create(new BasicAuthenticationHandler(ADMIN_UNAME, ADMIN_PWD));
- }
-
@BeforeAll
public static void createOIDCProviderWithoutDiscovery() throws Exception {
if (!OIDCClientDetector.isOIDCClientAvailable()) {
@@ -69,17 +49,17 @@ public class OIDCClientITCase extends AbstractITCase {
assertTrue(oidcProviderService.list().isEmpty());
- OIDCProviderTO oidcProviderTO = new OIDCProviderTO();
- oidcProviderTO.setAuthorizationEndpoint("AuthorizationEndpoint");
- oidcProviderTO.setClientID("ClientID");
- oidcProviderTO.setClientSecret("ClientSecret");
- oidcProviderTO.setIssuer("https://accounts.google.com");
- oidcProviderTO.setJwksUri("JwksUri");
- oidcProviderTO.setName("Google");
- oidcProviderTO.setTokenEndpoint("TokenEndpoint");
- oidcProviderTO.setUserinfoEndpoint("UserinfoEndpoint");
-
- admin.getService(OIDCProviderService.class).create(oidcProviderTO);
+ OIDCProviderTO google = new OIDCProviderTO();
+ google.setAuthorizationEndpoint("AuthorizationEndpoint");
+ google.setClientID("ClientID");
+ google.setClientSecret("ClientSecret");
+ google.setIssuer("https://accounts.google.com");
+ google.setJwksUri("JwksUri");
+ google.setName("Google");
+ google.setTokenEndpoint("TokenEndpoint");
+ google.setUserinfoEndpoint("UserinfoEndpoint");
+
+ oidcProviderService.create(google);
}
@AfterAll
@@ -88,15 +68,17 @@ public class OIDCClientITCase extends AbstractITCase {
return;
}
- for (OIDCProviderTO op : oidcProviderService.list()) {
+ oidcProviderService.list().forEach(op -> {
oidcProviderService.delete(op.getKey());
- }
+ });
}
@Test
public void createLoginRequest() {
assumeTrue(OIDCClientDetector.isOIDCClientAvailable());
+ SyncopeClient anonymous = clientFactory.create(
+ new AnonymousAuthenticationHandler(ANONYMOUS_UNAME, ANONYMOUS_KEY));
OIDCLoginRequestTO loginRequest = anonymous.getService(OIDCClientService.class).
createLoginRequest("http://localhost:9080/syncope-console/oidcclient/code-consumer", "Google");
@@ -113,40 +95,33 @@ public class OIDCClientITCase extends AbstractITCase {
public void setProviderMapping() {
assumeTrue(OIDCClientDetector.isOIDCClientAvailable());
- OIDCProviderTO ssoCircle = IterableUtils.find(oidcProviderService.list(), new Predicate<OIDCProviderTO>() {
+ OIDCProviderTO google = oidcProviderService.list().stream().
+ filter(object -> "Google".equals(object.getName())).findFirst().orElse(null);
+ assertNotNull(google);
+ assertFalse(google.isCreateUnmatching());
+ assertNull(google.getUserTemplate());
+ assertFalse(google.getItems().isEmpty());
+ assertNotEquals("fullname", google.getConnObjectKeyItem().getIntAttrName());
+ assertNotEquals("given_name", google.getConnObjectKeyItem().getExtAttrName());
- @Override
- public boolean evaluate(final OIDCProviderTO object) {
- return "Google".equals(object.getName());
- }
- });
- assertNotNull(ssoCircle);
- assertFalse(ssoCircle.isCreateUnmatching());
- assertNull(ssoCircle.getUserTemplate());
- assertFalse(ssoCircle.getItems().isEmpty());
- assertNotNull(ssoCircle.getConnObjectKeyItem());
- assertNotEquals("fullname", ssoCircle.getConnObjectKeyItem().getIntAttrName());
- assertNotEquals("given_name", ssoCircle.getConnObjectKeyItem().getExtAttrName());
-
- ssoCircle.setCreateUnmatching(true);
+ google.setCreateUnmatching(true);
UserTO userTemplate = new UserTO();
userTemplate.setRealm("'/'");
- ssoCircle.setUserTemplate(userTemplate);
+ google.setUserTemplate(userTemplate);
- ssoCircle.getItems().clear();
+ google.getItems().clear();
ItemTO keyMapping = new ItemTO();
keyMapping.setIntAttrName("fullname");
keyMapping.setExtAttrName("given_name");
- ssoCircle.setConnObjectKeyItem(keyMapping);
+ google.setConnObjectKeyItem(keyMapping);
- oidcProviderService.update(ssoCircle);
+ oidcProviderService.update(google);
- ssoCircle = oidcProviderService.read(ssoCircle.getKey());
- assertTrue(ssoCircle.isCreateUnmatching());
- assertEquals(userTemplate, ssoCircle.getUserTemplate());
- assertEquals("fullname", ssoCircle.getConnObjectKeyItem().getIntAttrName());
- assertEquals("given_name", ssoCircle.getConnObjectKeyItem().getExtAttrName());
+ google = oidcProviderService.read(google.getKey());
+ assertTrue(google.isCreateUnmatching());
+ assertEquals(userTemplate, google.getUserTemplate());
+ assertEquals("fullname", google.getConnObjectKeyItem().getIntAttrName());
+ assertEquals("given_name", google.getConnObjectKeyItem().getExtAttrName());
}
-
}
[2/2] syncope git commit: [SYNCOPE-1270] Adjusting test code
Posted by il...@apache.org.
[SYNCOPE-1270] Adjusting test code
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/49a88b12
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/49a88b12
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/49a88b12
Branch: refs/heads/2_0_X
Commit: 49a88b121653aebd2d8a9b5a16a6f285c6243bf5
Parents: 7e1bd36
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Sun Jun 10 18:06:30 2018 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Sun Jun 10 18:06:30 2018 +0200
----------------------------------------------------------------------
.../apache/syncope/fit/OIDCClientDetector.java | 2 +-
.../syncope/fit/core/OIDCClientITCase.java | 78 ++++++++------------
2 files changed, 31 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/49a88b12/fit/core-reference/src/test/java/org/apache/syncope/fit/OIDCClientDetector.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/OIDCClientDetector.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/OIDCClientDetector.java
index b08342e..b32682a 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/OIDCClientDetector.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/OIDCClientDetector.java
@@ -36,7 +36,7 @@ public class OIDCClientDetector {
try {
new SyncopeClientFactoryBean().
setAddress(AbstractITCase.ADDRESS).
- setContentType(SyncopeClientFactoryBean.ContentType.XML).
+ setContentType(SyncopeClientFactoryBean.ContentType.JSON).
create(new AnonymousAuthenticationHandler(
AbstractITCase.ANONYMOUS_UNAME, AbstractITCase.ANONYMOUS_KEY)).
getService(OIDCProviderService.class).list();
http://git-wip-us.apache.org/repos/asf/syncope/blob/49a88b12/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCClientITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCClientITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCClientITCase.java
index 33a9d44..a133459 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCClientITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCClientITCase.java
@@ -28,15 +28,12 @@ import static org.junit.Assert.assertTrue;
import org.apache.commons.collections4.IterableUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.syncope.client.lib.AnonymousAuthenticationHandler;
-import org.apache.syncope.client.lib.BasicAuthenticationHandler;
import org.apache.syncope.client.lib.SyncopeClient;
-import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
import org.apache.syncope.common.lib.to.ItemTO;
import org.apache.syncope.common.lib.to.OIDCLoginRequestTO;
import org.apache.syncope.common.lib.to.OIDCProviderTO;
import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.common.rest.api.service.OIDCClientService;
-import org.apache.syncope.common.rest.api.service.OIDCProviderService;
import org.apache.syncope.fit.AbstractITCase;
import org.apache.syncope.fit.OIDCClientDetector;
import org.junit.AfterClass;
@@ -46,21 +43,6 @@ import org.junit.Test;
public class OIDCClientITCase extends AbstractITCase {
- private static SyncopeClient anonymous;
-
- private static SyncopeClient admin;
-
- @BeforeClass
- public static void setup() {
- anonymous = new SyncopeClientFactoryBean().
- setAddress(ADDRESS).
- create(new AnonymousAuthenticationHandler(ANONYMOUS_UNAME, ANONYMOUS_KEY));
-
- admin = new SyncopeClientFactoryBean().
- setAddress(ADDRESS).
- create(new BasicAuthenticationHandler(ADMIN_UNAME, ADMIN_PWD));
- }
-
@BeforeClass
public static void createOIDCProviderWithoutDiscovery() throws Exception {
if (!OIDCClientDetector.isOIDCClientAvailable()) {
@@ -69,17 +51,17 @@ public class OIDCClientITCase extends AbstractITCase {
assertTrue(oidcProviderService.list().isEmpty());
- OIDCProviderTO oidcProviderTO = new OIDCProviderTO();
- oidcProviderTO.setAuthorizationEndpoint("AuthorizationEndpoint");
- oidcProviderTO.setClientID("ClientID");
- oidcProviderTO.setClientSecret("ClientSecret");
- oidcProviderTO.setIssuer("https://accounts.google.com");
- oidcProviderTO.setJwksUri("JwksUri");
- oidcProviderTO.setName("Google");
- oidcProviderTO.setTokenEndpoint("TokenEndpoint");
- oidcProviderTO.setUserinfoEndpoint("UserinfoEndpoint");
-
- admin.getService(OIDCProviderService.class).create(oidcProviderTO);
+ OIDCProviderTO google = new OIDCProviderTO();
+ google.setAuthorizationEndpoint("AuthorizationEndpoint");
+ google.setClientID("ClientID");
+ google.setClientSecret("ClientSecret");
+ google.setIssuer("https://accounts.google.com");
+ google.setJwksUri("JwksUri");
+ google.setName("Google");
+ google.setTokenEndpoint("TokenEndpoint");
+ google.setUserinfoEndpoint("UserinfoEndpoint");
+
+ oidcProviderService.create(google);
}
@AfterClass
@@ -97,6 +79,8 @@ public class OIDCClientITCase extends AbstractITCase {
public void createLoginRequest() {
Assume.assumeTrue(OIDCClientDetector.isOIDCClientAvailable());
+ SyncopeClient anonymous = clientFactory.create(
+ new AnonymousAuthenticationHandler(ANONYMOUS_UNAME, ANONYMOUS_KEY));
OIDCLoginRequestTO loginRequest = anonymous.getService(OIDCClientService.class).
createLoginRequest("http://localhost:9080/syncope-console/oidcclient/code-consumer", "Google");
@@ -113,40 +97,38 @@ public class OIDCClientITCase extends AbstractITCase {
public void setProviderMapping() {
Assume.assumeTrue(OIDCClientDetector.isOIDCClientAvailable());
- OIDCProviderTO ssoCircle = IterableUtils.find(oidcProviderService.list(), new Predicate<OIDCProviderTO>() {
+ OIDCProviderTO google = IterableUtils.find(oidcProviderService.list(), new Predicate<OIDCProviderTO>() {
@Override
public boolean evaluate(final OIDCProviderTO object) {
return "Google".equals(object.getName());
}
});
- assertNotNull(ssoCircle);
- assertFalse(ssoCircle.isCreateUnmatching());
- assertNull(ssoCircle.getUserTemplate());
- assertFalse(ssoCircle.getItems().isEmpty());
- assertNotNull(ssoCircle.getConnObjectKeyItem());
- assertNotEquals("fullname", ssoCircle.getConnObjectKeyItem().getIntAttrName());
- assertNotEquals("given_name", ssoCircle.getConnObjectKeyItem().getExtAttrName());
+ assertNotNull(google);
+ assertFalse(google.isCreateUnmatching());
+ assertNull(google.getUserTemplate());
+ assertFalse(google.getItems().isEmpty());
+ assertNotEquals("fullname", google.getConnObjectKeyItem().getIntAttrName());
+ assertNotEquals("given_name", google.getConnObjectKeyItem().getExtAttrName());
- ssoCircle.setCreateUnmatching(true);
+ google.setCreateUnmatching(true);
UserTO userTemplate = new UserTO();
userTemplate.setRealm("'/'");
- ssoCircle.setUserTemplate(userTemplate);
+ google.setUserTemplate(userTemplate);
- ssoCircle.getItems().clear();
+ google.getItems().clear();
ItemTO keyMapping = new ItemTO();
keyMapping.setIntAttrName("fullname");
keyMapping.setExtAttrName("given_name");
- ssoCircle.setConnObjectKeyItem(keyMapping);
+ google.setConnObjectKeyItem(keyMapping);
- oidcProviderService.update(ssoCircle);
+ oidcProviderService.update(google);
- ssoCircle = oidcProviderService.read(ssoCircle.getKey());
- assertTrue(ssoCircle.isCreateUnmatching());
- assertEquals(userTemplate, ssoCircle.getUserTemplate());
- assertEquals("fullname", ssoCircle.getConnObjectKeyItem().getIntAttrName());
- assertEquals("given_name", ssoCircle.getConnObjectKeyItem().getExtAttrName());
+ google = oidcProviderService.read(google.getKey());
+ assertTrue(google.isCreateUnmatching());
+ assertEquals(userTemplate, google.getUserTemplate());
+ assertNotEquals("fullname", google.getConnObjectKeyItem().getIntAttrName());
+ assertNotEquals("given_name", google.getConnObjectKeyItem().getExtAttrName());
}
-
}