@Inject public RequestInfoXPathSet( AdsApiConfiguration apiConfig, NodeExtractor nodeExtractor, Supplier<Transformer> transformerSupplier, @Named("libLogger") Logger libLogger) { Preconditions.checkNotNull(apiConfig); this.contextXPath = new IterableXPath(apiConfig.getRequestContextXPath()); this.contextName = Iterables.isEmpty(this.contextXPath) ? null : Iterables.getLast(this.contextXPath); this.nodeExtractor = Preconditions.checkNotNull(nodeExtractor); this.transformerSupplier = Preconditions.checkNotNull(transformerSupplier); this.libLogger = Preconditions.checkNotNull(libLogger); }
@Inject public ResponseInfoXPathSet(AdsApiConfiguration apiConfig, NodeExtractor nodeExtractor) { this.requestIdXPath = new IterableXPath(apiConfig.getRequestIdXPath()); this.responseTimeXPath = new IterableXPath(apiConfig.getResponseTimeXPath()); this.operationsCountXPath = new IterableXPath(apiConfig.getResponseOperationsCountXPath()); this.nodeExtractor = nodeExtractor; }
/** * Default constructor used by Guice. Takes {@link Supplier} instances for {@link XPath}, * {@link Transformer}, and {@link DocumentBuilder} because the corresponding factory objects are * <em>not</em> thread-safe. The Guice modules creating these suppliers should guarantee that the * {@link Supplier} <em>is</em> thread-safe, however. * * @param adsApiConfiguration the API configuration * @param libLogger the logger to use for errors * @param xpathSupplier a thread-safe supplier of {@link XPath} objects * @param transformerSupplier a thread-safe supplier of {@link Transformer} objects * @param documentBuilderSupplier a thread-safe supplier of {@link DocumentBuilder} objects */ @Inject public PrettyPrinter( AdsApiConfiguration adsApiConfiguration, @Named("libLogger") Logger libLogger, Supplier<XPath> xpathSupplier, Supplier<Transformer> transformerSupplier, Supplier<DocumentBuilder> documentBuilderSupplier) { String[] sensitiveXPathsArray = adsApiConfiguration.getSensitiveXPaths(); this.sensitiveXPathStrings = sensitiveXPathsArray == null ? ImmutableList.<String>of() : ImmutableList.<String>copyOf(sensitiveXPathsArray); this.libLogger = libLogger; this.xpathSupplier = xpathSupplier; this.transformerSupplier = transformerSupplier; this.documentBuilderSupplier = documentBuilderSupplier; }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(xpathSupplier.get()).thenReturn(XPathFactory.newInstance().newXPath()); when(documentBuilderSupplier.get()) .thenReturn(DocumentBuilderFactory.newInstance().newDocumentBuilder()); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); when(transformerSupplier.get()).thenReturn(transformer); when(adsApiConfiguration.getRequestIdXPath()).thenReturn(TEST_REQUEST_ID_XPATH); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(apiConfig.getResponseOperationsCountXPath()).thenReturn("/foo/bar/operations"); xPathSet = new ResponseInfoXPathSet(apiConfig, nodeExtractor); }
@Inject public ResponseInfoXPathSet(AdsApiConfiguration apiConfig, NodeExtractor nodeExtractor) { this.requestIdXPath = new IterableXPath(apiConfig.getRequestIdXPath()); this.responseTimeXPath = new IterableXPath(apiConfig.getResponseTimeXPath()); this.operationsCountXPath = new IterableXPath(apiConfig.getResponseOperationsCountXPath()); this.nodeExtractor = nodeExtractor; }
@Inject public RequestInfoXPathSet( AdsApiConfiguration apiConfig, NodeExtractor nodeExtractor, Supplier<Transformer> transformerSupplier, @Named("libLogger") Logger libLogger) { Preconditions.checkNotNull(apiConfig); this.contextXPath = new IterableXPath(apiConfig.getRequestContextXPath()); this.contextName = Iterables.isEmpty(this.contextXPath) ? null : Iterables.getLast(this.contextXPath); this.nodeExtractor = Preconditions.checkNotNull(nodeExtractor); this.transformerSupplier = Preconditions.checkNotNull(transformerSupplier); this.libLogger = Preconditions.checkNotNull(libLogger); }
/** * Default constructor used by Guice. Takes {@link Supplier} instances for {@link XPath}, * {@link Transformer}, and {@link DocumentBuilder} because the corresponding factory objects are * <em>not</em> thread-safe. The Guice modules creating these suppliers should guarantee that the * {@link Supplier} <em>is</em> thread-safe, however. * * @param adsApiConfiguration the API configuration * @param libLogger the logger to use for errors * @param xpathSupplier a thread-safe supplier of {@link XPath} objects * @param transformerSupplier a thread-safe supplier of {@link Transformer} objects * @param documentBuilderSupplier a thread-safe supplier of {@link DocumentBuilder} objects */ @Inject public PrettyPrinter( AdsApiConfiguration adsApiConfiguration, @Named("libLogger") Logger libLogger, Supplier<XPath> xpathSupplier, Supplier<Transformer> transformerSupplier, Supplier<DocumentBuilder> documentBuilderSupplier) { String[] sensitiveXPathsArray = adsApiConfiguration.getSensitiveXPaths(); this.sensitiveXPathStrings = sensitiveXPathsArray == null ? ImmutableList.<String>of() : ImmutableList.<String>copyOf(sensitiveXPathsArray); this.libLogger = libLogger; this.xpathSupplier = xpathSupplier; this.transformerSupplier = transformerSupplier; this.documentBuilderSupplier = documentBuilderSupplier; }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(apiConfig.getRequestContextXPath()).thenReturn("/foo/bar"); xPathSet = new RequestInfoXPathSet(apiConfig, nodeExtractor, transformerSupplier, logger); }
/** * Tests that pretty printing works properly under normal circumstances. */ @Test public void testPrettyPrint() throws SAXException, IOException, ParserConfigurationException { when(adsApiConfiguration.getSensitiveXPaths()).thenReturn(new String[] {TEST_SENSITIVE_XPATH}); String prettyPrintedXml = createPrettyPrinter().prettyPrint(TEST_XML); String expectedXml = TEST_XML.replace("moe", "REDACTED"); Document expectedDocument = XMLUnit.getControlDocumentBuilderFactory() .newDocumentBuilder() .parse(new InputSource(new StringReader(expectedXml))); Document actualDocument = XMLUnit.getTestDocumentBuilderFactory() .newDocumentBuilder() .parse(new InputSource(new StringReader(prettyPrintedXml))); XMLAssert.assertXMLEqual( XMLUnit.getWhitespaceStrippedDocument(expectedDocument), XMLUnit.getWhitespaceStrippedDocument(actualDocument)); }
@Test public void testToString() { when(apiConfig.getRequestContextXPath()).thenReturn("/foo/bar"); String toString = xPathSet.toString(); assertThat( "Missing label for context XPath", toString, Matchers.containsString("contextXPath")); assertThat( "toString should contain all of the context XPath elements", toString, Matchers.stringContainsInOrder(Arrays.asList("foo", "bar"))); assertThat("Missing label for context name", toString, Matchers.containsString("contextName")); } }
new XPathExpressionException("sanitize exception")); when(adsApiConfiguration.getSensitiveXPaths()).thenReturn(new String[] {TEST_SENSITIVE_XPATH});
@Test public void testGettersWithNullConfigXPaths() { when(apiConfig.getRequestContextXPath()).thenReturn(null); xPathSet = new RequestInfoXPathSet(apiConfig, nodeExtractor, transformerSupplier, logger); assertNull( "getContextName should have returned null when no context XPath was supplied", xPathSet.getContextName()); assertFalse( "getContextXPath should have returned an empty iterator when no context XPath was supplied", xPathSet.getContextXPath().iterator().hasNext()); }