Skip to content

Commit

Permalink
ProxyStore GetUrlOperation rename (#2451)
Browse files Browse the repository at this point in the history
* ProxyStore GetUrlOperation rename

* gh-2447 ProxyStore @test junit4-5 bug

Co-authored-by: GCHQDev404 <gchqdev404@users.noreply.github.com>
  • Loading branch information
GCHQDev404 and GCHQDev404 authored Jun 24, 2021
1 parent 48dd436 commit e1b1a85
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.exception.CloneFailedException;

import uk.gov.gchq.gaffer.operation.Operation;
Expand All @@ -31,7 +33,7 @@
@JsonPropertyOrder(value = {"class"}, alphabetic = true)
@Since("1.17.0")
@Summary("Gets the Proxy URL value from the store properties")
public class GetUrlOperation implements Output<String> {
public class GetProxyUrl implements Output<String> {

private HashMap<String, String> options = new HashMap<>();

Expand All @@ -41,8 +43,8 @@ public TypeReference<String> getOutputTypeReference() {
}

@Override
public Operation shallowClone() throws CloneFailedException {
return new GetUrlOperation.Builder().options(options).build();
public GetProxyUrl shallowClone() throws CloneFailedException {
return new GetProxyUrl.Builder().options(options).build();
}

@Override
Expand All @@ -55,9 +57,26 @@ public void setOptions(final Map<String, String> options) {
this.options = new HashMap<>(options);
}

public static class Builder extends Operation.BaseBuilder<GetUrlOperation, GetUrlOperation.Builder> {
@Override
public boolean equals(final Object o) {
return this == o
|| (o != null
&& getClass() == o.getClass()
&& new EqualsBuilder()
.append(options, ((GetProxyUrl) o).options)
.isEquals());
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(options)
.toHashCode();
}

public static class Builder extends Operation.BaseBuilder<GetProxyUrl, GetProxyUrl.Builder> {
public Builder() {
super(new GetUrlOperation());
super(new GetProxyUrl());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

import uk.gov.gchq.gaffer.operation.OperationException;
import uk.gov.gchq.gaffer.proxystore.ProxyProperties;
import uk.gov.gchq.gaffer.proxystore.operation.GetUrlOperation;
import uk.gov.gchq.gaffer.proxystore.operation.GetProxyUrl;
import uk.gov.gchq.gaffer.store.Context;
import uk.gov.gchq.gaffer.store.Store;
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;

public class GetUrlHandler implements OutputOperationHandler<GetUrlOperation, String> {
public class GetProxyUrlHandler implements OutputOperationHandler<GetProxyUrl, String> {
@Override
public String doOperation(final GetUrlOperation operation, final Context context, final Store store) throws OperationException {
public String doOperation(final GetProxyUrl operation, final Context context, final Store store) throws OperationException {
try {
return new ProxyProperties(store.getProperties().getProperties()).getGafferUrl().toString();
} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,43 @@
*/
package uk.gov.gchq.gaffer.proxystore.operation;

import uk.gov.gchq.gaffer.operation.Operation;
import org.junit.jupiter.api.Test;

import uk.gov.gchq.gaffer.operation.OperationTest;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;


public class GetUrlOperationTest extends OperationTest<GetUrlOperation> {
public class GetProxyUrlTest extends OperationTest<GetProxyUrl> {

private static final String A = "a";
private static final String ONE = "1";

@Test
@Override
public void builderShouldCreatePopulatedOperation() {
//given
GetUrlOperation op = getTestObject();
GetProxyUrl op = getTestObject();

//when
String value = op.getOption(A);
String actual = op.getOption(A);

//then
assertEquals(ONE, A);
assertEquals(ONE, actual);
}

@Test
@Override
public void shouldShallowCloneOperation() {
GetUrlOperation testObject = getTestObject();
Operation operation = testObject.shallowClone();
GetProxyUrl testObject = getTestObject();
GetProxyUrl operation = testObject.shallowClone();
assertEquals(testObject, operation);
assertFalse(testObject == operation);
}

@Override
protected GetUrlOperation getTestObject() {
String expected = ONE;
String a = A;
return new GetUrlOperation.Builder().option(a, expected).build();
protected GetProxyUrl getTestObject() {
return new GetProxyUrl.Builder().option(A, ONE).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import uk.gov.gchq.gaffer.proxystore.operation.GetUrlOperation;
import uk.gov.gchq.gaffer.proxystore.operation.GetProxyUrl;
import uk.gov.gchq.gaffer.store.Context;
import uk.gov.gchq.gaffer.store.Store;
import uk.gov.gchq.gaffer.store.StoreProperties;
Expand All @@ -29,7 +29,7 @@
import static uk.gov.gchq.gaffer.proxystore.ProxyProperties.GAFFER_HOST;
import static uk.gov.gchq.gaffer.proxystore.ProxyProperties.GAFFER_PORT;

public class GetUrlHandlerTest {
public class GetProxyUrlHandlerTest {


@Test
Expand All @@ -46,7 +46,7 @@ public void shouldGetURl() throws Exception {
String expected = String.format("http://%s:%s/rest/v2", host, port, DEFAULT_GAFFER_CONTEXT_ROOT);

//when
String url = new GetUrlHandler().doOperation(new GetUrlOperation(), new Context(), store);
String url = new GetProxyUrlHandler().doOperation(new GetProxyUrl(), new Context(), store);

//then
assertEquals(expected, url);
Expand Down

0 comments on commit e1b1a85

Please sign in to comment.