Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwdchang committed Aug 16, 2024
1 parent b460e2c commit 50bfcff
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,17 @@
import software.uncharted.terarium.hmiserver.utils.rebac.Schema;

@Service
public class WorkflowService extends TerariumAssetServiceWithSearch<Workflow, WorkflowRepository> {
public class WorkflowService extends TerariumAssetServiceWithoutSearch<Workflow, WorkflowRepository> {

public WorkflowService(
final ObjectMapper objectMapper,
final Config config,
final ElasticsearchConfiguration elasticConfig,
final ElasticsearchService elasticService,
final ProjectService projectService,
final ProjectAssetService projectAssetService,
final S3ClientService s3ClientService,
final WorkflowRepository repository
) {
super(
objectMapper,
config,
elasticConfig,
elasticService,
projectService,
projectAssetService,
s3ClientService,
repository,
Workflow.class
);
}

@Override
@Observed(name = "function_profile")
protected String getAssetIndex() {
return elasticConfig.getWorkflowIndex();
}

@Override
@Observed(name = "function_profile")
public String getAssetAlias() {
return elasticConfig.getWorkflowAlias();
super(objectMapper, config, projectService, projectAssetService, repository, s3ClientService, Workflow.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ public class WorkflowControllerTests extends TerariumApplicationTests {

@BeforeEach
public void setup() throws IOException {
workflowService.setupIndexAndAliasAndEnsureEmpty();

project = projectService.createProject(
(Project) new Project().setPublicAsset(true).setName("test-project-name").setDescription("my description")
);
}

@AfterEach
public void teardown() throws IOException {
workflowService.teardownIndexAndAlias();
}
public void teardown() throws IOException {}

@Test
@WithUserDetails(MockUser.URSULA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class TerariumAssetCloneServiceTests extends TerariumApplicationTests {
@BeforeEach
public void setup() throws IOException {
documentService.setupIndexAndAliasAndEnsureEmpty();
workflowService.setupIndexAndAliasAndEnsureEmpty();
project = projectService.createProject(
(Project) new Project().setPublicAsset(true).setName("test-project-name").setDescription("my description")
);
Expand All @@ -64,7 +63,6 @@ public void setup() throws IOException {
@AfterEach
public void teardown() throws IOException {
documentService.setupIndexAndAliasAndEnsureEmpty();
workflowService.setupIndexAndAliasAndEnsureEmpty();
}

static Grounding createGrounding(final String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,13 @@ public class WorkflowServiceTests extends TerariumApplicationTests {

@BeforeEach
public void setup() throws IOException {
workflowService.setupIndexAndAliasAndEnsureEmpty();
project = projectService.createProject(
(Project) new Project().setPublicAsset(true).setName("test-project-name").setDescription("my description")
);
}

@AfterEach
public void teardown() throws IOException {
workflowService.teardownIndexAndAlias();
}
public void teardown() throws IOException {}

static Workflow createWorkflow() throws Exception {
final WorkflowNode a = new WorkflowNode().setId(UUID.randomUUID());
Expand Down Expand Up @@ -270,75 +267,4 @@ public void testWorkflowsAreOpaque() throws Exception {
Assertions.assertTrue(n.has("somethingElse"));
});
}

@Test
@WithUserDetails(MockUser.URSULA)
public void testItCanSearchAssets() throws Exception {
final int NUM = 32;

List<Workflow> workflows = new ArrayList<>();
for (int i = 0; i < NUM; i++) {
workflows.add(createWorkflow(String.valueOf(i)));
}
workflows = workflowService.createAssets(workflows, project.getId(), Schema.Permission.WRITE);

final List<Workflow> results = workflowService.searchAssets(0, NUM, null);

Assertions.assertEquals(NUM, results.size());

for (int i = 0; i < results.size(); i++) {
Assertions.assertEquals(workflows.get(i).getName(), results.get(i).getName());
Assertions.assertEquals(workflows.get(i).getDescription(), results.get(i).getDescription());
Assertions.assertEquals(workflows.get(i).getTransform(), results.get(i).getTransform());
Assertions.assertEquals(
workflows.get(i).getCreatedOn().toInstant().getEpochSecond(),
results.get(i).getCreatedOn().toInstant().getEpochSecond()
);
Assertions.assertEquals(
workflows.get(i).getUpdatedOn().toInstant().getEpochSecond(),
results.get(i).getUpdatedOn().toInstant().getEpochSecond()
);
Assertions.assertEquals(workflows.get(i).getDeletedOn(), results.get(i).getDeletedOn());
Assertions.assertEquals(workflows.get(i).getNodes().size(), results.get(i).getNodes().size());
for (int j = 0; j < results.get(i).getNodes().size(); j++) {
Assertions.assertEquals(workflows.get(i).getNodes().get(j).getId(), results.get(i).getNodes().get(j).getId());
Assertions.assertEquals(
workflows.get(i).getNodes().get(j).getWorkflowId(),
results.get(i).getNodes().get(j).getWorkflowId()
);
}
Assertions.assertEquals(workflows.get(i).getEdges().size(), results.get(i).getEdges().size());
for (int j = 0; j < results.get(i).getEdges().size(); j++) {
Assertions.assertEquals(workflows.get(i).getEdges().get(j).getId(), results.get(i).getEdges().get(j).getId());
Assertions.assertEquals(
workflows.get(i).getEdges().get(j).getWorkflowId(),
results.get(i).getEdges().get(j).getWorkflowId()
);
}
}
}

@Test
@WithUserDetails(MockUser.URSULA)
public void testItCanSyncToNewIndex() throws Exception {
final int NUM = 32;

final List<Workflow> workflows = new ArrayList<>();
for (int i = 0; i < NUM; i++) {
workflows.add(createWorkflow(String.valueOf(i)));
}
workflowService.createAssets(workflows, project.getId(), Schema.Permission.WRITE);

final String currentIndex = workflowService.getCurrentAssetIndex();

Assertions.assertEquals(NUM, workflowService.searchAssets(0, NUM, null).size());

workflowService.syncAllAssetsToNewIndex(true);

final String newIndex = workflowService.getCurrentAssetIndex();

Assertions.assertEquals(NUM, workflowService.searchAssets(0, NUM, null).size());

Assertions.assertNotEquals(currentIndex, newIndex);
}
}

0 comments on commit 50bfcff

Please sign in to comment.