use of uk.gov.gchq.gaffer.store.schema.Schema.Builder in project Gaffer by gchq.
the class AbstractGraphLibraryTest method shouldNotOverwriteSchemaWithClashingName.
@Test
public void shouldNotOverwriteSchemaWithClashingName() throws Exception {
final String clashingId = "clashingId";
byte[] entitySchema = new Builder().entity("e1", new SchemaEntityDefinition.Builder().property("p1", "string").build()).type("string", String.class).build().toJson(true);
byte[] edgeSchema = new Builder().edge("e1", new SchemaEdgeDefinition.Builder().property("p1", "string").build()).type("string", String.class).build().toJson(true);
graphLibrary.addSchema(clashingId, Schema.fromJson(entitySchema));
assertThatExceptionOfType(OverwritingException.class).isThrownBy(() -> graphLibrary.add("graph", clashingId, Schema.fromJson(edgeSchema), TEST_PROPERTIES_ID, new StoreProperties())).withMessageContaining("schemaId clashingId already exists with a different schema");
Schema schemaFromLibrary = graphLibrary.getSchema(clashingId);
assertTrue(JsonUtil.equals(entitySchema, schemaFromLibrary.toJson(true)));
assertFalse(JsonUtil.equals(schemaFromLibrary.toJson(true), edgeSchema));
}
use of uk.gov.gchq.gaffer.store.schema.Schema.Builder in project Gaffer by gchq.
the class FederatedStoreTest method addGraphWithPaths.
private void addGraphWithPaths(final String graphId, final StoreProperties properties, final String... schemaPath) throws OperationException {
Schema.Builder schema = new Builder();
for (String path : schemaPath) {
schema.merge(getSchemaFromPath(path));
}
store.execute(new AddGraph.Builder().graphId(graphId).storeProperties(properties).isPublic(true).schema(schema.build()).build(), userContext);
}
use of uk.gov.gchq.gaffer.store.schema.Schema.Builder in project Gaffer by gchq.
the class FederatedStoreTest method shouldAddGraphWithPropertiesFromGraphLibraryOverridden.
@Test
public void shouldAddGraphWithPropertiesFromGraphLibraryOverridden() throws Exception {
// Given
assertFalse(library.getProperties(ID_PROPS_ACC_2).containsKey(UNUSUAL_KEY), KEY_DOES_NOT_BELONG);
// When
Builder schema = new Builder();
for (String path : new String[] { PATH_BASIC_ENTITY_SCHEMA_JSON }) {
schema.merge(getSchemaFromPath(path));
}
store.execute(new AddGraph.Builder().graphId(ACC_ID_2).storeProperties(PROPERTIES_ALT).parentPropertiesId(ID_PROPS_ACC_2).isPublic(true).schema(schema.build()).build(), userContext);
// Then
assertEquals(1, store.getGraphs(blankUser, null, ignore).size());
assertTrue(store.getGraphs(blankUser, null, ignore).iterator().next().getStoreProperties().containsKey(UNUSUAL_KEY));
assertFalse(library.getProperties(ID_PROPS_ACC_2).containsKey(UNUSUAL_KEY), KEY_DOES_NOT_BELONG);
assertNotNull(store.getGraphs(blankUser, null, ignore).iterator().next().getStoreProperties().getProperties().getProperty(UNUSUAL_KEY));
}
use of uk.gov.gchq.gaffer.store.schema.Schema.Builder in project Gaffer by gchq.
the class FederatedStoreTest method shouldThrowWithPropertiesErrorFromGraphLibrary.
@Test
public void shouldThrowWithPropertiesErrorFromGraphLibrary() throws Exception {
Builder schema = new Builder();
for (String path : new String[] { PATH_BASIC_EDGE_SCHEMA_JSON }) {
schema.merge(getSchemaFromPath(path));
}
final GraphLibrary mockLibrary = Mockito.mock(GraphLibrary.class);
final String error = "test Something went wrong";
Mockito.when(mockLibrary.getProperties(ID_PROPS_ACC_2)).thenThrow(new IllegalArgumentException(error));
store.setGraphLibrary(mockLibrary);
clearCache();
store.initialise(FEDERATED_STORE_ID, null, federatedProperties);
try {
store.execute(new AddGraph.Builder().graphId(ACC_ID_2).parentPropertiesId(ID_PROPS_ACC_2).isPublic(true).schema(schema.build()).build(), userContext);
fail("exception not thrown");
} catch (Exception e) {
assertEquals(error, e.getCause().getMessage());
}
Mockito.verify(mockLibrary).getProperties(ID_PROPS_ACC_2);
}
use of uk.gov.gchq.gaffer.store.schema.Schema.Builder in project Gaffer by gchq.
the class FederatedStoreTest method shouldAddGraphWithPropertiesAndSchemaFromGraphLibraryOverridden.
@Test
public void shouldAddGraphWithPropertiesAndSchemaFromGraphLibraryOverridden() throws Exception {
// Given
assertFalse(library.getProperties(ID_PROPS_ACC_2).containsKey(UNUSUAL_KEY), KEY_DOES_NOT_BELONG);
// When
Builder tempSchema = new Builder();
for (String path : new String[] { PATH_BASIC_EDGE_SCHEMA_JSON }) {
tempSchema.merge(getSchemaFromPath(path));
}
store.execute(new AddGraph.Builder().graphId(ACC_ID_2).isPublic(true).storeProperties(PROPERTIES_ALT).parentPropertiesId(ID_PROPS_ACC_2).schema(tempSchema.build()).parentSchemaIds(Lists.newArrayList(ID_SCHEMA_ENTITY)).build(), userContext);
// Then
assertEquals(1, store.getGraphs(blankUser, null, ignore).size());
assertTrue(store.getGraphs(blankUser, null, ignore).iterator().next().getStoreProperties().containsKey(UNUSUAL_KEY));
assertFalse(library.getProperties(ID_PROPS_ACC_2).containsKey(UNUSUAL_KEY), KEY_DOES_NOT_BELONG);
assertNotNull(store.getGraphs(blankUser, null, ignore).iterator().next().getStoreProperties().getProperties().getProperty(UNUSUAL_KEY));
assertTrue(store.getGraphs(blankUser, null, ignore).iterator().next().getSchema().getEntityGroups().contains("BasicEntity"));
}
Aggregations