use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class SaslAndHMACAuthenticatorTest method testSetupEmptyCredGraphNoPassDefault.
@Test(expected = IllegalStateException.class)
public void testSetupEmptyCredGraphNoPassDefault() {
final SaslAndHMACAuthenticator authenticator = createMockBuilder(SaslAndHMACAuthenticator.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(SaslAndHMACAuthenticator.CONFIG_DEFAULT_USER, "user");
expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
authenticator.setup(configMap);
}
use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class SaslAndHMACAuthenticatorTest method testPassEmptyCredGraphUserIndex.
@Test
public void testPassEmptyCredGraphUserIndex() {
final SaslAndHMACAuthenticator authenticator = createMockBuilder(SaslAndHMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").addMockedMethod("createSimpleAuthenticator").addMockedMethod("createHMACAuthenticator").createMock();
final Map<String, Object> configMap = new HashMap<>();
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 HMACAuthenticator hmacAuthenticator = createMock(HMACAuthenticator.class);
final JanusGraphSimpleAuthenticator janusSimpleAuthenticator = createMock(JanusGraphSimpleAuthenticator.class);
final SimpleAuthenticator simpleAuthenticator = createMock(SimpleAuthenticator.class);
final Transaction tx = createMock(Transaction.class);
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(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(true);
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);
tx.rollback();
expectLastCall();
replayAll();
authenticator.setup(configMap);
}
use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class SaslAndHMACAuthenticatorTest method testSetupDefaultUserNonEmptyCredGraph.
@Test
public void testSetupDefaultUserNonEmptyCredGraph() {
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);
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(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(true);
expect(graph.openManagement()).andReturn(mgmt);
expect(graph.tx()).andReturn(tx);
expect(credentialGraph.findUser("user")).andReturn(createMock(Vertex.class));
tx.rollback();
expectLastCall();
replayAll();
authenticator.setup(configMap);
}
use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class AbstractJanusGraphProvider method clear.
// @Override
// public <ID> ID reconstituteGraphSONIdentifier(final Class<? extends Element> clazz, final Object id) {
// if (Edge.class.isAssignableFrom(clazz)) {
// // JanusGraphSONModule toStrings the edgeId - expect a String value for the id
// if (!(id instanceof String)) throw new RuntimeException("Expected a String value for the RelationIdentifier");
// return (ID) RelationIdentifier.parse((String) id);
// } else {
// return (ID) id;
// }
// }
@Override
public void clear(Graph g, final Configuration configuration) throws Exception {
if (null != g) {
while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph();
JanusGraph graph = (JanusGraph) g;
if (graph.isOpen()) {
if (g.tx().isOpen())
g.tx().rollback();
try {
g.close();
} catch (IOException | IllegalStateException e) {
logger.warn("Titan graph may not have closed cleanly", e);
}
}
}
WriteConfiguration config = new CommonsConfiguration(configuration);
BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE);
if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) {
JanusGraphBaseTest.clearGraph(config);
}
}
use of org.janusgraph.core.JanusGraph in project janusgraph by JanusGraph.
the class AbstractJanusGraphProvider method loadGraphData.
@Override
public void loadGraphData(final Graph g, final LoadGraphWith loadGraphWith, final Class testClass, final String testName) {
if (loadGraphWith != null) {
this.createIndices((JanusGraph) g, loadGraphWith.value());
} else {
if (TransactionTest.class.equals(testClass) && testName.equalsIgnoreCase("shouldExecuteWithCompetingThreads")) {
JanusGraphManagement management = ((JanusGraph) g).openManagement();
management.makePropertyKey("blah").dataType(Double.class).make();
management.makePropertyKey("bloop").dataType(Integer.class).make();
management.makePropertyKey("test").dataType(Object.class).make();
management.makeEdgeLabel("friend").make();
management.commit();
}
}
super.loadGraphData(g, loadGraphWith, testClass, testName);
}
Aggregations