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);  }
@Test public void testLoadMetadataForEncass(){ JsonFileUtils jsonFileUtils = mock(JsonFileUtils.class); Set<DefaultMetadata> metadataSet = new HashSet<>(); DefaultMetadata encassMetadata = new DefaultMetadata(); encassMetadata.setName("TestEncass"); encassMetadata.setType(EntityTypes.ENCAPSULATED_ASSERTION_TYPE); encassMetadata.setId("testId"); encassMetadata.setGuid("testGuid"); metadataSet.add(encassMetadata); 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, Encass> encassMap = bundle.getEncasses(); assertNotNull(encassMap.get("TestEncass")); }
@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")); }