diff --git a/spring-data-rest-tests/pom.xml b/spring-data-rest-tests/pom.xml index 864f3850a..769975d91 100644 --- a/spring-data-rest-tests/pom.xml +++ b/spring-data-rest-tests/pom.xml @@ -20,7 +20,6 @@ spring-data-rest-tests-mongodb spring-data-rest-tests-security spring-data-rest-tests-shop - spring-data-rest-tests-solr diff --git a/spring-data-rest-tests/spring-data-rest-tests-solr/pom.xml b/spring-data-rest-tests/spring-data-rest-tests-solr/pom.xml deleted file mode 100644 index 0c4e2b824..000000000 --- a/spring-data-rest-tests/spring-data-rest-tests-solr/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ - - 4.0.0 - - org.springframework.data - spring-data-rest-tests - 3.3.7.BUILD-SNAPSHOT - - - Spring Data REST Tests - Solr - spring-data-rest-tests-solr - - - - - org.springframework.data - spring-data-rest-tests-core - 3.3.7.BUILD-SNAPSHOT - test-jar - - - - - - org.springframework.data - spring-data-solr - ${springdata.solr} - test - - - - com.fasterxml.jackson.core - jackson-core - - - - com.fasterxml.jackson.core - jackson-annotations - - - - org.apache.solr - solr-core - 8.4.1 - test - - - org.slf4j - slf4j-api - - - jdk.tools - jdk.tools - - - com.google - guava - - - - - - - diff --git a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/Product.java b/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/Product.java deleted file mode 100644 index d30cbcd36..000000000 --- a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/Product.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2014-2020 the original author or authors. - * - * 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 - * - * https://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.springframework.data.rest.webmvc.solr; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.springframework.data.annotation.Id; -import org.springframework.data.solr.core.mapping.Indexed; -import org.springframework.data.solr.core.mapping.SolrDocument; -import org.springframework.util.ObjectUtils; - -/** - * @author Christoph Strobl - */ -@SolrDocument(solrCoreName = "collection1") -public class Product { - - private @Id String id; - private @Indexed String name; - private @Indexed(name = "cat") List categories; - - public Product() {} - - public Product(String id, String name, String... categories) { - - this.id = id; - this.name = name; - this.categories = ObjectUtils.isEmpty(categories) ? Collections. emptyList() : Arrays.asList(categories); - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getCategories() { - return categories; - } - - public void setCategories(List categories) { - this.categories = categories; - } -} diff --git a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/ProductRepository.java b/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/ProductRepository.java deleted file mode 100644 index e2f78d4ba..000000000 --- a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/ProductRepository.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2014-2020 the original author or authors. - * - * 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 - * - * https://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.springframework.data.rest.webmvc.solr; - -import org.springframework.data.repository.PagingAndSortingRepository; - -/** - * @author Christoph Strobl - */ -public interface ProductRepository extends PagingAndSortingRepository {} diff --git a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/SolrInfrastructureConfig.java b/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/SolrInfrastructureConfig.java deleted file mode 100644 index dff36e034..000000000 --- a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/SolrInfrastructureConfig.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright 2014-2020 the original author or authors. - * - * 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 - * - * https://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.springframework.data.rest.webmvc.solr; - -import static org.springframework.data.rest.webmvc.solr.TestUtils.*; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.commons.io.FileUtils; -import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; -import org.apache.solr.core.CloseHook; -import org.apache.solr.core.CoreDescriptor; -import org.apache.solr.core.SolrCore; -import org.junit.ClassRule; -import org.junit.rules.TemporaryFolder; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.springframework.data.solr.core.SolrTemplate; -import org.springframework.data.solr.server.SolrClientFactory; -import org.springframework.data.solr.server.support.EmbeddedSolrServerFactory; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.FileCopyUtils; -import org.springframework.util.StringUtils; -import org.xml.sax.SAXException; - -/** - * @author Christoph Strobl - * @author Oliver Gierke - */ -@Configuration -public class SolrInfrastructureConfig { - - private static final String CORE_PROPERTIES = "name=collection1"; - private static final Resource MANAGED_SCHEMA = new ClassPathResource("managed-schema", SolrInfrastructureConfig.class); - private static final Resource SOLR_CONFIG = new ClassPathResource("solrconfig.xml", SolrInfrastructureConfig.class); - private static final Resource SOLR_SCHEMA = new ClassPathResource("schema.xml", SolrInfrastructureConfig.class); - private static final Resource SOLR_XML = new ClassPathResource("solr.xml", SolrInfrastructureConfig.class); - - @Bean - public SolrClientFactory solrClientFactory(final String solrHomeDir) - throws ParserConfigurationException, IOException, SAXException { - - prepareConfiguration(solrHomeDir); - return new EmbeddedSolrServerFactory(solrHomeDir); - } - - @Bean - public SolrTemplate solrTemplate(SolrClientFactory factory) { - - attachCloseHook(factory); - return new SolrTemplate(factory); - } - - private static void prepareConfiguration(final String solrHomePath) throws IOException { - - Map configParams = new HashMap(); - configParams.put("${data.dir}", solrHomePath); - configParams.put("${lucene.version}", "5.3.1"); - - Resource solrConfig = filterResource(SOLR_CONFIG, configParams); - Resource solrSchema = SOLR_SCHEMA; - Resource solrXml = SOLR_XML; - Resource solrManagedSchema = MANAGED_SCHEMA; - - File solrHomeDir = new File(solrHomePath); - File collectionDir = new File(solrHomeDir, "collection1"); - File confDir = new File(collectionDir, "conf"); - confDir.mkdirs(); - - FileCopyUtils.copy(solrXml.getInputStream(), new FileOutputStream(createFile(solrHomeDir, "solr.xml"))); - FileCopyUtils.copy(CORE_PROPERTIES.getBytes(), new FileOutputStream(createFile(collectionDir, "core.properties"))); - FileCopyUtils.copy(solrSchema.getInputStream(), new FileOutputStream(createFile(confDir, "schema.xml"))); - FileCopyUtils.copy(solrManagedSchema.getInputStream(), new FileOutputStream(createFile(confDir, "managed-schema"))); - FileCopyUtils.copy(solrConfig.getInputStream(), new FileOutputStream(createFile(confDir, "solrconfig.xml"))); - } - - private static File createFile(File parent, String child) throws IOException { - - File file = new File(parent, child); - if (!file.exists()) { - file.createNewFile(); - } - return file; - } - - /** - * {@link SpringRunner} executes {@link ClassRule}s before the actual shutdown of the {@link ApplicationContext}. This - * causes the {@link TemporaryFolder} to vanish before Solr can gracefully shutdown.
- * To prevent error messages popping up we register a {@link CloseHook} re adding the index directory and removing it - * after {@link SolrCore#close()}. - * - * @param factory - */ - private void attachCloseHook(SolrClientFactory factory) { - - EmbeddedSolrServer server = (EmbeddedSolrServer) factory.getSolrClient(); - - for (SolrCore core : server.getCoreContainer().getCores()) { - - core.addCloseHook(new CloseHook() { - - private String path; - - @Override - public void preClose(SolrCore core) { - - CoreDescriptor cd = core.getCoreDescriptor(); - - if (cd == null) { - return; - } - - File tmp = new File(core.getIndexDir()).getParentFile(); - - if (tmp.exists()) { - return; - } - - try { - - File indexFile = new File(tmp, "index"); - indexFile.mkdirs(); - - this.path = indexFile.getPath(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public void postClose(SolrCore core) { - - if (!StringUtils.hasText(this.path)) { - return; - } - - File tmp = new File(this.path); - - if (tmp.exists() && tmp.getPath().startsWith(FileUtils.getTempDirectoryPath())) { - - try { - FileUtils.deleteDirectory(tmp); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - }); - } - } -} diff --git a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/SolrTestBase.java b/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/SolrTestBase.java deleted file mode 100644 index 8682b2c48..000000000 --- a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/SolrTestBase.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2014-2020 the original author or authors. - * - * 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 - * - * https://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.springframework.data.rest.webmvc.solr; - -import org.junit.ClassRule; -import org.junit.rules.TemporaryFolder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.data.solr.repository.config.EnableSolrRepositories; -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Christoph Strobl - */ -@ContextConfiguration -public class SolrTestBase { - - public static @ClassRule TemporaryFolder TEMP_FOLDER = new TemporaryFolder(); - - @Configuration - @EnableSolrRepositories - @Import(SolrInfrastructureConfig.class) - static class MyConf { - - @Bean - String solrHomeDir() { - return TEMP_FOLDER.getRoot().getAbsolutePath(); - } - } -} diff --git a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/SolrWebTests.java b/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/SolrWebTests.java deleted file mode 100755 index d773c884b..000000000 --- a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/SolrWebTests.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2014-2020 the original author or authors. - * - * 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 - * - * https://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.springframework.data.rest.webmvc.solr; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -import java.util.Arrays; - -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.data.rest.tests.CommonWebTests; -import org.springframework.data.solr.repository.config.EnableSolrRepositories; -import org.springframework.hateoas.IanaLinkRelations; -import org.springframework.hateoas.Link; -import org.springframework.hateoas.LinkRelation; -import org.springframework.http.MediaType; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.test.context.ContextConfiguration; - -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * @author Christoph Strobl - */ -@ContextConfiguration(classes = { SolrWebTests.MyConf.class }) -public class SolrWebTests extends CommonWebTests { - - public static @ClassRule TemporaryFolder TEMP_FOLDER = new TemporaryFolder(); - - private static final Product PLAYSTATION = new Product("1", "playstation", "electronic", "game", "media"); - private static final Product GAMEBOY = new Product("2", "gameboy", "electronic"); - private static final Product AMIGA500 = new Product("3", "amiga500", "ancient"); - - private static final ObjectMapper MAPPER = new ObjectMapper(); - - @Configuration - @EnableSolrRepositories - @Import(value = { SolrInfrastructureConfig.class }) - static class MyConf { - - @Bean - String solrHomeDir() { - return TEMP_FOLDER.getRoot().getAbsolutePath(); - } - } - - @Autowired ProductRepository repo; - - @Override - @Before - public void setUp() { - - super.setUp(); - repo.saveAll(Arrays.asList(PLAYSTATION, GAMEBOY, AMIGA500)); - } - - @After - public void tearDown() { - repo.deleteAll(); - } - - @Test // DATAREST-387 - public void allowsPaginationThroughData() throws Exception { - - MockHttpServletResponse response = client.request("/products?page=0&size=1"); - - Link nextLink = client.assertHasLinkWithRel(IanaLinkRelations.NEXT, response); - assertDoesNotHaveLinkWithRel(IanaLinkRelations.PREV, response); - - response = client.request(nextLink); - client.assertHasLinkWithRel(IanaLinkRelations.PREV, response); - nextLink = client.assertHasLinkWithRel(IanaLinkRelations.NEXT, response); - - response = client.request(nextLink); - client.assertHasLinkWithRel(IanaLinkRelations.PREV, response); - assertDoesNotHaveLinkWithRel(IanaLinkRelations.NEXT, response); - } - - @Test // DATAREST-387 - public void allowsRetrievingDataById() throws Exception { - requestAndCompare(PLAYSTATION); - } - - @Test // DATAREST-387 - public void createsEntitesCorrectly() throws Exception { - - Product product = new Product("4", "iWatch", "trends", "scary"); - - mvc.perform( - put("/products/{id}", 4).content(MAPPER.writeValueAsString(product)).contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isCreated()).andReturn().getResponse(); - - assertJsonDocumentMatches(product); - } - - @Test // DATAREST-387 - public void deletesEntitiesCorrectly() throws Exception { - deleteAndVerify(new Link("/products/1")); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#expectedRootLinkRels() - */ - @Override - protected Iterable expectedRootLinkRels() { - return LinkRelation.manyOf("products"); - } - - private void assertJsonDocumentMatches(Product reference) throws Exception { - requestAndCompare(reference); - } - - private MockHttpServletResponse requestAndCompare(Product reference) throws Exception { - - MockHttpServletResponse response = client.request("/products/" + reference.getId()); - - assertJsonPathEquals("name", reference.getName(), response); - assertJsonPathEquals("categories", MAPPER.writeValueAsString(reference.getCategories()), response); - - return response; - } -} diff --git a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/TestUtils.java b/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/TestUtils.java deleted file mode 100644 index a66406adf..000000000 --- a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/java/org/springframework/data/rest/webmvc/solr/TestUtils.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2014-2020 the original author or authors. - * - * 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 - * - * https://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.springframework.data.rest.webmvc.solr; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.Map; - -import org.springframework.core.io.ByteArrayResource; -import org.springframework.core.io.Resource; -import org.springframework.util.Assert; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StreamUtils; -import org.springframework.util.StringUtils; - -/** - * Test helper methods. - * - * @author Oliver Gierke - * @author Christoph Strobl - */ -class TestUtils { - - private static final Charset UTF8 = Charset.forName("UTF-8"); - - /** - * Filters the given {@link Resource} by replacing values within. - * - * @param source must not be {@literal null}. - * @param replacements - * @return {@link Resource} with replaced values. - * @throws IOException - */ - public static Resource filterResource(Resource source, Map replacements) throws IOException { - - Assert.notNull(source, "Cannot filter 'null' resource"); - if (CollectionUtils.isEmpty(replacements)) { - return source; - } - - String temp = StreamUtils.copyToString(source.getInputStream(), UTF8); - - for (Map.Entry entry : replacements.entrySet()) { - temp = StringUtils.replace(temp, entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : ""); - } - - return new ByteArrayResource(temp.getBytes(UTF8)); - } -} diff --git a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/managed-schema b/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/managed-schema deleted file mode 100644 index fee19bad9..000000000 --- a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/managed-schema +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - id - diff --git a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/schema.xml b/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/schema.xml deleted file mode 100644 index fee19bad9..000000000 --- a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/schema.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - id - diff --git a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/solr.xml b/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/solr.xml deleted file mode 100644 index 659110c99..000000000 --- a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/solr.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - ${host:} - ${jetty.port:8983} - ${hostContext:solr} - ${zkClientTimeout:15000} - ${genericCoreNodeNames:true} - - - - ${socketTimeout:0} - ${connTimeout:0} - - - \ No newline at end of file diff --git a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/solrconfig.xml b/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/solrconfig.xml deleted file mode 100644 index 1190a2b69..000000000 --- a/spring-data-rest-tests/spring-data-rest-tests-solr/src/test/resources/org/springframework/data/rest/webmvc/solr/solrconfig.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - ${data.dir} - - ${lucene.version} - - - ${solr.commitwithin.softcommit:true} - - - - - explicit - true - text - - - -