1414
1515package org .eclipse .edc .policy .cel .function .context ;
1616
17- import org .assertj .core .api .Assertions ;
18- import org .eclipse .edc .iam .verifiablecredentials .spi .model .CredentialSubject ;
19- import org .eclipse .edc .iam .verifiablecredentials .spi .model .Issuer ;
20- import org .eclipse .edc .iam .verifiablecredentials .spi .model .VerifiableCredential ;
2117import org .eclipse .edc .participant .spi .ParticipantAgent ;
2218import org .eclipse .edc .participant .spi .ParticipantAgentPolicyContext ;
2319import org .junit .jupiter .api .Test ;
2420
25- import java .time .Instant ;
2621import java .util .List ;
2722import java .util .Map ;
2823
24+ import static org .assertj .core .api .Assertions .assertThat ;
2925import static org .eclipse .edc .junit .assertions .AbstractResultAssert .assertThat ;
26+ import static org .mockito .ArgumentMatchers .any ;
3027import static org .mockito .Mockito .mock ;
3128import static org .mockito .Mockito .when ;
3229
3330public class ParticipantAgentContextMapperTest {
3431
35- private final ParticipantAgentContextMapper <ParticipantAgentPolicyContext > mapper = new ParticipantAgentContextMapper <>();
32+ private final CelParticipantAgentClaimMapperRegistry claimMapperRegistry = mock ();
33+ private final ParticipantAgentContextMapper <ParticipantAgentPolicyContext > mapper = new ParticipantAgentContextMapper <>(claimMapperRegistry );
3634
3735 @ SuppressWarnings ("unchecked" )
3836 @ Test
@@ -45,66 +43,35 @@ void mapContext() {
4543
4644 assertThat (result ).isSucceeded ().satisfies (map -> {
4745 var agentMap = (Map <String , Object >) map .get ("agent" );
48- Assertions . assertThat (agentMap .get ("id" )).isEqualTo ("agent-id" );
49- Assertions . assertThat (agentMap .get ("attributes" )).isEqualTo (attributes );
50- Assertions . assertThat (agentMap .get ("claims" )).isEqualTo (Map .of ());
46+ assertThat (agentMap .get ("id" )).isEqualTo ("agent-id" );
47+ assertThat (agentMap .get ("attributes" )).isEqualTo (attributes );
48+ assertThat (agentMap .get ("claims" )).isEqualTo (Map .of ());
5149 });
5250
5351 }
5452
5553 @ SuppressWarnings ("unchecked" )
5654 @ Test
57- void mapContext_withCredentials () {
55+ void mapContext_claimsMapper () {
5856 var ctx = mock (ParticipantAgentPolicyContext .class );
57+ when (claimMapperRegistry .mapClaim (any ())).thenReturn (List .of (
58+ new CelClaim ("claim1" , "value1" ),
59+ new CelClaim ("claim2" , "value2" )
60+ ));
5961 var attributes = Map .of ("key1" , "value1" , "key2" , "value2" );
6062
61- var credentials = credentials ();
62- Map <String , Object > claims = Map .of (
63- "vc" , credentials
64- );
65- var participantAgent = new ParticipantAgent ("agent-id" , claims , attributes );
63+ var participantAgent = new ParticipantAgent ("agent-id" , Map .of (), attributes );
6664 when (ctx .participantAgent ()).thenReturn (participantAgent );
6765 var result = mapper .mapContext (ctx );
6866
6967 assertThat (result ).isSucceeded ().satisfies (map -> {
7068 var agentMap = (Map <String , Object >) map .get ("agent" );
71-
72- var expectedMap = Map .of ("vc" , List .of (
73- Map .of (
74- "@context" , List .of ("https://www.w3.org/2018/credentials/v1" , "https://www.w3.org/2018/credentials/examples/v1" ),
75- "id" , "http://example.edu/credentials/3732" ,
76- "type" , List .of ("VerifiableCredential" , "AlumniCredential" ),
77- "issuer" , "https://example.edu/issuers/14" ,
78- "issuanceDate" , credentials .get (0 ).getIssuanceDate ().toString (),
79- "credentialSubject" , List .of (Map .of (
80- "alumniOf" , "Example University" ,
81- "degree" , Map .of (
82- "type" , "BachelorDegree" ,
83- "name" , "Bachelor of Science and Arts"
84- )
85- ))
86- )
69+ assertThat (agentMap .get ("id" )).isEqualTo ("agent-id" );
70+ assertThat (agentMap .get ("attributes" )).isEqualTo (attributes );
71+ assertThat (agentMap .get ("claims" )).isEqualTo (Map .of (
72+ "claim1" , "value1" ,
73+ "claim2" , "value2"
8774 ));
88- Assertions .assertThat (agentMap .get ("claims" )).isEqualTo (expectedMap );
8975 });
9076 }
91-
92- @ SuppressWarnings ("unchecked" )
93- private List <VerifiableCredential > credentials () {
94- var vc = VerifiableCredential .Builder .newInstance ()
95- .contexts (List .of ("https://www.w3.org/2018/credentials/v1" , "https://www.w3.org/2018/credentials/examples/v1" ))
96- .id ("http://example.edu/credentials/3732" )
97- .types (List .of ("VerifiableCredential" , "AlumniCredential" ))
98- .issuer (new Issuer ("https://example.edu/issuers/14" , Map .of ()))
99- .issuanceDate (Instant .now ())
100- .credentialSubject (CredentialSubject .Builder .newInstance ()
101- .claim ("alumniOf" , "Example University" )
102- .claim ("degree" , Map .of (
103- "type" , "BachelorDegree" ,
104- "name" , "Bachelor of Science and Arts"
105- ))
106- .build ())
107- .build ();
108- return List .of (vc );
109- }
11077}
0 commit comments