From 800322d4396aad86626053e9c40e2adc203812db Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Wed, 23 Jul 2014 15:29:09 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud) 77117: Merged PLATFORM1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 73330: ACE-1690: SOLR 4 - Index nodes with bulk fetch for metadata - Added factory test and property exposer - Used exposed properties in CoreWatcherJob - TODO: MetadataTracker git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@77967 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco-solrclient-lib/pom.xml | 9 ++ .../solr/client/SOLRAPIClientFactoryTest.java | 98 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 search-services/alfresco-solrclient-lib/source/test-java/org/alfresco/solr/client/SOLRAPIClientFactoryTest.java diff --git a/search-services/alfresco-solrclient-lib/pom.xml b/search-services/alfresco-solrclient-lib/pom.xml index cff5548dd..88842c62c 100644 --- a/search-services/alfresco-solrclient-lib/pom.xml +++ b/search-services/alfresco-solrclient-lib/pom.xml @@ -36,6 +36,15 @@ junit test + + org.mockito + mockito-all + test + + + org.slf4j + slf4j-log4j12 + diff --git a/search-services/alfresco-solrclient-lib/source/test-java/org/alfresco/solr/client/SOLRAPIClientFactoryTest.java b/search-services/alfresco-solrclient-lib/source/test-java/org/alfresco/solr/client/SOLRAPIClientFactoryTest.java new file mode 100644 index 000000000..64428cb4d --- /dev/null +++ b/search-services/alfresco-solrclient-lib/source/test-java/org/alfresco/solr/client/SOLRAPIClientFactoryTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +package org.alfresco.solr.client; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.mockito.Mockito.when; + +import java.util.Properties; + +import org.alfresco.encryption.KeyResourceLoader; +import org.alfresco.repo.dictionary.NamespaceDAO; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.solr.client.SOLRAPIClient; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class SOLRAPIClientFactoryTest +{ + @Mock + private Properties props; + @Mock + private KeyResourceLoader keyResourceLoader; + @Mock + private DictionaryService dictionaryService; + @Mock + private NamespaceDAO namespaceDAO; + private SOLRAPIClientFactory factory; + + @Before + public void setUp() throws Exception + { + when(props.getProperty("alfresco.host", "localhost")).thenReturn("localhost"); + when(props.getProperty("alfresco.port", "8080")).thenReturn("8080"); + when(props.getProperty("alfresco.port.ssl", "8443")).thenReturn("8443"); + when(props.getProperty("alfresco.maxTotalConnections", "40")).thenReturn("40"); + when(props.getProperty("alfresco.maxHostConnections", "40")).thenReturn("40"); + when(props.getProperty("alfresco.socketTimeout", "0")).thenReturn("0"); + when(props.getProperty("alfresco.secureComms", "https")).thenReturn("none"); + when(props.getProperty("alfresco.encryption.ssl.keystore.location", + "ssl.repo.client.keystore")).thenReturn("ssl.repo.client.keystore"); + when(props.getProperty("alfresco.encryption.ssl.truststore.location", + "ssl.repo.client.truststore")).thenReturn("ssl.repo.client.truststore"); + + this.factory = new SOLRAPIClientFactory(); + } + + @Test + public void getsSameSOLRAPIClientForSameAlfresco() + { + SOLRAPIClient solrapiClient = factory.getSOLRAPIClient(props, keyResourceLoader, dictionaryService, + namespaceDAO); + assertNotNull(solrapiClient); + + SOLRAPIClient solrapiClient2 = factory.getSOLRAPIClient(props, keyResourceLoader, dictionaryService, + namespaceDAO); + assertNotNull(solrapiClient2); + + assertSame(solrapiClient, solrapiClient2); + } + + @Test + public void getsDifferentSOLRAPIClientForDifferentAlfresco() + { + SOLRAPIClient solrapiClient = factory.getSOLRAPIClient(props, keyResourceLoader, dictionaryService, + namespaceDAO); + assertNotNull(solrapiClient); + + when(props.getProperty("alfresco.port.ssl", "8443")).thenReturn("8444"); + SOLRAPIClient solrapiClient2 = factory.getSOLRAPIClient(props, keyResourceLoader, dictionaryService, + namespaceDAO); + assertNotNull(solrapiClient2); + + assertNotSame(solrapiClient, solrapiClient2); + } +}