Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into gh-3108-improve-te…
Browse files Browse the repository at this point in the history
…sting-for-gafferpopvertexproperty
  • Loading branch information
tb06904 committed Nov 22, 2023
2 parents 290a89a + 1ef3621 commit 7486658
Show file tree
Hide file tree
Showing 7 changed files with 433 additions and 5 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
Expand Up @@ -61,8 +61,8 @@ public CloseableIterator<R> execute(final ServiceCallContext ctx, final Map para
.build())
.build()).iterator());
} else {
return (CloseableIterator<R>) CloseableIterator.of(Arrays.asList(graph.execute(new OperationChain.Builder()
.first(new NamedOperation.Builder()
return CloseableIterator.of(Arrays.asList(graph.execute(new OperationChain.Builder()
.first(new NamedOperation.Builder<Void, R>()
.name(name)
.build())
.build())).iterator());
Expand Down
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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.service;

import org.apache.tinkerpop.gremlin.structure.service.Service;
import org.junit.jupiter.api.Test;

import uk.gov.gchq.gaffer.tinkerpop.GafferPopGraph;

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

public class GafferPopNamedOperationServiceFactoryTest {

private final GafferPopGraph graph = mock(GafferPopGraph.class);

@Test
void shouldCreateServiceWhenStartIsTrue() {
// Given
final GafferPopNamedOperationServiceFactory<String, String> namedOpServiceFactory = new GafferPopNamedOperationServiceFactory<>(graph);

// When
final Service<String, String> namedOpService = namedOpServiceFactory.createService(true, null);

// Then
assertThat(namedOpService)
.isNotNull()
.isExactlyInstanceOf(GafferPopNamedOperationService.class);
}

@Test
void shouldNotCreateServiceWhenStartIsFalse() {
// Given
final GafferPopNamedOperationServiceFactory<String, String> namedOpServiceFactory = new GafferPopNamedOperationServiceFactory<>(graph);

// When / Then
assertThatThrownBy(() -> namedOpServiceFactory.createService(false, null))
.isExactlyInstanceOf(UnsupportedOperationException.class)
.hasMessage(Service.Exceptions.cannotUseMidTraversal);
}

@Test
void shouldGetName() {
// When
final GafferPopNamedOperationServiceFactory<String, String> namedOpServiceFactory = new GafferPopNamedOperationServiceFactory<>(graph);

// Then
assertThat(namedOpServiceFactory.getName())
.isNotNull()
.isEqualTo("namedoperation");
}

@Test
void shouldSupportedTypes() {
// When
final GafferPopNamedOperationServiceFactory<String, String> namedOpServiceFactory = new GafferPopNamedOperationServiceFactory<>(graph);

// Then
assertThat(namedOpServiceFactory.getSupportedTypes())
.isNotNull()
.containsExactly(Service.Type.Start);
}
}
Loading

0 comments on commit 7486658

Please sign in to comment.