StorageAccountProviderSimpleBindingImpl implements StorageAccountProviderBinding { @Override public Element getElementFrom(StorageAccount acct, boolean includeCredentials, boolean includeHiddenOptions) { Element storageAcct = new Element("storageAcct"); storageAcct.setAttribute("ownerId", "0"); String isPrimary = acct.isPrimary() ? "1" : "0"; storageAcct.setAttribute("isPrimary", isPrimary); Element id = new Element("id"); id.addContent(acct.getId()); storageAcct.addContent(id); Element storageProviderType = new Element("storageProviderType"); storageProviderType.addContent(acct.getType().name()); storageAcct.addContent(storageProviderType); if (includeCredentials) { Element storageProviderCredential = new Element( "storageProviderCredential"); String uname = encryptionUtil.encrypt(acct.getUsername()); String pword = encryptionUtil.encrypt(acct.getPassword()); Element username = new Element("username"); Element password = new Element("password"); username.addContent(uname); password.addContent(pword); storageProviderCredential.addContent(username); storageProviderCredential.addContent(password); storageAcct.addContent(storageProviderCredential); } Map<String, String> options = acct.getOptions(); if (null != options && !options.isEmpty()) { Element storageProviderOptions = new Element( "storageProviderOptions"); storageAcct.addContent(storageProviderOptions); for (String key : options.keySet()) { if (includeHiddenOptions || !StorageAccount.OPTS.valueOf(key).isHidden()) { Element option = new Element("option"); option.setAttribute("name", key); option.setAttribute("value", options.get(key)); storageProviderOptions.addContent(option); } } } return storageAcct; } StorageAccountProviderSimpleBindingImpl(); @Override StorageAccount getAccountFromXml(Element xml); @Override Element getElementFrom(StorageAccount acct,
                                  boolean includeCredentials,
                                  boolean includeHiddenOptions);  }
@Test public void testGetElementFrom() { EncryptionUtil encryptionUtil = new EncryptionUtil(); String storeId = "store-id"; String username = "username"; String password = "password"; StorageProviderType type = StorageProviderType.AMAZON_S3; String hiddenOptionName = StorageAccount.OPTS.CF_KEY_ID.name(); String hiddenOptionValue = "option-value"; String openOptionName = StorageAccount.OPTS.WRITABLE.name(); String openOptionValue = "option-value"; StorageAccount account = new StorageAccountImpl(storeId, username, password, type); account.setOption(hiddenOptionName, hiddenOptionValue); account.setOption(openOptionName, openOptionValue); Element element = binding.getElementFrom(account, true, true); Assert.assertEquals(storeId, element.getChildText("id")); Assert.assertEquals(encryptionUtil.encrypt(username), element.getChild("storageProviderCredential") .getChildText("username")); Assert.assertEquals(encryptionUtil.encrypt(password), element.getChild("storageProviderCredential") .getChildText("password")); List<Element> options = element.getChild("storageProviderOptions").getChildren(); Assert.assertEquals(2, options.size()); verifyThatOptionIsContained(options, hiddenOptionName, hiddenOptionValue); verifyThatOptionIsContained(options, openOptionName, openOptionValue); element = binding.getElementFrom(account, false, true); Assert.assertEquals(storeId, element.getChildText("id")); Assert.assertNull(element.getChild("storageProviderCredential")); options = element.getChild("storageProviderOptions").getChildren(); Assert.assertEquals(2, options.size()); verifyThatOptionIsContained(options, hiddenOptionName, hiddenOptionValue); verifyThatOptionIsContained(options, openOptionName, openOptionValue); element = binding.getElementFrom(account, false, false); Assert.assertEquals(storeId, element.getChildText("id")); Assert.assertNull(element.getChild("storageProviderCredential")); options = element.getChild("storageProviderOptions").getChildren(); Assert.assertEquals(1, options.size()); verifyThatOptionIsContained(options, openOptionName, openOptionValue); }