Example #1
0
  public long insertLocation() {
    // First step: Get reference to writable database
    SQLiteDatabase db = new WeatherDbHelper(this.mContext).getWritableDatabase();

    // Create ContentValues of what you want to insert
    ContentValues weatherValues = TestUtilities.createNorthPoleLocationValues();

    // Insert ContentValues into database and get a row ID back
    long rowID = TestUtilities.insertNorthPoleLocationValues(this.mContext);
    assertFalse("Insert failed", rowID == -1);

    // Query the database and receive a Cursor back
    Cursor c =
        db.query(WeatherContract.LocationEntry.TABLE_NAME, null, null, null, null, null, null);

    // Move the cursor to a valid database row
    assertTrue("No records freturned from location query", c.moveToFirst());

    // Validate data in resulting Cursor with the original ContentValues
    // (you can use the validateCurrentRecord function in TestUtilities to validate the
    // query if you like)
    TestUtilities.validateCurrentRecord(
        "Location data read from DB did not match ContentValues", c, weatherValues);

    assertFalse("More than one record returned", c.moveToNext());

    // Finally, close the cursor and database
    c.close();
    db.close();
    return rowID;
  }
  // Make sure we can still delete after adding/updating stuff
  //
  // Student: Uncomment this test after you have completed writing the insert functionality
  // in your provider.  It relies on insertions with testInsertReadProvider, so insert and
  // query functionality must also be complete before this test can be used.
  public void testInsertReadProvider() {
    ContentValues testValues = TestUtilities.createMovie();
    // Register a content observer for our insert.  This time, directly with the content resolver
    TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
    mContext.getContentResolver().registerContentObserver(MovieEntry.CONTENT_URI, true, tco);
    Uri movieUri = mContext.getContentResolver().insert(MovieEntry.CONTENT_URI, testValues);

    // Did our content observer get called?  Students:  If this fails, your insert movie
    // isn't calling getContext().getContentResolver().notifyChange(uri, null);
    tco.waitForNotificationOrFail();
    mContext.getContentResolver().unregisterContentObserver(tco);

    long movieRowId = ContentUris.parseId(movieUri);

    // Verify we got a row back.
    assertTrue(movieRowId != -1);

    // Data's inserted.  IN THEORY.  Now pull some out to stare at it and verify it made
    // the round trip.

    // A cursor is your primary interface to the query results.
    Cursor cursor =
        mContext
            .getContentResolver()
            .query(
                MovieEntry.CONTENT_URI,
                null, // leaving "columns" null just returns all the columns.
                null, // cols for "where" clause
                null, // values for "where" clause
                null // sort order
                );

    TestUtilities.validateCursor(
        "testInsertReadProvider. Error validating MovieEntry.", cursor, testValues);
  }
Example #3
0
  public long insertReview(long movieId) {
    MovieDbHelper dbHelper = new MovieDbHelper(mContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    ContentValues testValues = TestUtilities.createReviewBladerunnerValues(movieId);
    long reviewRowId = db.insert(MoviesContract.ReviewEntry.TABLE_NAME, null, testValues);
    assertTrue(reviewRowId != -1);
    Cursor cursor =
        db.query(
            MoviesContract.ReviewEntry.TABLE_NAME, // Table to Query
            null, // all columns
            null, // Columns for the "where" clause
            null, // Values for the "where" clause
            null, // columns to group by
            null, // columns to filter by row groups
            null // sort order
            );
    assertTrue("Error: No Records returned from review query", cursor.moveToFirst());
    TestUtilities.validateCurrentRecord(
        "Error: Review Query Validation Failed", cursor, testValues);

    // Move the cursor to demonstrate that there is only one record in the database
    assertFalse("Error: More than one record returned from review query", cursor.moveToNext());

    // Sixth Step: Close Cursor and Database
    cursor.close();
    db.close();
    return reviewRowId;
  }
Example #4
0
  /*
     This test uses the database directly to insert and then uses the ContentProvider to
     read out the data.  Uncomment this test to see if your location queries are
     performing correctly.
  */
  public void testBasicLocationQueries() {
    // insert our test records into the database
    WeatherDatabaseHelper dbHelper = new WeatherDatabaseHelper(mContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    ContentValues testValues = TestUtilities.createNorthPoleLocationValues();
    long locationRowId = TestUtilities.insertNorthPoleLocationValues(mContext);

    // Test the basic content provider query
    Cursor locationCursor =
        mContext.getContentResolver().query(LocationEntry.CONTENT_URI, null, null, null, null);

    // Make sure we get the correct cursor out of the database
    TestUtilities.validateCursor(
        "testBasicLocationQueries, location query", locationCursor, testValues);

    // Has the NotificationUri been set correctly? --- we can only test this easily against API
    // level 19 or greater because getNotificationUri was added in API level 19.
    if (Build.VERSION.SDK_INT >= 19) {
      assertEquals(
          "Error: Location Query did not properly set NotificationUri",
          locationCursor.getNotificationUri(),
          LocationEntry.CONTENT_URI);
    }
  }
Example #5
0
  // Make sure we can still delete after adding/updating stuff
  //
  // Student: Uncomment this test after you have completed writing the delete functionality
  // in your provider.  It relies on insertions with testInsertReadProvider, so insert and
  // query functionality must also be complete before this test can be used.
  public void testDeleteRecords() {
    testInsertReadProvider();

    // Register a content observer for our location delete.
    TestUtilities.TestContentObserver locationObserver = TestUtilities.getTestContentObserver();
    mContext
        .getContentResolver()
        .registerContentObserver(LocationEntry.CONTENT_URI, true, locationObserver);

    // Register a content observer for our weather delete.
    TestUtilities.TestContentObserver weatherObserver = TestUtilities.getTestContentObserver();
    mContext
        .getContentResolver()
        .registerContentObserver(WeatherEntry.CONTENT_URI, true, weatherObserver);

    deleteAllRecordsFromProvider();

    // Students: If either of these fail, you most-likely are not calling the
    // getContext().getContentResolver().notifyChange(uri, null); in the ContentProvider
    // delete.  (only if the insertReadProvider is succeeding)
    locationObserver.waitForNotificationOrFail();
    weatherObserver.waitForNotificationOrFail();

    mContext.getContentResolver().unregisterContentObserver(locationObserver);
    mContext.getContentResolver().unregisterContentObserver(weatherObserver);
  }
  @Test
  public void test() {

    // Insert 25, 100, 10
    try {
      tMachine.getCoinSlot().addCoin(new Coin(25));
      tMachine.getCoinSlot().addCoin(new Coin(100));
      tMachine.getCoinSlot().addCoin(new Coin(10));
    } catch (DisabledException e) {
      e.printStackTrace();
    }

    // Press selection button zero
    tMachine.getSelectionButton(0).press();

    // Compare the extraction with expected results
    List<Object> extractedItems = Arrays.asList(tMachine.getDeliveryChute().removeItems());
    Object[] actualExtractedItems = TestUtilities.parseExtraction(extractedItems);
    Object[] expectedExtraction = {0, "stuff"};

    assertArrayEquals(expectedExtraction, actualExtractedItems);

    // Compare vending machine stored contents with expected output
    Object[] actualContents = TestUtilities.parseContents(TestUtilities.emptyContents(tMachine));
    Object[] expectedContents = {1400, 135};
    assertArrayEquals(expectedContents, actualContents);
  }
Example #7
0
  /*
     Students:  Here is where you will build code to test that we can insert and query the
     database.  We've done a lot of work for you.  You'll want to look in TestUtilities
     where you can use the "createWeatherValues" function.  You can
     also make use of the validateCurrentRecord function from within TestUtilities.
  */
  public long testWeatherTable() {
    // First insert the location, and then use the locationRowId to insert
    // the weather. Make sure to cover as many failure cases as you can.+
    long locationRowId = insertLocation();
    ContentValues weatherValues = TestUtilities.createWeatherValues(locationRowId);
    // Instead of rewriting all of the code we've already written in testLocationTable
    // we can move this code to insertLocation and then call insertLocation from both
    // tests. Why move it? We need the code to return the ID of the inserted location
    // and our testLocationTable can only return void because it's a test.
    SQLiteDatabase db = new WeatherDbHelper(this.mContext).getWritableDatabase();
    // Create ContentValues of what you want to insert
    // (you can use the createNorthPoleLocationValues if you wish)

    // Insert ContentValues into database and get a row ID back
    long id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, weatherValues);
    assertFalse("Insert failed. ", id == -1);
    // Query the database and receive a Cursor back
    Cursor c = db.rawQuery("SELECT * FROM " + WeatherContract.WeatherEntry.TABLE_NAME, null);
    // Move the cursor to a valid database row
    c.moveToFirst();
    // Validate data in resulting Cursor with the original ContentValues
    // (you can use the validateCurrentRecord function in TestUtilities to validate the
    // query if you like)
    TestUtilities.validateCurrentRecord("Nije isti location record", c, weatherValues);

    // Finally, close the cursor and database
    c.close();
    db.close();

    // Finally, close the cursor and database
    return id;
  }
 public void test_childrenByLinkDeclarationSpecialized() throws Exception {
   this.addNodeById("8758390115029078425");
   this.addNodeById("5815925154349132136");
   this.addNodeById("2166349271756548530");
   TestUtilities.assertEquals(
       Sequence.fromArray(
           new SNode[] {
             SNodeOperations.cast(
                 this.getNodeById("2600026384779198859"),
                 "jetbrains.mps.lang.smodelTests.structure.GrandChild")
           }),
       SNodeOperations.getChildren(
           SNodeOperations.cast(
               this.getNodeById("8758390115029078430"),
               "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept"),
           SLinkOperations.findLinkDeclaration(
               "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept",
               "specializedGranChild_0_1")));
   TestUtilities.assertEquals(
       Sequence.fromArray(
           new SNode[] {
             SNodeOperations.cast(
                 this.getNodeById("2600026384779198859"),
                 "jetbrains.mps.lang.smodelTests.structure.GrandChild")
           }),
       SNodeOperations.getChildren(
           SNodeOperations.cast(
               this.getNodeById("8758390115029078430"),
               "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept"),
           SLinkOperations.findLinkDeclaration(
               "jetbrains.mps.lang.smodelTests.structure.Child", "grandChild_0_1")));
 }
Example #9
0
  /*
      Students:  Here is where you will build code to test that we can insert and query the
      location database.  We've done a lot of work for you.  You'll want to look in TestUtilities
      where you can uncomment out the "createNorthPoleLocationValues" function.  You can
      also make use of the ValidateCurrentRecord function from within TestUtilities.
  */
  public void testLocationTable() {
    // First step: Get reference to writable database
    SQLiteDatabase db = new WeatherDbHelper(this.mContext).getWritableDatabase();

    // Create ContentValues of what you want to insert
    // (you can use the createNorthPoleLocationValues if you wish)
    ContentValues values = TestUtilities.createNorthPoleLocationValues();

    // Insert ContentValues into database and get a row ID back
    long row = db.insert(WeatherContract.LocationEntry.TABLE_NAME, null, values);
    assertTrue(row != -1);

    // Query the database and receive a Cursor back
    Cursor cursor =
        db.query(WeatherContract.LocationEntry.TABLE_NAME, null, null, null, null, null, null);

    // Move the cursor to a valid database row
    cursor.moveToFirst();

    // Validate data in resulting Cursor with the original ContentValues
    // (you can use the validateCurrentRecord function in TestUtilities to validate the
    // query if you like)
    TestUtilities.validateCurrentRecord("Error: Location Query validation", cursor, values);

    // Finally, close the cursor and database
    cursor.close();
    db.close();
  }
Example #10
0
  /*
      Students:  Here is where you will build code to test that we can insert and query the
      location database.  We've done a lot of work for you.  You'll want to look in TestUtilities
      where you can uncomment out the "createNorthPoleLocationValues" function.  You can
      also make use of the ValidateCurrentRecord function from within TestUtilities.
  */
  public long testLocationTable() {
    // First step: Get reference to writable database
    SQLiteDatabase db = new WeatherDbHelper(this.mContext).getWritableDatabase();
    // Create ContentValues of what you want to insert
    // (you can use the createNorthPoleLocationValues if you wish)
    TestUtilities tu = new TestUtilities();
    ContentValues cv = tu.createNorthPoleLocationValues();
    // Insert ContentValues into database and get a row ID back
    long id = db.insert(WeatherContract.LocationEntry.TABLE_NAME, null, cv);
    assertFalse("Insert failed. ", id == -1);
    // Query the database and receive a Cursor back
    Cursor c = db.rawQuery("SELECT * FROM " + WeatherContract.LocationEntry.TABLE_NAME, null);
    // Move the cursor to a valid database row
    c.moveToFirst();
    // Validate data in resulting Cursor with the original ContentValues
    // (you can use the validateCurrentRecord function in TestUtilities to validate the
    // query if you like)
    tu.validateCurrentRecord("Nije isti location record", c, cv);

    // Finally, close the cursor and database
    c.close();
    db.close();

    return id;
  }
  /**
   * <em>Note:</em> This test <i>does not</i> check {@code insert} function of {@code
   * ContentProvider}. The test only asserts that all columns were created with correct data type.
   * So, in this test, we use pure {@code insert} function of {@code SQLiteDatabase}
   */
  @Test
  public void checkInsertIntoLinkedArticlesTable() {
    ContentValues testValue = TestUtilities.createLinkedArticleValue();

    long rowId = db.insert(ArticleDatabase.Tables.LINKED_ARTICLES, null, testValue);

    assertTrue(rowId != -1);

    cursor =
        db.query(
            ArticleDatabase.Tables.LINKED_ARTICLES,
            null, // column
            null, // selections
            null, // selection args
            null, // groupBy
            null, // having
            null); // orderBy

    assertTrue("Error: No records returned from Linked Articles table", cursor.moveToFirst());
    TestUtilities.validateCurrentRecord(
        "Error: Linked Articles query validation failed", cursor, testValue);

    assertFalse(
        "Error: More than one record return from Linked Articles query", cursor.moveToNext());
  }
Example #12
0
  /*
     This test uses the provider to insert and then update the data. Uncomment this test to
     see if your update location is functioning correctly.
  */
  public void testUpdateLocation() {
    // Create a new map of values, where column names are the keys
    ContentValues values = TestUtilities.createNorthPoleLocationValues();

    Uri locationUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, values);
    long locationRowId = ContentUris.parseId(locationUri);

    // Verify we got a row back.
    assertTrue(locationRowId != -1);
    Log.d(LOG_TAG, "New row id: " + locationRowId);

    ContentValues updatedValues = new ContentValues(values);
    updatedValues.put(LocationEntry._ID, locationRowId);
    updatedValues.put(LocationEntry.CITY_NAME, "Santa's Village");

    // Create a cursor with observer to make sure that the content provider is notifying
    // the observers as expected
    Cursor locationCursor =
        mContext.getContentResolver().query(LocationEntry.CONTENT_URI, null, null, null, null);

    TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
    locationCursor.registerContentObserver(tco);

    int count =
        mContext
            .getContentResolver()
            .update(
                LocationEntry.CONTENT_URI,
                updatedValues,
                LocationEntry._ID + "= ?",
                new String[] {Long.toString(locationRowId)});
    assertEquals(count, 1);

    // Test to make sure our observer is called.  If not, we throw an assertion.
    //
    // Students: If your code is failing here, it means that your content provider
    // isn't calling getContext().getContentResolver().notifyChange(uri, null);
    tco.waitForNotificationOrFail();

    locationCursor.unregisterContentObserver(tco);
    // locationCursor.close();

    // A cursor is your primary interface to the query results.
    Cursor cursor =
        mContext
            .getContentResolver()
            .query(
                LocationEntry.CONTENT_URI,
                null, // projection
                LocationEntry._ID + " = " + locationRowId,
                null, // Values for the "where" clause
                null // sort order
                );

    TestUtilities.validateCursor(
        "testUpdateLocation.  Error validating location entry update.", cursor, updatedValues);

    // cursor.close();
  }
Example #13
0
  public long insertMovieXXX(int movieId) {
    // First step: Get reference to writable database
    // If there's an error in those massive SQL table creation Strings,
    // errors will be thrown here when you try to get a writable database.
    MovieDbHelper dbHelper = new MovieDbHelper(mContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    // Second Step: Create ContentValues of what you want to insert
    // (you can use the createNorthPoleLocationValues if you wish)
    ContentValues testValues;
    if (movieId == 1) {
      testValues = TestUtilities.createMovieBladerunnerValues();
    } else {
      testValues = TestUtilities.createMovieCasablancaValues();
    }

    // Third Step: Insert ContentValues into database and get a row ID back
    long locationRowId;
    locationRowId = db.insert(MoviesContract.MovieEntry.TABLE_NAME, null, testValues);

    // Verify we got a row back.
    assertTrue(locationRowId != -1);

    // Data's inserted.  IN THEORY.  Now pull some out to stare at it and verify it made
    // the round trip.

    // Fourth Step: Query the database and receive a Cursor back
    // A cursor is your primary interface to the query results.
    Cursor cursor =
        db.query(
            MoviesContract.MovieEntry.TABLE_NAME, // Table to Query
            null, // all columns
            null, // Columns for the "where" clause
            null, // Values for the "where" clause
            null, // columns to group by
            null, // columns to filter by row groups
            null // sort order
            );

    // Move the cursor to a valid database row and check to see if we got any records back
    // from the query
    assertTrue("Error: No Records returned from movie query", cursor.moveToFirst());

    // Fifth Step: Validate data in resulting Cursor with the original ContentValues
    // (you can use the validateCurrentRecord function in TestUtilities to validate the
    // query if you like)
    TestUtilities.validateCurrentRecord("Error: Movie Query Validation Failed", cursor, testValues);

    // Move the cursor to demonstrate that there is only one record in the database
    assertFalse("Error: More than one record returned from movie query", cursor.moveToNext());

    // Sixth Step: Close Cursor and Database
    cursor.close();
    db.close();
    return locationRowId;
  }
  public void testConversionToAllFormats() throws Throwable {

    Iterator i = ImageWriterFactoryImpl.RULES.keySet().iterator();
    while (i.hasNext()) {
      String rule = (String) i.next();
      RenderedOp image =
          TestUtilities.transcodeToImage(expectations, rule, "animated_indexed.gif", null, true);
      TestUtilities.checkConversionResult(rule, image);
    }
  }
Example #15
0
  /*
     Students:  Here is where you will build code to test that we can insert and query the
     database.  We've done a lot of work for you.  You'll want to look in TestUtilities
     where you can use the "createWeatherValues" function.  You can
     also make use of the validateCurrentRecord function from within TestUtilities.
  */
  public void testWeatherTable() {
    // First insert the location, and then use the locationRowId to insert
    // the weather. Make sure to cover as many failure cases as you can.

    // Instead of rewriting all of the code we've already written in testLocationTable
    // we can move this code to insertLocation and then call insertLocation from both
    // tests. Why move it? We need the code to return the ID of the inserted location
    // and our testLocationTable can only return void because it's a test.

    long locationRowId = insertLocation();

    // Make sure we have a valid row ID.
    assertFalse("Error: Location Not Inserted Correctly", locationRowId == -1L);

    // First step: Get reference to writable database
    // If there's an error in those massive SQL table creation Strings,
    // errors will be thrown here when you try to get a writable database.
    WeatherDbHelper dbHelper = new WeatherDbHelper(mContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    // Second Step (Weather): Create weather values
    ContentValues weatherValues = TestUtilities.createWeatherValues(locationRowId);

    // Third Step (Weather): Insert ContentValues into database and get a row ID back
    long weatherRowId = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, weatherValues);
    assertTrue(weatherRowId != -1);

    // Fourth Step: Query the database and receive a Cursor back
    // A cursor is your primary interface to the query results.
    Cursor weatherCursor =
        db.query(
            WeatherContract.WeatherEntry.TABLE_NAME, // Table to Query
            null, // leaving "columns" null just returns all the columns.
            null, // cols for "where" clause
            null, // values for "where" clause
            null, // columns to group by
            null, // columns to filter by row groups
            null // sort order
            );

    // Move the cursor to the first valid database row and check to see if we have any rows
    assertTrue("Error: No Records returned from location query", weatherCursor.moveToFirst());

    // Fifth Step: Validate the location Query
    TestUtilities.validateCurrentRecord(
        "testInsertReadDb weatherEntry failed to validate", weatherCursor, weatherValues);

    // Move the cursor to demonstrate that there is only one record in the database
    assertFalse(
        "Error: More than one record returned from weather query", weatherCursor.moveToNext());

    // Sixth Step: Close cursor and database
    weatherCursor.close();
    dbHelper.close();
  }
Example #16
0
 public long insertLocation() {
   SQLiteDatabase db = new WeatherDbHelper(this.mContext).getWritableDatabase();
   // Create ContentValues of what you want to insert
   // (you can use the createNorthPoleLocationValues if you wish)
   TestUtilities tu = new TestUtilities();
   ContentValues cv = tu.createNorthPoleLocationValues();
   // Insert ContentValues into database and get a row ID back
   long id = db.insert(WeatherContract.LocationEntry.TABLE_NAME, null, cv);
   assertFalse("Insert failed. ", id == -1);
   // Query the database and receive a Cursor back
   db.close();
   return id;
 }
Example #17
0
  public void testInsert() throws Throwable {
    SQLiteDatabase db = new DatabaseHelper(mContext).getWritableDatabase();

    ContentValues eventValues = TestUtilities.getEventContentValues("123", "321");
    ContentValues placeValues = TestUtilities.getPlaceContentValues("321");

    long placeRowId = db.insertOrThrow(Contracts.PlaceEntry.TABLE_NAME, null, placeValues);
    long eventRowId = db.insertOrThrow(Contracts.EventEntry.TABLE_NAME, null, eventValues);

    assertTrue("Error: Failure to insert place " + placeRowId, placeRowId != -1);
    assertTrue("Error: Failure to insert event " + eventRowId, eventRowId != -1);

    db.close();
  }
 public void test_roles() throws Exception {
   this.addNodeById("2906110183022219846");
   this.addNodeById("2906110183022219807");
   this.addNodeById("2906110183022219843");
   this.addNodeById("2906110183022354865");
   this.addNodeById("2906110183022432276");
   TestUtilities.assertEquals(
       Sequence.fromArray(
           new String[] {
             SPropertyOperations.getString(
                 SLinkOperations.findLinkDeclaration(
                     "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer", "root"),
                 "role"),
             SPropertyOperations.getString(
                 SLinkOperations.findLinkDeclaration(
                     "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer", "leftChild"),
                 "role"),
             SPropertyOperations.getString(
                 SLinkOperations.findLinkDeclaration(
                     "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer",
                     "rightChild"),
                 "role")
           }),
       Sequence.fromIterable(
               SNodeOperations.getReferences(
                   SNodeOperations.cast(
                       this.getNodeById("2906110183022219844"),
                       "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer")))
           .select(
               new ISelector<SReference, String>() {
                 public String select(SReference it) {
                   return SLinkOperations.getRole(it);
                 }
               }));
 }
 public void test_target() throws Exception {
   this.addNodeById("2906110183022219846");
   this.addNodeById("2906110183022219807");
   this.addNodeById("2906110183022219843");
   this.addNodeById("2906110183022354865");
   this.addNodeById("2906110183022432276");
   TestUtilities.assertEquals(
       Sequence.fromArray(
           new SNode[] {
             SNodeOperations.cast(
                 this.getNodeById("2906110183022219847"),
                 "jetbrains.mps.lang.smodelTests.structure.Root"),
             SNodeOperations.cast(
                 this.getNodeById("2906110183022219848"),
                 "jetbrains.mps.lang.smodelTests.structure.Child"),
             SNodeOperations.cast(
                 this.getNodeById("2906110183022311236"),
                 "jetbrains.mps.lang.smodelTests.structure.ChildSubConcept")
           }),
       Sequence.fromIterable(
               SNodeOperations.getReferences(
                   SNodeOperations.cast(
                       this.getNodeById("2906110183022219844"),
                       "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer")))
           .select(
               new ISelector<SReference, SNode>() {
                 public SNode select(SReference it) {
                   return SLinkOperations.getTargetNode(it);
                 }
               }));
 }
Example #20
0
  @Before
  public void setUp() throws Exception {

    // Construct the vending machine
    int[] coinKinds = {5, 10, 25, 100};
    tMachine = new VendingMachine(coinKinds, 1, 10, 10, 10);
    new VendingMachineLogic(tMachine);

    // Configure the vending machine
    List<String> popNames = new ArrayList<String>();
    popNames.add("stuff");

    List<Integer> popCosts = new ArrayList<Integer>();
    popCosts.add(135);

    tMachine.configure(popNames, popCosts);

    // Load the vending machine
    List<Integer> coinCounts = new ArrayList<Integer>();
    coinCounts.add(10);
    coinCounts.add(10);
    coinCounts.add(10);
    coinCounts.add(10);

    List<Integer> popCanCounts = new ArrayList<Integer>();
    popCanCounts.add(1);

    TestUtilities.stock(coinCounts, popCanCounts, tMachine);
  }
 public void test_childContainingRoles() throws Exception {
   this.addNodeById("8758390115029078425");
   this.addNodeById("5815925154349132136");
   this.addNodeById("2166349271756548530");
   TestUtilities.assertEquals(
       Sequence.fromArray(
           new String[] {
             SPropertyOperations.getString(
                 SLinkOperations.findLinkDeclaration(
                     "jetbrains.mps.lang.smodelTests.structure.Root", "child_1_n"),
                 "role"),
             SPropertyOperations.getString(
                 SLinkOperations.findLinkDeclaration(
                     "jetbrains.mps.lang.smodelTests.structure.Root", "childSubConcept_0_n"),
                 "role")
           }),
       ListSequence.fromList(
               SNodeOperations.getChildren(
                   SNodeOperations.cast(
                       this.getNodeById("8758390115029078426"),
                       "jetbrains.mps.lang.smodelTests.structure.Root")))
           .select(
               new ISelector<SNode, String>() {
                 public String select(SNode it) {
                   return SNodeOperations.getContainingLinkRole(it);
                 }
               }));
 }
Example #22
0
 /** A check for serialization. */
 @Test
 public void testSerialization2() {
   PaintMap m1 = new PaintMap();
   m1.put("K1", Color.red);
   m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow));
   PaintMap m2 = (PaintMap) TestUtilities.serialised(m1);
   assertEquals(m1, m2);
 }
Example #23
0
 public static void testInstancesCurrentlyMonitoredByHTM-ITTitleVerification(
         WebDriver driver) {
     String instancesCurrentlyMonitoredByHTM-ITSectionTitle = TestUtilities
             .waitGetText(INSTANCES_CURRENTLY_MONITORED_BY_HTM-IT_TITLE,
                     driver, WAIT_TIME);
     Assert.assertEquals(instancesCurrentlyMonitoredByHTM-ITSectionTitle,
             "Instances Currently Monitored by HTM-IT");
 }
Example #24
0
  /*
     Students:  Here is where you will build code to test that we can insert and query the
     database.  We've done a lot of work for you.  You'll want to look in TestUtilities
     where you can use the "createWeatherValues" function.  You can
     also make use of the validateCurrentRecord function from within TestUtilities.
  */
  public void testWeatherTable() {
    // First insert the location, and then use the locationRowId to insert
    // the weather. Make sure to cover as many failure cases as you can.

    // Instead of rewriting all of the code we've already written in testLocationTable
    // we can move this code to insertLocation and then call insertLocation from both
    // tests. Why move it? We need the code to return the ID of the inserted location
    // and our testLocationTable can only return void because it's a test.

    long locationRowId = insertLocation();

    assertFalse("Error: Location Not Inserted Correctly", locationRowId == -1L);
    // First step: Get reference to writable database

    WeatherDbHelper dbHelper = new WeatherDbHelper(mContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    // Create ContentValues of what you want to insert
    // (you can use the createWeatherValues TestUtilities function if you wish)
    ContentValues weatherValues = TestUtilities.createWeatherValues(locationRowId);

    // Insert ContentValues into database and get a row ID back
    long weatherRowId = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, weatherValues);
    assertTrue(weatherRowId != -1);

    // Query the database and receive a Cursor back
    Cursor weatherCursor =
        db.query(WeatherContract.WeatherEntry.TABLE_NAME, null, null, null, null, null, null);

    // Move the cursor to a valid database row
    assertTrue("Error: No Records returned from location query", weatherCursor.moveToFirst());

    // Validate data in resulting Cursor with the original ContentValues
    // (you can use the validateCurrentRecord function in TestUtilities to validate the
    // query if you like)
    TestUtilities.validateCurrentRecord(
        "testInsertReadDb weatherEntry failed to validate", weatherCursor, weatherValues);

    assertFalse(
        "Error: More thant one record returned from weather query", weatherCursor.moveToNext());

    // Finally, close the cursor and database
    weatherCursor.close();
    db.close();
  }
Example #25
0
 @Before
 public void setUp() {
   tmp = TestUtilities.getTmpDir();
   metaDir = new File(tmp, "meta").getAbsolutePath();
   store = new TimestampDataStore("creation");
   store.setDataDir(tmp);
   theDate = new Date();
   otherDate = new Date();
 }
Example #26
0
 public static void testInstancesCurrentlyMonitoredByHTM-ITColumnNamesVerification(
         WebDriver driver) {
     String instanceColumn1 = TestUtilities.waitGetText(INSTANCE_COLUMN,
             driver, WAIT_TIME);
     String serviceColumn2 = TestUtilities.waitGetText(SERVICE_COLUMN,
             driver, WAIT_TIME);
     String regionColumn3 = TestUtilities.waitGetText(REGION_COLUMN, driver,
             WAIT_TIME);
     String statusColumn4 = TestUtilities.waitGetText(STATUS_COLUMN, driver,
             WAIT_TIME);
     String removeColumn5 = TestUtilities.waitGetText(REMOVE_COLUMN, driver,
             WAIT_TIME);
     Assert.assertEquals(instanceColumn1, "Instance");
     Assert.assertEquals(serviceColumn2, "Service");
     Assert.assertEquals(regionColumn3, "Region");
     Assert.assertEquals(statusColumn4, "Status");
     Assert.assertEquals(removeColumn5, "Remove");
 }
Example #27
0
  /*
     Students:  Here is where you will build code to test that we can insert and query the
     database.  We've done a lot of work for you.  You'll want to look in TestUtilities
     where you can use the "createWeatherValues" function.  You can
     also make use of the validateCurrentRecord function from within TestUtilities.
  */
  public void testWeatherTable() {
    // First insert the location, and then use the locationRowId to insert
    // the weather. Make sure to cover as many failure cases as you can.

    SQLiteDatabase db = new WeatherDbHelper(this.mContext).getWritableDatabase();

    // Create ContentValues of what you want to insert
    // (you can use the createNorthPoleLocationValues if you wish)
    ContentValues values = TestUtilities.createNorthPoleLocationValues();

    long row = db.insert(WeatherContract.LocationEntry.TABLE_NAME, null, values);
    // Instead of rewriting all of the code we've already written in testLocationTable
    // we can move this code to insertLocation and then call insertLocation from both
    // tests. Why move it? We need the code to return the ID of the inserted location
    // and our testLocationTable can only return void because it's a test.

    // First step: Get reference to writable database

    // Create ContentValues of what you want to insert
    // (you can use the createWeatherValues TestUtilities function if you wish)
    ContentValues weatherValue = TestUtilities.createWeatherValues(row);

    // Insert ContentValues into database and get a row ID back
    long weatherRow = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, weatherValue);
    assertTrue(weatherRow != -1);

    // Query the database and receive a Cursor back
    Cursor cursor =
        db.query(WeatherContract.WeatherEntry.TABLE_NAME, null, null, null, null, null, null);

    // Move the cursor to a valid database row
    cursor.moveToFirst();

    // Validate data in resulting Cursor with the original ContentValues
    // (you can use the validateCurrentRecord function in TestUtilities to validate the
    // query if you like)
    TestUtilities.validateCurrentRecord("Error: Location Query validation", cursor, weatherValue);

    // Finally, close the cursor and database
    cursor.close();
    db.close();
  }
 /**
  * This block is walking up the class hierarchy of the current unit test looking for
  * PerSuiteUnitTestData annotations. If it finds one, it will run it once, then add it to a set so
  * that it does not get run again. This is needed so that multiple tests can extend from the same
  * suite and so that there can be multiple suites throughout the test source branch.
  *
  * @throws Exception if a PerSuiteDataLoaderLifecycle is unable to be started
  */
 protected void startSuiteDataLoaderLifecycles() throws Exception {
   List<Class> classes =
       TestUtilities.getHierarchyClassesToHandle(
           getClass(),
           new Class[] {PerSuiteUnitTestData.class},
           perSuiteDataLoaderLifecycleNamesRun);
   for (Class c : classes) {
     new PerSuiteDataLoaderLifecycle(c).start();
     perSuiteDataLoaderLifecycleNamesRun.add(c.getName());
   }
 }
Example #29
0
  public void testWeatherTable() {
    // First insert the location, and then use the locationRowId to insert
    // the weather. Make sure to cover as many failure cases as you can.
    long location = insertLocation();

    // First step: Get reference to writable database
    SQLiteDatabase db = new WeatherDbHelper(this.mContext).getWritableDatabase();

    // Create ContentValues of what you want to insert
    // (you can use the createWeatherValues TestUtilities function if you wish)
    ContentValues weatherValues = TestUtilities.createWeatherValues(location);

    // Insert ContentValues into database and get a row ID back
    long weatherRowId = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, weatherValues);
    assertFalse("Insert failed", weatherRowId == -1);

    // Query the database and receive a Cursor back
    Cursor c =
        db.query(
            WeatherContract.WeatherEntry.TABLE_NAME, // Table to Query
            null, // leaving "columns" null just returns all the columns.
            null, // cols for "where" clause
            null, // values for "where" clause
            null, // columns to group by
            null, // columns to filter by row groups
            null // sort order
            );

    // Move the cursor to a valid database row
    assertTrue("No records freturned from weather query", c.moveToFirst());

    // Validate data in resulting Cursor with the original ContentValues
    // (you can use the validateCurrentRecord function in TestUtilities to validate the
    // query if you like)
    TestUtilities.validateCurrentRecord(
        "testInsertReadDb weatherEntry failed to validate", c, weatherValues);

    // Finally, close the cursor and database
    c.close();
    db.close();
  }
Example #30
0
  /*
     This test uses the database directly to insert and then uses the ContentProvider to
     read out the data.  Uncomment this test to see if the basic weather query functionality
     given in the ContentProvider is working correctly.
  */
  public void testBasicWeatherQuery() {
    // insert our test records into the database
    WeatherDatabaseHelper dbHelper = new WeatherDatabaseHelper(mContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    long locationRowId = TestUtilities.insertNorthPoleLocationValues(mContext);

    // Fantastic.  Now that we have a location, add some weather!
    ContentValues weatherValues = TestUtilities.createWeatherValues(locationRowId);

    long weatherRowId = db.insert(WeatherEntry.TABLE_NAME, null, weatherValues);
    assertTrue("Unable to Insert WeatherEntry into the Database", weatherRowId != -1);

    db.close();

    // Test the basic content provider query
    Cursor weatherCursor =
        mContext.getContentResolver().query(WeatherEntry.CONTENT_URI, null, null, null, null);

    // Make sure we get the correct cursor out of the database
    TestUtilities.validateCursor("testBasicWeatherQuery", weatherCursor, weatherValues);
  }