Search in sources :

Example 16 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistryTest method puttingInternalTokenWithDuplicateNamedNotAllowed.

@Test
void puttingInternalTokenWithDuplicateNamedNotAllowed() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1, true));
    registry.put(new NamedToken(INBOUND2_TYPE, 2, true));
    NamedToken token = new NamedToken(INBOUND1_TYPE, 3, true);
    NonUniqueTokenException exception = assertThrows(NonUniqueTokenException.class, () -> registry.put(token));
    assertThat(exception.getMessage()).contains(format("The testType %s is not unique", token));
}
Also used : NonUniqueTokenException(org.neo4j.token.api.NonUniqueTokenException) NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 17 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistryTest method puttingPublicTokenWithDuplicateNamedNotAllowed.

@Test
void puttingPublicTokenWithDuplicateNamedNotAllowed() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1));
    registry.put(new NamedToken(INBOUND2_TYPE, 2));
    NamedToken token = new NamedToken(INBOUND1_TYPE, 3);
    NonUniqueTokenException exception = assertThrows(NonUniqueTokenException.class, () -> registry.put(token));
    assertThat(exception.getMessage()).contains(format("The testType %s is not unique", token));
}
Also used : NonUniqueTokenException(org.neo4j.token.api.NonUniqueTokenException) NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 18 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistryTest method getTokenMustNotFindInternalTokens.

@Test
void getTokenMustNotFindInternalTokens() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1, true));
    assertThat(registry.getToken(1)).isNull();
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 19 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistryTest method putAllMustNotThrowWhenPublicAndInternalTokenHaveSameName.

@Test
void putAllMustNotThrowWhenPublicAndInternalTokenHaveSameName() {
    registry.putAll(asList(new NamedToken(INBOUND1_TYPE, 1), new NamedToken(INBOUND1_TYPE, 2, true)));
    assertThat(registry.getId(INBOUND1_TYPE)).isEqualTo(1);
    assertThat(registry.getIdInternal(INBOUND1_TYPE)).isEqualTo(2);
    assertThat(registry.getToken(1)).isEqualTo(new NamedToken(INBOUND1_TYPE, 1));
    assertThat(registry.getTokenInternal(1)).isNull();
    assertThat(registry.getToken(2)).isNull();
    assertThat(registry.getTokenInternal(2)).isEqualTo(new NamedToken(INBOUND1_TYPE, 2, true));
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 20 with NamedToken

use of org.neo4j.token.api.NamedToken in project neo4j by neo4j.

the class TokenRegistryTest method mustKeepOriginalInternalTokenWhenAddDuplicate.

@Test
void mustKeepOriginalInternalTokenWhenAddDuplicate() {
    registry.put(new NamedToken(INBOUND1_TYPE, 1, true));
    registry.put(new NamedToken(INBOUND2_TYPE, 2, true));
    assertThrows(NonUniqueTokenException.class, () -> registry.put(new NamedToken(INBOUND1_TYPE, 3, true)));
    assertEquals(1, registry.getIdInternal(INBOUND1_TYPE).intValue());
    assertEquals(2, registry.getIdInternal(INBOUND2_TYPE).intValue());
    assertNull(registry.getTokenInternal(3));
    assertNull(registry.getToken(3));
}
Also used : NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Aggregations

NamedToken (org.neo4j.token.api.NamedToken)63 Test (org.junit.jupiter.api.Test)41 ArrayList (java.util.ArrayList)6 TokenNotFoundException (org.neo4j.token.api.TokenNotFoundException)6 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5 SchemaRule (org.neo4j.internal.schema.SchemaRule)5 NonUniqueTokenException (org.neo4j.token.api.NonUniqueTokenException)5 TokenHolder (org.neo4j.token.api.TokenHolder)5 AlreadyConstrainedException (org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 IntSupplier (java.util.function.IntSupplier)3 KernelException (org.neo4j.exceptions.KernelException)3 Iterators (org.neo4j.internal.helpers.collection.Iterators)3 IdCapacityExceededException (org.neo4j.internal.id.IdCapacityExceededException)3 Token (org.neo4j.internal.kernel.api.Token)3 TokenWrite.checkValidTokenName (org.neo4j.internal.kernel.api.TokenWrite.checkValidTokenName)3 LabelNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException)3 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)3 RelationshipTypeIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException)3