View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.persistence.jpa;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import org.apache.syncope.common.keymaster.client.api.ConfParamOps;
24  import org.apache.syncope.common.keymaster.client.api.DomainOps;
25  import org.apache.syncope.core.persistence.api.DomainHolder;
26  import org.apache.syncope.core.persistence.api.DomainRegistry;
27  import org.apache.syncope.core.persistence.api.content.ContentLoader;
28  import org.apache.syncope.core.provisioning.api.ConnectorManager;
29  import org.apache.syncope.core.provisioning.api.ImplementationLookup;
30  import org.apache.syncope.core.spring.security.DefaultPasswordGenerator;
31  import org.apache.syncope.core.spring.security.PasswordGenerator;
32  import org.apache.syncope.core.spring.security.SecurityProperties;
33  import org.springframework.beans.factory.annotation.Value;
34  import org.springframework.context.ConfigurableApplicationContext;
35  import org.springframework.context.annotation.Bean;
36  import org.springframework.context.annotation.Configuration;
37  import org.springframework.context.annotation.Import;
38  import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
39  import org.springframework.core.io.DefaultResourceLoader;
40  import org.springframework.core.io.Resource;
41  
42  @Import(PersistenceContext.class)
43  @Configuration(proxyBeanMethods = false)
44  public class PersistenceTestContext {
45  
46      @Bean
47      public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
48          PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
49  
50          DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
51  
52          List<Resource> locations = new ArrayList<>();
53          for (String location : System.getProperty("CORE_PROPERTIES").split(",")) {
54              locations.add(resourceLoader.getResource(location));
55          }
56          ppc.setLocations(locations.toArray(Resource[]::new));
57  
58          return ppc;
59      }
60  
61      @Value("${security.adminUser}")
62      private String adminUser;
63  
64      @Value("${security.anonymousUser}")
65      private String anonymousUser;
66  
67      @Bean
68      public String adminUser() {
69          return adminUser;
70      }
71  
72      @Bean
73      public String anonymousUser() {
74          return anonymousUser;
75      }
76  
77      @Bean
78      public TestInitializer testInitializer(
79              final StartupDomainLoader domainLoader,
80              final DomainHolder domainHolder,
81              final ContentLoader contentLoader,
82              final ConfigurableApplicationContext ctx) {
83  
84          return new TestInitializer(domainLoader, domainHolder, contentLoader, ctx);
85      }
86  
87      @Bean
88      public SecurityProperties securityProperties() {
89          return new SecurityProperties();
90      }
91  
92      @Bean
93      public PasswordGenerator passwordGenerator() {
94          return new DefaultPasswordGenerator();
95      }
96  
97      @Bean
98      public ImplementationLookup implementationLookup() {
99          return new DummyImplementationLookup();
100     }
101 
102     @Bean
103     public ConfParamOps confParamOps() {
104         return new DummyConfParamOps();
105     }
106 
107     @Bean
108     public DomainOps domainOps(final DomainRegistry domainRegistry) {
109         return new DummyDomainOps(domainRegistry);
110     }
111 
112     @Bean
113     public ConnectorManager connectorManager() {
114         return new DummyConnectorManager();
115     }
116 }