Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing enum, refactor test to follow correct naming #155

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
public enum GeoNetworkField {
creation,
revision,
;
publication,
}
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ public BulkResponse executeBulk(BulkRequest.Builder bulkRequest, Callback callba
}
}

protected BulkResponse reduceResponse(BulkResponse in) {
protected static BulkResponse reduceResponse(BulkResponse in) {
List<BulkResponseItem> errors = in.items()
.stream()
.filter(p -> p.status() != HttpStatus.CREATED.value() || p.status() != HttpStatus.OK.value())
.filter(p -> !(p.status() == HttpStatus.CREATED.value() || p.status() == HttpStatus.OK.value()))
.toList();

return errors.isEmpty() ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@ActiveProfiles("test")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class GeoNetworkServiceTests extends BaseTestClass {
public class GeoNetworkServiceIT extends BaseTestClass {
// Must use the impl to access protected method for testing
@Autowired
protected GeoNetworkServiceImpl geoNetworkService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import au.org.aodn.esindexer.BaseTestClass;
import au.org.aodn.esindexer.configuration.GeoNetworkSearchTestConfig;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.core.BulkResponse;
import co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -15,6 +17,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.ActiveProfiles;

import java.io.IOException;
Expand All @@ -26,7 +29,7 @@
@ActiveProfiles("test")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class IndexerServiceTests extends BaseTestClass {
public class IndexerServiceIT extends BaseTestClass {

@Autowired
protected GeoNetworkServiceImpl geoNetworkService;
Expand Down Expand Up @@ -250,7 +253,7 @@ public void verifyThumbnailLinkNullAdbbdedOnIndex() throws IOException {
String test = String.valueOf(Objects.requireNonNull(objectNodeHit.source()));
String expected = indexerObjectMapper.readTree(expectedData).toPrettyString();
String actual = indexerObjectMapper.readTree(test).toPrettyString();
logger.info("{}", actual);

JSONAssert.assertEquals(expected, actual, JSONCompareMode.STRICT);
} catch (JSONException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package au.org.aodn.esindexer.service;

import co.elastic.clients.elasticsearch._types.ErrorCause;
import co.elastic.clients.elasticsearch.core.BulkResponse;
import co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem;
import co.elastic.clients.elasticsearch.core.bulk.OperationType;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;

/**
* Unit test that do not require other dependent software running goes here
*/
@Slf4j
public class IndexerServiceTest {
/**
* Verify this function, it should only return error if items contains status no CREATED or OK
*/
@Test
public void verifyReduceResponse() {
BulkResponse bulkResponse = BulkResponse.of(b ->
b.items(
BulkResponseItem.of(i -> i
.status(HttpStatus.CREATED.value())
.operationType(OperationType.Create)
.index("A")
),
BulkResponseItem.of(i -> i
.status(HttpStatus.OK.value())
.operationType(OperationType.Update)
.index("A")
))
.errors(false).took(1)
);

bulkResponse = IndexerServiceImpl.reduceResponse(bulkResponse);
Assertions.assertFalse(bulkResponse.errors(), "Should not contain error");

bulkResponse = BulkResponse.of(b ->
b.items(
BulkResponseItem.of(i -> i
.status(HttpStatus.CREATED.value())
.operationType(OperationType.Create)
.index("B")
),
BulkResponseItem.of(i -> i
.status(HttpStatus.NOT_EXTENDED.value())
.operationType(OperationType.Index)
.index("B")
))
.errors(false).took(1)
);

bulkResponse = IndexerServiceImpl.reduceResponse(bulkResponse);
Assertions.assertTrue(bulkResponse.errors(), "Should contain error");
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package au.org.aodn.esindexer.service;

import au.org.aodn.esindexer.BaseTestClass;
import au.org.aodn.esindexer.utils.SummariesUtils;
import au.org.aodn.stac.model.*;
import org.junit.jupiter.api.*;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -16,15 +13,14 @@
import static org.mockito.Mockito.*;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class RankingServiceTests extends BaseTestClass {
class RankingServiceIT extends BaseTestClass {

@Value("${elasticsearch.index.name}")
protected String INDEX_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
import co.elastic.clients.elasticsearch.core.search.TotalHits;
import co.elastic.clients.json.JsonData;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import jakarta.xml.bind.JAXBException;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand All @@ -47,7 +45,7 @@
*/
@Slf4j
@SpringBootTest(classes = {StacCollectionMapperServiceImpl.class})
public class StacCollectionMapperServiceTests {
public class StacCollectionMapperServiceTest {

protected ObjectMapper objectMapper = new ObjectMapper();
protected JaxbUtils<MDMetadataType> jaxbUtils = new JaxbUtils<>(MDMetadataType.class);
Expand Down Expand Up @@ -88,7 +86,7 @@ protected void verify(String expected) throws JsonProcessingException, JSONExcep
);
}

public StacCollectionMapperServiceTests() throws JAXBException {
public StacCollectionMapperServiceTest() throws JAXBException {
GeometryUtils.setExecutorService(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
GeometryUtils.init();
}
Expand Down Expand Up @@ -397,6 +395,19 @@ public void verifyNonNodedIntersectionsWorks() throws IOException, JSONException
String expected = readResourceFile("classpath:canned/sample_non_noded_intersections_stac.json");
indexerService.indexMetadata(xml);

verify(expected);
}
/**
* There is a missing enum publication, this case is check if we works after fix
* @throws IOException - Not expect to throw
* @throws JSONException - Not expect to throw
*/
@Test
public void verifyNoMissingGeonetworkFieldEnum() throws IOException, JSONException {
String xml = readResourceFile("classpath:canned/sample_geoenum_publication.xml");
String expected = readResourceFile("classpath:canned/sample_geoenum_publication_stac.json");
indexerService.indexMetadata(xml);

verify(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@ActiveProfiles("test")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VocabServiceTest extends BaseTestClass {
public class VocabServiceIT extends BaseTestClass {

@Autowired
VocabService vocabService;
Expand Down
Loading
Loading