-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AJ-1591: no-db solution for instance-to-workspace association (#492)
- Loading branch information
Showing
8 changed files
with
152 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
service/src/main/java/org/databiosphere/workspacedataservice/shared/model/WorkspaceId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.databiosphere.workspacedataservice.shared.model; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Model to represent a workspace id, which currently is a UUID. Since we use UUIDs throughout our | ||
* code for multiple use cases, this wrapper class exists to help disambiguate between those UUIDs. | ||
* | ||
* @param id the workspace's id | ||
*/ | ||
public record WorkspaceId(UUID id) { | ||
|
||
// disallow nulls | ||
public WorkspaceId { | ||
if (id == null) { | ||
throw new IllegalArgumentException("Id cannot be null"); | ||
} | ||
} | ||
|
||
/** | ||
* Create a new WorkspaceId using the given id | ||
* | ||
* @param id the workspace's id | ||
* @return new WorkspaceId | ||
*/ | ||
public static WorkspaceId of(UUID id) { | ||
return new WorkspaceId(id); | ||
} | ||
|
||
/** | ||
* Create a new WorkspaceId using the given id | ||
* | ||
* @par public static WorkspaceId fromString(String id) { return | ||
* WorkspaceId.of(UUID.fromString(id)); }am id the workspace's id | ||
* @return new WorkspaceId | ||
*/ | ||
@Override | ||
public String toString() { | ||
return this.id().toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...t/java/org/databiosphere/workspacedataservice/service/InstanceServiceNoWorkspaceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.databiosphere.workspacedataservice.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.UUID; | ||
import org.databiosphere.workspacedataservice.shared.model.InstanceId; | ||
import org.databiosphere.workspacedataservice.shared.model.WorkspaceId; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
@DirtiesContext | ||
@SpringBootTest | ||
@TestPropertySource(properties = {"twds.instance.workspace-id="}) | ||
class InstanceServiceNoWorkspaceTest { | ||
|
||
@Autowired private InstanceService instanceService; | ||
|
||
@Value("${twds.instance.workspace-id:}") | ||
private String workspaceIdProperty; | ||
|
||
@Test | ||
void assumptions() { | ||
// ensure the test is set up correctly, with an empty twds.instance.workspace-id property | ||
assertThat(workspaceIdProperty).isEmpty(); | ||
} | ||
|
||
// when twds.instance.workspace-id is empty, instanceService.getWorkspaceId will echo the | ||
// instanceid back as the workspace id | ||
@Test | ||
void getWorkspaceId() { | ||
InstanceId instanceId = InstanceId.of(UUID.randomUUID()); | ||
assertEquals(WorkspaceId.of(instanceId.id()), instanceService.getWorkspaceId(instanceId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters