Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
1f7b0d8
refactor: remove business logic
jkoenig134 Sep 16, 2024
3b80b8b
refactor: make modular
jkoenig134 Sep 16, 2024
24641ff
refactor: reformat
jkoenig134 Sep 16, 2024
58dd6bb
test: add AccountTest using testcontainers
jkoenig134 Sep 16, 2024
424ff09
test: add more account routes
jkoenig134 Sep 16, 2024
6a3f25d
refactor: rename reorder
jkoenig134 Sep 16, 2024
36d7951
feat: implement challenges
jkoenig134 Sep 17, 2024
f37b5ba
chore: update tests
jkoenig134 Sep 17, 2024
ddffb4d
refactor: update error decoder
jkoenig134 Sep 17, 2024
48b5c9f
refactor: update models
jkoenig134 Sep 17, 2024
482adf4
refactor: add reuests
jkoenig134 Sep 17, 2024
cb44f02
chore: formatting
jkoenig134 Sep 17, 2024
3d03d2e
chore: formatting
jkoenig134 Sep 17, 2024
9b2dd6c
chore: formatting
jkoenig134 Sep 17, 2024
5371126
chore: formatting
jkoenig134 Sep 17, 2024
4202834
feat: implement IncomingRequestsEndpoint
jkoenig134 Sep 17, 2024
202f42d
feat: update MessagesEndpoint
jkoenig134 Sep 17, 2024
0d8d063
feat: implement OutgoingRequestsEndpoint
jkoenig134 Sep 17, 2024
eaf762c
feat: implement RelationshipsEndpoint
jkoenig134 Sep 17, 2024
f88c75c
feat: implement RelationshipTemplatesEndpoint
jkoenig134 Sep 17, 2024
b5de67e
fix: compiler issues
jkoenig134 Sep 17, 2024
a079b0c
fix: add ArbitraryMessageContent
jkoenig134 Sep 17, 2024
0ee7ca7
feat: implement TokensEndpoint
jkoenig134 Sep 17, 2024
d0b7c9f
chore: remove import statement
jkoenig134 Sep 17, 2024
6d1a1c5
test: add tokens test
jkoenig134 Sep 17, 2024
8697fc9
fix: make test working
jkoenig134 Sep 17, 2024
9d666b3
ci: add test pipeline
jkoenig134 Sep 17, 2024
0c4028f
ci: simplify pipeline
jkoenig134 Sep 17, 2024
166951b
ci: actually run tests
jkoenig134 Sep 17, 2024
41855f4
ci: actually run tests
jkoenig134 Sep 17, 2024
f256606
ci: actually run tests
jkoenig134 Sep 17, 2024
cb5911e
ci: actually run tests
jkoenig134 Sep 17, 2024
fab5c10
ci: actually run tests
jkoenig134 Sep 17, 2024
a27c7b6
ci: actually run tests
jkoenig134 Sep 17, 2024
125013b
ci: upload backbone logs on fail
jkoenig134 Sep 17, 2024
e17f5df
fix: add getters
jkoenig134 Sep 17, 2024
8835b4c
Merge branch 'main' into refactor/remove-business-logic-and-make-modular
jkoenig134 Oct 11, 2024
c2e7c43
chore: add testcontainers
jkoenig134 Oct 11, 2024
147c387
chore: remove fromWrapper methods
jkoenig134 Oct 11, 2024
3abea72
fix: use Builder.Default
jkoenig134 Oct 11, 2024
07ef2c0
ci: only sign if CI env is set
jkoenig134 Oct 11, 2024
07a1fc3
fix: migrate gradle
jkoenig134 Oct 11, 2024
b43426f
chore: remove isX
jkoenig134 Oct 14, 2024
59bc4b4
fix: update field name as the annotation did not function
NikolaVetnic Oct 21, 2024
b1fec4c
feat: update header
NikolaVetnic Oct 21, 2024
cff14af
feat: add relationship template tests
NikolaVetnic Oct 21, 2024
a5c8268
feat: add relationship and relationship template methods
NikolaVetnic Oct 21, 2024
915f5ee
chore: update reference
NikolaVetnic Oct 21, 2024
fa9e2bd
refactor: use TestUtils method
NikolaVetnic Oct 21, 2024
bdb37ef
feat: add relationship tests without decomposition
NikolaVetnic Oct 21, 2024
eb964e5
Merge branch 'main' into test/add-remining-tests
jkoenig134 May 15, 2025
0a1d590
chore: optimize imports
jkoenig134 May 15, 2025
d6a478d
Merge branch 'main' into test/add-remining-tests
jkoenig134 May 15, 2025
79f1131
chore: undo
jkoenig134 May 15, 2025
6475fd4
chore: add import
jkoenig134 May 15, 2025
1a1ba58
fix: correct exception place
jkoenig134 May 15, 2025
692ad66
chore: change isOwn
jkoenig134 May 15, 2025
1e2faf2
Merge branch 'main' into test/add-remining-tests
jkoenig134 May 15, 2025
97a2101
chore: remove unused file
jkoenig134 May 15, 2025
07a1902
chore: exclude challenges test
jkoenig134 May 16, 2025
c8c9cd9
chore: .class
jkoenig134 May 16, 2025
569f8b5
chore: remove exclude again
jkoenig134 May 16, 2025
858e77d
Merge branch 'main' into test/add-remining-tests
jkoenig134 May 16, 2025
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
2 changes: 1 addition & 1 deletion src/test/java/eu/enmeshed/ChallengesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void setUp() {
client1 = ConnectorClient.create(connector1.getConnectionString(), connector1.getApiKey());
client2 = ConnectorClient.create(connector2.getConnectionString(), connector2.getApiKey());

relationship = TestUtils.establishRelationship(client1, client2);
relationship = TestUtils.Relationships.establishRelationship(client1, client2);
}

@Test
Expand Down
154 changes: 154 additions & 0 deletions src/test/java/eu/enmeshed/RelationshipTemplateTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package eu.enmeshed;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

import eu.enmeshed.model.relationshipTemplates.ArbitraryRelationshipTemplateContent;
import eu.enmeshed.model.relationshipTemplates.RelationshipTemplate;
import eu.enmeshed.model.relationshipTemplates.RelationshipTemplateContentDerivation;
import eu.enmeshed.requests.relationshipTemplates.CreateOwnRelationshipTemplateRequest;
import eu.enmeshed.requests.relationshipTemplates.GetOwnRelationshipTemplatesQuery;
import eu.enmeshed.requests.relationshipTemplates.GetRelationshipTemplatesQuery;
import eu.enmeshed.utils.ConnectorContainer;
import eu.enmeshed.utils.TestUtils;
import java.time.ZonedDateTime;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

@Testcontainers
public class RelationshipTemplateTest {

@Container
public static ConnectorContainer connector1 = new ConnectorContainer();
@Container
public static ConnectorContainer connector2 = new ConnectorContainer();

private static ConnectorClient client1;
private static ConnectorClient client2;

@BeforeAll
public static void setUp() {
client1 = ConnectorClient.create(connector1.getConnectionString(), connector1.getApiKey());
client2 = ConnectorClient.create(connector2.getConnectionString(), connector2.getApiKey());
}

@Test
public void createTemplate() {

var template = client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequest(1)).getResult();

assertThat(template.getId(), CoreMatchers.startsWith("RLT"));
assertThat(template.getCreatedBy(), CoreMatchers.equalTo(client1.account.getIdentityInfo().getResult().getAddress()));
}

@Test
public void createTemplateWithUndefinedMaxNumberOfAllocations() {

var template = client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequestWithUndefinedMaxNumberOfAllocations()).getResult();

assertThat(template.getId(), CoreMatchers.startsWith("RLT"));
assertThat(template.getMaxNumberOfAllocations(), CoreMatchers.nullValue());
}

@Test
public void readTemplateWithUndefinedMaxNumberOfAllocations() {

var createdTemplate = client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequestWithUndefinedMaxNumberOfAllocations()).getResult();
var createdTemplateId = createdTemplate.getId();

var response = client1.relationshipTemplates.getRelationshipTemplate(createdTemplateId).getResult();

assertThat(response.getId(), CoreMatchers.startsWith("RLT"));
assertThat(response.getMaxNumberOfAllocations(), CoreMatchers.nullValue());
}

@Test
public void seeIfTemplateExistsInOwnTemplates() {

var createdTemplate = client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequest(1)).getResult();

var ownTemplates = client1.relationshipTemplates.getOwnRelationshipTemplates(GetOwnRelationshipTemplatesQuery.builder().maxNumberOfAllocations(1).build()).getResult();
var ownTemplateIds = ownTemplates.stream().map(t -> createdTemplate.getId()).toList();

assertThat(ownTemplateIds, CoreMatchers.hasItem(createdTemplate.getId()));
}

@Test
public void seeIfTemplateExistsWhenFetchingWithId() {

var createdTemplate = client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequest(1)).getResult();

var fetchedTemplate = client1.relationshipTemplates.getRelationshipTemplate(createdTemplate.getId()).getResult();

assertThat(fetchedTemplate.getId(), CoreMatchers.startsWith("RLT"));
assertThat(fetchedTemplate.getCreatedBy(), CoreMatchers.equalTo(client1.account.getIdentityInfo().getResult().getAddress()));
}

@Test
public void expectValidationErrorForSendingMaxNumberOfAllocationsIsZero() {

var exception = assertThrows(
Exception.class,
() -> client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequest(0)).getResult());

assertThat(exception.getMessage(), CoreMatchers.equalTo("maxNumberOfAllocations must be >= 1"));
}

@Test
public void queryTemplates() {
var template1 = client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequest(1)).getResult();
var template2 = client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequest(1)).getResult();
var template3 = client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequest(1)).getResult();

var templates = client1.relationshipTemplates.getRelationshipTemplates(GetRelationshipTemplatesQuery.builder()
.maxNumberOfAllocations(1)
.isOwn(true)
.build()).getResult();

assertThat(templates.stream().map(RelationshipTemplate::getId).toList(), CoreMatchers.hasItems(template1.getId(), template2.getId(), template3.getId()));
}

@Test
public void queryOwnTemplates() {
var template1 = client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequest(1)).getResult();
var template2 = client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequest(1)).getResult();
var template3 = client1.relationshipTemplates.createOwnRelationshipTemplate(getCreateOwnTemplateRequest(1)).getResult();

var templates = client1.relationshipTemplates.getOwnRelationshipTemplates(GetOwnRelationshipTemplatesQuery.builder()
.maxNumberOfAllocations(1)
.build()).getResult();

assertThat(templates.stream().map(RelationshipTemplate::getId).toList(), CoreMatchers.hasItems(template1.getId(), template2.getId(), template3.getId()));
}

@Test
public void queryPeerTemplates() {
var templateId1 = TestUtils.RelationshipTemplates.exchangeTemplate(client1, client2).getId();
var templateId2 = TestUtils.RelationshipTemplates.exchangeTemplate(client1, client2).getId();
var templateId3 = TestUtils.RelationshipTemplates.exchangeTemplate(client1, client2).getId();

var templates = client2.relationshipTemplates.getRelationshipTemplates(GetRelationshipTemplatesQuery.builder()
.maxNumberOfAllocations(1)
.isOwn(false)
.build()).getResult();

assertThat(templates.stream().map(RelationshipTemplate::getId).toList(), CoreMatchers.hasItems(templateId1, templateId2, templateId3));
}

private CreateOwnRelationshipTemplateRequest<RelationshipTemplateContentDerivation> getCreateOwnTemplateRequest(int maxNumberOfAllocations) {
return
CreateOwnRelationshipTemplateRequest.builder()
.maxNumberOfAllocations(maxNumberOfAllocations)
.content(ArbitraryRelationshipTemplateContent.builder().value("value").build())
.expiresAt(ZonedDateTime.now().plusDays(1)).build();
}

private CreateOwnRelationshipTemplateRequest<RelationshipTemplateContentDerivation> getCreateOwnTemplateRequestWithUndefinedMaxNumberOfAllocations() {
return CreateOwnRelationshipTemplateRequest.builder()
.content(ArbitraryRelationshipTemplateContent.builder().value("value").build())
.expiresAt(ZonedDateTime.now().plusDays(1)).build();
}
}
99 changes: 99 additions & 0 deletions src/test/java/eu/enmeshed/RelationshipTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package eu.enmeshed;

import static org.hamcrest.MatcherAssert.assertThat;

import eu.enmeshed.model.relationships.RelationshipAuditLogEntry.Reason;
import eu.enmeshed.model.relationships.RelationshipStatus;
import eu.enmeshed.utils.ConnectorContainer;
import eu.enmeshed.utils.TestUtils;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Testcontainers;

@Testcontainers
public class RelationshipTest {

private ConnectorClient client1;
private ConnectorClient client2;

@BeforeEach
public void setUp() {
// recreate containers before each test case due to relationships created in different tests interfered with each other
ConnectorContainer connector1 = new ConnectorContainer();
ConnectorContainer connector2 = new ConnectorContainer();

connector1.start();
connector2.start();

client1 = ConnectorClient.create(connector1.getConnectionString(), connector1.getApiKey());
client2 = ConnectorClient.create(connector2.getConnectionString(), connector2.getApiKey());
}

@Test
public void shouldCreateRelationship() {

var relationshipId = TestUtils.Relationships.establishRelationship(client1, client2).getId();

expectRelationshipToHaveStatus(client1, relationshipId, RelationshipStatus.ACTIVE);
expectRelationshipToHaveStatus(client2, relationshipId, RelationshipStatus.ACTIVE);
}

@Test
public void rejectRelationship() {

var relationshipId = TestUtils.Relationships.rejectRelationship(client1, client2).getId();

expectRelationshipToHaveStatus(client1, relationshipId, RelationshipStatus.REJECTED);
expectRelationshipToHaveStatus(client2, relationshipId, RelationshipStatus.REJECTED);
}

@Test
public void revokeRelationship() {

var relationshipId = TestUtils.Relationships.revokeRelationship(client1, client2).getId();

expectRelationshipToHaveStatus(client1, relationshipId, RelationshipStatus.REVOKED);
expectRelationshipToHaveStatus(client2, relationshipId, RelationshipStatus.REVOKED);
}

@Test
public void terminateAndReactivateRelationship() {

var relationshipId = TestUtils.Relationships.establishAndTerminateRelationship(client1, client2).getId();

expectRelationshipToHaveStatus(client1, relationshipId, RelationshipStatus.TERMINATED);
expectRelationshipToHaveStatus(client2, relationshipId, RelationshipStatus.TERMINATED);

TestUtils.Relationships.reactivateRelationship(client1, client2, relationshipId);
expectRelationshipToHaveStatusAndReason(client1, relationshipId, RelationshipStatus.TERMINATED, Reason.REACTIVATION_REQUESTED);
expectRelationshipToHaveStatusAndReason(client2, relationshipId, RelationshipStatus.TERMINATED, Reason.REACTIVATION_REQUESTED);

TestUtils.Relationships.rejectReactivationOfRelationship(client2, client1, relationshipId);
expectRelationshipToHaveStatusAndReason(client1, relationshipId, RelationshipStatus.TERMINATED, Reason.REJECTION_OF_REACTIVATION);
expectRelationshipToHaveStatusAndReason(client2, relationshipId, RelationshipStatus.TERMINATED, Reason.REJECTION_OF_REACTIVATION);

TestUtils.Relationships.reactivateRelationship(client1, client2, relationshipId);
TestUtils.Relationships.revokeReactivationOfRelationship(client1, client2, relationshipId);
expectRelationshipToHaveStatusAndReason(client1, relationshipId, RelationshipStatus.TERMINATED, Reason.REVOCATION_OF_REACTIVATION);
expectRelationshipToHaveStatusAndReason(client2, relationshipId, RelationshipStatus.TERMINATED, Reason.REVOCATION_OF_REACTIVATION);

TestUtils.Relationships.reactivateRelationship(client1, client2, relationshipId);
TestUtils.Relationships.acceptReactivationOfRelationship(client2, client1, relationshipId);
expectRelationshipToHaveStatusAndReason(client1, relationshipId, RelationshipStatus.ACTIVE, Reason.ACCEPTANCE_OF_REACTIVATION);
expectRelationshipToHaveStatusAndReason(client2, relationshipId, RelationshipStatus.ACTIVE, Reason.ACCEPTANCE_OF_REACTIVATION);
}

private void expectRelationshipToHaveStatus(ConnectorClient client, String relationshipId, RelationshipStatus status)
{
var response = client.relationships.getRelationship(relationshipId).getResult();
assertThat(response.getStatus(), CoreMatchers.equalTo(status));
}

private void expectRelationshipToHaveStatusAndReason(ConnectorClient client, String relationshipId, RelationshipStatus status, Reason reason)
{
var response = client.relationships.getRelationship(relationshipId).getResult();
assertThat(response.getStatus(), CoreMatchers.equalTo(status));
assertThat(response.getAuditLog().get(response.getAuditLog().size() - 1).getReason(), CoreMatchers.equalTo(reason));
}
}
Loading