Search in sources :

Example 6 with StringArray

use of com.linkedin.data.template.StringArray in project rest.li by linkedin.

the class TestActionsResource method testArrayTypesOnActions.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testArrayTypesOnActions(RootBuilderWrapper<?, ?> builders) throws RemoteInvocationException {
    //Record template array
    MessageArray inputMessageArray = new MessageArray();
    inputMessageArray.add(new Message().setId("My Message Id").setMessage("My Message"));
    inputMessageArray.add(new Message().setId("My Message Id 2").setMessage("My Message 2"));
    Request<MessageArray> messageArrayRequest = builders.<MessageArray>action("EchoMessageArray").setActionParam("Messages", inputMessageArray).build();
    MessageArray messageArray = getClient().sendRequest(messageArrayRequest).getResponse().getEntity();
    Assert.assertEquals(messageArray.get(0).getId(), "My Message Id");
    Assert.assertEquals(messageArray.get(0).getMessage(), "My Message");
    Assert.assertEquals(messageArray.get(1).getId(), "My Message Id 2");
    Assert.assertEquals(messageArray.get(1).getMessage(), "My Message 2");
    //Primitive type array
    StringArray inputStringArray = new StringArray();
    inputStringArray.add("message1");
    inputStringArray.add("message2");
    Request<StringArray> stringArrayRequest = builders.<StringArray>action("EchoStringArray").setActionParam("Strings", inputStringArray).build();
    StringArray stringArray = getClient().sendRequest(stringArrayRequest).getResponse().getEntity();
    Assert.assertEquals(stringArray.get(0), "message1");
    Assert.assertEquals(stringArray.get(1), "message2");
    //Enum array
    ToneArray inputTonesArray = new ToneArray();
    inputTonesArray.add(Tone.SINCERE);
    inputTonesArray.add(Tone.FRIENDLY);
    Request<ToneArray> toneArrayRequest = builders.<ToneArray>action("EchoToneArray").setActionParam("Tones", inputTonesArray).build();
    ToneArray tones = getClient().sendRequest(toneArrayRequest).getResponse().getEntity();
    Assert.assertEquals(tones.get(0), Tone.SINCERE);
    Assert.assertEquals(tones.get(1), Tone.FRIENDLY);
}
Also used : ToneArray(com.linkedin.restli.examples.greetings.api.ToneArray) Message(com.linkedin.restli.examples.greetings.api.Message) StringArray(com.linkedin.data.template.StringArray) MessageArray(com.linkedin.restli.examples.greetings.api.MessageArray) Test(org.testng.annotations.Test)

Example 7 with StringArray

use of com.linkedin.data.template.StringArray in project rest.li by linkedin.

the class GroupGenerator method create.

public static Group create(int groupID, String name) {
    Group group = new Group();
    group.setApprovalModes(1);
    group.setBadge(Badge.FEATURED);
    group.setCategoriesEnabled(PostCategory.DISCUSSION);
    group.setCategoriesForModeratorsOnly(PostCategory.DISCUSSION);
    group.setCategory(1);
    group.setContactability(Contactability.CONTACTABLE);
    group.setContactEmail("bob@example.com");
    group.setCreatedTimestamp(System.currentTimeMillis());
    group.setDescription("long description long description long description long description long description long description long description long description long description long description long description long description long description long description long description ");
    group.setDirectoryPresence(DirectoryPresence.PUBLIC);
    group.setHasEmailExport(true);
    group.setHasMemberInvites(false);
    group.setHasMemberRoster(true);
    group.setHasNetworkUpdates(true);
    group.setHasSettings(true);
    group.setHideSubgroups(false);
    group.setHomeSiteUrl("http://www.example.com");
    group.setId(groupID);
    group.setIsOpenToNonMembers(true);
    group.setLargeLogoMediaUrl("/0/0/1/skafhdsjahiuewh");
    group.setLastModifiedTimestamp(System.currentTimeMillis());
    group.setLocale("en_US");
    Location location = new Location();
    location.setCountryCode("us");
    StringArray geoPlaceCodes = new StringArray();
    geoPlaceCodes.add("1-2-3-4-5");
    location.setGeoPlaceCodes(geoPlaceCodes);
    location.setGeoPostalCode("94043");
    location.setGmtOffset(-8f);
    location.setLatitude(122.1f);
    location.setLongitude(37.4f);
    location.setPostalCode("94043");
    location.setRegionCode(37);
    location.setUsesDaylightSavings(true);
    group.setLocation(location);
    group.setMaxFeeds(100);
    group.setMaxIdentityChanges(5);
    group.setMaxMembers(2000);
    group.setMaxModerators(10);
    group.setMaxSubgroups(20);
    group.setName(name);
    group.setNewsFormat(NewsFormat.RECENT);
    group.setNonMemberPermissions(NonMemberPermissions.COMMENT_AND_POST_WITH_MODERATION);
    group.setNumIdentityChanges(5);
    group.setNumMemberFlagsToDelete(3);
    group.setOpenedToNonMembersTimestamp(System.currentTimeMillis());
    group.setOtherCategory(3);
    // group.setParentGroupId();
    StringArray preApprovedEmailDomains = new StringArray();
    preApprovedEmailDomains.add("example.com");
    preApprovedEmailDomains.add("linkedin.com");
    group.setPreApprovedEmailDomains(preApprovedEmailDomains);
    group.setPreModerateMembersWithLowConnections(true);
    group.setPreModerateNewMembersPeriodInDays(3);
    group.setPreModeration(PreModerationType.COMMENTS);
    group.setPreModerationCategories(PostCategory.JOB);
    group.setRules("No spam, please");
    group.setSharingKey("HJFD3JH98JKH3");
    group.setShortDescription("short description");
    group.setSmallLogoMediaUrl("/0/0/1/skafhdsjahiuewh");
    group.setState(State.ACTIVE);
    group.setVanityUrl(name.toLowerCase().replace(' ', '-'));
    group.setVisibility(Visibility.PUBLIC);
    return group;
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) StringArray(com.linkedin.data.template.StringArray) Location(com.linkedin.restli.examples.groups.api.Location)

Example 8 with StringArray

use of com.linkedin.data.template.StringArray in project rest.li by linkedin.

the class RequestBuilderSpecGenerator method generateRootRequestBuilder.

private RootBuilderSpec generateRootRequestBuilder(RootBuilderSpec parentRootBuilder, ResourceSchema resource, String sourceFile, Map<String, String> pathKeyTypes) throws IOException {
    ValidationResult validationResult = ValidateDataAgainstSchema.validate(resource.data(), resource.schema(), new ValidationOptions(RequiredMode.MUST_BE_PRESENT));
    if (!validationResult.isValid()) {
        throw new IllegalArgumentException(String.format("Resource validation error.  Resource File '%s', Error Details '%s'", sourceFile, validationResult.toString()));
    }
    String packageName = resource.getNamespace();
    String resourceName = CodeUtil.capitalize(resource.getName());
    String className;
    if (_version == RestliVersion.RESTLI_2_0_0) {
        className = getBuilderClassNameByVersion(RestliVersion.RESTLI_2_0_0, null, resource.getName(), true);
    } else {
        className = getBuilderClassNameByVersion(RestliVersion.RESTLI_1_0_0, null, resource.getName(), true);
    }
    RootBuilderSpec rootBuilderSpec = null;
    if (resource.hasCollection()) {
        rootBuilderSpec = new CollectionRootBuilderSpec(resource);
    } else if (resource.hasSimple()) {
        rootBuilderSpec = new SimpleRootBuilderSpec(resource);
    } else if (resource.hasActionsSet()) {
        rootBuilderSpec = new ActionSetRootBuilderSpec(resource);
    } else {
        throw new IllegalArgumentException("unsupported resource type for resource: '" + resourceName + '\'');
    }
    rootBuilderSpec.setNamespace(packageName);
    rootBuilderSpec.setClassName(className);
    if (_version == RestliVersion.RESTLI_2_0_0) {
        rootBuilderSpec.setBaseClassName("BuilderBase");
    }
    rootBuilderSpec.setSourceIdlName(sourceFile);
    String resourcePath = getResourcePath(resource.getPath());
    rootBuilderSpec.setResourcePath(resourcePath);
    List<String> pathKeys = getPathKeys(resourcePath);
    rootBuilderSpec.setPathKeys(pathKeys);
    rootBuilderSpec.setParentRootBuilder(parentRootBuilder);
    StringArray supportsList = null;
    RestMethodSchemaArray restMethods = null;
    FinderSchemaArray finders = null;
    ResourceSchemaArray subresources = null;
    ActionSchemaArray resourceActions = null;
    ActionSchemaArray entityActions = null;
    String keyClass = null;
    if (resource.getCollection() != null) {
        CollectionSchema collection = resource.getCollection();
        String keyName = collection.getIdentifier().getName();
        // Complex key is not supported
        keyClass = collection.getIdentifier().getType();
        pathKeyTypes.put(keyName, collection.getIdentifier().getType());
        supportsList = collection.getSupports();
        restMethods = collection.getMethods();
        finders = collection.getFinders();
        subresources = collection.getEntity().getSubresources();
        resourceActions = collection.getActions();
        entityActions = collection.getEntity().getActions();
    } else if (resource.getSimple() != null) {
        SimpleSchema simpleSchema = resource.getSimple();
        keyClass = "Void";
        supportsList = simpleSchema.getSupports();
        restMethods = simpleSchema.getMethods();
        subresources = simpleSchema.getEntity().getSubresources();
        resourceActions = simpleSchema.getActions();
    } else if (resource.getActionsSet() != null) {
        ActionsSetSchema actionsSet = resource.getActionsSet();
        resourceActions = actionsSet.getActions();
    }
    Set<ResourceMethod> supportedMethods = getSupportedMethods(supportsList);
    if (!supportedMethods.isEmpty()) {
        for (ResourceMethod resourceMethod : supportedMethods) {
            validateResourceMethod(resource, resourceName, resourceMethod);
        }
    }
    List<RootBuilderMethodSpec> restMethodSpecs = new ArrayList<RootBuilderMethodSpec>();
    List<RootBuilderMethodSpec> finderSpecs = new ArrayList<RootBuilderMethodSpec>();
    List<RootBuilderMethodSpec> resourceActionSpecs = new ArrayList<RootBuilderMethodSpec>();
    List<RootBuilderMethodSpec> entityActionSpecs = new ArrayList<RootBuilderMethodSpec>();
    List<RootBuilderSpec> subresourceSpecs = new ArrayList<RootBuilderSpec>();
    String schemaClass = resource.getSchema();
    if (restMethods != null) {
        restMethodSpecs = generateBasicMethods(rootBuilderSpec, keyClass, schemaClass, supportedMethods, restMethods, resourceName, pathKeys, pathKeyTypes);
    }
    if (finders != null) {
        finderSpecs = generateFinders(rootBuilderSpec, finders, keyClass, schemaClass, resourceName, pathKeys, pathKeyTypes);
    }
    if (resourceActions != null) {
        resourceActionSpecs = generateActions(rootBuilderSpec, resourceActions, keyClass, resourceName, pathKeys, pathKeyTypes);
    }
    if (entityActions != null) {
        entityActionSpecs = generateActions(rootBuilderSpec, entityActions, keyClass, resourceName, pathKeys, pathKeyTypes);
    }
    if (subresources != null) {
        subresourceSpecs = generateSubResources(sourceFile, rootBuilderSpec, subresources, pathKeyTypes);
    }
    // assign to rootBuilderClass
    if (rootBuilderSpec instanceof CollectionRootBuilderSpec) {
        CollectionRootBuilderSpec rootBuilder = (CollectionRootBuilderSpec) rootBuilderSpec;
        rootBuilder.setRestMethods(restMethodSpecs);
        rootBuilder.setFinders(finderSpecs);
        rootBuilder.setResourceActions(resourceActionSpecs);
        rootBuilder.setEntityActions(entityActionSpecs);
        rootBuilder.setSubresources(subresourceSpecs);
    } else if (rootBuilderSpec instanceof SimpleRootBuilderSpec) {
        SimpleRootBuilderSpec rootBuilder = (SimpleRootBuilderSpec) rootBuilderSpec;
        rootBuilder.setRestMethods(restMethodSpecs);
        rootBuilder.setResourceActions(resourceActionSpecs);
        rootBuilder.setSubresources(subresourceSpecs);
    } else if (rootBuilderSpec instanceof ActionSetRootBuilderSpec) {
        ActionSetRootBuilderSpec rootBuilder = (ActionSetRootBuilderSpec) rootBuilderSpec;
        rootBuilder.setResourceActions(resourceActionSpecs);
    }
    registerBuilderSpec(rootBuilderSpec);
    return rootBuilderSpec;
}
Also used : RestMethodSchemaArray(com.linkedin.restli.restspec.RestMethodSchemaArray) CollectionSchema(com.linkedin.restli.restspec.CollectionSchema) SimpleSchema(com.linkedin.restli.restspec.SimpleSchema) ArrayList(java.util.ArrayList) ResourceSchemaArray(com.linkedin.restli.restspec.ResourceSchemaArray) ActionSetRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionSetRootBuilderSpec) ValidationResult(com.linkedin.data.schema.validation.ValidationResult) ValidationOptions(com.linkedin.data.schema.validation.ValidationOptions) ActionsSetSchema(com.linkedin.restli.restspec.ActionsSetSchema) CollectionRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.CollectionRootBuilderSpec) StringArray(com.linkedin.data.template.StringArray) RootBuilderMethodSpec(com.linkedin.restli.tools.clientgen.builderspec.RootBuilderMethodSpec) FinderSchemaArray(com.linkedin.restli.restspec.FinderSchemaArray) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) RootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.RootBuilderSpec) SimpleRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.SimpleRootBuilderSpec) CollectionRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.CollectionRootBuilderSpec) ActionSetRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionSetRootBuilderSpec) SimpleRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.SimpleRootBuilderSpec) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Example 9 with StringArray

use of com.linkedin.data.template.StringArray in project rest.li by linkedin.

the class TestResourceCompatibilityChecker method testFailCollectionFile.

@Test
public void testFailCollectionFile() throws IOException {
    final SchemaParser sp = new SchemaParser();
    sp.parse("\"StringRef\"");
    final Collection<CompatibilityInfo> resourceTestErrors = new HashSet<CompatibilityInfo>();
    final Collection<CompatibilityInfo> modelTestErrors = new HashSet<CompatibilityInfo>();
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "identifier", "params"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to long"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "supports"), CompatibilityInfo.Type.ARRAY_NOT_CONTAIN, new StringArray(Arrays.asList("batch_get", "create", "delete", "get", "get_all"))));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "methods"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "batch_get"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "search", "metadata", "type"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from array to int"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "search", "assocKeys"), CompatibilityInfo.Type.VALUE_NOT_EQUAL, new StringArray(Arrays.asList("q", "s")), new StringArray(Arrays.asList("q", "changed_key"))));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "finders", "find_assocKey_downgrade", "assocKeys"), CompatibilityInfo.Type.FINDER_ASSOCKEYS_DOWNGRADE));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "bitfield", "items"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from boolean to int"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "someString", "type"), CompatibilityInfo.Type.TYPE_UNKNOWN, sp.errorMessage()));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "actions", "oneAction", "parameters", "stringMap", "type"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to int"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "anotherAction", "parameters"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "subMap"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "exceptionTest", "throws"), CompatibilityInfo.Type.ARRAY_NOT_CONTAIN, new StringArray(Arrays.asList("com.linkedin.groups.api.GroupOwnerException", "java.io.FileNotFoundException"))));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters", "a", "optional"), CompatibilityInfo.Type.PARAMETER_WRONG_OPTIONALITY));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters", "b", "type"), CompatibilityInfo.Type.TYPE_ERROR, "schema type changed from string to int"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters"), CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, "e"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "parameters"), CompatibilityInfo.Type.PARAMETER_NEW_REQUIRED, "f"));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("", "collection", "entity", "actions", "someAction", "returns"), CompatibilityInfo.Type.TYPE_MISSING));
    resourceTestErrors.add(new CompatibilityInfo(Arrays.asList("", "collection", "finders", "oneFinder"), CompatibilityInfo.Type.PAGING_REMOVED));
    modelTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("com.linkedin.greetings.api.Greeting"), CompatibilityInfo.Type.TYPE_BREAKS_NEW_READER, "new record added required fields newField"));
    modelTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("com.linkedin.greetings.api.Greeting"), CompatibilityInfo.Type.TYPE_BREAKS_OLD_READER, "new record removed required fields message"));
    modelTestErrors.add(new CompatibilityInfo(Arrays.<Object>asList("com.linkedin.greetings.api.Greeting", "id", "string"), CompatibilityInfo.Type.TYPE_BREAKS_NEW_AND_OLD_READERS, "schema type changed from long to string"));
    final ResourceSchema prevResource = idlToResource(IDLS_SUFFIX + PREV_COLL_FILE);
    final ResourceSchema currResource = idlToResource(IDLS_SUFFIX + CURR_COLL_FAIL_FILE);
    ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevResource, prevSchemaResolver, currResource, incompatSchemaResolver);
    Assert.assertFalse(checker.check(CompatibilityLevel.BACKWARDS));
    final Collection<CompatibilityInfo> resourceIncompatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getRestSpecIncompatibles());
    for (CompatibilityInfo te : resourceTestErrors) {
        Assert.assertTrue(resourceIncompatibles.contains(te), "Reported resource incompatibles should contain: " + te.toString());
        resourceIncompatibles.remove(te);
    }
    Assert.assertTrue(resourceIncompatibles.isEmpty());
    final Collection<CompatibilityInfo> modelIncompatibles = new HashSet<CompatibilityInfo>(checker.getInfoMap().getModelIncompatibles());
    for (CompatibilityInfo te : modelTestErrors) {
        Assert.assertTrue(modelIncompatibles.contains(te), "Reported model incompatibles should contain: " + te.toString());
        modelIncompatibles.remove(te);
    }
    Assert.assertTrue(modelIncompatibles.isEmpty());
// ignore compatibles
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) StringArray(com.linkedin.data.template.StringArray) CompatibilityInfo(com.linkedin.restli.tools.idlcheck.CompatibilityInfo) SchemaParser(com.linkedin.data.schema.SchemaParser) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with StringArray

use of com.linkedin.data.template.StringArray in project rest.li by linkedin.

the class ResourceSchemaToResourceSpecTranslator method associationToResourceSpec.

private ResourceSpec associationToResourceSpec(ResourceSchema resourceSchema, AssociationSchema association) {
    ActionSchemaArray actions = null, entityActions = null;
    StringArray supports = association.getSupports();
    if (association.hasActions()) {
        actions = association.getActions();
    }
    if (association.getEntity().hasActions()) {
        entityActions = association.getEntity().getActions();
    }
    String schema = resourceSchema.getSchema();
    AssocKeySchemaArray assocKeys = association.getAssocKeys();
    Map<String, CompoundKey.TypeInfo> keyParts = new HashMap<String, CompoundKey.TypeInfo>();
    for (AssocKeySchema assocKey : assocKeys) {
        TypeSpec<?> type = toTypeSpec(RestSpecCodec.textToSchema(assocKey.getType(), _schemaResolver));
        keyParts.put(assocKey.getName(), new CompoundKey.TypeInfo(type, type));
    }
    return buildResourceSpec(supports, new TypeSpec<CompoundKey>(CompoundKey.class, null), null, keyParts, schema, actions, entityActions);
}
Also used : AssocKeySchemaArray(com.linkedin.restli.restspec.AssocKeySchemaArray) StringArray(com.linkedin.data.template.StringArray) HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) AssocKeySchema(com.linkedin.restli.restspec.AssocKeySchema)

Aggregations

StringArray (com.linkedin.data.template.StringArray)25 Test (org.testng.annotations.Test)12 ActionSchemaArray (com.linkedin.restli.restspec.ActionSchemaArray)5 HashMap (java.util.HashMap)5 DataMap (com.linkedin.data.DataMap)4 ArrayList (java.util.ArrayList)4 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)3 D2LoadBalancerStrategyProperties (com.linkedin.d2.D2LoadBalancerStrategyProperties)2 com.linkedin.d2.hashConfigType (com.linkedin.d2.hashConfigType)2 com.linkedin.d2.quarantineInfo (com.linkedin.d2.quarantineInfo)2 DataList (com.linkedin.data.DataList)2 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)2 DataSchema (com.linkedin.data.schema.DataSchema)2 MapDataSchema (com.linkedin.data.schema.MapDataSchema)2 ValidationOptions (com.linkedin.data.schema.validation.ValidationOptions)2 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)2 BooleanArray (com.linkedin.data.template.BooleanArray)2 BytesArray (com.linkedin.data.template.BytesArray)2 DoubleArray (com.linkedin.data.template.DoubleArray)2 FloatArray (com.linkedin.data.template.FloatArray)2