### Question:
NetworkServiceDescriptorParser { public Optional<NetworkServiceDescriptor> parse(final byte[] zipBytes) { try { final Map<String, FileEntry> files = getZipContent(zipBytes); if (isMetaFilePresent(files)) { final Optional<ToscaMetadata> optional = toscaMetadataParser.parse(files.get(TOSCA_META_PATH_FILE_NAME)); if (optional.isPresent()) { final ToscaMetadata toscaMetadata = optional.get(); logger.info("Parsed ToscaMetadata {}", toscaMetadata); final String entryDefinitionFile = toscaMetadata.getEntry(ENTRY_DEFINITIONS); if (entryDefinitionFile != null && files.containsKey(entryDefinitionFile)) { final Map<String, Object> fileContent = fileParser.getFileContent(files.get(entryDefinitionFile)); final Map<String, Object> topologyTemplates = getTopologyTemplates(fileContent); final Map<String, Object> nodeTemplates = getNodeTemplates(topologyTemplates); final Optional<NetworkServiceDescriptor> nsdOptional = getNetworkServiceDescriptor(topologyTemplates); if (nsdOptional.isPresent()) { final NetworkServiceDescriptor networkServiceDescriptor = nsdOptional.get(); networkServiceDescriptor.setVnfs(getVirtualNetworkFunctions(nodeTemplates)); return Optional.of(networkServiceDescriptor); } } } } logger.error("Unable to find {} file in {}", TOSCA_META_PATH_FILE_NAME, files); } catch (final Exception exception) { logger.error("Unable to parse nsd zip content", exception); } return Optional.empty(); } @Autowired  NetworkServiceDescriptorParser(final ToscaMetadataParser toscaMetadataParser, final FileParser fileParser); Optional<NetworkServiceDescriptor> parse(final byte[] zipBytes); static final String NS_NODE_TYPE; }### Answer:
@Test public void testValidEtsiNsd_ableToParseIt() throws IOException { final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(VALID_ETSI_NSD_FILE))); final Optional<NetworkServiceDescriptor> optional = objUnderTest.parse(zipBytes); assertTrue(optional.isPresent()); final NetworkServiceDescriptor actualNsd = optional.get(); assertEquals(NetworkServiceDescriptorParser.NS_NODE_TYPE, actualNsd.getType()); assertFalse(actualNsd.getProperties().isEmpty()); final Map<String, Object> actualNsdProperties = actualNsd.getProperties(); assertEquals(5, actualNsdProperties.size()); assertEquals("ffdddc5d-a44b-45ae-8fc3-e6551cce350f", actualNsdProperties.get("descriptor_id")); assertEquals(5, actualNsd.getVnfs().size()); }
@Test public void testEmptyEtsiNsd_returnEmptyOptional() throws IOException { assertFalse(objUnderTest.parse(new byte[] {}).isPresent()); }
@Test public void testInvalidEtsiNsd_returnEmptyOptional() throws IOException { final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(INVALID_ETSI_NSD_FILE))); assertFalse(objUnderTest.parse(zipBytes).isPresent()); }