use of uk.gov.gchq.gaffer.operation.impl.DiscardOutput in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldAddAllOperationsWithNoAuthsGivenPath.
@Test
public void shouldAddAllOperationsWithNoAuthsGivenPath() throws IOException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
Operation validate = new Validate();
Operation getAdjacentIds = new GetAdjacentIds();
Operation count = new Count<>();
Operation countGroups = new CountGroups();
Operation getElements = new GetElements();
Operation getAllElements = new GetAllElements();
Operation limit = new Limit<>();
final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getElements).then(getAllElements).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(validate).then(getAdjacentIds).then(count).then(discardOutput).then(countGroups).then(getElements).then(getAllElements).then(limit).then(validate).then(count).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.DiscardOutput in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldAddAllOperationsWithFirstAuthsGivenPath.
@Test
public void shouldAddAllOperationsWithFirstAuthsGivenPath() throws IOException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
User user = new User.Builder().opAuths("auth1", "auth2").build();
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
Operation getAdjacentIds = new GetAdjacentIds();
Operation getElements = new GetElements();
Operation getAllElements = new GetAllElements();
final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getElements).then(getAllElements).build();
// When
hook.preExecute(opChain, new Context(user));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(getAdjacentIds).then(getElements).then(getAllElements).then(splitStore).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.DiscardOutput in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldClearListWhenAddingOperations.
@Test
public void shouldClearListWhenAddingOperations() throws IOException {
// Given
final AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
hook.setBefore(null);
hook.setAfter(null);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
Operation count = new Count<>();
Operation getElements = new GetElements();
final OperationChain opChain = new OperationChain.Builder().first(getElements).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(getElements).then(count).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.DiscardOutput in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldHandleNestedOperationChain.
@Test
public void shouldHandleNestedOperationChain() throws SerialisationException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
Operation validate = new Validate();
Operation getAdjacentIds = new GetAdjacentIds();
Operation count = new Count<>();
Operation countGroups = new CountGroups();
Operation getElements = new GetElements();
If ifOp = new If.Builder<>().conditional(new Conditional(new Exists(), new GetElements())).then(new GetElements()).otherwise(new GetAllElements()).build();
Operation getAllElements = new GetAllElements();
Operation limit = new Limit<>();
final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(new OperationChain.Builder().first(getElements).then(getAllElements).build()).then(ifOp).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(validate).then(getAdjacentIds).then(count).then(discardOutput).then((Operation) new OperationChain.Builder().first(countGroups).then(getElements).then(getAllElements).then(limit).then(validate).build()).then(new If.Builder<>().conditional(new Conditional(new Exists(), new OperationChain<>(new CountGroups(), new GetElements()))).then(new OperationChain<>(new CountGroups(), new GetElements())).otherwise(new OperationChain<>(new GetAllElements(), new Limit<>(), new Validate())).build()).then(new Count()).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.DiscardOutput in project Gaffer by gchq.
the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveAllOpAuthsForNestedOperations.
@Test
public void shouldRejectOperationChainWhenUserDoesntHaveAllOpAuthsForNestedOperations() {
// Given
final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
final OperationChain opChain = new OperationChain.Builder().first(new GetElements()).then(new GenerateObjects<>()).then(new DiscardOutput()).then(new TestOperationsImpl(Collections.singletonList(new GetAllElements()))).build();
final User user = new User.Builder().opAuths("SuperUser", "ReadUser", "User").build();
// When/Then
assertThatExceptionOfType(UnauthorisedException.class).isThrownBy(() -> hook.preExecute(opChain, new Context(user))).extracting("message").isNotNull();
}
Aggregations