Search in sources :

Example 1 with PropertyKeyMaker

use of org.janusgraph.core.schema.PropertyKeyMaker in project janusgraph by JanusGraph.

the class SaslAndHMACAuthenticatorTest method testSetupEmptyCredGraphNoUserIndex.

@Test
public void testSetupEmptyCredGraphNoUserIndex() {
    final SaslAndHMACAuthenticator authenticator = createMockBuilder(SaslAndHMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").addMockedMethod("createHMACAuthenticator").createMock();
    final Map<String, Object> configMap = new HashMap<String, Object>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(SaslAndHMACAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    configMap.put(SaslAndHMACAuthenticator.CONFIG_DEFAULT_USER, "user");
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final ManagementSystem mgmt = createMock(ManagementSystem.class);
    final JanusGraphSimpleAuthenticator janusSimpleAuthenticator = createMock(JanusGraphSimpleAuthenticator.class);
    final HMACAuthenticator hmacAuthenticator = createMock(HMACAuthenticator.class);
    final SimpleAuthenticator simpleAuthenticator = createMock(SimpleAuthenticator.class);
    final Transaction tx = createMock(Transaction.class);
    final PropertyKey pk = createMock(PropertyKey.class);
    final PropertyKeyMaker pkm = createMock(PropertyKeyMaker.class);
    final JanusGraphManagement.IndexBuilder indexBuilder = createMock(JanusGraphManagement.IndexBuilder.class);
    final JanusGraphIndex index = createMock(JanusGraphIndex.class);
    final PropertyKey[] pks = { pk };
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(authenticator.createSimpleAuthenticator()).andReturn(janusSimpleAuthenticator);
    expect(authenticator.createHMACAuthenticator()).andReturn(hmacAuthenticator);
    hmacAuthenticator.setup(configMap);
    expectLastCall();
    expect(janusSimpleAuthenticator.createSimpleAuthenticator()).andReturn(simpleAuthenticator);
    simpleAuthenticator.setup(configMap);
    expectLastCall();
    expect(credentialGraph.findUser("user")).andReturn(null);
    expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
    expect(graph.openManagement()).andReturn(mgmt).times(2);
    expect(graph.tx()).andReturn(tx);
    expect(index.getFieldKeys()).andReturn(pks);
    expect(index.getIndexStatus(eq(pk))).andReturn(SchemaStatus.ENABLED);
    tx.rollback();
    expectLastCall();
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(false);
    expect(mgmt.makePropertyKey(PROPERTY_USERNAME)).andReturn(pkm);
    expect(pkm.dataType(eq(String.class))).andReturn(pkm);
    expect(pkm.cardinality(Cardinality.SINGLE)).andReturn(pkm);
    expect(pkm.make()).andReturn(pk);
    expect(mgmt.buildIndex(eq("byUsername"), eq(Vertex.class))).andReturn(indexBuilder);
    expect(mgmt.getGraphIndex(eq("byUsername"))).andReturn(index);
    expect(indexBuilder.addKey(eq(pk))).andReturn(indexBuilder);
    expect(indexBuilder.unique()).andReturn(indexBuilder);
    expect(indexBuilder.buildCompositeIndex()).andReturn(index);
    mgmt.commit();
    expectLastCall();
    mgmt.rollback();
    expectLastCall();
    replayAll();
    authenticator.setup(configMap);
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) HashMap(java.util.HashMap) JanusGraph(org.janusgraph.core.JanusGraph) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) SimpleAuthenticator(org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 2 with PropertyKeyMaker

use of org.janusgraph.core.schema.PropertyKeyMaker in project janusgraph by JanusGraph.

the class JanusGraphSimpleAuthenticatorTest method testSetupEmptyCredGraphNoUserIndex.

@Test
public void testSetupEmptyCredGraphNoUserIndex() {
    final JanusGraphSimpleAuthenticator authenticator = createMockBuilder(JanusGraphSimpleAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").createMock();
    final Map<String, Object> configMap = new HashMap<String, Object>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_USER, "user");
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final ManagementSystem mgmt = createMock(ManagementSystem.class);
    final Transaction tx = createMock(Transaction.class);
    final PropertyKey pk = createMock(PropertyKey.class);
    final PropertyKeyMaker pkm = createMock(PropertyKeyMaker.class);
    final JanusGraphManagement.IndexBuilder indexBuilder = createMock(JanusGraphManagement.IndexBuilder.class);
    final JanusGraphIndex index = createMock(JanusGraphIndex.class);
    final PropertyKey[] pks = { pk };
    final SimpleAuthenticator sa = createMock(SimpleAuthenticator.class);
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(authenticator.createSimpleAuthenticator()).andReturn(sa);
    expect(credentialGraph.findUser("user")).andReturn(null);
    expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
    expect(graph.openManagement()).andReturn(mgmt);
    expect(graph.tx()).andReturn(tx);
    sa.setup(configMap);
    EasyMock.expectLastCall();
    graph.close();
    EasyMock.expectLastCall();
    tx.rollback();
    EasyMock.expectLastCall();
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(false);
    expect(mgmt.makePropertyKey(PROPERTY_USERNAME)).andReturn(pkm);
    expect(pkm.dataType(eq(String.class))).andReturn(pkm);
    expect(pkm.cardinality(Cardinality.SINGLE)).andReturn(pkm);
    expect(pkm.make()).andReturn(pk);
    expect(mgmt.buildIndex(eq("byUsername"), eq(Vertex.class))).andReturn(indexBuilder);
    expect(mgmt.getGraphIndex(eq("byUsername"))).andReturn(index);
    expect(indexBuilder.addKey(eq(pk))).andReturn(indexBuilder);
    expect(indexBuilder.unique()).andReturn(indexBuilder);
    expect(indexBuilder.buildCompositeIndex()).andReturn(index);
    expect(index.getFieldKeys()).andReturn(pks);
    expect(index.getIndexStatus(eq(pk))).andReturn(SchemaStatus.ENABLED);
    expect(graph.tx()).andReturn(tx);
    expect(graph.openManagement()).andReturn(mgmt);
    tx.rollback();
    EasyMock.expectLastCall().atLeastOnce();
    mgmt.commit();
    EasyMock.expectLastCall();
    mgmt.rollback();
    EasyMock.expectLastCall();
    replayAll();
    authenticator.setup(configMap);
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) HashMap(java.util.HashMap) JanusGraph(org.janusgraph.core.JanusGraph) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) SimpleAuthenticator(org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 3 with PropertyKeyMaker

use of org.janusgraph.core.schema.PropertyKeyMaker in project janusgraph by JanusGraph.

the class JanusGraphDefaultSchemaMakerTest method mockPropertyKeyMaker.

private PropertyKeyMaker mockPropertyKeyMaker() {
    PropertyKeyMaker propertyKeyMaker = createMock(PropertyKeyMaker.class);
    PropertyKey pk = createMock(PropertyKey.class);
    expect(propertyKeyMaker.make()).andReturn(pk).anyTimes();
    expect(propertyKeyMaker.getName()).andReturn("Quux").anyTimes();
    expect(propertyKeyMaker.cardinality(Cardinality.SINGLE)).andReturn(propertyKeyMaker).anyTimes();
    expect(propertyKeyMaker.dataType(String.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(Character.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(Boolean.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(Byte.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(Short.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(Integer.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(Long.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(Float.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(Double.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(Date.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(Geoshape.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(UUID.class)).andReturn(propertyKeyMaker);
    expect(propertyKeyMaker.dataType(Object.class)).andReturn(propertyKeyMaker);
    replayAll();
    return propertyKeyMaker;
}
Also used : PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) PropertyKey(org.janusgraph.core.PropertyKey)

Example 4 with PropertyKeyMaker

use of org.janusgraph.core.schema.PropertyKeyMaker in project janusgraph by JanusGraph.

the class HMACAuthenticatorTest method testSetupEmptyCredGraphNoUserIndex.

@Test
public void testSetupEmptyCredGraphNoUserIndex() {
    final HMACAuthenticator authenticator = createMockBuilder(HMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").createMock();
    final Map<String, Object> configMap = new HashMap<String, Object>();
    configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
    configMap.put(HMACAuthenticator.CONFIG_HMAC_SECRET, "secret");
    configMap.put(HMACAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
    configMap.put(HMACAuthenticator.CONFIG_DEFAULT_USER, "user");
    final JanusGraph graph = createMock(JanusGraph.class);
    final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
    final ManagementSystem mgmt = createMock(ManagementSystem.class);
    final Transaction tx = createMock(Transaction.class);
    final PropertyKey pk = createMock(PropertyKey.class);
    final PropertyKeyMaker pkm = createMock(PropertyKeyMaker.class);
    final JanusGraphManagement.IndexBuilder indexBuilder = createMock(JanusGraphManagement.IndexBuilder.class);
    final JanusGraphIndex index = createMock(JanusGraphIndex.class);
    final PropertyKey[] pks = { pk };
    expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
    expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
    expect(credentialGraph.findUser("user")).andReturn(null);
    expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
    expect(graph.openManagement()).andReturn(mgmt).times(2);
    expect(graph.tx()).andReturn(tx);
    expect(index.getFieldKeys()).andReturn(pks);
    expect(index.getIndexStatus(eq(pk))).andReturn(SchemaStatus.ENABLED);
    tx.rollback();
    expectLastCall();
    expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(false);
    expect(mgmt.makePropertyKey(PROPERTY_USERNAME)).andReturn(pkm);
    expect(pkm.dataType(eq(String.class))).andReturn(pkm);
    expect(pkm.cardinality(Cardinality.SINGLE)).andReturn(pkm);
    expect(pkm.make()).andReturn(pk);
    expect(mgmt.buildIndex(eq("byUsername"), eq(Vertex.class))).andReturn(indexBuilder);
    expect(mgmt.getGraphIndex(eq("byUsername"))).andReturn(index);
    expect(indexBuilder.addKey(eq(pk))).andReturn(indexBuilder);
    expect(indexBuilder.unique()).andReturn(indexBuilder);
    expect(indexBuilder.buildCompositeIndex()).andReturn(index);
    mgmt.commit();
    expectLastCall();
    mgmt.rollback();
    expectLastCall();
    replayAll();
    authenticator.setup(configMap);
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) CredentialGraph(org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph) HashMap(java.util.HashMap) JanusGraph(org.janusgraph.core.JanusGraph) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 5 with PropertyKeyMaker

use of org.janusgraph.core.schema.PropertyKeyMaker in project janusgraph by JanusGraph.

the class JanusGraphDefaultSchemaMakerTest method testMakePropertyKey.

@Test
public void testMakePropertyKey() {
    PropertyKeyMaker pkm = mockPropertyKeyMaker();
    DefaultSchemaMaker schemaMaker = JanusGraphDefaultSchemaMaker.INSTANCE;
    byte b = 100;
    short s = 10000;
    schemaMaker.makePropertyKey(pkm, "Foo");
    schemaMaker.makePropertyKey(pkm, 'f');
    schemaMaker.makePropertyKey(pkm, true);
    schemaMaker.makePropertyKey(pkm, b);
    schemaMaker.makePropertyKey(pkm, s);
    schemaMaker.makePropertyKey(pkm, 100);
    schemaMaker.makePropertyKey(pkm, 100L);
    schemaMaker.makePropertyKey(pkm, 100.0f);
    schemaMaker.makePropertyKey(pkm, 1.23e2);
    schemaMaker.makePropertyKey(pkm, new Date());
    schemaMaker.makePropertyKey(pkm, Geoshape.point(42.3601f, 71.0589f));
    schemaMaker.makePropertyKey(pkm, UUID.randomUUID());
    schemaMaker.makePropertyKey(pkm, new Object());
    verifyAll();
}
Also used : PropertyKeyMaker(org.janusgraph.core.schema.PropertyKeyMaker) DefaultSchemaMaker(org.janusgraph.core.schema.DefaultSchemaMaker) Date(java.util.Date) Test(org.junit.Test)

Aggregations

PropertyKeyMaker (org.janusgraph.core.schema.PropertyKeyMaker)6 PropertyKey (org.janusgraph.core.PropertyKey)5 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 CredentialGraph (org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraph)3 Transaction (org.apache.tinkerpop.gremlin.structure.Transaction)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 JanusGraph (org.janusgraph.core.JanusGraph)3 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)3 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)3 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)3 SimpleAuthenticator (org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator)2 Date (java.util.Date)1 AtlasCardinality (org.apache.atlas.repository.graphdb.AtlasCardinality)1 AtlasPropertyKey (org.apache.atlas.repository.graphdb.AtlasPropertyKey)1 Cardinality (org.janusgraph.core.Cardinality)1 DefaultSchemaMaker (org.janusgraph.core.schema.DefaultSchemaMaker)1