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 2019/11/27 14:48:43 UTC
[syncope] 02/02: [SYNCOPE-1513] Fixing basic console tests
This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git
commit 25515a6e5ee6290adc1879e4cfe65ea0e87746ec
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Wed Nov 27 15:38:52 2019 +0100
[SYNCOPE-1513] Fixing basic console tests
---
.../syncope/client/console/AbstractTest.java | 141 ------------
.../syncope/client/console/AbstractTest.java | 236 +++++++++++++++++++++
.../console/SyncopeConsoleApplicationTest.java | 0
.../console/src/test/resources/log4j2.xml | 0
4 files changed, 236 insertions(+), 141 deletions(-)
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
deleted file mode 100644
index 6e4372b..0000000
--- a/client/console/src/test/java/org/apache/syncope/client/console/AbstractTest.java
+++ /dev/null
@@ -1,141 +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.syncope.client.console;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Properties;
-import java.util.stream.Stream;
-import javax.servlet.ServletContext;
-import org.apache.commons.lang3.tuple.Pair;
-import org.apache.cxf.jaxrs.client.Client;
-import org.apache.syncope.client.console.init.ClassPathScanImplementationLookup;
-import org.apache.syncope.client.console.init.ConsoleInitializer;
-import org.apache.syncope.client.console.init.MIMETypesLoader;
-import org.apache.syncope.client.lib.AuthenticationHandler;
-import org.apache.syncope.client.lib.SyncopeClient;
-import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
-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.DomainTO;
-import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.rest.api.service.DomainService;
-import org.apache.syncope.common.rest.api.service.SyncopeService;
-import org.apache.wicket.util.tester.WicketTester;
-import org.junit.jupiter.api.BeforeAll;
-
-public abstract class AbstractTest {
-
- protected static Properties PROPS;
-
- public interface SyncopeServiceClient extends SyncopeService, Client {
- }
-
- @BeforeAll
- public static void loadProps() throws IOException {
- PROPS = new Properties();
- try (InputStream is = AbstractTest.class.getResourceAsStream("/console.properties")) {
- PROPS.load(is);
- }
- }
-
- protected static final WicketTester TESTER = new WicketTester(new SyncopeConsoleApplication() {
-
- @Override
- protected void init() {
- ServletContext ctx = getServletContext();
- ClassPathScanImplementationLookup lookup = new ClassPathScanImplementationLookup();
- lookup.load();
- ctx.setAttribute(ConsoleInitializer.CLASSPATH_LOOKUP, lookup);
-
- MIMETypesLoader mimeTypes = new MIMETypesLoader();
- mimeTypes.load();
- ctx.setAttribute(ConsoleInitializer.MIMETYPES_LOADER, mimeTypes);
-
- super.init();
- }
-
- @Override
- public List<String> getDomains() {
- return super.getDomains();
- }
-
- private SyncopeService getSyncopeService() {
- SyncopeServiceClient service = mock(SyncopeServiceClient.class);
- when(service.type(anyString())).thenReturn(service);
- when(service.accept(anyString())).thenReturn(service);
-
- when(service.platform()).thenReturn(new PlatformInfo());
- when(service.system()).thenReturn(new SystemInfo());
-
- NumbersInfo numbersInfo = new NumbersInfo();
- Stream.of(NumbersInfo.ConfItem.values()).
- forEach(item -> numbersInfo.getConfCompleteness().put(item.name(), true));
- when(service.numbers()).thenReturn(numbersInfo);
-
- return service;
- }
-
- private UserTO getUserTO() {
- UserTO userTO = new UserTO();
- userTO.setUsername("username");
- return userTO;
- }
-
- private DomainService getDomainService() {
- DomainService domainService = mock(DomainService.class);
- DomainTO domainTO = new DomainTO();
- domainTO.setKey(SyncopeConstants.MASTER_DOMAIN);
- when(domainService.list()).thenReturn(Collections.singletonList(domainTO));
- return domainService;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public SyncopeClientFactoryBean newClientFactory() {
- SyncopeClient client = mock(SyncopeClient.class);
-
- when(client.self()).thenReturn(Pair.of(new HashMap<>(), getUserTO()));
-
- SyncopeService syncopeService = getSyncopeService();
- when(client.getService(SyncopeService.class)).thenReturn(syncopeService);
-
- DomainService domainService = getDomainService();
- when(client.getService(DomainService.class)).thenReturn(domainService);
-
- SyncopeClientFactoryBean clientFactory = mock(SyncopeClientFactoryBean.class);
- when(clientFactory.setDomain(any())).thenReturn(clientFactory);
- when(clientFactory.create(any(AuthenticationHandler.class))).thenReturn(client);
- when(clientFactory.create(anyString(), anyString())).thenReturn(client);
-
- return clientFactory;
- }
- });
-
-}
diff --git a/client/idrepo/console/src/test/java/org/apache/syncope/client/console/AbstractTest.java b/client/idrepo/console/src/test/java/org/apache/syncope/client/console/AbstractTest.java
new file mode 100644
index 0000000..8f34e28
--- /dev/null
+++ b/client/idrepo/console/src/test/java/org/apache/syncope/client/console/AbstractTest.java
@@ -0,0 +1,236 @@
+/*
+ * 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 static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.giffing.wicket.spring.boot.context.extensions.WicketApplicationInitConfiguration;
+import com.giffing.wicket.spring.boot.context.extensions.boot.actuator.WicketEndpointRepository;
+import com.giffing.wicket.spring.boot.starter.app.classscanner.candidates.WicketClassCandidatesHolder;
+import com.giffing.wicket.spring.boot.starter.configuration.extensions.core.settings.general.GeneralSettingsProperties;
+import com.giffing.wicket.spring.boot.starter.configuration.extensions.external.spring.boot.actuator.WicketEndpointRepositoryDefault;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Properties;
+import java.util.stream.Stream;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.cxf.jaxrs.client.Client;
+import org.apache.syncope.client.console.AbstractTest.TestSyncopeWebApplication.SyncopeServiceClient;
+import org.apache.syncope.client.console.commons.AnyDirectoryPanelAditionalActionLinksProvider;
+import org.apache.syncope.client.console.commons.AnyWizardBuilderAdditionalSteps;
+import org.apache.syncope.client.console.commons.ExternalResourceProvider;
+import org.apache.syncope.client.console.commons.IdRepoAnyDirectoryPanelAditionalActionLinksProvider;
+import org.apache.syncope.client.console.commons.IdRepoAnyWizardBuilderAdditionalSteps;
+import org.apache.syncope.client.console.commons.IdRepoExternalResourceProvider;
+import org.apache.syncope.client.console.commons.IdRepoImplementationInfoProvider;
+import org.apache.syncope.client.console.commons.IdRepoPolicyTabProvider;
+import org.apache.syncope.client.console.commons.IdRepoStatusProvider;
+import org.apache.syncope.client.console.commons.IdRepoVirSchemaDetailsPanelProvider;
+import org.apache.syncope.client.console.commons.ImplementationInfoProvider;
+import org.apache.syncope.client.console.commons.PolicyTabProvider;
+import org.apache.syncope.client.console.commons.PreviewUtils;
+import org.apache.syncope.client.console.commons.StatusProvider;
+import org.apache.syncope.client.console.commons.VirSchemaDetailsPanelProvider;
+import org.apache.syncope.client.console.init.ClassPathScanImplementationLookup;
+import org.apache.syncope.client.console.init.MIMETypesLoader;
+import org.apache.syncope.client.lib.AuthenticationHandler;
+import org.apache.syncope.client.lib.SyncopeClient;
+import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
+import org.apache.syncope.common.keymaster.client.api.DomainOps;
+import org.apache.syncope.common.keymaster.client.api.ServiceOps;
+import org.apache.syncope.common.keymaster.client.api.model.Domain;
+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.UserTO;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.rest.api.service.SyncopeService;
+import org.apache.wicket.util.tester.WicketTester;
+import org.junit.jupiter.api.BeforeAll;
+import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+public abstract class AbstractTest {
+
+ @ImportAutoConfiguration
+ @Configuration
+ public static class SyncopeConsoleWebApplicationTestConfig {
+
+ @Bean
+ public ServiceOps selfServiceOps() {
+ return mock(ServiceOps.class);
+ }
+
+ @Bean
+ public DomainOps domainOps() {
+ DomainOps domainOps = mock(DomainOps.class);
+ when(domainOps.list()).thenReturn(List.of(new Domain.Builder(SyncopeConstants.MASTER_DOMAIN).build()));
+ return domainOps;
+ }
+
+ @Bean
+ public GeneralSettingsProperties generalSettingsProperties() {
+ return new GeneralSettingsProperties();
+ }
+
+ @Bean
+ public List<WicketApplicationInitConfiguration> configurations() {
+ return List.of();
+ }
+
+ @Bean
+ public WicketClassCandidatesHolder wicketClassCandidatesHolder() {
+ return new WicketClassCandidatesHolder();
+ }
+
+ @Bean
+ public WicketEndpointRepository wicketEndpointRepository() {
+ return new WicketEndpointRepositoryDefault();
+ }
+
+ @Bean
+ public ClassPathScanImplementationLookup classPathScanImplementationLookup() {
+ ClassPathScanImplementationLookup lookup = new ClassPathScanImplementationLookup();
+ lookup.load();
+ return lookup;
+ }
+
+ @Bean
+ public MIMETypesLoader mimeTypesLoader() {
+ MIMETypesLoader mimeTypesLoader = new MIMETypesLoader();
+ mimeTypesLoader.load();
+ return mimeTypesLoader;
+ }
+
+ @Bean
+ public PreviewUtils previewUtils() {
+ return new PreviewUtils();
+ }
+
+ @Bean
+ public ExternalResourceProvider resourceProvider() {
+ return new IdRepoExternalResourceProvider();
+ }
+
+ @Bean
+ public AnyWizardBuilderAdditionalSteps anyWizardBuilderAdditionalSteps() {
+ return new IdRepoAnyWizardBuilderAdditionalSteps();
+ }
+
+ @Bean
+ public StatusProvider statusProvider() {
+ return new IdRepoStatusProvider();
+ }
+
+ @Bean
+ public VirSchemaDetailsPanelProvider virSchemaDetailsPanelProvider() {
+ return new IdRepoVirSchemaDetailsPanelProvider();
+ }
+
+ @Bean
+ public AnyDirectoryPanelAditionalActionLinksProvider anyDirectoryPanelAditionalActionLinksProvider() {
+ return new IdRepoAnyDirectoryPanelAditionalActionLinksProvider();
+ }
+
+ @Bean
+ public ImplementationInfoProvider implementationInfoProvider() {
+ return new IdRepoImplementationInfoProvider();
+ }
+
+ @Bean
+ public PolicyTabProvider policyTabProvider() {
+ return new IdRepoPolicyTabProvider();
+ }
+ }
+
+ public static class TestSyncopeWebApplication extends SyncopeWebApplication {
+
+ public interface SyncopeServiceClient extends SyncopeService, Client {
+ }
+
+ private SyncopeService getSyncopeService() {
+ SyncopeServiceClient service = mock(SyncopeServiceClient.class);
+ when(service.type(anyString())).thenReturn(service);
+ when(service.accept(anyString())).thenReturn(service);
+
+ when(service.platform()).thenReturn(new PlatformInfo());
+ when(service.system()).thenReturn(new SystemInfo());
+
+ NumbersInfo numbersInfo = new NumbersInfo();
+ Stream.of(NumbersInfo.ConfItem.values()).
+ forEach(item -> numbersInfo.getConfCompleteness().put(item.name(), true));
+ when(service.numbers()).thenReturn(numbersInfo);
+
+ return service;
+ }
+
+ private UserTO getUserTO() {
+ UserTO userTO = new UserTO();
+ userTO.setUsername("username");
+ return userTO;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public SyncopeClientFactoryBean newClientFactory() {
+ SyncopeClient client = mock(SyncopeClient.class);
+
+ when(client.self()).thenReturn(Pair.of(new HashMap<>(), getUserTO()));
+
+ SyncopeService syncopeService = getSyncopeService();
+ when(client.getService(SyncopeService.class)).thenReturn(syncopeService);
+
+ SyncopeClientFactoryBean clientFactory = mock(SyncopeClientFactoryBean.class);
+ when(clientFactory.setDomain(any())).thenReturn(clientFactory);
+ when(clientFactory.create(any(AuthenticationHandler.class))).thenReturn(client);
+ when(clientFactory.create(anyString(), anyString())).thenReturn(client);
+
+ return clientFactory;
+ }
+ }
+
+ protected static Properties PROPS;
+
+ protected static WicketTester TESTER;
+
+ @BeforeAll
+ public static void loadProps() throws IOException {
+ PROPS = new Properties();
+ try (InputStream is = AbstractTest.class.getResourceAsStream("/console.properties")) {
+ PROPS.load(is);
+ }
+ }
+
+ @BeforeAll
+ public static void setupTester() throws IOException {
+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
+ ctx.register(SyncopeConsoleWebApplicationTestConfig.class);
+ ctx.register(TestSyncopeWebApplication.class);
+ ctx.refresh();
+
+ TESTER = new WicketTester(ctx.getBean(SyncopeWebApplication.class));
+ }
+}
diff --git a/client/console/src/test/java/org/apache/syncope/client/console/SyncopeConsoleApplicationTest.java b/client/idrepo/console/src/test/java/org/apache/syncope/client/console/SyncopeConsoleApplicationTest.java
similarity index 100%
rename from client/console/src/test/java/org/apache/syncope/client/console/SyncopeConsoleApplicationTest.java
rename to client/idrepo/console/src/test/java/org/apache/syncope/client/console/SyncopeConsoleApplicationTest.java
diff --git a/client/console/src/test/resources/log4j2.xml b/client/idrepo/console/src/test/resources/log4j2.xml
similarity index 100%
rename from client/console/src/test/resources/log4j2.xml
rename to client/idrepo/console/src/test/resources/log4j2.xml