Skip to content

Commit

Permalink
test: add elastic dao test for operation requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pfeil committed Aug 20, 2023
1 parent e2f0de4 commit 620e459
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*/
package edu.kit.datamanager.pit.elasticsearch;

import java.util.Collection;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

/**
Expand All @@ -27,7 +30,13 @@
public interface PidRecordElasticRepository extends ElasticsearchRepository<PidRecordElasticWrapper, String> {

Page<PidRecordElasticWrapper> findByPid(String pid, Pageable pageable);
Page<PidRecordElasticWrapper> findBySupportedLocation(String location);
Page<PidRecordElasticWrapper> findBySupportedType(String type);

@Query("{\"match\": {\"supportedLocations\": \"?0\"}}")
Collection<PidRecordElasticWrapper> findBySupportedLocationsContain(
String location
);

@Query("{\"match\": {\"supportedTypes\": \"?0\"}}")
Collection<PidRecordElasticWrapper> findBySupportedTypesContain(String type);

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public class PidRecordElasticWrapper {
@Field(type = FieldType.Text)
private List<String> read = new ArrayList<>();

protected PidRecordElasticWrapper() {
// for PidRecordElasticRepository
}

public PidRecordElasticWrapper(PIDRecord pidRecord, Operations recordOperations) {
pid = pidRecord.getPid();
PidDatabaseObject simple = new PidDatabaseObject(pidRecord);
Expand All @@ -80,4 +84,71 @@ public PidRecordElasticWrapper(PIDRecord pidRecord, Operations recordOperations)
e.printStackTrace();
}
}

/**
* Generated with Lombok
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((pid == null) ? 0 : pid.hashCode());
result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
result = prime * result + ((created == null) ? 0 : created.hashCode());
result = prime * result + ((lastUpdate == null) ? 0 : lastUpdate.hashCode());
result = prime * result + ((supportedTypes == null) ? 0 : supportedTypes.hashCode());
result = prime * result + ((supportedLocations == null) ? 0 : supportedLocations.hashCode());
result = prime * result + ((read == null) ? 0 : read.hashCode());
return result;
}

/**
* Generated with Lombok
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PidRecordElasticWrapper other = (PidRecordElasticWrapper) obj;
if (pid == null) {
if (other.pid != null)
return false;
} else if (!pid.equals(other.pid))
return false;
if (attributes == null) {
if (other.attributes != null)
return false;
} else if (!attributes.equals(other.attributes))
return false;
if (created == null) {
if (other.created != null)
return false;
} else if (!created.equals(other.created))
return false;
if (lastUpdate == null) {
if (other.lastUpdate != null)
return false;
} else if (!lastUpdate.equals(other.lastUpdate))
return false;
if (supportedTypes == null) {
if (other.supportedTypes != null)
return false;
} else if (!supportedTypes.equals(other.supportedTypes))
return false;
if (supportedLocations == null) {
if (other.supportedLocations != null)
return false;
} else if (!supportedLocations.equals(other.supportedLocations))
return false;
if (read == null) {
if (other.read != null)
return false;
} else if (!read.equals(other.read))
return false;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Collection;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -81,4 +83,23 @@ void testStorageWithDateNull() throws JacksonException {
dao.save(w);
assertEquals(1, dao.count());
}

@Test
@Transactional
void testRetrieveBySupportedType() throws JacksonException {
PIDRecord r = new PIDRecord();
r.setPid("not-a-pid");
String supportedType = "some/supported-type";
r.addEntry("21.T11148/2694e4a7a5a00d44e62b", "", supportedType);
r.addEntry("21.T11148/2694e4a7a5a00d44e62b", "", "second/supported-type");
PidRecordElasticWrapper w = new PidRecordElasticWrapper(r, typingService.getOperations());
assertEquals(0, dao.count());
dao.save(w);
assertEquals(1, dao.count());
Collection<PidRecordElasticWrapper> result = dao.findBySupportedLocationsContain("other/type");
assertEquals(0, result.size());
result = dao.findBySupportedTypesContain(supportedType);
assertEquals(1, result.size());
assertEquals(w, result.iterator().next());
}
}

0 comments on commit 620e459

Please sign in to comment.