CombinedCLIParser extends AbstractCLIParser { @Override public <T> boolean isApplicableTo(Attachment attachment, User user, T context) throws TException { AttachmentContent attachmentContent = attachmentContentProvider.getAttachmentContent(attachment); return attachmentContent.getFilename().endsWith(XML_FILE_EXTENSION) && hasCombinedCLIRootElement(attachmentContent, user, context); } CombinedCLIParser(AttachmentConnector attachmentConnector, AttachmentContentProvider attachmentContentProvider, ComponentDatabaseHandler componentDatabaseHandler); @Override boolean isApplicableTo(Attachment attachment, User user, T context); @Override List<LicenseInfoParsingResult> getLicenseInfos(Attachment attachment, User user, T context); static final String EXTERNAL_ID_CORRELATION_KEY; }
@Test public void testIsApplicableTo() throws Exception { when(connector.getAttachmentStream(content, new User(), new Project())).thenReturn(makeAttachmentContentStream(TEST_XML_FILENAME)); assertTrue(parser.isApplicableTo(attachment, new User(), new Project())); }
@Test public void testIsApplicableToFailsOnIncorrectRootElement() throws Exception { AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml"); when(connector.getAttachmentStream(content, new User(), new Project())).thenReturn(new ReaderInputStream(new StringReader("<wrong-root/>"))); assertFalse(parser.isApplicableTo(attachment, new User(), new Project())); }
@Test public void testIsApplicableToFailsOnMalformedXML() throws Exception { AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml"); when(connector.getAttachmentStream(content, new User(), new Project())).thenReturn(new ReaderInputStream(new StringReader("this is not an xml file"))); assertFalse(parser.isApplicableTo(attachment, new User(), new Project())); }