Skip to content

Commit

Permalink
fix(test): fix test cases with cloudant SDK
Browse files Browse the repository at this point in the history
Also migrate some functions from DatabaseConnectorCloudant to
LuceneAwareCouchDbConnector which are specific to Lucene

Signed-off-by: Gaurav Mishra <mishra.gaurav@siemens.com>
  • Loading branch information
GMishx committed Sep 10, 2024
1 parent c97502c commit 322068c
Show file tree
Hide file tree
Showing 69 changed files with 776 additions and 697 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.ibm.cloud.cloudant.v1.model.DesignDocumentViewsMapReduce;
import com.ibm.cloud.cloudant.v1.model.PostViewOptions;
import com.ibm.cloud.cloudant.v1.model.ViewResult;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseRepositoryCloudantClient;
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage;
Expand Down Expand Up @@ -67,7 +68,7 @@ public List<AttachmentUsage> getUsageForAttachment(String ownerId, String attach
.getPostViewQueryBuilder(AttachmentUsage.class, "usagesByAttachment")
.includeDocs(true)
.reduce(false)
.keys(List.of(new String[] { ownerId, attachmentContentId }))
.keys(List.of(List.of(ownerId, attachmentContentId)))
.build();
return queryView(viewQuery);
}
Expand Down Expand Up @@ -97,7 +98,7 @@ public List<AttachmentUsage> getUsageForAttachment(String ownerId, String attach
.getPostViewQueryBuilder(AttachmentUsage.class, "usagesByAttachmentUsageType")
.includeDocs(true)
.reduce(false)
.keys(List.of(new String[] { ownerId, attachmentContentId, filter }))
.keys(List.of(List.of(ownerId, attachmentContentId, filter)))
.build();
return queryView(viewQuery);
}
Expand All @@ -107,7 +108,7 @@ public List<AttachmentUsage> getUsedAttachments(String usedById, String filter)
.getPostViewQueryBuilder(AttachmentUsage.class, "usedAttachmentsUsageType")
.includeDocs(true)
.reduce(false)
.keys(List.of(new String[] { usedById, filter }))
.keys(List.of(List.of(usedById, filter)))
.build();
return queryView(viewQuery);
}
Expand All @@ -125,9 +126,9 @@ public Map<Map<String, String>, Integer> getAttachmentUsageCount(Map<String, Set
return result.getRows().stream().collect(Collectors.toMap(key -> {
String json = key.getKey().toString();
String replace = json.replace("[", "").replace("]", "").replaceAll("\"", "");
List<String> relIdAttachmentToUsageType = new ArrayList<>(Arrays.asList(replace.split(",")));
List<String> relIdAttachmentToUsageType = Arrays.stream(StringUtils.stripAll(replace.split(","))).toList();
return ImmutableMap.of(relIdAttachmentToUsageType.get(0), relIdAttachmentToUsageType.get(1));
}, val -> ((Double) val.getValue()).intValue()));
}, val -> (Double.valueOf(val.getValue().toString())).intValue()));
}

public List<AttachmentUsage> getUsageForAttachments(Map<String, Set<String>> attachments, String filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ComponentSearchHandler {

private static final Logger log = LogManager.getLogger(ComponentSearchHandler.class);

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("components",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class ModerationSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("moderations",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

public class ObligationElementSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("obligationelements",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class ObligationSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("obligations",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

public class PackageSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("packages",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class ProjectSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("projects",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class ReleaseSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("releases",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class UserSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("users",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseRepositoryCloudantClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class VendorSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("vendors",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class SpdxDocumentSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("SPDXDocument",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class SpdxDocumentCreationInfoSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("documentCreationInformation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class SpdxPackageInfoSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("packageInformation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.eclipse.sw360.common.utils.BackendUtils;
import org.eclipse.sw360.datahandler.TestUtils;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.datahandler.common.DatabaseSettingsTest;
import org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler;
Expand Down Expand Up @@ -96,8 +97,8 @@ public class BulkDeleteUtilTest {

private Map<String, Vendor> vendors;
private ComponentDatabaseHandler handler;
private DatabaseConnector databaseConnector;
private DatabaseConnector changeLogsDatabaseConnector;
private DatabaseConnectorCloudant databaseConnector;
private DatabaseConnectorCloudant changeLogsDatabaseConnector;
private BulkDeleteUtil bulkDeleteUtil;

private int nextReleaseVersion = 0;
Expand Down Expand Up @@ -126,8 +127,8 @@ public void setUp() throws Exception {
TestUtils.createDatabase(DatabaseSettingsTest.getConfiguredClient(), changeLogsDbName);

// Prepare the database
databaseConnector = new DatabaseConnector(DatabaseSettingsTest.getConfiguredHttpClient(), dbName);
changeLogsDatabaseConnector = new DatabaseConnector(DatabaseSettingsTest.getConfiguredHttpClient(), changeLogsDbName);
databaseConnector = new DatabaseConnectorCloudant(DatabaseSettingsTest.getConfiguredClient(), dbName);
changeLogsDatabaseConnector = new DatabaseConnectorCloudant(DatabaseSettingsTest.getConfiguredClient(), changeLogsDbName);

// Prepare vendors
for (Vendor vendor : vendors.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.eclipse.sw360.common.utils.BackendUtils;
import org.eclipse.sw360.datahandler.TestUtils;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.common.SW360Constants;
import org.eclipse.sw360.datahandler.common.DatabaseSettingsTest;
import org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler;
Expand Down Expand Up @@ -140,7 +141,7 @@ public void setUp() throws Exception {
TestUtils.createDatabase(DatabaseSettingsTest.getConfiguredClient(), dbName);

// Prepare the database
DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettingsTest.getConfiguredHttpClient(), dbName);
DatabaseConnectorCloudant databaseConnector = new DatabaseConnectorCloudant(DatabaseSettingsTest.getConfiguredClient(), dbName);

for (Vendor vendor : vendors.values()) {
databaseConnector.add(vendor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.google.common.collect.ImmutableSet;
import org.eclipse.sw360.datahandler.TestUtils;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.common.DatabaseSettingsTest;
import org.eclipse.sw360.datahandler.db.ComponentSearchHandler;
import org.eclipse.sw360.datahandler.thrift.ThriftClients;
Expand Down Expand Up @@ -75,7 +76,7 @@ public void setUp() throws Exception {
TestUtils.createDatabase(DatabaseSettingsTest.getConfiguredClient(), dbName);

// Prepare the database
DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettingsTest.getConfiguredHttpClient(), dbName);
DatabaseConnectorCloudant databaseConnector = new DatabaseConnectorCloudant(DatabaseSettingsTest.getConfiguredClient(), dbName);

for (Component component : components) {
databaseConnector.add(component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void updateFossologyProcessInRelease(ExternalToolProcess fossologyProces
// because our workflow in between might have taken some time, we have to
// refetch the release to get the current version (as another thread might have
// written changes to the release which results in a new version so that we
// would get a org.ektorp.UpdateConflictException on trying to write)
// would get a conflict error on trying to write)
release = componentClient.getReleaseById(release.getId(), user);
Iterator<ExternalToolProcess> oldFossologyProcessIterator = SW360Utils
.getNotOutdatedExternalToolProcessesForTool(release, ExternalTool.FOSSOLOGY).iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class HealthHandlerTest {
@Test
public void testGetHealthFailsUponMissingDB() throws MalformedURLException {
TestUtils.deleteAllDatabases();
HealthHandler healthHandler = new HealthHandler(DatabaseSettingsTest.getConfiguredHttpClient());
HealthHandler healthHandler = new HealthHandler(DatabaseSettingsTest.getConfiguredClient());
final Health health = healthHandler.getHealthOfSpecificDbs(DATABASES_TO_CHECK);
assertEquals(Status.DOWN, health.status);
assertEquals(DATABASES_TO_CHECK.size(), health.getDetails().size());
Expand All @@ -45,7 +45,7 @@ public void testGetHealth() throws MalformedURLException {
TestUtils.createDatabase(DatabaseSettingsTest.getConfiguredClient(), database);
}

HealthHandler healthHandler = new HealthHandler(DatabaseSettingsTest.getConfiguredHttpClient());
HealthHandler healthHandler = new HealthHandler(DatabaseSettingsTest.getConfiguredClient());
final Health health = healthHandler.getHealthOfSpecificDbs(DATABASES_TO_CHECK);
assertEquals(Status.UP, health.status);
assertEquals(new HashMap<>(), health.getDetails());
Expand All @@ -60,7 +60,7 @@ public void testGetHealthWithPartialDBMissing() throws MalformedURLException {
final String couchDbDatabase = DatabaseSettingsTest.COUCH_DB_DATABASE;
TestUtils.createDatabase(DatabaseSettingsTest.getConfiguredClient(), couchDbDatabase);

HealthHandler healthHandler = new HealthHandler(DatabaseSettingsTest.getConfiguredHttpClient());
HealthHandler healthHandler = new HealthHandler(DatabaseSettingsTest.getConfiguredClient());
final Health health = healthHandler.getHealthOfSpecificDbs(DATABASES_TO_CHECK);
assertEquals(Status.ERROR, health.getStatus());
assertEquals(DATABASES_TO_CHECK.size() -1, health.getDetails().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
import org.eclipse.sw360.licenses.db.LicenseDatabaseHandler;
import org.eclipse.sw360.datahandler.db.ObligationElementSearchHandler;

import com.cloudant.client.api.CloudantClient;

import org.apache.thrift.TException;
import java.nio.ByteBuffer;

import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import java.io.IOException;

import static org.eclipse.sw360.datahandler.common.SW360Assert.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package org.eclipse.sw360.moderation.testutil;

import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.common.DatabaseSettingsTest;
import org.eclipse.sw360.datahandler.thrift.moderation.DocumentType;
import org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest;
Expand All @@ -25,7 +26,7 @@ public class DatabaseTestSetup {

public static void main(String[] args) throws MalformedURLException {

DatabaseConnector db = new DatabaseConnector(DatabaseSettingsTest.getConfiguredHttpClient(), DatabaseSettingsTest.COUCH_DB_DATABASE);
DatabaseConnectorCloudant db = new DatabaseConnectorCloudant(DatabaseSettingsTest.getConfiguredClient(), DatabaseSettingsTest.COUCH_DB_DATABASE);

Project project = new Project().setName("Test Project");
project.addToModerators("user1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.google.common.collect.ImmutableMap;
import org.eclipse.sw360.datahandler.TestUtils;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.common.DatabaseSettingsTest;
import org.eclipse.sw360.datahandler.common.SW360Utils;
import org.eclipse.sw360.datahandler.db.AttachmentDatabaseHandler;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void setUp() throws Exception {
TestUtils.createDatabase(DatabaseSettingsTest.getConfiguredClient(), dbName);

// Prepare the database
DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettingsTest.getConfiguredHttpClient(), dbName);
DatabaseConnectorCloudant databaseConnector = new DatabaseConnectorCloudant(DatabaseSettingsTest.getConfiguredClient(), dbName);
for (Project project : projects) {
databaseConnector.add(project);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
package org.eclipse.sw360.search;

import com.cloudant.client.api.CloudantClient;
import com.google.common.collect.ImmutableMap;

import com.ibm.cloud.cloudant.v1.Cloudant;
Expand All @@ -33,7 +32,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
public abstract class AbstractDatabaseSearchHandler {

private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "/lucene";
private static final String DDOC_NAME = DEFAULT_DESIGN_PREFIX + "lucene";

private static final NouveauIndexDesignDocument luceneSearchView
= new NouveauIndexDesignDocument("all", new NouveauIndexFunction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.eclipse.sw360.search.common.SearchConstants.NAME_MAX_LENGTH;

/**
* Helper class to help parse JSON documents from lucene-ektorp
* Helper class to help parse JSON documents from lucene
*
* @author cedric.bodet@tngtech.com
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package org.eclipse.sw360.vendors;

import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.common.DatabaseSettingsTest;
import org.eclipse.sw360.datahandler.thrift.vendors.Vendor;
import org.eclipse.sw360.datahandler.thrift.vendors.VendorService;
Expand All @@ -30,7 +31,7 @@ public class TestVendorClient {

@SuppressWarnings("unused")
public static void InitDatabase() throws MalformedURLException {
DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettingsTest.getConfiguredHttpClient(), DatabaseSettingsTest.COUCH_DB_DATABASE);
DatabaseConnectorCloudant databaseConnector = new DatabaseConnectorCloudant(DatabaseSettingsTest.getConfiguredClient(), DatabaseSettingsTest.COUCH_DB_DATABASE);

databaseConnector.add(new Vendor().setShortname("Microsoft").setFullname("Microsoft Corporation").setUrl("http://www.microsoft.com"));
databaseConnector.add(new Vendor().setShortname("Apache").setFullname("The Apache Software Foundation").setUrl("http://www.apache.org"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.eclipse.sw360.vendors;

import org.eclipse.sw360.datahandler.TestUtils;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.common.DatabaseSettingsTest;
import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary;
import org.eclipse.sw360.datahandler.thrift.vendors.Vendor;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void setUp() throws Exception {
TestUtils.createDatabase(DatabaseSettingsTest.getConfiguredClient(), dbName);

// Prepare the database
DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettingsTest.getConfiguredHttpClient(), dbName);
DatabaseConnectorCloudant databaseConnector = new DatabaseConnectorCloudant(DatabaseSettingsTest.getConfiguredClient(), dbName);
vendorList = new ArrayList<>();
vendorList.add(new Vendor().setShortname("Microsoft").setFullname("Microsoft Corporation").setUrl("http://www.microsoft.com"));
vendorList.add(new Vendor().setShortname("Apache").setFullname("The Apache Software Foundation").setUrl("http://www.apache.org"));
Expand All @@ -48,7 +49,7 @@ public void setUp() throws Exception {
databaseConnector.add(vendor);
}

vendorHandler = new VendorHandler(DatabaseSettingsTest.getConfiguredClient(), DatabaseSettingsTest.getConfiguredHttpClient(), dbName);
vendorHandler = new VendorHandler(DatabaseSettingsTest.getConfiguredClient(), dbName);
}

@After
Expand Down
Loading

0 comments on commit 322068c

Please sign in to comment.