Skip to content

Commit

Permalink
Gh-3080: Add testing for GafferPopGraphFeatures (#3093)
Browse files Browse the repository at this point in the history
Co-authored-by: GCHQDeveloper314 <94527357+GCHQDeveloper314@users.noreply.github.com>
Co-authored-by: t92549 <80890692+t92549@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 22, 2023
1 parent d48db5e commit 1ef3621
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Features.VertexPropertyFeatures properties() {

@Override
public boolean willAllowId(final Object id) {
return true;
return id != null;
}
}

Expand All @@ -87,7 +87,7 @@ public boolean supportsRemoveProperty() {

@Override
public boolean willAllowId(final Object id) {
return true;
return id != null;
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ public boolean supportsRemoveProperty() {

@Override
public boolean willAllowId(final Object id) {
return true;
return id != null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2023 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.tinkerpop;

import org.apache.tinkerpop.gremlin.structure.Graph.Features;

import org.junit.jupiter.api.Test;

import uk.gov.gchq.gaffer.tinkerpop.GafferPopGraphFeatures.GafferPopGraphEdgeFeatures;
import uk.gov.gchq.gaffer.tinkerpop.GafferPopGraphFeatures.GafferPopGraphGraphFeatures;
import uk.gov.gchq.gaffer.tinkerpop.GafferPopGraphFeatures.GafferPopGraphVertexFeatures;
import uk.gov.gchq.gaffer.tinkerpop.GafferPopGraphFeatures.GafferPopGraphVertexPropertyFeatures;
import uk.gov.gchq.gaffer.types.TypeSubTypeValue;

import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

public class GafferPopGraphFeaturesTest {
public static final String STRING_ID = "testId";
public static final Integer INT_ID = 1;
public static final UUID UUID_ID = UUID.randomUUID();
public static final TypeSubTypeValue TSTV_ID = new TypeSubTypeValue("myType", "mySubType", "30");
final GafferPopGraph graph = mock(GafferPopGraph.class);
final Features features = new GafferPopGraphFeatures();

@Test
void shouldHaveCertainGafferPopGraphGraphFeatures() {
given(graph.features()).willReturn(features);
final Features graphFeatures = graph.features();

assertThat(graphFeatures.graph()).isInstanceOf(GafferPopGraphGraphFeatures.class);
assertThat(graphFeatures.graph().supportsTransactions()).isFalse();
assertThat(graphFeatures.graph().supportsThreadedTransactions()).isFalse();
assertThat(graphFeatures.graph().supportsComputer()).isFalse();
}

@Test
void shouldHaveCertainGafferPopGraphVertexFeatures() {
given(graph.features()).willReturn(features);

final Features vertexFeatures = graph.features();

assertThat(vertexFeatures.vertex()).isInstanceOf(GafferPopGraphVertexFeatures.class);
assertThat(vertexFeatures.vertex().supportsRemoveVertices()).isFalse();
assertThat(vertexFeatures.vertex().supportsRemoveProperty()).isFalse();
assertThat(vertexFeatures.vertex().willAllowId(STRING_ID)).isTrue();
assertThat(vertexFeatures.vertex().willAllowId(INT_ID)).isTrue();
assertThat(vertexFeatures.vertex().willAllowId(UUID_ID)).isTrue();
assertThat(vertexFeatures.vertex().willAllowId(TSTV_ID)).isTrue();
assertThat(vertexFeatures.vertex().willAllowId(null)).isFalse();
}

@Test
void shouldHaveCertainGafferPopGraphEdgeFeatures() {
given(graph.features()).willReturn(features);

final Features edgeFeatures = graph.features();

assertThat(edgeFeatures.edge()).isInstanceOf(GafferPopGraphEdgeFeatures.class);
assertThat(edgeFeatures.edge().supportsRemoveEdges()).isFalse();
assertThat(edgeFeatures.edge().supportsRemoveProperty()).isFalse();
assertThat(edgeFeatures.edge().willAllowId(STRING_ID)).isTrue();
assertThat(edgeFeatures.vertex().willAllowId(INT_ID)).isTrue();
assertThat(edgeFeatures.vertex().willAllowId(UUID_ID)).isTrue();
assertThat(edgeFeatures.vertex().willAllowId(TSTV_ID)).isTrue();
assertThat(edgeFeatures.vertex().willAllowId(null)).isFalse();
}

@Test
void shouldReturnStringOfFeatures() {
given(graph.features()).willReturn(features);

assertThat(graph.features().toString()).contains("FEATURES", "GraphFeatures", "VariableFeatures",
"VertexFeatures", "VertexPropertyFeatures", "EdgeFeatures", "EdgePropertyFeatures");
}

@Test
void shouldHaveCertainGafferPopGraphVertexPropertyFeatures() {
given(graph.features()).willReturn(features);

final Features.VertexPropertyFeatures vertexPropertyFeatures = graph.features().vertex().properties();

assertThat(vertexPropertyFeatures).isInstanceOf(GafferPopGraphVertexPropertyFeatures.class);
assertThat(vertexPropertyFeatures.supportsRemoveProperty()).isFalse();
assertThat(vertexPropertyFeatures.willAllowId(STRING_ID)).isTrue();
assertThat(vertexPropertyFeatures.willAllowId(INT_ID)).isTrue();
assertThat(vertexPropertyFeatures.willAllowId(UUID_ID)).isTrue();
assertThat(vertexPropertyFeatures.willAllowId(TSTV_ID)).isTrue();
assertThat(vertexPropertyFeatures.willAllowId(null)).isFalse();
}
}

0 comments on commit 1ef3621

Please sign in to comment.