PduV2Factory implements PduFactory { public AggregatorConfiguration readAggregatorConfigurationResponse(KSIRequestContext context, ServiceCredentials credentials, TLVElement input) throws KSIException { return this.aggregatorPduV2Factory.readAggregatorConfigurationResponse(context, credentials, input); } PduV2Factory();  PduV2Factory(AggregatorPduV2Factory aggregatorPduV2Factory, ExtenderPduV2Factory extenderPduV2Factory);  PduV2Factory(AggregatorPduV2Factory aggregatorPduV2Factory);  PduV2Factory(ExtenderPduV2Factory extenderPduV2Factory); AggregationRequest createAggregationRequest(KSIRequestContext context, ServiceCredentials credentials, DataHash imprint, Long level); AggregationResponse readAggregationResponse(KSIRequestContext context, ServiceCredentials credentials, TLVElement input); AggregationRequest createAggregatorConfigurationRequest(KSIRequestContext context, ServiceCredentials credentials); AggregatorConfiguration readAggregatorConfigurationResponse(KSIRequestContext context, ServiceCredentials credentials, TLVElement input); ExtensionRequest createExtensionRequest(KSIRequestContext context, ServiceCredentials credentials, Date aggregationTime, Date publicationTime); ExtensionResponse readExtensionResponse(KSIRequestContext context, ServiceCredentials credentials, TLVElement input); ExtensionRequest createExtensionConfigurationRequest(KSIRequestContext context, ServiceCredentials credentials); ExtenderConfiguration readExtenderConfigurationResponse(ServiceCredentials credentials, TLVElement input);  }
@Test public void testAggregationConfigurationResponseParsingWithMultiplePayloadsV2() throws Exception { AggregatorConfiguration cnf = pduFactory.readAggregatorConfigurationResponse(requestContext, CREDENTIALS, loadTlv("pdu/aggregation/aggregator-response-with-conf-ack-and-signature.tlv")); Assert.assertEquals(cnf.getAggregationAlgorithm(), HashAlgorithm.SHA2_384); Assert.assertTrue(cnf.getAggregationPeriod().equals(12288L)); Assert.assertTrue(cnf.getMaximumLevel().equals(19L)); Assert.assertTrue(cnf.getMaximumRequests().equals(17L)); Assert.assertTrue(cnf.getParents().size() == 3); for (String parent : cnf.getParents()){ Assert.assertTrue(parent.contains(".url")); } }
@Test public void testAggregationResponseParsingWithMultipleConfsV2() throws Exception { AggregatorConfiguration cnf = pduFactory.readAggregatorConfigurationResponse(requestContext, CREDENTIALS, loadTlv("pdu/aggregation/aggregator-response-multiple-confs.tlv")); Assert.assertNotNull(cnf); Assert.assertEquals(cnf.getAggregationAlgorithm(), HashAlgorithm.RIPEMD_160); Assert.assertTrue(cnf.getAggregationPeriod().equals(2L)); Assert.assertTrue(cnf.getMaximumLevel().equals(2L)); Assert.assertTrue(cnf.getMaximumRequests().equals(2L)); Assert.assertTrue(cnf.getParents().size() == 1); for (String parent : cnf.getParents()){ Assert.assertEquals(parent, "anon"); } }
@Test public void testAggregationResponseParsingWithEmptyConfV2() throws Exception { AggregatorConfiguration cnf = pduFactory.readAggregatorConfigurationResponse(requestContext, CREDENTIALS, loadTlv("pdu/aggregation/aggregator-response-with-empty-conf.tlv")); Assert.assertNotNull(cnf); Assert.assertNull(cnf.getAggregationAlgorithm()); Assert.assertNull(cnf.getAggregationPeriod()); Assert.assertNull(cnf.getMaximumLevel()); Assert.assertNull(cnf.getMaximumRequests()); Assert.assertTrue(cnf.getParents().isEmpty()); }
@Test public void testReadAggregatorConfigurationResponse() throws Exception { AggregatorConfiguration response = pduFactory.readAggregatorConfigurationResponse(requestContext, CREDENTIALS, loadTlv("pdu/aggregation/aggregation-conf-response-ok.tlv")); Assert.assertNotNull(response); Assert.assertNotNull(response.getAggregationAlgorithm()); Assert.assertNotNull(response.getAggregationPeriod()); Assert.assertNotNull(response.getMaximumLevel()); Assert.assertNotNull(response.getMaximumRequests()); Assert.assertNotNull(response.getParents()); Assert.assertEquals(response.getParents().size(), 3); }
@Test(expectedExceptions = KSIProtocolException.class, expectedExceptionsMessageRegExp = "Received unknown response to PDU v2 aggregation request.") public void testReadV1AggregatorConfigurationResponse() throws Exception { pduFactory.readAggregatorConfigurationResponse(requestContext, CREDENTIALS, loadTlv("aggregation-203-error.tlv")); }