Skip to content

Commit

Permalink
gh-2559 null check & tidy test
Browse files Browse the repository at this point in the history
  • Loading branch information
p3430233 committed Jan 14, 2022
1 parent 8005377 commit 12b7b9d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
30 changes: 28 additions & 2 deletions core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,38 @@
import uk.gov.gchq.gaffer.serialisation.Serialiser;
import uk.gov.gchq.gaffer.store.library.GraphLibrary;
import uk.gov.gchq.gaffer.store.library.NoGraphLibrary;
import uk.gov.gchq.gaffer.store.operation.*;
import uk.gov.gchq.gaffer.store.operation.GetSchema;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.HasTrait;
import uk.gov.gchq.gaffer.store.operation.OperationChainValidator;
import uk.gov.gchq.gaffer.store.operation.OperationUtil;
import uk.gov.gchq.gaffer.store.operation.add.AddSchemaToLibrary;
import uk.gov.gchq.gaffer.store.operation.add.AddStorePropertiesToLibrary;
import uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclaration;
import uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclarations;
import uk.gov.gchq.gaffer.store.operation.handler.*;
import uk.gov.gchq.gaffer.store.operation.handler.AddSchemaToLibraryHandler;
import uk.gov.gchq.gaffer.store.operation.handler.AddStorePropertiesToLibraryHandler;
import uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.CountHandler;
import uk.gov.gchq.gaffer.store.operation.handler.DiscardOutputHandler;
import uk.gov.gchq.gaffer.store.operation.handler.ForEachHandler;
import uk.gov.gchq.gaffer.store.operation.handler.GetSchemaHandler;
import uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler;
import uk.gov.gchq.gaffer.store.operation.handler.GetVariableHandler;
import uk.gov.gchq.gaffer.store.operation.handler.GetVariablesHandler;
import uk.gov.gchq.gaffer.store.operation.handler.GetWalksHandler;
import uk.gov.gchq.gaffer.store.operation.handler.HasTraitHandler;
import uk.gov.gchq.gaffer.store.operation.handler.IfHandler;
import uk.gov.gchq.gaffer.store.operation.handler.LimitHandler;
import uk.gov.gchq.gaffer.store.operation.handler.MapHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationChainHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler;
import uk.gov.gchq.gaffer.store.operation.handler.ReduceHandler;
import uk.gov.gchq.gaffer.store.operation.handler.SetVariableHandler;
import uk.gov.gchq.gaffer.store.operation.handler.ValidateHandler;
import uk.gov.gchq.gaffer.store.operation.handler.ValidateOperationChainHandler;
import uk.gov.gchq.gaffer.store.operation.handler.WhileHandler;
import uk.gov.gchq.gaffer.store.operation.handler.compare.MaxHandler;
import uk.gov.gchq.gaffer.store.operation.handler.compare.MinHandler;
import uk.gov.gchq.gaffer.store.operation.handler.compare.SortHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public Boolean doOperation(final HasTrait operation, final Context context, fina
.options(operation.getOptions())
.build(), context
);
return null != traits && traits.contains(operation.getTrait());

if (null == traits) {
return false;
}
return traits.contains(operation.getTrait());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import uk.gov.gchq.gaffer.store.library.GraphLibrary;
import uk.gov.gchq.gaffer.store.operation.GetSchema;
import uk.gov.gchq.gaffer.store.operation.GetTraits;
import uk.gov.gchq.gaffer.store.operation.HasTrait;
import uk.gov.gchq.gaffer.store.operation.OperationChainValidator;
import uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclaration;
import uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclarations;
Expand Down Expand Up @@ -551,6 +552,7 @@ public void shouldReturnAllSupportedOperations() throws Exception {
Map.class,
If.class,
GetTraits.class,
HasTrait.class,
While.class,
Join.class,
ToSingletonList.class,
Expand Down Expand Up @@ -658,6 +660,7 @@ public void shouldReturnAllSupportedOperationsWhenJobTrackerIsDisabled() throws
DiscardOutput.class,
GetSchema.class,
GetTraits.class,
HasTrait.class,
Map.class,
If.class,
While.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public class HasTraitHandlerTest {
public static final String STORE_ID = "StoreId";
public static final String STRING = "string";
private Store store;
private StoreTrait VISIBILITY = StoreTrait.VISIBILITY;
private StoreTrait QUERY_AGGREGATION = StoreTrait.QUERY_AGGREGATION;
private StoreTrait TRANSFORMATION = StoreTrait.TRANSFORMATION;
private static final StoreTrait VISIBILITY = StoreTrait.VISIBILITY;
private static final StoreTrait QUERY_AGGREGATION = StoreTrait.QUERY_AGGREGATION;
private static final StoreTrait TRANSFORMATION = StoreTrait.TRANSFORMATION;
private Set<StoreTrait> expectedTraits;
private Schema string;

Expand Down Expand Up @@ -77,26 +77,13 @@ public void tearDown() throws Exception {
}
@Test
public void shouldHighlightDifferenceWhenSettingCurrentTraitsOption() throws Exception {
// Given
store.initialise(STORE_ID, new Schema(), new StoreProperties());

// When
Boolean presentInDefaultTraits = store.execute(
new HasTrait.Builder()
.currentTraits(false)
.trait(QUERY_AGGREGATION)
.build(),
new Context(testUser()));

Boolean presentInCurrentTraits = store.execute(
new HasTrait.Builder()
.currentTraits(true)
.trait(QUERY_AGGREGATION)
.build(),
new Context(testUser()));
Boolean presentInDefaultTraits = hasStoreTrait(new Schema(), QUERY_AGGREGATION, false);
Boolean presentInCurrentTraits = hasStoreTrait(new Schema(), QUERY_AGGREGATION, true);

// Then
assertNotEquals(presentInDefaultTraits, presentInCurrentTraits);
assertFalse(presentInCurrentTraits);
assertTrue(presentInDefaultTraits);

}

Expand Down Expand Up @@ -200,8 +187,7 @@ public void shouldGetTraitsForSchemaWithAggregatorAndGroupBy() throws Exception
.build())
.build())
.merge(string)
.build()
, TRANSFORMATION, true);
.build(), TRANSFORMATION, true);

final Boolean absent = hasStoreTrait(new Schema.Builder()
.entity("e1", new SchemaEntityDefinition.Builder()
Expand Down

0 comments on commit 12b7b9d

Please sign in to comment.