@SuppressWarnings("deprecation") @Test public void testStrategy() throws Exception { StorageStrategyService service = EasyMock.createMock(StorageStrategyService.class); SnmpAgentConfig agentConfig = new SnmpAgentConfig(InetAddressUtils.addr("127.0.0.1")); agentConfig.setPort(1161); EasyMock.expect(service.getAgentConfig()).andReturn(agentConfig).anyTimes(); EasyMock.replay(service); HostFileSystemStorageStrategy strategy = new HostFileSystemStorageStrategy(); strategy.setResourceTypeName("hrStorageIndex"); strategy.setStorageStrategyService(service); String parentResource = "1"; MockCollectionResource resource = new MockCollectionResource(parentResource, "1", "hrStorageIndex"); resource.getAttribtueMap().put("hrStorageDescr", "/"); String resourceName = strategy.getResourceNameFromIndex(resource); Assert.assertEquals("_root_fs", resourceName); resource.setInstance("8"); resource.getAttribtueMap().put("hrStorageDescr", "Volumes-iDisk"); Assert.assertEquals("Volumes-iDisk", strategy.getResourceNameFromIndex(resource)); Assert.assertEquals("1" + File.separator + "hrStorageIndex" + File.separator + "_root_fs", strategy.getRelativePathForAttribute(parentResource, resourceName, null)); EasyMock.verify(service); }
@Override public String getResourceNameFromIndex(CollectionResource resource) { StringAttributeVisitor visitor = new StringAttributeVisitor(HR_STORAGE_DESC); resource.visit(visitor); String value = (visitor.getValue() != null ? visitor.getValue() : resource.getInstance()); if (value.equals("/")) return "_root_fs"; return value.replaceFirst("/", "").replaceAll("\\s", "").replaceAll("/", "-").replaceAll(":\\\\.*", ""); }
HostFileSystemStorageStrategy extends IndexStorageStrategy { @Override public String getResourceNameFromIndex(CollectionResource resource) { StringAttributeVisitor visitor = new StringAttributeVisitor(HR_STORAGE_DESC); resource.visit(visitor); String value = (visitor.getValue() != null ? visitor.getValue() : resource.getInstance()); if (value.equals("/")) return "_root_fs"; return value.replaceFirst("/", "").replaceAll("\\s", "").replaceAll("/", "-").replaceAll(":\\\\.*", ""); } }
HostFileSystemStorageStrategy extends IndexStorageStrategy { @Override public String getResourceNameFromIndex(CollectionResource resource) { StringAttributeVisitor visitor = new StringAttributeVisitor(HR_STORAGE_DESC); resource.visit(visitor); String value = (visitor.getValue() != null ? visitor.getValue() : resource.getInstance()); if (value.equals("/")) return "_root_fs"; return value.replaceFirst("/", "").replaceAll("\\s", "").replaceAll("/", "-").replaceAll(":\\\\.*", ""); }  }
HostFileSystemStorageStrategy extends IndexStorageStrategy { @Override public String getResourceNameFromIndex(CollectionResource resource) { StringAttributeVisitor visitor = new StringAttributeVisitor(HR_STORAGE_DESC); resource.visit(visitor); String value = (visitor.getValue() != null ? visitor.getValue() : resource.getInstance()); if (value.equals("/")) return "_root_fs"; return value.replaceFirst("/", "").replaceAll("\\s", "").replaceAll("/", "-").replaceAll(":\\\\.*", ""); }  @Override String getResourceNameFromIndex(CollectionResource resource); }
HostFileSystemStorageStrategy extends IndexStorageStrategy { @Override public String getResourceNameFromIndex(CollectionResource resource) { StringAttributeVisitor visitor = new StringAttributeVisitor(HR_STORAGE_DESC); resource.visit(visitor); String value = (visitor.getValue() != null ? visitor.getValue() : resource.getInstance()); if (value.equals("/")) return "_root_fs"; return value.replaceFirst("/", "").replaceAll("\\s", "").replaceAll("/", "-").replaceAll(":\\\\.*", ""); }  @Override String getResourceNameFromIndex(CollectionResource resource); static String HR_STORAGE_DESC; }