use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class OperationsTest method runForSecurityLevel.
protected String runForSecurityLevel(Executable executable, AccessMode mode, boolean shoudldBeAuthorized) throws Exception {
SecurityContext securityContext = SecurityContext.authDisabled(mode, ClientConnectionInfo.EMBEDDED_CONNECTION, DB_NAME);
when(transaction.securityContext()).thenReturn(securityContext);
when(transaction.securityAuthorizationHandler()).thenReturn(new SecurityAuthorizationHandler(securityLog));
when(nodeCursor.next()).thenReturn(true);
when(nodeCursor.hasLabel(2)).thenReturn(false);
when(nodeCursor.hasLabel(3)).thenReturn(true);
when(tokenHolders.labelTokens().getTokenById(anyInt())).thenReturn(new NamedToken("Label", 2));
if (shoudldBeAuthorized) {
assertAuthorized(executable);
return null;
} else {
AuthorizationViolationException exception = assertThrows(AuthorizationViolationException.class, executable);
return exception.getMessage();
}
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class BatchingTokenRepositoryTest method shouldFlushNewTokens.
@Test
void shouldFlushNewTokens() {
// given
try (NeoStores stores = newNeoStores(StoreType.PROPERTY_KEY_TOKEN, StoreType.PROPERTY_KEY_TOKEN_NAME)) {
TokenStore<PropertyKeyTokenRecord> tokenStore = stores.getPropertyKeyTokenStore();
int rounds = 3;
int tokensPerRound = 4;
BatchingPropertyKeyTokenRepository repo = new BatchingPropertyKeyTokenRepository(tokenStore);
// when first creating some tokens
int expectedId = 0;
int tokenNameAsInt = 0;
for (int round = 0; round < rounds; round++) {
for (int i = 0; i < tokensPerRound; i++) {
int tokenId = repo.getOrCreateId(String.valueOf(tokenNameAsInt++));
assertEquals(expectedId + i, tokenId);
}
assertEquals(expectedId, tokenStore.getHighId());
repo.flush(NULL);
assertEquals(expectedId + tokensPerRound, tokenStore.getHighId());
expectedId += tokensPerRound;
}
repo.flush(NULL);
List<NamedToken> tokens = tokenStore.getTokens(NULL);
assertEquals(tokensPerRound * rounds, tokens.size());
for (NamedToken token : tokens) {
assertEquals(token.id(), parseInt(token.name()));
}
}
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class TokenRegistryTest method putAllMustThrowOnDuplicateNameWithExistingToken.
@Test
void putAllMustThrowOnDuplicateNameWithExistingToken() {
registry.put(new NamedToken(INBOUND1_TYPE, 1));
assertThrows(NonUniqueTokenException.class, () -> registry.putAll(singletonList(new NamedToken(INBOUND1_TYPE, 2))));
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class TokenRegistryTest method setInitialTokensMustNotThrowOnDuplicateWithExistingToken.
@Test
void setInitialTokensMustNotThrowOnDuplicateWithExistingToken() {
registry.put(new NamedToken(INBOUND1_TYPE, 1));
registry.setInitialTokens(singletonList(new NamedToken(INBOUND1_TYPE, 1)));
}
use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.
the class TokenRegistry method insertAllChecked.
private Registries insertAllChecked(List<NamedToken> tokens, Registries registries) {
MutableObjectIntMap<String> uniquePublicNames = new ObjectIntHashMap<>();
MutableObjectIntMap<String> uniqueInternalNames = new ObjectIntHashMap<>();
MutableIntSet uniqueIds = new IntHashSet();
for (NamedToken token : tokens) {
if (token.isInternal()) {
checkNameUniqueness(uniqueInternalNames, token, registries);
checkNameUniqueness(registries.internalNameToId, token, registries);
uniqueInternalNames.put(token.name(), token.id());
} else {
checkNameUniqueness(uniquePublicNames, token, registries);
checkNameUniqueness(registries.publicNameToId, token, registries);
uniquePublicNames.put(token.name(), token.id());
}
if (!uniqueIds.add(token.id()) || registries.idToToken.containsKey(token.id())) {
NamedToken existingToken = registries.idToToken.get(token.id());
throw new NonUniqueTokenException(tokenType, token, existingToken);
}
insertUnchecked(token, registries);
}
return registries;
}
Aggregations