@Test void load() throws Exception { TrustedCertLoader loader = new TrustedCertLoader(); Bundle bundle = new Bundle(); loader.load(bundle, buildTrustedCertElement(DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), BigInteger.valueOf(123456L))); assertFalse(bundle.getTrustedCerts().isEmpty()); assertEquals(1, bundle.getTrustedCerts().size()); TrustedCert cert = bundle.getTrustedCerts().get("Cert"); assertNotNull(cert); assertNotNull(cert.getCertificateData()); CertificateData certData = cert.getCertificateData(); assertEquals("Encoded", certData.getEncodedData()); assertEquals("Issuer", certData.getIssuerName()); assertEquals("SN", certData.getSubjectName()); assertEquals(BigInteger.valueOf(123456L), certData.getSerialNumber()); final BeanInfo info = Introspector.getBeanInfo(TrustedCert.class); final Map<String, PropertyDescriptor> properties = stream(info.getPropertyDescriptors()).collect(toMap(FeatureDescriptor::getName, Function.identity())); CERT_PROPERTIES.forEach((k,v) -> { try { boolean value = (boolean) properties.get(k).getReadMethod().invoke(cert); assertTrue(value, "property " + k + " is not true"); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }); }
@Override public void load(Bundle bundle, Element element) { final Element trustedCertElem = getSingleChildElement(getSingleChildElement(element, RESOURCE), TRUSTED_CERT); final String name = getSingleChildElementTextContent(trustedCertElem, NAME); final Map<String, Object> properties = mapPropertiesElements(getSingleChildElement(trustedCertElem, PROPERTIES, true), PROPERTIES); TrustedCert cert = new TrustedCert(properties, getCertData(trustedCertElem)); cert.setId(trustedCertElem.getAttribute(ATTRIBUTE_ID)); cert.setName(getSingleChildElementTextContent(trustedCertElem, NAME)); Set<Annotation> annotations = new HashSet<>(); Annotation bundleEntity = new Annotation(AnnotationType.BUNDLE_HINTS); bundleEntity.setId(trustedCertElem.getAttribute(ATTRIBUTE_ID)); annotations.add(bundleEntity); cert.setAnnotations(annotations); bundle.getTrustedCerts().put(name, cert); }
TrustedCertLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element trustedCertElem = getSingleChildElement(getSingleChildElement(element, RESOURCE), TRUSTED_CERT); final String name = getSingleChildElementTextContent(trustedCertElem, NAME); final Map<String, Object> properties = mapPropertiesElements(getSingleChildElement(trustedCertElem, PROPERTIES, true), PROPERTIES); TrustedCert cert = new TrustedCert(properties, getCertData(trustedCertElem)); cert.setId(trustedCertElem.getAttribute(ATTRIBUTE_ID)); cert.setName(getSingleChildElementTextContent(trustedCertElem, NAME)); Set<Annotation> annotations = new HashSet<>(); Annotation bundleEntity = new Annotation(AnnotationType.BUNDLE_HINTS); bundleEntity.setId(trustedCertElem.getAttribute(ATTRIBUTE_ID)); annotations.add(bundleEntity); cert.setAnnotations(annotations); bundle.getTrustedCerts().put(name, cert); } }
TrustedCertLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element trustedCertElem = getSingleChildElement(getSingleChildElement(element, RESOURCE), TRUSTED_CERT); final String name = getSingleChildElementTextContent(trustedCertElem, NAME); final Map<String, Object> properties = mapPropertiesElements(getSingleChildElement(trustedCertElem, PROPERTIES, true), PROPERTIES); TrustedCert cert = new TrustedCert(properties, getCertData(trustedCertElem)); cert.setId(trustedCertElem.getAttribute(ATTRIBUTE_ID)); cert.setName(getSingleChildElementTextContent(trustedCertElem, NAME)); Set<Annotation> annotations = new HashSet<>(); Annotation bundleEntity = new Annotation(AnnotationType.BUNDLE_HINTS); bundleEntity.setId(trustedCertElem.getAttribute(ATTRIBUTE_ID)); annotations.add(bundleEntity); cert.setAnnotations(annotations); bundle.getTrustedCerts().put(name, cert); }  }
TrustedCertLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element trustedCertElem = getSingleChildElement(getSingleChildElement(element, RESOURCE), TRUSTED_CERT); final String name = getSingleChildElementTextContent(trustedCertElem, NAME); final Map<String, Object> properties = mapPropertiesElements(getSingleChildElement(trustedCertElem, PROPERTIES, true), PROPERTIES); TrustedCert cert = new TrustedCert(properties, getCertData(trustedCertElem)); cert.setId(trustedCertElem.getAttribute(ATTRIBUTE_ID)); cert.setName(getSingleChildElementTextContent(trustedCertElem, NAME)); Set<Annotation> annotations = new HashSet<>(); Annotation bundleEntity = new Annotation(AnnotationType.BUNDLE_HINTS); bundleEntity.setId(trustedCertElem.getAttribute(ATTRIBUTE_ID)); annotations.add(bundleEntity); cert.setAnnotations(annotations); bundle.getTrustedCerts().put(name, cert); }  @Override void load(Bundle bundle, Element element); @Override String getEntityType(); }
TrustedCertLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element trustedCertElem = getSingleChildElement(getSingleChildElement(element, RESOURCE), TRUSTED_CERT); final String name = getSingleChildElementTextContent(trustedCertElem, NAME); final Map<String, Object> properties = mapPropertiesElements(getSingleChildElement(trustedCertElem, PROPERTIES, true), PROPERTIES); TrustedCert cert = new TrustedCert(properties, getCertData(trustedCertElem)); cert.setId(trustedCertElem.getAttribute(ATTRIBUTE_ID)); cert.setName(getSingleChildElementTextContent(trustedCertElem, NAME)); Set<Annotation> annotations = new HashSet<>(); Annotation bundleEntity = new Annotation(AnnotationType.BUNDLE_HINTS); bundleEntity.setId(trustedCertElem.getAttribute(ATTRIBUTE_ID)); annotations.add(bundleEntity); cert.setAnnotations(annotations); bundle.getTrustedCerts().put(name, cert); }  @Override void load(Bundle bundle, Element element); @Override String getEntityType();  }