Search in sources :

Example 1 with Builder

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));
}
Also used : Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 2 with Builder

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);
}
Also used : Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder)

Example 3 with Builder

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));
}
Also used : AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) FederatedGetTraitsHandlerTest(uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest) Test(org.junit.jupiter.api.Test)

Example 4 with Builder

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);
}
Also used : HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreException(uk.gov.gchq.gaffer.store.StoreException) FederatedGetTraitsHandlerTest(uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest) Test(org.junit.jupiter.api.Test)

Example 5 with Builder

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"));
}
Also used : Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) FederatedGetTraitsHandlerTest(uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest) Test(org.junit.jupiter.api.Test)

Aggregations

Builder (uk.gov.gchq.gaffer.store.schema.Schema.Builder)7 Test (org.junit.jupiter.api.Test)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)3 FederatedGetTraitsHandlerTest (uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest)3 GetSchema (uk.gov.gchq.gaffer.store.operation.GetSchema)3 List (java.util.List)2 Graph (uk.gov.gchq.gaffer.graph.Graph)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 CacheOperationException (uk.gov.gchq.gaffer.cache.exception.CacheOperationException)1 AddGraph (uk.gov.gchq.gaffer.federatedstore.operation.AddGraph)1 StoreException (uk.gov.gchq.gaffer.store.StoreException)1 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)1 GraphLibrary (uk.gov.gchq.gaffer.store.library.GraphLibrary)1 HashMapGraphLibrary (uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary)1