@Test public void testLoadMetadataForPolicy(){ JsonFileUtils jsonFileUtils = mock(JsonFileUtils.class); Set<DefaultMetadata> metadataSet = new HashSet<>(); DefaultMetadata policyMetadata = new DefaultMetadata(); policyMetadata.setName("TestPolicy"); policyMetadata.setType(EntityTypes.POLICY_TYPE); policyMetadata.setId("testId"); policyMetadata.setGuid("testGuid"); metadataSet.add(policyMetadata); BundleDefinedEntities bundleDefinedEntities = new BundleDefinedEntities(); bundleDefinedEntities.setDefinedEntities(metadataSet); when(jsonFileUtils.readBundleMetadataFile(any(File.class))).thenReturn(bundleDefinedEntities); EntityBundleLoader loader = new EntityBundleLoader(documentTools, registry, jsonFileUtils); Bundle bundle = loader.loadMetadata(mock(File.class), BundleLoadingOperation.EXPORT); Map<String, Policy> policyMap = bundle.getPolicies(); assertNotNull(policyMap.get("TestPolicy")); }
public Bundle loadMetadata(File dependencyMetadataPath, BundleLoadingOperation loadingMode) { final Bundle bundle = new Bundle(); bundle.setLoadingMode(loadingMode); BundleDefinedEntities bundleDefinedEntities = jsonFileUtils.readBundleMetadataFile(dependencyMetadataPath); Collection<DefaultMetadata> metadataCollection = bundleDefinedEntities.getDefinedEntities(); if (metadataCollection != null) { metadataCollection.forEach(metadata -> { if (EntityTypes.ENCAPSULATED_ASSERTION_TYPE.equals(metadata.getType())) { Encass encass = getEncassFromMetadata(metadata); Map<String, Encass> encassMap = bundle.getEncasses(); encassMap.put(encass.getName(), encass); } else if (EntityTypes.POLICY_TYPE.equals(metadata.getType())) { Policy policy = getPolicyFromMetadata(metadata); Map<String, Policy> policyMap = bundle.getPolicies(); policyMap.put(metadata.getName(), policy); } }); } return bundle; }
EntityBundleLoader { public Bundle loadMetadata(File dependencyMetadataPath, BundleLoadingOperation loadingMode) { final Bundle bundle = new Bundle(); bundle.setLoadingMode(loadingMode); BundleDefinedEntities bundleDefinedEntities = jsonFileUtils.readBundleMetadataFile(dependencyMetadataPath); Collection<DefaultMetadata> metadataCollection = bundleDefinedEntities.getDefinedEntities(); if (metadataCollection != null) { metadataCollection.forEach(metadata -> { if (EntityTypes.ENCAPSULATED_ASSERTION_TYPE.equals(metadata.getType())) { Encass encass = getEncassFromMetadata(metadata); Map<String, Encass> encassMap = bundle.getEncasses(); encassMap.put(encass.getName(), encass); } else if (EntityTypes.POLICY_TYPE.equals(metadata.getType())) { Policy policy = getPolicyFromMetadata(metadata); Map<String, Policy> policyMap = bundle.getPolicies(); policyMap.put(metadata.getName(), policy); } }); } return bundle; } }
EntityBundleLoader { public Bundle loadMetadata(File dependencyMetadataPath, BundleLoadingOperation loadingMode) { final Bundle bundle = new Bundle(); bundle.setLoadingMode(loadingMode); BundleDefinedEntities bundleDefinedEntities = jsonFileUtils.readBundleMetadataFile(dependencyMetadataPath); Collection<DefaultMetadata> metadataCollection = bundleDefinedEntities.getDefinedEntities(); if (metadataCollection != null) { metadataCollection.forEach(metadata -> { if (EntityTypes.ENCAPSULATED_ASSERTION_TYPE.equals(metadata.getType())) { Encass encass = getEncassFromMetadata(metadata); Map<String, Encass> encassMap = bundle.getEncasses(); encassMap.put(encass.getName(), encass); } else if (EntityTypes.POLICY_TYPE.equals(metadata.getType())) { Policy policy = getPolicyFromMetadata(metadata); Map<String, Policy> policyMap = bundle.getPolicies(); policyMap.put(metadata.getName(), policy); } }); } return bundle; } @Inject  EntityBundleLoader(final DocumentTools documentTools, final BundleEntityLoaderRegistry entityLoaderRegistry, final JsonFileUtils jsonFileUtils); }
EntityBundleLoader { public Bundle loadMetadata(File dependencyMetadataPath, BundleLoadingOperation loadingMode) { final Bundle bundle = new Bundle(); bundle.setLoadingMode(loadingMode); BundleDefinedEntities bundleDefinedEntities = jsonFileUtils.readBundleMetadataFile(dependencyMetadataPath); Collection<DefaultMetadata> metadataCollection = bundleDefinedEntities.getDefinedEntities(); if (metadataCollection != null) { metadataCollection.forEach(metadata -> { if (EntityTypes.ENCAPSULATED_ASSERTION_TYPE.equals(metadata.getType())) { Encass encass = getEncassFromMetadata(metadata); Map<String, Encass> encassMap = bundle.getEncasses(); encassMap.put(encass.getName(), encass); } else if (EntityTypes.POLICY_TYPE.equals(metadata.getType())) { Policy policy = getPolicyFromMetadata(metadata); Map<String, Policy> policyMap = bundle.getPolicies(); policyMap.put(metadata.getName(), policy); } }); } return bundle; } @Inject  EntityBundleLoader(final DocumentTools documentTools, final BundleEntityLoaderRegistry entityLoaderRegistry, final JsonFileUtils jsonFileUtils); Bundle load(List<File> fileSet, BundleLoadingOperation loadingMode, String... entityTypes); Bundle load(File dependencyBundlePath, BundleLoadingOperation loadingMode, String... entityTypes); Bundle loadMetadata(File dependencyMetadataPath, BundleLoadingOperation loadingMode); }
EntityBundleLoader { public Bundle loadMetadata(File dependencyMetadataPath, BundleLoadingOperation loadingMode) { final Bundle bundle = new Bundle(); bundle.setLoadingMode(loadingMode); BundleDefinedEntities bundleDefinedEntities = jsonFileUtils.readBundleMetadataFile(dependencyMetadataPath); Collection<DefaultMetadata> metadataCollection = bundleDefinedEntities.getDefinedEntities(); if (metadataCollection != null) { metadataCollection.forEach(metadata -> { if (EntityTypes.ENCAPSULATED_ASSERTION_TYPE.equals(metadata.getType())) { Encass encass = getEncassFromMetadata(metadata); Map<String, Encass> encassMap = bundle.getEncasses(); encassMap.put(encass.getName(), encass); } else if (EntityTypes.POLICY_TYPE.equals(metadata.getType())) { Policy policy = getPolicyFromMetadata(metadata); Map<String, Policy> policyMap = bundle.getPolicies(); policyMap.put(metadata.getName(), policy); } }); } return bundle; } @Inject  EntityBundleLoader(final DocumentTools documentTools, final BundleEntityLoaderRegistry entityLoaderRegistry, final JsonFileUtils jsonFileUtils); Bundle load(List<File> fileSet, BundleLoadingOperation loadingMode, String... entityTypes); Bundle load(File dependencyBundlePath, BundleLoadingOperation loadingMode, String... entityTypes); Bundle loadMetadata(File dependencyMetadataPath, BundleLoadingOperation loadingMode);  }