Skip to content

Commit

Permalink
Fix broken unit test with API change
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Dec 5, 2024
1 parent 48513f8 commit 04801d2
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import org.opensearch.migrations.MigrationMode;
import org.opensearch.migrations.bulkload.common.OpenSearchClient;
import org.opensearch.migrations.bulkload.models.GlobalMetadata;
import org.opensearch.migrations.bulkload.version_os_2_11.GlobalMetadataCreator_OS_2_11.TemplateTypes;
import org.opensearch.migrations.metadata.CreationResult;
import org.opensearch.migrations.metadata.CreationResult.CreationFailureType;
import org.opensearch.migrations.metadata.tracing.IMetadataMigrationContexts.IClusterMetadataContext;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
Expand All @@ -22,7 +22,6 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
Expand All @@ -46,15 +45,18 @@ void testCreate() {
doReturn(filledOptional).when(client).createIndexTemplate(any(), any(), any());
doReturn(filledOptional).when(client).createLegacyTemplate(any(), any(), any());

var creator = spy(new GlobalMetadataCreator_OS_2_11(client, List.of("lit1"), List.of(), null));
doReturn(Map.of("lit1", obj, "lit2", obj, ".lits", obj)).when(creator).getAllTemplates(any(), eq(TemplateTypes.LEGACY_INDEX_TEMPLATE));
doReturn(Map.of("it1", obj, ".its", obj)).when(creator).getAllTemplates(any(), eq(TemplateTypes.INDEX_TEMPLATE));
doReturn(Map.of("ct1", obj, ".cts", obj)).when(creator).getAllTemplates(any(), eq(TemplateTypes.COMPONENT_TEMPLATE));

var globalMetadata = mock(GlobalMetadata.class);
doReturn(obj).when(globalMetadata).getComponentTemplates();
doReturn(obj).when(globalMetadata).getIndexTemplates();
doReturn(obj).when(globalMetadata).getTemplates();
var componentTemplates = mapper.createObjectNode().put("type", "component");
var indexTemplates = mapper.createObjectNode().put("type", "index");
var legacyTemplates = mapper.createObjectNode().put("type", "legacy");
doReturn(componentTemplates).when(globalMetadata).getComponentTemplates();
doReturn(indexTemplates).when(globalMetadata).getIndexTemplates();
doReturn(legacyTemplates).when(globalMetadata).getTemplates();

var creator = spy(new GlobalMetadataCreator_OS_2_11(client, List.of("lit1"), List.of(), null));
doReturn(Map.of("lit1", obj, "lit2", obj, ".lits", obj)).when(creator).getAllTemplates(legacyTemplates);
doReturn(Map.of("it1", obj, ".its", obj)).when(creator).getAllTemplates(indexTemplates);
doReturn(Map.of("ct1", obj, ".cts", obj)).when(creator).getAllTemplates(componentTemplates);

var results = creator.create(globalMetadata, MigrationMode.PERFORM, context);
assertThat(results.fatalIssueCount(), equalTo(0L));
Expand Down

0 comments on commit 04801d2

Please sign in to comment.