Search in sources :

Example 1 with GetProxyProperties

use of uk.gov.gchq.gaffer.proxystore.operation.GetProxyProperties in project Gaffer by gchq.

the class GetProxyPropertiesHandler method doOperation.

/**
 * This implementation could work with with any store and properties but gets ONLY the Proxy Properties value from the Proxy store.
 *
 * @param operation the {@link GetProxyProperties} to be executed
 * @param context   the operation chain context, containing the user who executed the operation
 * @param store     the {@link Store} the operation should be run on
 * @return          the proxy specific properties only.
 * @throws OperationException Error making return string map
 */
@Override
public Map<String, Object> doOperation(final GetProxyProperties operation, final Context context, final Store store) throws OperationException {
    try {
        ProxyProperties properties = new ProxyProperties(store.getProperties().getProperties());
        HashMap<String, Object> rtn = new HashMap<>();
        rtn.put(GAFFER_CONTEXT_ROOT, properties.getGafferContextRoot());
        rtn.put(GAFFER_HOST, properties.getGafferHost());
        rtn.put(GAFFER_PORT, String.valueOf(properties.getGafferPort()));
        rtn.put(CONNECT_TIMEOUT, String.valueOf(properties.getConnectTimeout()));
        rtn.put(READ_TIMEOUT, String.valueOf(properties.getReadTimeout()));
        rtn.put(URL_INFERRED, properties.getGafferUrl().toString());
        return rtn;
    } catch (final Exception e) {
        throw new OperationException("Error making return string map", e);
    }
}
Also used : GetProxyProperties(uk.gov.gchq.gaffer.proxystore.operation.GetProxyProperties) ProxyProperties(uk.gov.gchq.gaffer.proxystore.ProxyProperties) HashMap(java.util.HashMap) OperationException(uk.gov.gchq.gaffer.operation.OperationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 2 with GetProxyProperties

use of uk.gov.gchq.gaffer.proxystore.operation.GetProxyProperties in project Gaffer by gchq.

the class GetProxyPropertiesHandlerTest method shouldGetURl.

@Test
public void shouldGetURl() throws Exception {
    // given
    Store store = Mockito.mock(Store.class);
    ProxyProperties properties = new ProxyProperties();
    properties.set(GAFFER_PORT, PORT);
    properties.set(GAFFER_HOST, HOST);
    properties.set(GAFFER_CONTEXT_ROOT, DEFAULT_GAFFER_CONTEXT_ROOT);
    properties.setConnectTimeout(999);
    properties.set(EXTRA_KEY, "value");
    Mockito.when(store.getProperties()).thenReturn(properties);
    HashMap expected = getExpected(properties);
    // when
    Map<String, Object> actual = new GetProxyPropertiesHandler().doOperation(new GetProxyProperties(), new Context(), store);
    // then
    assertFalse(actual.containsKey(EXTRA_KEY));
    assertTrue(actual.containsKey(URL_INFERRED));
    assertEquals(expected, actual);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetProxyProperties(uk.gov.gchq.gaffer.proxystore.operation.GetProxyProperties) ProxyProperties(uk.gov.gchq.gaffer.proxystore.ProxyProperties) HashMap(java.util.HashMap) Store(uk.gov.gchq.gaffer.store.Store) GetProxyProperties(uk.gov.gchq.gaffer.proxystore.operation.GetProxyProperties) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)2 ProxyProperties (uk.gov.gchq.gaffer.proxystore.ProxyProperties)2 GetProxyProperties (uk.gov.gchq.gaffer.proxystore.operation.GetProxyProperties)2 Test (org.junit.jupiter.api.Test)1 OperationException (uk.gov.gchq.gaffer.operation.OperationException)1 Context (uk.gov.gchq.gaffer.store.Context)1 Store (uk.gov.gchq.gaffer.store.Store)1