@@ -154,4 +154,45 @@ void encryptionAndDecryptionWithValidKey() throws Exception {
154154 assertThat (dataStream .toByteArray ()).isEqualTo (data );
155155 }
156156 }
157+
158+ @ Test
159+ void collection () throws Exception {
160+ var kasInfos = new ArrayList <>();
161+ var kasInfo = new Config .KASInfo ();
162+ kasInfo .URL = "https://api.example.com/kas" ;
163+ kasInfo .PublicKey = null ;
164+ kasInfo .KID = KID ;
165+ kasInfos .add (kasInfo );
166+
167+ Config .NanoTDFConfig config = Config .newNanoTDFConfig (
168+ Config .withNanoKasInformation (kasInfos .toArray (new Config .KASInfo [0 ])),
169+ Config .witDataAttributes ("https://example.com/attr/Classification/value/S" ,
170+ "https://example.com/attr/Classification/value/X" ),
171+ Config .withCollection ()
172+ );
173+
174+ ByteBuffer byteBuffer = ByteBuffer .wrap (new byte []{});
175+
176+ NanoTDF nanoTDF = new NanoTDF ();
177+ ByteBuffer header = getHeaderBuffer (byteBuffer ,nanoTDF , config );
178+ for (int i = 0 ; i < Config .MAX_COLLECTION_ITERATION - 10 ; i ++) {
179+ config .collectionConfig .getHeaderInfo ();
180+
181+ }
182+ for (int i = 1 ; i < 10 ; i ++) {
183+ ByteBuffer newHeader = getHeaderBuffer (byteBuffer ,nanoTDF , config );
184+ assertThat (header ).isEqualTo (newHeader );
185+ }
186+
187+ ByteBuffer newHeader = getHeaderBuffer (byteBuffer ,nanoTDF , config );
188+ assertThat (header ).isNotEqualTo (newHeader );
189+ }
190+
191+ private ByteBuffer getHeaderBuffer (ByteBuffer input , NanoTDF nanoTDF , Config .NanoTDFConfig config ) throws Exception {
192+ ByteArrayOutputStream tdfOutputStream = new ByteArrayOutputStream ();
193+ nanoTDF .createNanoTDF (input , tdfOutputStream , config , kas );
194+ ByteBuffer tdf = ByteBuffer .wrap (tdfOutputStream .toByteArray ());
195+ Header header = new Header (tdf );
196+ return tdf .slice (0 , header .getTotalSize ());
197+ }
157198}
0 commit comments