TaxonomyResourceProvider extends BaseResourceProvider implements ResourceProvider { @Override public void createResource(Request request) throws InvalidPayloadException, ResourceAlreadyExistsException { resourceDefinition.validateCreatePayload(request); synchronized (TaxonomyResourceProvider.class) { ensureTaxonomyDoesntExist(request); doCreateResource(request); } } TaxonomyResourceProvider(AtlasTypeSystem typeSystem); @Override Result getResourceById(Request request); @Override Result getResources(Request request); @Override void createResource(Request request); @Override Collection<String> createResources(Request request); @Override void deleteResourceById(Request request); @Override void updateResourceById(Request request); static final String DEFAULT_TAXONOMY_NAME; static final String DEFAULT_TAXONOMY_DESCRIPTION; static final String NAMESPACE_ATTRIBUTE_NAME; static final String TAXONOMY_TERM_TYPE; static final String TAXONOMY_NS; }
@Test(expectedExceptions = InvalidPayloadException.class) public void testCreateResource_invalidRequest__noName() throws Exception { AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class); QueryFactory queryFactory = createStrictMock(QueryFactory.class); AtlasQuery query = createStrictMock(AtlasQuery.class); replay(typeSystem, queryFactory, query); Map<String, Object> requestProperties = new HashMap<>(); requestProperties.put("description", "test"); Request userRequest = new InstanceRequest(requestProperties); TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem); provider.setQueryFactory(queryFactory); provider.createResource(userRequest); }
@Test(expectedExceptions = ResourceAlreadyExistsException.class) public void testCreateResource_invalidRequest__alreadyExists() throws Exception { AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class); QueryFactory queryFactory = createStrictMock(QueryFactory.class); AtlasQuery query = createStrictMock(AtlasQuery.class); Capture<Request> requestCapture = newCapture(); Collection<Map<String, Object>> queryResult = new ArrayList<>(); Map<String, Object> queryResultRow = new HashMap<>(); queryResult.add(queryResultRow); queryResultRow.put("mame", "taxonomyName"); queryResultRow.put("description", "test taxonomy description"); queryResultRow.put("creation_time", "04/20/2016"); expect(queryFactory.createTaxonomyQuery(capture(requestCapture))).andReturn(query); expect(query.execute()).andReturn(queryResult); replay(typeSystem, queryFactory, query); Map<String, Object> requestProperties = new HashMap<>(); requestProperties.put("name", "taxonomyName"); Request userRequest = new InstanceRequest(requestProperties); TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem); provider.setQueryFactory(queryFactory); provider.createResource(userRequest); }
@Test public void testCreateResource() throws Exception { AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class); QueryFactory queryFactory = createStrictMock(QueryFactory.class); AtlasQuery query = createStrictMock(AtlasQuery.class); Capture<ResourceDefinition> resourceDefinitionCapture = newCapture(); Capture<Request> requestCapture = newCapture(); Collection<Map<String, Object>> queryResult = new ArrayList<>(); expect(queryFactory.createTaxonomyQuery(capture(requestCapture))).andReturn(query); expect(query.execute()).andReturn(queryResult); expect(typeSystem.createEntity(capture(resourceDefinitionCapture), capture(requestCapture))).andReturn("testGuid"); replay(typeSystem, queryFactory, query); Map<String, Object> requestProperties = new HashMap<>(); requestProperties.put("name", "taxonomyName"); Request userRequest = new InstanceRequest(requestProperties); TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem); provider.setQueryFactory(queryFactory); provider.createResource(userRequest); assertEquals(new TaxonomyResourceDefinition().getTypeName(), resourceDefinitionCapture.getValue().getTypeName()); Request request = requestCapture.getValue(); assertNull(request.getQueryString()); assertEquals(requestProperties, request.getQueryProperties()); verify(typeSystem, queryFactory, query); }