Search in sources :

Example 1 with ResourceLookupContext

use of org.apache.ranger.plugin.service.ResourceLookupContext in project ranger by apache.

the class TestNiFiClient method testGetResourcesNoUserInput.

@Test
public void testGetResourcesNoUserInput() throws Exception {
    ResourceLookupContext resourceLookupContext = Mockito.mock(ResourceLookupContext.class);
    when(resourceLookupContext.getUserInput()).thenReturn("");
    final List<String> expectedResources = new ArrayList<>();
    expectedResources.add("/system");
    expectedResources.add("/controller");
    expectedResources.add("/flow");
    expectedResources.add("/provenance");
    expectedResources.add("/proxy");
    expectedResources.add("/resources");
    List<String> resources = niFiClient.getResources(resourceLookupContext);
    Assert.assertNotNull(resources);
    Assert.assertEquals(expectedResources.size(), resources.size());
    resources.removeAll(expectedResources);
    Assert.assertEquals(0, resources.size());
}
Also used : ResourceLookupContext(org.apache.ranger.plugin.service.ResourceLookupContext) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with ResourceLookupContext

use of org.apache.ranger.plugin.service.ResourceLookupContext in project ranger by apache.

the class TestNiFiClient method testGetResourcesWithUserInputBeginning.

@Test
public void testGetResourcesWithUserInputBeginning() throws Exception {
    ResourceLookupContext resourceLookupContext = Mockito.mock(ResourceLookupContext.class);
    when(resourceLookupContext.getUserInput()).thenReturn("/pr");
    final List<String> expectedResources = new ArrayList<>();
    expectedResources.add("/provenance");
    expectedResources.add("/proxy");
    List<String> resources = niFiClient.getResources(resourceLookupContext);
    Assert.assertNotNull(resources);
    Assert.assertEquals(expectedResources.size(), resources.size());
    resources.removeAll(expectedResources);
    Assert.assertEquals(0, resources.size());
}
Also used : ResourceLookupContext(org.apache.ranger.plugin.service.ResourceLookupContext) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with ResourceLookupContext

use of org.apache.ranger.plugin.service.ResourceLookupContext in project ranger by apache.

the class TestNiFiClient method testGetResourcesWithUserInputAnywhere.

@Test
public void testGetResourcesWithUserInputAnywhere() throws Exception {
    ResourceLookupContext resourceLookupContext = Mockito.mock(ResourceLookupContext.class);
    when(resourceLookupContext.getUserInput()).thenReturn("trol");
    final List<String> expectedResources = new ArrayList<>();
    expectedResources.add("/controller");
    List<String> resources = niFiClient.getResources(resourceLookupContext);
    Assert.assertNotNull(resources);
    Assert.assertEquals(expectedResources.size(), resources.size());
    resources.removeAll(expectedResources);
    Assert.assertEquals(0, resources.size());
}
Also used : ResourceLookupContext(org.apache.ranger.plugin.service.ResourceLookupContext) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with ResourceLookupContext

use of org.apache.ranger.plugin.service.ResourceLookupContext in project ranger by apache.

the class TestNiFiClient method testGetResourcesErrorResponse.

@Test
public void testGetResourcesErrorResponse() throws Exception {
    final String errorMsg = "unknown error";
    niFiClient = new MockNiFiClient(errorMsg, Response.Status.BAD_REQUEST.getStatusCode());
    ResourceLookupContext resourceLookupContext = Mockito.mock(ResourceLookupContext.class);
    when(resourceLookupContext.getUserInput()).thenReturn("");
    try {
        niFiClient.getResources(resourceLookupContext);
        Assert.fail("should have thrown exception");
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains(errorMsg));
    }
}
Also used : ResourceLookupContext(org.apache.ranger.plugin.service.ResourceLookupContext) Test(org.junit.Test)

Example 5 with ResourceLookupContext

use of org.apache.ranger.plugin.service.ResourceLookupContext in project ranger by apache.

the class TestRangerServiceHBase method setup.

@Before
public void setup() {
    configs = new HashMap<String, String>();
    lookupContext = new ResourceLookupContext();
    buildHbaseConnectionConfig();
    buildLookupContext();
    sd = new RangerServiceDef(sdName, "org.apache.ranger.services.hbase.RangerServiceHBase", "TestService", "test servicedef description", null, null, null, null, null, null, null);
    svc = new RangerService(sdName, serviceName, "unit test hbase resource lookup and validateConfig", null, configs);
    svcHBase = new RangerServiceHBase();
    svcHBase.init(sd, svc);
}
Also used : ResourceLookupContext(org.apache.ranger.plugin.service.ResourceLookupContext) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerService(org.apache.ranger.plugin.model.RangerService) Before(org.junit.Before)

Aggregations

ResourceLookupContext (org.apache.ranger.plugin.service.ResourceLookupContext)6 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 RangerService (org.apache.ranger.plugin.model.RangerService)1 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)1 VXString (org.apache.ranger.view.VXString)1 Before (org.junit.Before)1