PoliciesModelFactory { public static ResourceKey newResourceKey(final CharSequence typeWithPath) { if (typeWithPath instanceof ResourceKey) { return (ResourceKey) typeWithPath; } argumentNotEmpty(typeWithPath, "typeWithPath"); final Validator validator = NoControlCharactersValidator.getInstance(typeWithPath); if (!validator.isValid()) { throw PolicyEntryInvalidException.newBuilder() .message("The Policy Resource " + typeWithPath + " is invalid") .description(validator.getReason().orElse(null)) .build(); } final String[] typeWithPathSplit = splitTypeWithPath(typeWithPath.toString()); return ImmutableResourceKey.newInstance(typeWithPathSplit[0], JsonPointer.of(typeWithPathSplit[1])); } private  PoliciesModelFactory(); static Label newLabel(final CharSequence labelValue); static SubjectIssuer newSubjectIssuer(final CharSequence subjectIssuer); static SubjectId newSubjectId(final SubjectIssuer issuer, final CharSequence subject); static SubjectId newSubjectId(final CharSequence subjectIssuerWithId); static SubjectType newSubjectType(final CharSequence subjectType); static Subject newSubject(final SubjectId subjectId); static Subject newSubject(final SubjectId subjectId, final SubjectType subjectType); static Subject newSubject(final CharSequence subjectIssuerWithId, final JsonObject jsonObject); static Subjects emptySubjects(); static Subjects newSubjects(final Iterable<Subject> subjects); static Subjects newSubjects(final Subject subject, final Subject... furtherSubjects); static Subjects newSubjects(final JsonObject jsonObject); static ResourceKey newResourceKey(final CharSequence typeWithPath); static ResourceKey newResourceKey(final CharSequence resourceType, final CharSequence resourcePath); static ResourceKey newResourceKey(final JsonPointer pointer); static Resource newResource(final CharSequence resourceType, final CharSequence resourcePath,
            final EffectedPermissions effectedPermissions); static Resource newResource(final ResourceKey resourceKey, final JsonValue effectedPermissions); static Resource newResource(final ResourceKey resourceKey, final EffectedPermissions effectedPermissions); static Resources emptyResources(); static Resources newResources(final Iterable<Resource> resources); static Resources newResources(final Resource resource, final Resource... furtherResources); static Resources newResources(final JsonObject jsonObject); static EffectedPermissions newEffectedPermissions(@Nullable final Iterable<String> grantedPermissions,
            @Nullable final Iterable<String> revokedPermissions); static PolicyRevision newPolicyRevision(final long revisionNumber); static Permissions noPermissions(); static Permissions newPermissions(final Collection<String> permissions); static Permissions newPermissions(final String permission, final String... furtherPermissions); static PolicyEntry newPolicyEntry(final CharSequence label, final Iterable<Subject> subjects,
            final Iterable<Resource> resources); static PolicyEntry newPolicyEntry(final CharSequence label, final JsonObject jsonObject); static PolicyEntry newPolicyEntry(final CharSequence label, final JsonValue jsonValue); static PolicyEntry newPolicyEntry(final CharSequence label, final String jsonString); static Iterable<PolicyEntry> newPolicyEntries(final JsonObject jsonObject); static Iterable<PolicyEntry> newPolicyEntries(final String jsonString); static PolicyBuilder newPolicyBuilder(); @Deprecated static PolicyBuilder newPolicyBuilder(final CharSequence id); static PolicyBuilder newPolicyBuilder(final PolicyId id); static PolicyBuilder newPolicyBuilder(final Policy existingPolicy); @Deprecated static PolicyBuilder newPolicyBuilder(final CharSequence id, final Iterable<PolicyEntry> policyEntries); static PolicyBuilder newPolicyBuilder(final PolicyId id, final Iterable<PolicyEntry> policyEntries); @Deprecated static Policy newPolicy(final CharSequence id, final PolicyEntry entry,
            final PolicyEntry... furtherEntries); static Policy newPolicy(final PolicyId id, final PolicyEntry entry,
            final PolicyEntry... furtherEntries); @Deprecated static Policy newPolicy(final CharSequence id, final Iterable<PolicyEntry> entries); static Policy newPolicy(final PolicyId id, final Iterable<PolicyEntry> entries); static Policy newPolicy(final JsonObject jsonObject); static Policy newPolicy(final String jsonString);  }
@Test public void resourceKeysFromDifferentInstantiationsAreEqual() { final ResourceKey key1 = PoliciesModelFactory.newResourceKey("thing:/foo/bar"); final ResourceKey key2 = PoliciesModelFactory.newResourceKey("thing", JsonFactory.newPointer("/foo/bar")); final ResourceKey key3 = PoliciesModelFactory.newResourceKey(JsonPointer.of("thing:/foo/bar")); final ResourceKey key4 = PoliciesModelFactory.newResourceKey(JsonPointer.of("thing:").append(JsonPointer.of("foo/bar"))); assertThat(key1).isEqualTo(key2); assertThat(key1).isEqualTo(key3); assertThat(key1).isEqualTo(key4); }
@Test(expected = PolicyEntryInvalidException.class) public void createInvalidResourceKey() { final String invalidResourceKey = "thing:/foo/bar\u0001"; PoliciesModelFactory.newResourceKey(invalidResourceKey); }
@Test public void createValidMaxLengthResourceKey() { PoliciesModelFactory.newResourceKey(generateStringWithMaxLength("thing:")); }
@Test(expected = PolicyEntryInvalidException.class) public void createTooLargeResourceKey() { PoliciesModelFactory.newResourceKey(generateStringExceedingMaxLength("thing:")); }