use of org.janusgraph.core.JanusGraph 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);
}
use of org.janusgraph.core.JanusGraph 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);
}
use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class JanusGraphSimpleAuthenticatorTest method testSetupEmptyCredGraphNoPassDefault.
@Test(expected = IllegalStateException.class)
public void testSetupEmptyCredGraphNoPassDefault() {
final JanusGraphSimpleAuthenticator authenticator = createMockBuilder(JanusGraphSimpleAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").createMock();
final JanusGraph graph = createMock(JanusGraph.class);
final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
final Map<String, Object> configMap = new HashMap<String, Object>();
configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
configMap.put(JanusGraphSimpleAuthenticator.CONFIG_DEFAULT_USER, "user");
expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
expect(credentialGraph.countUsers()).andReturn(0l);
authenticator.setup(configMap);
}
use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class ElasticSearchConfigTest method testJanusGraphFactoryBuilder.
@Test
public void testJanusGraphFactoryBuilder() {
final JanusGraphFactory.Builder builder = JanusGraphFactory.build();
builder.set("storage.backend", "inmemory");
builder.set("index." + INDEX_NAME + ".elasticsearch.hostname", esr.getHostname() + ":" + ElasticsearchRunner.PORT);
// Must not throw an exception
final JanusGraph graph = builder.open();
assertTrue(graph.isOpen());
graph.close();
}
use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class GraphOfTheGodsFactory method main.
/**
* Calls {@link JanusGraphFactory#open(String)}, passing the JanusGraph configuration file path
* which must be the sole element in the {@code args} array, then calls
* {@link #load(org.janusgraph.core.JanusGraph)} on the opened graph,
* then calls {@link org.janusgraph.core.JanusGraph#close()}
* and returns.
* <p/>
* This method may call {@link System#exit(int)} if it encounters an error, such as
* failure to parse its arguments. Only use this method when executing main from
* a command line. Use one of the other methods on this class ({@link #create(String)}
* or {@link #load(org.janusgraph.core.JanusGraph)}) when calling from
* an enclosing application.
*
* @param args a singleton array containing a path to a JanusGraph config properties file
*/
public static void main(String[] args) {
if (null == args || 1 != args.length) {
System.err.println("Usage: GraphOfTheGodsFactory <janusgraph-config-file>");
System.exit(1);
}
JanusGraph g = JanusGraphFactory.open(args[0]);
load(g);
g.close();
}
Aggregations