android.test.suitebuilder.annotation.MediumTest Java Examples

The following examples show how to use android.test.suitebuilder.annotation.MediumTest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccessTokenTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testFromSSOWithExpiresString() {
    List<String> permissions = Utility.arrayList("stream_publish", "go_outside_and_play");
    String token = "AnImaginaryTokenValue";

    Intent intent = new Intent();
    intent.putExtra("access_token", token);
    intent.putExtra("expires_in", "60");
    intent.putExtra("extra_extra", "Something unrelated");

    AccessToken accessToken = AccessToken
            .createFromWebBundle(permissions, intent.getExtras(), AccessTokenSource.FACEBOOK_APPLICATION_WEB);

    TestUtils.assertSamePermissions(permissions, accessToken);
    assertEquals(token, accessToken.getToken());
    assertEquals(AccessTokenSource.FACEBOOK_APPLICATION_WEB, accessToken.getSource());
    assertTrue(!accessToken.isInvalid());
}
 
Example #2
Source File: AuthorizationClientTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testGetTokenHandlesNoResult() {
    MockAuthorizationClient client = new MockAuthorizationClient();
    AuthorizationClient.GetTokenAuthHandler handler = client.new GetTokenAuthHandler();

    AuthorizationClient.AuthorizationRequest request = createRequest();
    assertEquals(PERMISSIONS.size(), request.getPermissions().size());

    client.setRequest(request);
    handler.getTokenCompleted(request, null);

    assertNull(client.result);
    assertTrue(client.triedNextHandler);

    assertEquals(PERMISSIONS.size(), request.getPermissions().size());
}
 
Example #3
Source File: AuthorizationClientTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testGetTokenHandlesSuccessWithSomePermissions() {
    Bundle bundle = new Bundle();
    bundle.putStringArrayList(NativeProtocol.EXTRA_PERMISSIONS, new ArrayList<String>(Arrays.asList("go outside")));
    bundle.putLong(NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, new Date().getTime() / 1000 + EXPIRES_IN_DELTA);
    bundle.putString(NativeProtocol.EXTRA_ACCESS_TOKEN, ACCESS_TOKEN);

    MockAuthorizationClient client = new MockAuthorizationClient();
    AuthorizationClient.GetTokenAuthHandler handler = client.new GetTokenAuthHandler();

    AuthorizationClient.AuthorizationRequest request = createRequest();
    assertEquals(PERMISSIONS.size(), request.getPermissions().size());

    client.setRequest(request);
    handler.getTokenCompleted(request, bundle);

    assertNull(client.result);
    assertTrue(client.triedNextHandler);

    assertEquals(1, request.getPermissions().size());
    assertTrue(request.getPermissions().contains("come back in"));
}
 
Example #4
Source File: FacebookActivityTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testLaunchingWithValidNativeLinkingIntent() {
    final String token = "A token less unique than most";

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtras(getNativeLinkingExtras(token));
    setActivityIntent(intent);

    assertNull(Session.getActiveSession());

    FacebookTestActivity activity = getActivity();
    Session activeSession = Session.getActiveSession();
    assertNull(activeSession);
    assertTrue(activity.hasNativeLinkIntentForTesting());
}
 
Example #5
Source File: GraphObjectFactoryTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testObjectWrapsJSONCollection() throws JSONException {
    JSONObject jsonLocation = new JSONObject();
    jsonLocation.put("city", "Seattle");

    JSONArray jsonArray = new JSONArray();
    jsonArray.put(jsonLocation);

    JSONObject jsonLocations = new JSONObject();
    jsonLocations.put("locations", jsonArray);

    Locations locations = GraphObject.Factory.create(jsonLocations, Locations.class);
    Collection<GraphLocation> locationsGraphObjectCollection = locations.getLocations();
    assertTrue(locationsGraphObjectCollection != null);

    GraphLocation graphLocation = locationsGraphObjectCollection.iterator().next();
    assertTrue(graphLocation != null);
    assertEquals("Seattle", graphLocation.getCity());
}
 
Example #6
Source File: AccessTokenTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testFromDialog() {
    List<String> permissions = Utility.arrayList("stream_publish", "go_outside_and_play");
    String token = "AnImaginaryTokenValue";

    Bundle bundle = new Bundle();
    bundle.putString("access_token", token);
    bundle.putString("expires_in", "60");

    AccessToken accessToken = AccessToken.createFromWebBundle(permissions, bundle, AccessTokenSource.WEB_VIEW);
    TestUtils.assertSamePermissions(permissions, accessToken);
    assertEquals(token, accessToken.getToken());
    assertEquals(AccessTokenSource.WEB_VIEW, accessToken.getSource());
    assertTrue(!accessToken.isInvalid());
}
 
Example #7
Source File: WorkQueueTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testRunSomething() {
    CountingRunnable run = new CountingRunnable();
    assertEquals(0, run.getRunCount());

    ScriptableExecutor executor = new ScriptableExecutor();
    assertEquals(0, executor.getPendingCount());

    WorkQueue manager = new WorkQueue(1, executor);

    addActiveWorkItem(manager, run);
    assertEquals(1, executor.getPendingCount());
    assertEquals(0, run.getRunCount());

    executeNext(manager, executor);
    assertEquals(0, executor.getPendingCount());
    assertEquals(1, run.getRunCount());
}
 
Example #8
Source File: GraphObjectFactoryTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testCanCastCollectionOfGraphObjects() throws JSONException {
    JSONObject jsonSeattle = new JSONObject();
    jsonSeattle.put("city", "Seattle");

    JSONArray jsonArray = new JSONArray();
    jsonArray.put(jsonSeattle);

    GraphObjectList<GraphObject> collection = GraphObject.Factory
            .createList(jsonArray, GraphObject.class);

    GraphObjectList<GraphLocation> locationCollection = collection.castToListOf(GraphLocation.class);
    assertTrue(locationCollection != null);

    GraphLocation seattle = locationCollection.iterator().next();
    assertTrue(seattle != null);
    assertEquals("Seattle", seattle.getCity());
}
 
Example #9
Source File: RequestTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testSingleGetToHttpRequest() throws Exception {
    Request requestMe = new Request(null, "TourEiffel");
    HttpURLConnection connection = Request.toHttpConnection(requestMe);

    assertTrue(connection != null);

    assertEquals("GET", connection.getRequestMethod());
    assertEquals("/" + ServerProtocol.getAPIVersion() + "/TourEiffel", connection.getURL().getPath());

    assertTrue(connection.getRequestProperty("User-Agent").startsWith("FBAndroidSDK"));

    Uri uri = Uri.parse(connection.getURL().toString());
    assertEquals("android", uri.getQueryParameter("sdk"));
    assertEquals("json", uri.getQueryParameter("format"));
}
 
Example #10
Source File: AsyncRequestTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@MediumTest
@LargeTest
public void testExecuteSingleGetUsingHttpURLConnection() {
    final TestSession session = openTestSessionWithSharedUser();
    Request request = new Request(session, "TourEiffel", null, null, new ExpectSuccessCallback() {
        @Override
        protected void performAsserts(Response response) {
            assertNotNull(response);
            GraphPlace graphPlace = response.getGraphObjectAs(GraphPlace.class);
            assertEquals("Paris", graphPlace.getLocation().getCity());
        }
    });
    HttpURLConnection connection = Request.toHttpConnection(request);

    TestRequestAsyncTask task = new TestRequestAsyncTask(connection, Arrays.asList(new Request[] { request }));

    task.executeOnBlockerThread();

    // Wait on 2 signals: request and task will both signal.
    waitAndAssertSuccess(2);
}
 
Example #11
Source File: GraphObjectFactoryTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testCollectionIterator() throws JSONException {
    JSONArray array = new JSONArray();
    array.put(5);
    array.put(-1);

    Collection<Integer> collection = GraphObject.Factory.createList(array, Integer.class);
    Iterator<Integer> iter = collection.iterator();
    assertTrue(iter.hasNext());
    assertTrue(iter.next() == 5);
    assertTrue(iter.hasNext());
    assertTrue(iter.next() == -1);
    assertFalse(iter.hasNext());

    for (Integer i : collection) {
        assertNotSame(0, i);
    }
}
 
Example #12
Source File: SessionTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testOpenFailure() {
    SessionStatusCallbackRecorder statusRecorder = new SessionStatusCallbackRecorder();
    MockTokenCachingStrategy cache = new MockTokenCachingStrategy(null, 0);
    ScriptedSession session = createScriptedSessionOnBlockerThread(cache);
    Exception openException = new Exception();

    session.addAuthorizeResult(openException);
    session.openForRead(new Session.OpenRequest(getActivity()).setCallback(statusRecorder));
    statusRecorder.waitForCall(session, SessionState.OPENING, null);

    // Verify we get the expected exception and no saved state.
    statusRecorder.waitForCall(session, SessionState.CLOSED_LOGIN_FAILED, openException);
    assertTrue(cache.getSavedState() == null);

    // Wait a bit so we can fail if any unexpected calls arrive on the
    // recorder.
    stall(STRAY_CALLBACK_WAIT_MILLISECONDS);
    statusRecorder.close();
}
 
Example #13
Source File: RequestTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@MediumTest
@LargeTest
public void testFacebookErrorResponseCreatesError() {
    Request request = new Request(null, "somestringthatshouldneverbeavalidfobjectid");
    Response response = request.executeAndWait();

    assertTrue(response != null);

    FacebookRequestError error = response.getError();
    assertNotNull(error);
    FacebookException exception = error.getException();
    assertNotNull(exception);

    assertTrue(exception instanceof FacebookServiceException);
    assertNotNull(error.getErrorType());
    assertTrue(error.getErrorCode() != FacebookRequestError.INVALID_ERROR_CODE);
    assertNotNull(error.getRequestResultBody());
}
 
Example #14
Source File: AccessTokenTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testFromNativeLogin() {
    ArrayList<String> permissions = Utility.arrayList("stream_publish", "go_outside_and_play");
    String token = "AnImaginaryTokenValue";

    long nowSeconds = new Date().getTime() / 1000;
    Intent intent = new Intent();
    intent.putExtra(NativeProtocol.EXTRA_ACCESS_TOKEN, token);
    intent.putExtra(NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, nowSeconds + 60L);
    intent.putExtra(NativeProtocol.EXTRA_PERMISSIONS, permissions);

    AccessToken accessToken = AccessToken.createFromNativeLogin(
            intent.getExtras(), AccessTokenSource.FACEBOOK_APPLICATION_NATIVE);
    TestUtils.assertSamePermissions(permissions, accessToken);
    assertEquals(token, accessToken.getToken());
    assertEquals(AccessTokenSource.FACEBOOK_APPLICATION_NATIVE, accessToken.getSource());
    assertTrue(!accessToken.isInvalid());
}
 
Example #15
Source File: FileLruCacheTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest @MediumTest @LargeTest
public void testCacheClear() throws Exception {
    int dataSize = 1024;
    byte[] data = generateBytes(dataSize);
    String key = "a";

    // Limit to 2x to allow for extra header data
    FileLruCache cache = new FileLruCache(getContext(), "testCacheClear", limitCacheSize(2*dataSize));
    TestUtils.clearFileLruCache(cache);

    put(cache, key, data);
    checkValue(cache, key, data);

    TestUtils.clearFileLruCache(cache);
    assertEquals(false, hasValue(cache, key));
    assertEquals(0, cache.sizeInBytesForTest());
}
 
Example #16
Source File: RequestTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@MediumTest
@LargeTest
public void testExecutePlaceRequestWithSearchText() {
    TestSession session = openTestSessionWithSharedUser();

    // Pass a distance without a location to ensure it is correctly ignored.
    Request request = Request.newPlacesSearchRequest(session, null, 1000, 5, "Starbucks", null);
    Response response = request.executeAndWait();
    assertNotNull(response);

    assertNull(response.getError());

    GraphMultiResult graphResult = response.getGraphObjectAs(GraphMultiResult.class);
    assertNotNull(graphResult);

    List<GraphObject> results = graphResult.getData();
    assertNotNull(results);

    assertNotNull(response.getRawResponse());
}
 
Example #17
Source File: AccessTokenTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testCreateFromExistingToken() {
    final String token = "A token of my esteem";
    final List<String> permissions = Arrays.asList("walk", "chew gum");
    final Date expires = new Date(2025, 5, 3);
    final Date lastRefresh = new Date(2023, 8, 15);
    final AccessTokenSource source = AccessTokenSource.WEB_VIEW;

    AccessToken accessToken = AccessToken
            .createFromExistingAccessToken(token, expires, lastRefresh, source, permissions);

    assertEquals(token, accessToken.getToken());
    assertEquals(expires, accessToken.getExpires());
    assertEquals(lastRefresh, accessToken.getLastRefresh());
    assertEquals(source, accessToken.getSource());
    assertEquals(permissions, accessToken.getPermissions());
}
 
Example #18
Source File: BatchRequestTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@MediumTest
@LargeTest
public void testExecuteBatchRequestsPathEncoding() throws IOException {
    // ensures that paths passed to batch requests are encoded properly before
    // we send it up to the server

    TestSession session = openTestSessionWithSharedUser();

    Request request1 = new Request(session, "TourEiffel");
    request1.setBatchEntryName("eiffel");
    request1.setBatchEntryOmitResultOnSuccess(false);
    Request request2 = new Request(session, "{result=eiffel:$.id}");

    List<Response> responses = Request.executeBatchAndWait(request1, request2);
    assertEquals(2, responses.size());
    assertTrue(responses.get(0).getError() == null);
    assertTrue(responses.get(1).getError() == null);

    GraphPlace eiffelTower1 = responses.get(0).getGraphObjectAs(GraphPlace.class);
    GraphPlace eiffelTower2 = responses.get(1).getGraphObjectAs(GraphPlace.class);
    assertTrue(eiffelTower1 != null);
    assertTrue(eiffelTower2 != null);

    assertEquals("Paris", eiffelTower1.getLocation().getCity());
    assertEquals("Paris", eiffelTower2.getLocation().getCity());
}
 
Example #19
Source File: WorkQueueTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testRunParallel() {
    final int workTotal = 100;

    CountingRunnable run = new CountingRunnable();
    ScriptableExecutor executor = new ScriptableExecutor();
    WorkQueue manager = new WorkQueue(workTotal, executor);

    for (int i = 0; i < workTotal; i++) {
        assertEquals(i, executor.getPendingCount());
        addActiveWorkItem(manager, run);
    }

    for (int i = 0; i < workTotal; i++) {
        assertEquals(workTotal - i, executor.getPendingCount());
        assertEquals(i, run.getRunCount());
        executeNext(manager, executor);
    }
    assertEquals(0, executor.getPendingCount());
    assertEquals(workTotal, run.getRunCount());
}
 
Example #20
Source File: GraphObjectFactoryTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testMapGet() throws JSONException {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("hello", "world");
    jsonObject.put("hocus", "pocus");

    GraphObject graphObject = GraphObject.Factory.create(jsonObject);
    assertEquals("world", graphObject.asMap().get("hello"));
    assertTrue(graphObject.getProperty("fred") == null);
}
 
Example #21
Source File: GraphObjectFactoryTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testCanTreatAsGraphPlace() {
    GraphPlace graphPlace = GraphObject.Factory.create(GraphPlace.class);

    graphPlace.setName("hello");
    assertEquals("hello", graphPlace.getName());
}
 
Example #22
Source File: BatchRequestTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testCreateNonemptyRequestBatch() {
    Request meRequest = Request.newMeRequest(null, null);

    RequestBatch batch = new RequestBatch(new Request[] { meRequest, meRequest });
    assertEquals(2, batch.size());
    assertEquals(meRequest, batch.get(0));
    assertEquals(meRequest, batch.get(1));
}
 
Example #23
Source File: GraphObjectFactoryTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testCastingToSameTypeGivesSameObject() {
    Base base = GraphObject.Factory.create(Base.class);

    Base cast = base.cast(Base.class);

    assertTrue(base == cast);
}
 
Example #24
Source File: SettingsTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest @MediumTest @LargeTest
public void testLoadDefaultsDoesNotOverwrite() {
    Settings.setApplicationId("hello");
    Settings.setClientToken("world");

    Settings.loadDefaultsFromMetadata(getActivity());

    assertEquals("hello", Settings.getApplicationId());
    assertEquals("world", Settings.getClientToken());
}
 
Example #25
Source File: BatchRequestTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testBatchWithoutAppIDIsError() {
    Request request1 = new Request(null, "TourEiffel", null, null, new ExpectFailureCallback());
    Request request2 = new Request(null, "SpaceNeedle", null, null, new ExpectFailureCallback());
    Request.executeBatchAndWait(request1, request2);
}
 
Example #26
Source File: GraphObjectFactoryTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testSetCharProperty() {
    GraphObjectWithPrimitives graphObject = GraphObject.Factory.create(GraphObjectWithPrimitives.class);

    graphObject.setChar('z');
    assertEquals('z', graphObject.getChar());
}
 
Example #27
Source File: GraphObjectFactoryTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testCollectionPutOfWrapperPutsJSONObject() throws JSONException {
    JSONObject jsonObject = new JSONObject();

    GraphObject graphObject = GraphObject.Factory.create(jsonObject);
    graphObject.setProperty("hello", "world");
    graphObject.setProperty("hocus", "pocus");

    GraphObjectList<GraphObject> parentList = GraphObject.Factory
            .createList(GraphObject.class);
    parentList.add(graphObject);

    JSONArray jsonArray = parentList.getInnerJSONArray();

    Object obj = jsonArray.opt(0);

    assertNotNull(obj);
    assertEquals(jsonObject, obj);

    parentList.set(0, graphObject);

    obj = jsonArray.opt(0);

    assertNotNull(obj);
    assertEquals(jsonObject, obj);
}
 
Example #28
Source File: GraphObjectFactoryTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testGetInnerJSONObject() throws JSONException {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("hello", "world");
    jsonObject.put("hocus", "pocus");

    GraphObject graphObject = GraphObject.Factory.create(jsonObject);

    assertEquals(jsonObject, graphObject.getInnerJSONObject());
}
 
Example #29
Source File: RequestTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testExecuteBatchWithNullRequestThrows() {
    try {
        Request.executeBatchAndWait(new Request[]{null});
        fail("expected NullPointerException");
    } catch (NullPointerException exception) {
    }
}
 
Example #30
Source File: RequestTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@SmallTest
@MediumTest
@LargeTest
public void testToHttpConnectionWithZeroRequestsThrows() {
    try {
        Request.toHttpConnection(new Request[]{});
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException exception) {
    }
}