Search in sources :

Example 11 with ShareOpenGraphContent

use of com.facebook.share.model.ShareOpenGraphContent in project facebook-android-sdk by facebook.

the class ShareContentValidationTest method testItValidateShareOpenGraphWithNoTypeByMessage.

@Test(expected = FacebookException.class)
public void testItValidateShareOpenGraphWithNoTypeByMessage() {
    ShareOpenGraphAction shareOpenGraphAction = new ShareOpenGraphAction.Builder().setActionType(null).build();
    ShareOpenGraphContent shareOpenGraphContent = new ShareOpenGraphContent.Builder().setAction(shareOpenGraphAction).build();
    ShareContentValidation.validateForMessage(shareOpenGraphContent);
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with ShareOpenGraphContent

use of com.facebook.share.model.ShareOpenGraphContent in project facebook-android-sdk by facebook.

the class ShareContentValidationTest method testItAcceptsShareOpenGraphContent.

@Test
public void testItAcceptsShareOpenGraphContent() {
    String actionKey = "foo";
    String actionValue = "fooValue";
    ShareOpenGraphAction shareOpenGraphAction = new ShareOpenGraphAction.Builder().putString(actionKey, actionValue).setActionType(actionKey).build();
    ShareOpenGraphContent shareOpenGraphContent = new ShareOpenGraphContent.Builder().setPreviewPropertyName(actionKey).setAction(shareOpenGraphAction).build();
    ShareContentValidation.validateForMessage(shareOpenGraphContent);
    ShareContentValidation.validateForNativeShare(shareOpenGraphContent);
    ShareContentValidation.validateForApiShare(shareOpenGraphContent);
    ShareContentValidation.validateForWebShare(shareOpenGraphContent);
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with ShareOpenGraphContent

use of com.facebook.share.model.ShareOpenGraphContent in project facebook-android-sdk by facebook.

the class ShareInternalUtilityTest method testJsonSerializationOfOpenGraph.

@Test
public void testJsonSerializationOfOpenGraph() {
    String placeId = "1";
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder().setAction(new ShareOpenGraphAction.Builder().putStringArrayList("tags", new ArrayList<String>() {

        {
            add("2");
            add("4");
        }
    }).build()).setPeopleIds(new ArrayList<String>() {

        {
            add("1");
            add("1");
            add("2");
            add("3");
        }
    }).setPlaceId(placeId).build();
    try {
        JSONObject object = ShareInternalUtility.toJSONObjectForCall(null, content);
        List<String> peopleIds = Utility.jsonArrayToStringList(object.getJSONArray("tags"));
        assertEquals(4, peopleIds.size());
        for (int i = 1; i < 5; ++i) {
            assertTrue(peopleIds.contains(Integer.valueOf(i).toString()));
        }
        assertEquals(placeId, object.getString("place"));
    } catch (JSONException ex) {
        // Fail
        assertNotNull(ex);
        return;
    }
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) Test(org.junit.Test)

Example 14 with ShareOpenGraphContent

use of com.facebook.share.model.ShareOpenGraphContent in project facebook-android-sdk by facebook.

the class RequestTests method testShareOpenGraphContent.

@LargeTest
public void testShareOpenGraphContent() throws Exception {
    ShareOpenGraphObject ogObject = new ShareOpenGraphObject.Builder().putString("og:title", "a title").putString("og:type", TEST_OG_OBJECT_TYPE).putString("og:description", "a description").build();
    ShareOpenGraphAction ogAction = new ShareOpenGraphAction.Builder().setActionType(TEST_OG_ACTION_TYPE).putObject("test", ogObject).build();
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder().setAction(ogAction).setPreviewPropertyName("test").build();
    final ShareApi shareApi = new ShareApi(content);
    final AtomicReference<String> actionId = new AtomicReference<>(null);
    getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            shareApi.share(new FacebookCallback<Sharer.Result>() {

                @Override
                public void onSuccess(Sharer.Result result) {
                    actionId.set(result.getPostId());
                    notifyShareFinished();
                }

                @Override
                public void onCancel() {
                    notifyShareFinished();
                }

                @Override
                public void onError(FacebookException error) {
                    notifyShareFinished();
                }

                private void notifyShareFinished() {
                    synchronized (shareApi) {
                        shareApi.notifyAll();
                    }
                }
            });
        }
    });
    synchronized (shareApi) {
        shareApi.wait(REQUEST_TIMEOUT_MILLIS);
    }
    assertNotNull(actionId.get());
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphObject(com.facebook.share.model.ShareOpenGraphObject) AtomicReference(java.util.concurrent.atomic.AtomicReference) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) Sharer(com.facebook.share.Sharer) ShareApi(com.facebook.share.ShareApi) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)14 ShareOpenGraphAction (com.facebook.share.model.ShareOpenGraphAction)9 Test (org.junit.Test)6 ShareLinkContent (com.facebook.share.model.ShareLinkContent)4 ShareOpenGraphObject (com.facebook.share.model.ShareOpenGraphObject)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 FacebookException (com.facebook.FacebookException)3 Sharer (com.facebook.share.Sharer)3 ArrayList (java.util.ArrayList)3 Bundle (android.os.Bundle)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)2 ShareApi (com.facebook.share.ShareApi)2 SharePhoto (com.facebook.share.model.SharePhoto)2 SharePhotoContent (com.facebook.share.model.SharePhotoContent)2 ShareVideoContent (com.facebook.share.model.ShareVideoContent)2 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Intent (android.content.Intent)1