Search in sources :

Example 26 with Request

use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.

the class TaxonomyServiceTest method testCreateTaxonomy.

@Test
public void testCreateTaxonomy() throws Exception {
    MetadataService metadataService = createStrictMock(MetadataService.class);
    AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class);
    ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
    ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
    UriInfo uriInfo = createNiceMock(UriInfo.class);
    URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy");
    Capture<Request> requestCapture = newCapture();
    String body = "{ \"description\" : \"test description\" } ";
    // set mock expectations
    expect(uriInfo.getRequestUri()).andReturn(uri);
    expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition");
    taxonomyResourceProvider.createResource(capture(requestCapture));
    replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
    // instantiate service and invoke method being tested
    TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, null);
    Response response = service.createTaxonomy(body, null, uriInfo, "testTaxonomy");
    Request request = requestCapture.getValue();
    assertEquals(request.getQueryProperties().size(), 2);
    assertEquals(request.getQueryProperties().get("name"), "testTaxonomy");
    assertEquals(request.getQueryProperties().get("description"), "test description");
    assertNull(request.getQueryString());
    assertEquals(response.getStatus(), 201);
    BaseService.Results createResults = (BaseService.Results) response.getEntity();
    assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy");
    assertEquals(createResults.status, 201);
    verify(uriInfo, taxonomyResourceProvider, termResourceProvider);
}
Also used : Request(org.apache.atlas.catalog.Request) URI(java.net.URI) MetadataService(org.apache.atlas.services.MetadataService) AtlasTypeDefStore(org.apache.atlas.store.AtlasTypeDefStore) Response(javax.ws.rs.core.Response) TaxonomyResourceProvider(org.apache.atlas.catalog.TaxonomyResourceProvider) ResourceProvider(org.apache.atlas.catalog.ResourceProvider) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 27 with Request

use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.

the class TermResourceDefinitionTest method testValidate_nameOnly.

@Test
public void testValidate_nameOnly() throws Exception {
    Map<String, Object> properties = new HashMap<>();
    properties.put("name", "taxonomy1.termName");
    Request request = new InstanceRequest(properties);
    ResourceDefinition termDefinition = new TermResourceDefinition();
    termDefinition.validateCreatePayload(request);
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Test(org.testng.annotations.Test)

Example 28 with Request

use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.

the class TermResourceDefinitionTest method testFilterProperties_Instance.

@Test
public void testFilterProperties_Instance() {
    Map<String, Object> resourceProps = new HashMap<>();
    resourceProps.put("id", "111-222-333");
    resourceProps.put("name", "nameVal");
    resourceProps.put("type", "someType");
    resourceProps.put("foo", "fooVal");
    resourceProps.put("bar", "barVal");
    resourceProps.put("description", "desc");
    resourceProps.put("creation_time", "2016:10:10");
    resourceProps.put("acceptable_use", "something");
    resourceProps.put("available_as_tag", true);
    resourceProps.put("other", "otherVal");
    Request request = new InstanceRequest(resourceProps);
    request.addAdditionalSelectProperties(Collections.singleton("foo"));
    ResourceDefinition termDefinition = new TermResourceDefinition();
    Map<String, Object> filteredProperties = termDefinition.filterProperties(request, resourceProps);
    assertEquals(filteredProperties.size(), 6);
    // registered collection props
    assertTrue(filteredProperties.containsKey("name"));
    assertTrue(filteredProperties.containsKey("description"));
    assertTrue(filteredProperties.containsKey("available_as_tag"));
    assertTrue(filteredProperties.containsKey("acceptable_use"));
    assertTrue(filteredProperties.containsKey("creation_time"));
    // added prop
    assertTrue(filteredProperties.containsKey("foo"));
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Test(org.testng.annotations.Test)

Example 29 with Request

use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.

the class TermResourceDefinitionTest method testFilterProperties_Collection.

@Test
public void testFilterProperties_Collection() {
    Map<String, Object> resourceProps = new HashMap<>();
    resourceProps.put("id", "111-222-333");
    resourceProps.put("name", "nameVal");
    resourceProps.put("type", "someType");
    resourceProps.put("foo", "fooVal");
    resourceProps.put("bar", "barVal");
    resourceProps.put("description", "desc");
    resourceProps.put("creation_time", "2016:10:10");
    resourceProps.put("acceptable_use", "something");
    resourceProps.put("available_as_tag", true);
    resourceProps.put("other", "otherVal");
    Request request = new CollectionRequest(resourceProps, "someProperty:someValue");
    request.addAdditionalSelectProperties(Collections.singleton("foo"));
    ResourceDefinition termDefinition = new TermResourceDefinition();
    Map<String, Object> filteredProps = termDefinition.filterProperties(request, resourceProps);
    assertEquals(filteredProps.size(), 3);
    // registered collection props
    assertTrue(filteredProps.containsKey("name"));
    assertTrue(filteredProps.containsKey("description"));
    // added prop
    assertTrue(filteredProps.containsKey("foo"));
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) Test(org.testng.annotations.Test)

Example 30 with Request

use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.

the class TermResourceDefinitionTest method testValidate_missingName.

@Test(expectedExceptions = InvalidPayloadException.class)
public void testValidate_missingName() throws Exception {
    Map<String, Object> properties = new HashMap<>();
    properties.put("description", "foo");
    Request request = new InstanceRequest(properties);
    ResourceDefinition termDefinition = new TermResourceDefinition();
    termDefinition.validateCreatePayload(request);
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Test(org.testng.annotations.Test)

Aggregations

Request (org.apache.atlas.catalog.Request)45 Test (org.testng.annotations.Test)45 CollectionRequest (org.apache.atlas.catalog.CollectionRequest)30 InstanceRequest (org.apache.atlas.catalog.InstanceRequest)30 HashMap (java.util.HashMap)12 Response (javax.ws.rs.core.Response)12 UriInfo (javax.ws.rs.core.UriInfo)12 ResourceProvider (org.apache.atlas.catalog.ResourceProvider)12 TaxonomyResourceProvider (org.apache.atlas.catalog.TaxonomyResourceProvider)12 MetadataService (org.apache.atlas.services.MetadataService)12 AtlasTypeDefStore (org.apache.atlas.store.AtlasTypeDefStore)12 URI (java.net.URI)10 TermPath (org.apache.atlas.catalog.TermPath)9 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 JsonSerializer (org.apache.atlas.catalog.JsonSerializer)6 Result (org.apache.atlas.catalog.Result)6 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)3 Pipe (com.tinkerpop.pipes.Pipe)3 ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)3