use of xades4j.algorithms.XPathTransform in project xades4j by luisgoncalves.
the class XPathTransformParamsMarshallerTest method testMarshalXPathParametersWithNamespacePrefixes.
@Test
public void testMarshalXPathParametersWithNamespacePrefixes() throws Exception {
XPathTransform xpath = new XPathTransform("foo:elem1/bar:elem2").withNamespace("foo", "http://test.xades4j/ns1").withNamespace("bar", "http://test.xades4j/ns2");
List<Node> params = sut.marshalParameters(xpath, doc);
assertEquals(1, params.size());
Element paramNode = (Element) params.get(0);
Map<String, String> namespaces = xpath.getNamespaces();
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
String ns = paramNode.getAttributeNS(Constants.NamespaceSpecNS, entry.getKey());
assertNotNull(ns);
assertFalse(ns.isEmpty());
assertEquals(entry.getValue(), ns);
}
}
use of xades4j.algorithms.XPathTransform in project xades4j by luisgoncalves.
the class DataObjectDescTest method testWithTransform.
@Test
public void testWithTransform() throws Exception {
System.out.println("withTransform");
Document doc = SignatureServicesTestBase.getNewDocument();
DataObjectDesc instance = new DataObjectDescTestImpl().withTransform(new XPathTransform("xpath")).withTransform(XPath2Filter.subtract("xpath1").intersect("xpath2")).withTransform(new GenericAlgorithm("uri", doc.createElement("param1"), doc.createElement("param2")));
Algorithm[] transforms = instance.getTransforms().toArray(new Algorithm[0]);
assertEquals(3, transforms.length);
assertEquals(XPathTransform.class, transforms[0].getClass());
assertEquals(XPath2FilterTransform.class, transforms[1].getClass());
assertEquals(GenericAlgorithm.class, transforms[2].getClass());
}
use of xades4j.algorithms.XPathTransform in project xades4j by luisgoncalves.
the class SignerBESTest method testSignBESDetachedWithXPathAndNamespaces.
@Test
public void testSignBESDetachedWithXPathAndNamespaces() throws Exception {
System.out.println("signBESDetachedWithXPathAndNamespaces");
Document doc = getNewDocument();
XadesSigner signer = new XadesBesSigningProfile(keyingProviderMy).withBasicSignatureOptionsProvider(MyBasicSignatureOptionsProvider.class).newSigner();
DataObjectDesc obj1 = new DataObjectReference("document.xml").withTransform(new XPathTransform("/collection/album/foo:tracks").withNamespace("foo", "http://test.xades4j/tracks")).withDataObjectFormat(new DataObjectFormatProperty("text/xml"));
DataObjectDesc obj2 = new DataObjectReference("document.xml").withTransform(XPath2Filter.intersect("/collection/album/bar:tracks/bar:song[@tracknumber = 1]").withNamespace("bar", "http://test.xades4j/tracks"));
SignedDataObjects objs = new SignedDataObjects(obj1, obj2).withBaseUri(new File("src/test/xml/").toURI().toString());
signer.sign(objs, doc);
outputDocument(doc, "detached.bes.xml");
}
Aggregations