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 2020/03/17 16:52:42 UTC
[syncope] branch 2_1_X updated: Additional fixes to SYNCOPE-1542
(#167)
This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/2_1_X by this push:
new c5626b5 Additional fixes to SYNCOPE-1542 (#167)
c5626b5 is described below
commit c5626b5aa7850325f3b938c73586a81115d7322a
Author: Andrea Patricelli <an...@apache.org>
AuthorDate: Tue Mar 17 17:52:34 2020 +0100
Additional fixes to SYNCOPE-1542 (#167)
---
.../console/panels/search/SearchClausePanel.java | 2 +-
.../syncope/client/console/AbstractAdminTest.java | 31 +++++++++++
.../syncope/client/console/AbstractTest.java | 48 ++++++++++++++++
.../console/panels/search/UserSearchPanelTest.java | 64 ++++++++++++++++++++++
4 files changed, 144 insertions(+), 1 deletion(-)
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchClausePanel.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchClausePanel.java
index d096f8b..0acd0fc 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchClausePanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/search/SearchClausePanel.java
@@ -420,7 +420,7 @@ public class SearchClausePanel extends FieldPanel<SearchClause> {
}
AjaxTextFieldPanel property = new AjaxTextFieldPanel(
- "property", "property", new PropertyModel<>(searchClause, "property"), false);
+ "property", "property", new PropertyModel<>(searchClause, "property"), true) ;
property.hideLabel().setOutputMarkupId(true).setEnabled(true);
property.setChoices(properties.getObject());
field.add(property);
diff --git a/client/console/src/test/java/org/apache/syncope/client/console/AbstractAdminTest.java b/client/console/src/test/java/org/apache/syncope/client/console/AbstractAdminTest.java
new file mode 100644
index 0000000..882f77a
--- /dev/null
+++ b/client/console/src/test/java/org/apache/syncope/client/console/AbstractAdminTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.syncope.client.console;
+
+import java.util.Locale;
+import org.junit.jupiter.api.BeforeAll;
+
+public abstract class AbstractAdminTest extends AbstractTest {
+
+ @BeforeAll
+ public static void authenticate() {
+ SyncopeConsoleSession.get().signIn("", "");
+ SyncopeConsoleSession.get().setLocale(Locale.ENGLISH);
+ }
+}
diff --git a/client/console/src/test/java/org/apache/syncope/client/console/AbstractTest.java b/client/console/src/test/java/org/apache/syncope/client/console/AbstractTest.java
index 6e4372b..4b81f7b 100644
--- a/client/console/src/test/java/org/apache/syncope/client/console/AbstractTest.java
+++ b/client/console/src/test/java/org/apache/syncope/client/console/AbstractTest.java
@@ -43,9 +43,16 @@ import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.info.NumbersInfo;
import org.apache.syncope.common.lib.info.PlatformInfo;
import org.apache.syncope.common.lib.info.SystemInfo;
+import org.apache.syncope.common.lib.to.AnyTypeTO;
import org.apache.syncope.common.lib.to.DomainTO;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
+import org.apache.syncope.common.rest.api.beans.SchemaQuery;
+import org.apache.syncope.common.rest.api.service.AnyTypeService;
import org.apache.syncope.common.rest.api.service.DomainService;
+import org.apache.syncope.common.rest.api.service.SchemaService;
import org.apache.syncope.common.rest.api.service.SyncopeService;
import org.apache.wicket.util.tester.WicketTester;
import org.junit.jupiter.api.BeforeAll;
@@ -57,6 +64,12 @@ public abstract class AbstractTest {
public interface SyncopeServiceClient extends SyncopeService, Client {
}
+ public interface AnyTypeServiceClient extends AnyTypeService, Client {
+ }
+
+ public interface SchemaServiceClient extends SchemaService, Client {
+ }
+
@BeforeAll
public static void loadProps() throws IOException {
PROPS = new Properties();
@@ -116,6 +129,35 @@ public abstract class AbstractTest {
return domainService;
}
+ private SchemaService getSchemaService() {
+ SchemaServiceClient service = mock(SchemaServiceClient.class);
+
+ when(service.type(anyString())).thenReturn(service);
+ when(service.accept(anyString())).thenReturn(service);
+
+ PlainSchemaTO firstname = new PlainSchemaTO();
+ firstname.setKey("firstname");
+ firstname.setType(AttrSchemaType.String);
+ firstname.setAnyTypeClass("minimal user");
+ firstname.setMandatoryCondition("false");
+ when(service.search(any(SchemaQuery.class))).thenReturn(Collections.singletonList(firstname));
+ return service;
+ }
+
+ private AnyTypeService getAnyTypeService() {
+ AnyTypeServiceClient service = mock(AnyTypeServiceClient.class);
+
+ when(service.type(anyString())).thenReturn(service);
+ when(service.accept(anyString())).thenReturn(service);
+
+ AnyTypeTO anyTypeTO = new AnyTypeTO();
+ anyTypeTO.setKey("123456");
+ anyTypeTO.setKind(AnyTypeKind.USER);
+
+ when(service.read(anyString())).thenReturn(anyTypeTO);
+ return service;
+ }
+
@SuppressWarnings("unchecked")
@Override
public SyncopeClientFactoryBean newClientFactory() {
@@ -126,6 +168,12 @@ public abstract class AbstractTest {
SyncopeService syncopeService = getSyncopeService();
when(client.getService(SyncopeService.class)).thenReturn(syncopeService);
+ SchemaService schemaService = getSchemaService();
+ when(client.getService(SchemaService.class)).thenReturn(schemaService);
+
+ AnyTypeService anyTypeService = getAnyTypeService();
+ when(client.getService(AnyTypeService.class)).thenReturn(anyTypeService);
+
DomainService domainService = getDomainService();
when(client.getService(DomainService.class)).thenReturn(domainService);
diff --git a/client/console/src/test/java/org/apache/syncope/client/console/panels/search/UserSearchPanelTest.java b/client/console/src/test/java/org/apache/syncope/client/console/panels/search/UserSearchPanelTest.java
new file mode 100644
index 0000000..60d529d
--- /dev/null
+++ b/client/console/src/test/java/org/apache/syncope/client/console/panels/search/UserSearchPanelTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.syncope.client.console.panels.search;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.syncope.client.console.AbstractAdminTest;
+import org.apache.wicket.model.util.ListModel;
+import org.apache.wicket.util.tester.FormTester;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class UserSearchPanelTest extends AbstractAdminTest {
+
+ @Test
+ public void test() {
+ List<SearchClause> clauses = new ArrayList<>();
+ SearchClause clause = new SearchClause();
+ clauses.add(clause);
+ clause.setComparator(SearchClause.Comparator.EQUALS);
+ clause.setType(SearchClause.Type.ATTRIBUTE);
+ clause.setProperty("username");
+
+ TESTER.startComponentInPage(new UserSearchPanel.Builder(
+ new ListModel<>(clauses)).required(true).enableSearch().build("content"));
+
+ FormTester formTester = TESTER.newFormTester("content:searchFormContainer:search:multiValueContainer:innerForm");
+
+ Assertions.assertNotNull(formTester.getForm().get("content:view:0:panel:container:property:textField"));
+
+ formTester.setValue("content:view:0:panel:container:property:textField", "firstname");
+ formTester.setValue("content:view:0:panel:container:value:textField", "vincenzo");
+ assertEquals("username", formTester.getForm().
+ get("content:view:0:panel:container:property:textField").getDefaultModelObjectAsString());
+ assertNull(formTester.getForm().get("content:view:0:panel:container:value:textField").
+ getDefaultModelObject());
+ formTester.submit(formTester.getForm().get("content:view:0:panel:container:operatorContainer:operator:search"));
+ assertEquals("firstname", formTester.getForm().get(
+ "content:view:0:panel:container:property:textField").getDefaultModelObjectAsString());
+ assertEquals("vincenzo", formTester.getForm().get("content:view:0:panel:container:value:textField").
+ getDefaultModelObjectAsString());
+
+ }
+
+}