EDXLDistributionPayloadSizeExtractor { public List<String> getPayloadSizes(EDXLDistribution alertMessage) { List<String> payloadSize = new ArrayList<>(); if (alertMessage != null) { List<ContentObjectType> contents = alertMessage.getContentObject(); for (ContentObjectType message : contents) { payloadSize.add(getPayloadSize(message)); } } return payloadSize; }  List<String> getPayloadSizes(EDXLDistribution alertMessage);  }
@Test public void testPayloadSizeOnSingleNonXMLPayload() { EDXLDistribution alert = new EDXLDistribution(); setNonXmlPayloadWithSize(alert, BigInteger.TEN); EDXLDistributionPayloadSizeExtractor extractor = new EDXLDistributionPayloadSizeExtractor(); assertEquals(BigInteger.TEN.toString(), extractor.getPayloadSizes(alert).get(0)); }
@Test public void testPayloadSizeOnSingleNonXMLEmptyPayload() { EDXLDistribution alert = new EDXLDistribution(); ContentObjectType payload = new ContentObjectType(); NonXMLContentType payloadContent = createMockNonXmlPayload(); payload.setNonXMLContent(payloadContent); alert.getContentObject().add(payload); EDXLDistributionPayloadSizeExtractor extractor = new EDXLDistributionPayloadSizeExtractor(); assertTrue(extractor.getPayloadSizes(alert).size() == 1); assertEquals("0", extractor.getPayloadSizes(alert).get(0)); }
@Test public void testPayloadSizeMultipleNonXMLPayload() { EDXLDistribution alert = new EDXLDistribution(); setNonXmlPayloadWithSize(alert, BigInteger.TEN); alert.getContentObject().add(setNonXmlPayloadObject(BigInteger.TEN)); BigInteger testSize = BigInteger.TEN; EDXLDistributionPayloadSizeExtractor extractor = new EDXLDistributionPayloadSizeExtractor(); assertTrue(extractor.getPayloadSizes(alert).size() == 2); assertEquals(testSize.toString(), extractor.getPayloadSizes(alert).get(0)); assertEquals(testSize.toString(), extractor.getPayloadSizes(alert).get(1)); }
@Test public void testPayloadSizeXmlPayload() { EDXLDistributionPayloadSizeExtractor extractor = new EDXLDistributionPayloadSizeExtractor(); EDXLDistribution alert = new EDXLDistribution(); setXmlPayload(alert); List<String> payloadSizes = extractor.getPayloadSizes(alert); assertEquals(1, payloadSizes.size()); assertEquals("0", payloadSizes.get(0)); }
@Test public void testPayloadSizeMixedPayload() { EDXLDistribution alert = new EDXLDistribution(); setXmlPayload(alert); setNonXmlPayloadWithSize(alert, BigInteger.TEN); EDXLDistributionPayloadSizeExtractor extractor = new EDXLDistributionPayloadSizeExtractor(); List<String> payloadSizes = extractor.getPayloadSizes(alert); assertEquals(2, payloadSizes.size()); assertEquals("0", payloadSizes.get(0)); assertEquals("10", payloadSizes.get(1)); }
@Test public void testPayloadSizeContentXMLbothXMLContentTypesEmpty() { EDXLDistributionPayloadSizeExtractor extractor = new EDXLDistributionPayloadSizeExtractor(); EDXLDistribution alert = new EDXLDistribution(); final List<AnyXMLType> emptyList = mock(List.class); XmlContentType contentType = new XmlContentType() { @Override public List<AnyXMLType> getKeyXMLContent() { return emptyList; } @Override public List<AnyXMLType> getEmbeddedXMLContent() { return emptyList; } }; when(emptyList.size()).thenReturn(0, 0); ContentObjectType payload = new ContentObjectType(); payload.setXmlContent(contentType); alert.getContentObject().add(payload); List<String> payloadSizes = extractor.getPayloadSizes(alert); assertEquals(1, payloadSizes.size()); assertEquals("0", payloadSizes.get(0)); }
@Test public void testPayloadSizeContentXMLMixedXMLContentTypeSizes() { EDXLDistributionPayloadSizeExtractor extractor = new EDXLDistributionPayloadSizeExtractor(); EDXLDistribution alert = new EDXLDistribution(); final List<AnyXMLType> keyList = mock(List.class, "keyList"); final List<AnyXMLType> embeddedList = mock(List.class, "embeddedList"); XmlContentType contentType = new XmlContentType() { @Override public List<AnyXMLType> getKeyXMLContent() { return keyList; } @Override public List<AnyXMLType> getEmbeddedXMLContent() { return embeddedList; } }; when(keyList.size()).thenReturn(4); when(embeddedList.size()).thenReturn(5); ContentObjectType payload = new ContentObjectType(); payload.setXmlContent(contentType); alert.getContentObject().add(payload); List<String> payloadSizes = extractor.getPayloadSizes(alert); assertEquals(1, payloadSizes.size()); assertEquals("9", payloadSizes.get(0)); }