Android Open Source - gasp-gcm-client Database Test






From Project

Back to project page gasp-gcm-client.

License

The source code is released under:

Apache License

If you think the Android project gasp-gcm-client listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cloudbees.gasp.adapter;
/*ww w.ja v a2  s . c  o m*/
import android.test.AndroidTestCase;

import com.cloudbees.gasp.model.Restaurant;
import com.cloudbees.gasp.model.Review;
import com.cloudbees.gasp.model.User;

import java.util.List;

/**
 * Copyright (c) 2013 Mark Prichard, CloudBees
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Tests GaspDataAdapter insert/delete methods
 */
public class DatabaseTest extends AndroidTestCase {

    private static final int testId = 1;
    private static final int testUserId = 1;
    private static final int testRestaurantId = 1;
    private static final int testStar = 1;
    private static final String testComment = "Test Comment";
    private static final String testName = "Test Name";
    private static final String testWebsite = "http://www.restaurant.com/";
    private static final String testPlacesId = "1234567890";
    private static final String testPlacesId2 = "0123456789";
    private static final String testPlacesId3 = "0000000000";

    protected void setUp() {
        ReviewDataAdapter reviewData = new ReviewDataAdapter(getContext());
        reviewData.open();
        try {
            List<Review> reviewList = reviewData.getAll();
            for (Review review : reviewList) {
                reviewData.delete(review);
            }
        } catch (Exception e) {
        } finally {
            reviewData.close();
        }

        RestaurantDataAdapter restaurantAdapter = new RestaurantDataAdapter(getContext());
        restaurantAdapter.open();
        try {
            List<Restaurant> restaurantList = restaurantAdapter.getAll();
            for (Restaurant restaurant : restaurantList) {
                restaurantAdapter.delete(restaurant);
            }
        } catch (Exception e) {
        } finally {
            restaurantAdapter.close();
        }

        UserDataAdapter userAdapter = new UserDataAdapter(getContext());
        userAdapter.open();
        try {
            List<User> userList = userAdapter.getAll();
            for (User user : userList) {
                userAdapter.delete(user);
            }
        } catch (Exception e) {
        } finally {
            userAdapter.close();
        }
    }

    protected void tearDown() {
    }

    public void testReviewAdapter() {
        ReviewDataAdapter reviewData = new ReviewDataAdapter(getContext());
        List<Review> reviewList;

        reviewData.open();
        assertEquals(0, reviewData.getLastId());
        reviewData.close();

        Review review = new Review();

        review.setId(testId);
        review.setRestaurant_id(testRestaurantId);
        review.setUser_id(testUserId);
        review.setComment(testComment);
        review.setStar(testStar);

        reviewData.open();
        reviewData.insert(review);
        reviewList = reviewData.getAll();
        assertEquals(reviewList.size(), 1);

        assertEquals(reviewList.get(0).getId(), testId);
        assertEquals(reviewList.get(0).getUser_id(), testUserId);
        assertEquals(reviewList.get(0).getRestaurant_id(), testRestaurantId);
        assertEquals(reviewList.get(0).getComment(), testComment);
        assertEquals(reviewList.get(0).getStar(), testStar);

        review.setId(testId + 1);
        reviewData.insert(review);
        reviewList = reviewData.getAll();
        assertEquals(reviewList.size(), 2);
        assertEquals(reviewList.get(1).getId(), testId + 1);
        assertEquals(2, reviewData.getLastId());

        reviewData.delete(review);
        reviewList = reviewData.getAll();
        assertEquals(reviewList.size(), 1);
        reviewData.close();

        reviewData.open();
        assertEquals(1, reviewData.getLastId());
        reviewData.close();
    }

    public void testRestaurantAdapter() {
        RestaurantDataAdapter restaurantData = new RestaurantDataAdapter(getContext());
        List<Restaurant> restaurantList;

        restaurantData.open();
        assertEquals(0, restaurantData.getLastId());
        restaurantData.close();

        Restaurant restaurant = new Restaurant();

        restaurant.setId(testId);
        restaurant.setName(testName);
        restaurant.setWebsite(testWebsite);
        restaurant.setPlacesId(testPlacesId);

        restaurantData.open();
        restaurantData.insert(restaurant);
        restaurantList = restaurantData.getAll();
        assertEquals(restaurantList.size(), 1);

        assertEquals(restaurantList.get(0).getId(), testId);
        assertEquals(restaurantList.get(0).getName(), testName);
        assertEquals(restaurantList.get(0).getWebsite(), testWebsite);
        assertEquals(restaurantList.get(0).getPlacesId(), testPlacesId);

        restaurant.setId(testId + 1);
        restaurant.setPlacesId(testPlacesId2);
        restaurantData.insert(restaurant);
        restaurantList = restaurantData.getAll();
        assertEquals(restaurantList.size(), 2);
        assertEquals(restaurantList.get(1).getId(), 2);

        Restaurant testResult = restaurantData.findRestaurantByPlacesId(testPlacesId2);
        assert (testResult.getPlacesId().equals(testPlacesId2));
        assertEquals(2, restaurantData.getLastId());

        assert (restaurantData.findRestaurantByPlacesId(testPlacesId3) == null);

        restaurantData.delete(restaurant);
        restaurantList = restaurantData.getAll();
        assertEquals(restaurantList.size(), 1);

        restaurantData.close();

        restaurantData.open();
        restaurantData.getLastId();
        restaurantData.close();
    }

    public void testUserAdapter() {
        UserDataAdapter userData = new UserDataAdapter(getContext());
        List<User> userList;

        userData.open();
        assertEquals(0, userData.getLastId());
        userData.close();

        User user = new User();

        user.setId(testId);
        user.setName(testName);

        userData.open();
        userData.insert(user);
        userList = userData.getAll();
        assertEquals(userList.size(), 1);

        assertEquals(userList.get(0).getId(), testId);
        assertEquals(userList.get(0).getName(), testName);

        user.setId(testId + 1);
        userData.insert(user);
        userList = userData.getAll();
        assertEquals(userList.size(), 2);
        assertEquals(userList.get(1).getId(), 2);
        assertEquals(2, userData.getLastId());

        userData.delete(user);
        userList = userData.getAll();
        assertEquals(userList.size(), 1);

        userData.close();

        userData.open();
        userData.getLastId();
        userData.close();
    }
}




Java Source Code List

com.cloudbees.gasp.activity.ConsoleActivityTest.java
com.cloudbees.gasp.activity.ConsoleActivity.java
com.cloudbees.gasp.activity.PlacesActivityTest.java
com.cloudbees.gasp.activity.PlacesActivity.java
com.cloudbees.gasp.activity.PlacesDetailActivityTest.java
com.cloudbees.gasp.activity.PlacesDetailActivity.java
com.cloudbees.gasp.activity.RestaurantListActivityTest.java
com.cloudbees.gasp.activity.RestaurantListActivity.java
com.cloudbees.gasp.activity.ReviewActivity.java
com.cloudbees.gasp.activity.ReviewListActivityTest.java
com.cloudbees.gasp.activity.ReviewListActivity.java
com.cloudbees.gasp.activity.SetPreferencesActivity.java
com.cloudbees.gasp.activity.TestParams.java
com.cloudbees.gasp.activity.TwitterStreamActivityTest.java
com.cloudbees.gasp.activity.TwitterStreamActivity.java
com.cloudbees.gasp.activity.UserListActivityTest.java
com.cloudbees.gasp.activity.UserListActivity.java
com.cloudbees.gasp.adapter.DataAdapterQueryTest.java
com.cloudbees.gasp.adapter.DatabaseTest.java
com.cloudbees.gasp.adapter.GaspDataAdapter.java
com.cloudbees.gasp.adapter.GaspSQLiteHelper.java
com.cloudbees.gasp.adapter.RestaurantArrayAdapter.java
com.cloudbees.gasp.adapter.RestaurantDataAdapter.java
com.cloudbees.gasp.adapter.ReviewArrayAdapter.java
com.cloudbees.gasp.adapter.ReviewDataAdapter.java
com.cloudbees.gasp.adapter.UserArrayAdapter.java
com.cloudbees.gasp.adapter.UserDataAdapter.java
com.cloudbees.gasp.fragment.AddEventFragment.java
com.cloudbees.gasp.fragment.DeleteEventFragment.java
com.cloudbees.gasp.fragment.GaspDatabaseFragment.java
com.cloudbees.gasp.fragment.GaspRestaurantFragment.java
com.cloudbees.gasp.fragment.GaspReviewFragment.java
com.cloudbees.gasp.fragment.LocationFragment.java
com.cloudbees.gasp.fragment.NearbySearchFragment.java
com.cloudbees.gasp.fragment.PlaceDetailsFragment.java
com.cloudbees.gasp.fragment.PreferencesFragment.java
com.cloudbees.gasp.fragment.RESTResponderFragment.java
com.cloudbees.gasp.fragment.TwitterAuthenticationFragment.java
com.cloudbees.gasp.fragment.TwitterResponderFragment.java
com.cloudbees.gasp.gcm.GCMBroadcastReceiver.java
com.cloudbees.gasp.gcm.GCMIntentService.java
com.cloudbees.gasp.gcm.GCMRegistration.java
com.cloudbees.gasp.location.GooglePlacesClient.java
com.cloudbees.gasp.location.NearbySearchTest.java
com.cloudbees.gasp.location.PlaceDetailsTest.java
com.cloudbees.gasp.location.PlaceEventsTest.java
com.cloudbees.gasp.model.EventRequest.java
com.cloudbees.gasp.model.EventResponse.java
com.cloudbees.gasp.model.GaspDataObject.java
com.cloudbees.gasp.model.Geometry.java
com.cloudbees.gasp.model.Location.java
com.cloudbees.gasp.model.ModelObjectTest.java
com.cloudbees.gasp.model.PlaceDetail.java
com.cloudbees.gasp.model.PlaceDetails.java
com.cloudbees.gasp.model.PlaceEvent.java
com.cloudbees.gasp.model.Place.java
com.cloudbees.gasp.model.Places.java
com.cloudbees.gasp.model.Query.java
com.cloudbees.gasp.model.Restaurant.java
com.cloudbees.gasp.model.Review.java
com.cloudbees.gasp.model.TwitterStatus.java
com.cloudbees.gasp.model.TwitterStatuses.java
com.cloudbees.gasp.model.TwitterTokenResponse.java
com.cloudbees.gasp.model.User.java
com.cloudbees.gasp.robotium.NavigationTest.java
com.cloudbees.gasp.server.GaspEntityTest.java
com.cloudbees.gasp.server.GaspRestaurantTest.java
com.cloudbees.gasp.server.GaspReviewTest.java
com.cloudbees.gasp.server.GaspServerAPI.java
com.cloudbees.gasp.service.AsyncRESTClient.java
com.cloudbees.gasp.service.AsyncRestTestAll.java
com.cloudbees.gasp.service.AsyncRestTestIndex.java
com.cloudbees.gasp.service.IRESTListener.java
com.cloudbees.gasp.service.RESTIntentService.java
com.cloudbees.gasp.service.RestaurantSyncServiceTest.java
com.cloudbees.gasp.service.RestaurantSyncService.java
com.cloudbees.gasp.service.RestaurantUpdateServiceTest.java
com.cloudbees.gasp.service.RestaurantUpdateService.java
com.cloudbees.gasp.service.ReviewSyncServiceTest.java
com.cloudbees.gasp.service.ReviewSyncService.java
com.cloudbees.gasp.service.ReviewUpdateServiceTest.java
com.cloudbees.gasp.service.ReviewUpdateService.java
com.cloudbees.gasp.service.TwitterServiceTest.java
com.cloudbees.gasp.service.UserSyncServiceTest.java
com.cloudbees.gasp.service.UserSyncService.java
com.cloudbees.gasp.service.UserUpdateServiceTest.java
com.cloudbees.gasp.service.UserUpdateService.java
com.cloudbees.gasp.twitter.TwitterAPI.java
com.cloudbees.gasp.twitter.TwitterAuthServiceTest.java
com.cloudbees.gasp.twitter.TwitterAuthentication.java