-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into gh-2840-mapstore-matchedvertex-inconsistent
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../java/uk/gov/gchq/gaffer/federated/simple/operation/FederatedOperationChainValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2024 Crown Copyright | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.gchq.gaffer.federated.simple.operation; | ||
|
||
import uk.gov.gchq.gaffer.core.exception.GafferRuntimeException; | ||
import uk.gov.gchq.gaffer.operation.Operation; | ||
import uk.gov.gchq.gaffer.operation.OperationException; | ||
import uk.gov.gchq.gaffer.store.Context; | ||
import uk.gov.gchq.gaffer.store.Store; | ||
import uk.gov.gchq.gaffer.store.operation.GetSchema; | ||
import uk.gov.gchq.gaffer.store.operation.OperationChainValidator; | ||
import uk.gov.gchq.gaffer.store.schema.Schema; | ||
import uk.gov.gchq.gaffer.store.schema.ViewValidator; | ||
import uk.gov.gchq.gaffer.user.User; | ||
|
||
/** | ||
* Extends {@link OperationChainValidator} and uses the FederatedStore to get | ||
* the merged schema based on the operation options. | ||
*/ | ||
public class FederatedOperationChainValidator extends OperationChainValidator { | ||
|
||
public FederatedOperationChainValidator(final ViewValidator viewValidator) { | ||
super(viewValidator); | ||
} | ||
|
||
@Override | ||
protected Schema getSchema(final Operation operation, final User user, final Store store) { | ||
try { | ||
return store.execute(new GetSchema.Builder().options(operation.getOptions()).build(), new Context(user)); | ||
} catch (final OperationException e) { | ||
throw new GafferRuntimeException("Unable to get merged schema for graph " + store.getGraphId(), e); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...a/uk/gov/gchq/gaffer/federated/simple/operation/FederatedOperationChainValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2024 Crown Copyright | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.gchq.gaffer.federated.simple.operation; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import uk.gov.gchq.gaffer.core.exception.GafferRuntimeException; | ||
import uk.gov.gchq.gaffer.federated.simple.FederatedStore; | ||
import uk.gov.gchq.gaffer.operation.Operation; | ||
import uk.gov.gchq.gaffer.operation.OperationException; | ||
import uk.gov.gchq.gaffer.store.Context; | ||
import uk.gov.gchq.gaffer.store.operation.GetSchema; | ||
import uk.gov.gchq.gaffer.store.schema.Schema; | ||
import uk.gov.gchq.gaffer.store.schema.ViewValidator; | ||
import uk.gov.gchq.gaffer.user.User; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
class FederatedOperationChainValidatorTest { | ||
final ViewValidator viewValidator = mock(ViewValidator.class); | ||
final FederatedOperationChainValidator validator = new FederatedOperationChainValidator(viewValidator); | ||
final FederatedStore store = mock(FederatedStore.class); | ||
final User user = mock(User.class); | ||
final Operation op = mock(Operation.class); | ||
final Schema schema = mock(Schema.class); | ||
|
||
@Test | ||
void shouldGetMergedSchema() throws OperationException { | ||
// Given | ||
when(store.execute(any(GetSchema.class), any(Context.class))).thenReturn(schema); | ||
|
||
// When | ||
final Schema result = validator.getSchema(op, user, store); | ||
|
||
verify(store).execute(any(GetSchema.class), any(Context.class)); | ||
// Then | ||
assertThat(result).isEqualTo(schema); | ||
} | ||
|
||
@Test | ||
void shouldThrowException() throws OperationException { | ||
// Given | ||
when(store.execute(any(GetSchema.class), any(Context.class))).thenThrow(GafferRuntimeException.class); | ||
|
||
// When/Then | ||
try { | ||
validator.getSchema(op, user, store); | ||
fail("Exception expected"); | ||
} catch (final Exception e) { | ||
verify(store).execute(any(GetSchema.class), any(Context.class)); | ||
assertThat(e).isInstanceOf(GafferRuntimeException.class); | ||
} | ||
} | ||
} |