Skip to content

Commit

Permalink
move testcases and remove now useless test, use solr service inject
Browse files Browse the repository at this point in the history
  • Loading branch information
mprins committed Jul 8, 2024
1 parent 36cb931 commit c4e3f6d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1363,10 +1363,8 @@ public void createSolrIndex() throws Exception {
logger.info("Creating Solr index");
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
final String solrUrl =
"http://"
+ (connectToSpatialDbsAtLocalhost ? "127.0.0.1" : "solr")
+ ":8983/solr/"
+ solrCoreName;
"http://" + (connectToSpatialDbsAtLocalhost ? "127.0.0.1" : "solr") + ":8983/solr/";
this.solrService.setSolrUrl(solrUrl);
SolrHelper solrHelper = new SolrHelper(this.solrService.getSolrClientForIndexing());

Check warning on line 1368 in src/main/java/nl/b3p/tailormap/api/configuration/dev/PopulateTestData.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/configuration/dev/PopulateTestData.java#L1367-L1368

Added lines #L1367 - L1368 were not covered by tests

GeoService geoService = geoServiceRepository.findById("snapshot-geoserver").orElseThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import nl.b3p.tailormap.api.geotools.featuresources.FeatureSourceFactoryHelper;
import nl.b3p.tailormap.api.persistence.SearchIndex;
import nl.b3p.tailormap.api.persistence.TMFeatureType;
import nl.b3p.tailormap.api.repository.FeatureSourceRepository;
import nl.b3p.tailormap.api.repository.FeatureTypeRepository;
import nl.b3p.tailormap.api.repository.GeoServiceRepository;
import nl.b3p.tailormap.api.repository.SearchIndexRepository;
import nl.b3p.tailormap.api.solr.SolrHelper;
import nl.b3p.tailormap.api.solr.SolrService;
Expand All @@ -30,7 +28,6 @@
import org.apache.solr.common.SolrException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -45,33 +42,20 @@
/** Admin controller for Solr. */
@RestController
public class SolrAdminController {
@Value("${tailormap-api.solr-url}")
private String solrUrl;

@Value("${tailormap-api.solr-core-name:tailormap}")
private String solrCoreName;

private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final FeatureSourceFactoryHelper featureSourceFactoryHelper;

private final FeatureSourceRepository featureSourceRepository;
private final FeatureTypeRepository featureTypeRepository;
private final GeoServiceRepository geoServiceRepository;
private final SearchIndexRepository searchIndexRepository;
private final SolrService solrService;

public SolrAdminController(
FeatureSourceFactoryHelper featureSourceFactoryHelper,
FeatureSourceRepository featureSourceRepository,
FeatureTypeRepository featureTypeRepository,
GeoServiceRepository geoServiceRepository,
SearchIndexRepository searchIndexRepository,
SolrService solrService) {

Check warning on line 56 in src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java#L56

Added line #L56 was not covered by tests
this.featureSourceFactoryHelper = featureSourceFactoryHelper;
this.featureSourceRepository = featureSourceRepository;
this.featureTypeRepository = featureTypeRepository;
this.geoServiceRepository = geoServiceRepository;
this.searchIndexRepository = searchIndexRepository;
this.solrService = solrService;

Check warning on line 60 in src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java#L60

Added line #L60 was not covered by tests
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ public interface ApplicationRepository extends JpaRepository<Application, Long>
/**
* Find all applications that have a layer that is linked to a specific (Solr) index.
*
* @param indexId The index id to search for //TODO: This query is not working as expected. It
* should return all applications that have a layer that is linked to a specific (Solr) index.
* @param indexId The index id to search for
*/
@NonNull
@PreAuthorize("permitAll()")
@Query(
value =
"select * from application app, lateral jsonb_path_query(gs.settings, ('$.layerSettings.**{1}.searchIndex.searchIndexId ? (@ == '||:indexId||')')::jsonpath)",
"select * from application app, lateral jsonb_path_query(app.settings, ('$.layerSettings.**{1}.searchIndexId ? (@ == '||:indexId||')')::jsonpath)",
nativeQuery = true)
List<Application> findByIndexId(@Param("indexId") @NonNull Long indexId);
}
8 changes: 6 additions & 2 deletions src/main/java/nl/b3p/tailormap/api/solr/SolrService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SolrService {
*/
public SolrClient getSolrClientForIndexing() {
return new ConcurrentUpdateHttp2SolrClient.Builder(

Check warning on line 29 in src/main/java/nl/b3p/tailormap/api/solr/SolrService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/solr/SolrService.java#L29

Added line #L29 was not covered by tests
solrUrl + solrCoreName,
this.solrUrl + this.solrCoreName,
new Http2SolrClient.Builder()
.withFollowRedirects(true)
.withConnectionTimeout(10000, TimeUnit.MILLISECONDS)
Expand All @@ -44,9 +44,13 @@ public SolrClient getSolrClientForIndexing() {
* @return the Solr client
*/
public SolrClient getSolrClientForSearching() {
return new Http2SolrClient.Builder(solrUrl + solrCoreName)
return new Http2SolrClient.Builder(this.solrUrl + this.solrCoreName)
.withConnectionTimeout(10, TimeUnit.SECONDS)
.withFollowRedirects(true)
.build();

Check warning on line 50 in src/main/java/nl/b3p/tailormap/api/solr/SolrService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/solr/SolrService.java#L47-L50

Added lines #L47 - L50 were not covered by tests
}

public void setSolrUrl(String solrUrl) {
this.solrUrl = solrUrl;
}

Check warning on line 55 in src/main/java/nl/b3p/tailormap/api/solr/SolrService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/solr/SolrService.java#L54-L55

Added lines #L54 - L55 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import static org.hibernate.validator.internal.util.Contracts.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import nl.b3p.tailormap.api.annotation.PostgresIntegrationTest;
import nl.b3p.tailormap.api.persistence.Application;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -30,4 +33,17 @@ void should_not_find_application_by_nonexistent_name() {
Application a = applicationRepository.findByName("does-not-exist");
assertNull(a);
}

@Test
void it_should_find_application_using_findByIndexId_with_valid_ID() {
final Application application = applicationRepository.findByIndexId(2L).get(0);
Assertions.assertNotNull(application);
assertEquals("default", application.getName());
}

@Test
void it_should_not_find_applications_findByIndexId_with_invalid_ID() {
final List<Application> applications = applicationRepository.findByIndexId(-2L);
assertTrue(applications.isEmpty());
}
}

This file was deleted.

0 comments on commit c4e3f6d

Please sign in to comment.