/*******************************************************************************
 * Copyright 2016 Net Wolf UK
 *
 * Licensed 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 debrepo.teamcity.mock;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.File;

import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import jetbrains.buildServer.controllers.AuthorizationInterceptor;
import jetbrains.buildServer.serverSide.ConfigActionFactory;
import jetbrains.buildServer.serverSide.ProjectManager;
import jetbrains.buildServer.serverSide.SBuildServer;
import jetbrains.buildServer.serverSide.ServerPaths;
import jetbrains.buildServer.serverSide.auth.SecurityContext;
import jetbrains.buildServer.serverSide.impl.ConfigActionFactoryImpl;
import jetbrains.buildServer.serverSide.settings.ProjectSettingsManager;
import jetbrains.buildServer.web.openapi.PageExtension;
import jetbrains.buildServer.web.openapi.PagePlace;
import jetbrains.buildServer.web.openapi.PagePlaces;
import jetbrains.buildServer.web.openapi.PlaceId;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import jetbrains.buildServer.web.openapi.WebControllerManager;

@Configuration
public class TestMocks {
	
	@Bean
	SBuildServer sbBuildServer() {
		return mock(SBuildServer.class);
	}
	
	@Bean
	WebControllerManager webControllerManager() {
		return mock(WebControllerManager.class);
	}
	
	@Bean
	AuthorizationInterceptor authorizationInterceptor() {
		return mock(AuthorizationInterceptor.class);
	}
	
	@Bean
	ProjectManager projectManager() {
		return mock(ProjectManager.class);
	}
	
	@Bean
	ProjectSettingsManager projectSettingsManager() {
		return mock(ProjectSettingsManager.class);
	}

	@Bean
	ServerPaths serverPaths() {
		ServerPaths serverPaths = mock(ServerPaths.class);
		when(serverPaths.getPluginDataDirectory()).thenReturn(new File("target/pluginData"));
		return serverPaths;
	}
	
	@Bean
	PluginDescriptor pluginDescriptor() {
		PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
		when(pluginDescriptor.getPluginName()).thenReturn("tcDebRepository");
		when(pluginDescriptor.getPluginResourcesPath(anyString())).thenReturn("something/debRepository/projectConfigTab.jsp");
		return pluginDescriptor;
	}
	
	@Bean
	SecurityContext securityContext() {
		return mock(SecurityContext.class);
	}
	
	@Bean 
	PagePlaces pagePlaces() {
		PagePlaces pagePlaces = mock(PagePlaces.class);
		when(pagePlaces.getPlaceById(PlaceId.EDIT_PROJECT_PAGE_TAB)).thenReturn(pagePlace());
		when(pagePlaces.getPlaceById(PlaceId.BUILD_CONF_TAB)).thenReturn(pagePlace());
		return pagePlaces;
	}
	
	@Bean 
	PagePlace pagePlace() {
		PagePlace pagePlace = mock(PagePlace.class);
		return pagePlace;
	}
	
	@Bean 
	ConfigActionFactory configActionFactory() {
		return new ConfigActionFactoryImpl(securityContext());
	}
}

@@ -834,56 +834,8 @@
 ng;%0A
-import static org.mockito.ArgumentMatchers.any;%0A
 impo
@@ -870,16 +870,16 @@
 o.mock;%0A
+
 import s
@@ -937,36 +937,8 @@
 e;%0A%0A
-import org.mockito.Mockito;%0A
 impo
@@ -1118,69 +1118,8 @@
 or;%0A
-import jetbrains.buildServer.serverSide.ConfigActionFactory;%0A
 impo
@@ -1343,78 +1343,8 @@
 xt;%0A
-import jetbrains.buildServer.serverSide.impl.ConfigActionFactoryImpl;%0A
 impo
@@ -1416,64 +1416,8 @@
 er;%0A
-import jetbrains.buildServer.web.openapi.PageExtension;%0A
 impo
@@ -3237,119 +3237,6 @@
 %7D%0A%09%0A
-%09@Bean %0A%09ConfigActionFactory configActionFactory() %7B%0A%09%09return new ConfigActionFactoryImpl(securityContext());%0A%09%7D%0A
 %7D%0A

Remove references to ConfigActionFactory. Fixes issue #6