/** * Helper method that converts the given object into a {@link NamespaceEntity} */ static NamespaceEntity toEntity(Type type, NamespaceKey path, Object config, boolean keyNormalization) { final NameSpaceContainer container = new NameSpaceContainer(); final NamespaceInternalKey namespaceInternalKey = new NamespaceInternalKey(path, keyNormalization); container.setType(type); switch (type) { case DATASET: container.setDataset((DatasetConfig) config); break; case FOLDER: container.setFolder((FolderConfig) config); break; case HOME: container.setHome((HomeConfig) config); break; case SOURCE: container.setSource((SourceConfig) config); break; case SPACE: container.setSpace((SpaceConfig) config); break; default: throw new UnsupportedOperationException("Unknown type: " + type); } container.setFullPathList(path.getPathComponents()); return new NamespaceEntity(namespaceInternalKey, container); } }
@Test public void testDeleteSpace() throws Exception { Space space = new Space("space-id", "mySpace", "1", 0L, null); NameSpaceContainer namespaceContainer = new NameSpaceContainer(); namespaceContainer.setSpace(catalogServiceHelper.getSpaceConfig(space)); namespaceContainer.setType(NameSpaceContainer.Type.SPACE); when(namespaceService.getEntityById(space.getId())).thenReturn(namespaceContainer); catalogServiceHelper.deleteCatalogItem(space.getId(), space.getTag()); verify(namespaceService, times(1)).deleteSpace(new NamespaceKey(space.getName()), space.getTag()); }
@Test public void testGetSpaceCatalogEntityById() throws Exception { SpaceConfig spaceConfig = new SpaceConfig(); spaceConfig.setId(new EntityId("space-id")); spaceConfig.setName("mySpace"); NameSpaceContainer namespaceContainer = new NameSpaceContainer(); namespaceContainer.setType(NameSpaceContainer.Type.SPACE); namespaceContainer.setSpace(spaceConfig); when(namespaceService.getEntityById(spaceConfig.getId().getId())).thenReturn(namespaceContainer); when(namespaceService.getEntities(Collections.singletonList(new NamespaceKey(spaceConfig.getName())))).thenReturn(Collections.singletonList(namespaceContainer)); // for children listing, we just send the space back to keep it simple when(namespaceService.list(new NamespaceKey(spaceConfig.getName()))).thenReturn(Collections.singletonList(namespaceContainer)); Optional<CatalogEntity> catalogEntityById = catalogServiceHelper.getCatalogEntityById(spaceConfig.getId().getId()); assertTrue(catalogEntityById.isPresent()); CatalogEntity catalogEntity = catalogEntityById.get(); assertTrue(catalogEntity instanceof Space); Space space = (Space) catalogEntity; assertEquals(space.getId(), spaceConfig.getId().getId()); assertEquals(space.getChildren().size(), 1); }