@Before
 public void setUp() {
   // Get everything primed and ready to roll
   H2Util.getInstance().setDatabaseLocation("~/mangotesting.db");
   H2Util.getInstance().initializeSchemaOnDb();
   TestUtility.executeInserts();
 }
  @Test
  public void testRemoveMovieFromList() {
    TestUtility.executeInserts();

    DBMovie dieHard = new DBMovie();
    dieHard.setId(1);
  }
  @Test
  public void testRemoveList() {
    TestUtility.executeInserts();

    H2ListsDAO.getInstance().removeList("Action Marathon");
    assertTrue(H2ListsDAO.getInstance().getAllLists().size() == 0);
  }
 public void run() {
   HazelcastClient hClient = TestUtility.newHazelcastClient(h);
   while (run) {
     Map<String, String> clientMap = hClient.getMap("putFromMultipleThreads");
     clientMap.put(String.valueOf(counter.incrementAndGet()), String.valueOf(counter.get()));
   }
 }
  @Test
  public void testGetAllLists() {
    TestUtility.executeInserts();

    List<String> lists = H2ListsDAO.getInstance().getAllLists();
    assertTrue(lists.size() == 1);
    assertTrue(lists.contains("Action Marathon"));
  }
  @Test
  public void testGetMoviesInList() {
    TestUtility.executeInserts();

    List<Movie> marathonMovies = H2ListsDAO.getInstance().getMoviesInList("Action Marathon");
    assertEquals("Die Hard", marathonMovies.get(0).getTitle());
    assertEquals("Die Hard: With a Vengeance", marathonMovies.get(1).getTitle());
  }
  @Test
  public void testGetBorrowedMovies() {
    TestUtility.executeInserts();

    DBPerson zach = new DBPerson();
    zach.setId(2);
    List<Movie> movies = H2PersonDAO.getInstance().getBorrowedMovies(zach);
    assertTrue(movies.size() == 1);
    assertTrue(movies.get(0).getTitle().equals("Die Hard: With a Vengeance"));
  }
  @Test
  public void testGetAllPersons() {
    TestUtility.executeInserts();

    List<Person> people = H2PersonDAO.getInstance().getAllPersons();
    String[] names = {"Paul Osborne", "Zachary Varberg", "Kyle Ronning"};
    List<String> namesList = Arrays.asList(names);
    for (Person p : people) {
      assertTrue(namesList.contains(p.getName()));
    }
  }
  @Test
  public void testReturnMovie() {
    // TODO: things still need to be sorted out with how borrower
    // ids are handles here and there.
    TestUtility.executeInserts();

    DBMovie dieHard = new DBMovie();
    dieHard.setId(1);
    dieHard.getTitle();
    H2PersonDAO.getInstance().returnMovie(dieHard);
    H2MovieDAO.getInstance().getMovieInfo(dieHard);
    assertTrue(dieHard.getBorrower() == null);
  }
  @Test
  public void testReorderMoviesInList() {
    TestUtility.executeInserts();

    // get the movies and reorder them
    List<Movie> movies = H2ListsDAO.getInstance().getMoviesInList("Action Marathon");
    ArrayList<Movie> newMoviesList = new ArrayList<Movie>();
    newMoviesList.add(movies.get(1));
    newMoviesList.add(movies.get(0));

    H2ListsDAO.getInstance().reorderMoviesInList("Action Marathon", newMoviesList);

    List<Movie> moviesAgain = H2ListsDAO.getInstance().getMoviesInList("Action Marathon");
    assertEquals("Die Hard: With a Vengeance", moviesAgain.get(0).getTitle());
    assertEquals("Die Hard", moviesAgain.get(1).getTitle());
  }
  @Test
  public void testBorrowMovie() {
    TestUtility.executeInserts();

    // setup people and movie
    DBPerson kyle = new DBPerson();
    kyle.setId(3);
    DBMovie dieHard = new DBMovie();
    dieHard.setId(1);

    // borrow die hard to kyle
    H2PersonDAO.getInstance().borrowMovie(kyle, dieHard);
    H2MovieDAO.getInstance().updateMovie(dieHard);

    assertTrue(((DBPerson) dieHard.getBorrower()).getId() == kyle.getId());
  }
  @Test
  public void compareInfoLevelOutput() throws Exception {
    final List<String> failures = new ArrayList<String>();
    for (final InfoLevel infoLevel : InfoLevel.values()) {
      if (infoLevel == InfoLevel.unknown) {
        continue;
      }
      for (final SchemaTextDetailType schemaTextDetailType : SchemaTextDetailType.values()) {
        final String referenceFile = schemaTextDetailType + "_" + infoLevel + ".txt";

        final File testOutputFile =
            File.createTempFile("schemacrawler." + referenceFile + ".", ".test");
        testOutputFile.delete();

        final OutputOptions outputOptions =
            new OutputOptions(OutputFormat.text.name(), testOutputFile);
        outputOptions.setNoInfo(false);
        outputOptions.setNoHeader(false);
        outputOptions.setNoFooter(false);

        final Config config =
            Config.load(
                SchemaCrawlerOutputTest.class.getResourceAsStream(
                    "/hsqldb.INFORMATION_SCHEMA.config.properties"));
        final SchemaCrawlerOptions schemaCrawlerOptions = new SchemaCrawlerOptions(config);
        schemaCrawlerOptions.setSchemaInfoLevel(infoLevel.getSchemaInfoLevel());

        final DatabaseConnectionOptions connectionOptions =
            testUtility.getDatabaseConnectionOptions();

        final Executable executable = new SchemaCrawlerExecutable(schemaTextDetailType.name());
        executable.setSchemaCrawlerOptions(schemaCrawlerOptions);
        executable.setOutputOptions(outputOptions);
        executable.execute(connectionOptions.getConnection());

        failures.addAll(
            TestUtility.compareOutput(
                INFO_LEVEL_OUTPUT + referenceFile,
                testOutputFile,
                outputOptions.getOutputFormat()));
      }
    }
    if (failures.size() > 0) {
      fail(failures.toString());
    }
  }
  @Test
  public void testPopulatePerson() {
    TestUtility.executeInserts();

    // Paul is id 1
    DBPerson paul = new DBPerson();
    paul.setId(1);

    try {
      H2PersonDAO.getInstance().populatePerson(paul);
    } catch (PersonNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    assertTrue(paul.getName().equals("Paul Osborne"));
    assertTrue(paul.getAddress().equals("3001 Hampshire Ave N"));
    assertTrue(paul.getEmail().equals("*****@*****.**"));
    assertTrue(paul.getPhoneNumber().equals("7637970688"));
  }
  /** Test of updatePerson method, of class H2PersonDAO. */
  @Test
  public void testUpdatePerson() {
    TestUtility.executeInserts();

    DBPerson p = new DBPerson();
    p.setId(1); // Paul is person 1
    p.setName("Some name that is not Paul");
    p.setEmail("*****@*****.**");
    p.setAddress("3899 drive");
    p.setPhoneNumber("38828810083");
    H2PersonDAO.getInstance().updatePerson(p);

    List<Person> people = H2PersonDAO.getInstance().getAllPersons();
    ArrayList<String> names = new ArrayList<String>();
    for (Person person : people) {
      names.add(person.getName());
    }

    assertTrue(names.contains("Some name that is not Paul"));
  }
  @Test
  public void testGetOwnedMovies() {
    TestUtility.executeInserts();

    DBPerson paul = new DBPerson();
    paul.setId(1);
    try {
      H2PersonDAO.getInstance().populatePerson(paul);
    } catch (PersonNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    List<Movie> paulsMovies = H2PersonDAO.getInstance().getOwnedMovies(paul);
    ArrayList<String> movieStrings = new ArrayList<String>();
    for (Movie m : paulsMovies) {
      movieStrings.add(m.getTitle());
    }

    assertTrue(movieStrings.contains("Die Hard"));
    assertTrue(movieStrings.contains("Die Hard: With a Vengeance"));
  }
Пример #16
0
  @Test
  public void testCreateLocation() throws Exception {
    Time time = Time.of(2015, 12, 24, 9, 1, 0);
    UserLocation mc =
        TestUtility.createUserLocation(
            "+94770780210", "CDC47124648058A", 98.0f, "Home", 79.857488, 6.8781381, time);

    HTTP.Response response =
        HTTP.POST(server.httpURI().resolve("/contra/location/create").toString(), mc);

    // Check the status.
    assertEquals("Error in request.", HttpURLConnection.HTTP_OK, response.status());

    // Do not use the exact location for withinDistance
    Result result =
        server
            .graph()
            .execute(
                "START n = node:location_layer('withinDistance:[6.8781381, 79.857487, 0.1]') RETURN n.name as name");

    Map<String, Object> map = result.next();

    assertEquals("Location is not created.", "Home", map.get("name"));
  }
  /** Test of addPerson method, of class H2PersonDAO. */
  @Test
  public void testAddPerson() {
    TestUtility.executeInserts();

    DBPerson p = new DBPerson();
    p.setName("Bob Billy McTest");
    p.setEmail("*****@*****.**");
    p.setAddress("123 the lane");
    p.setPhoneNumber("952.883.3918");

    try {
      H2PersonDAO.getInstance().addPerson(p);
    } catch (PersonExistsException pee) {
      fail("Why was this thrown?");
    }

    List<Person> people = H2PersonDAO.getInstance().getAllPersons();
    ArrayList<String> names = new ArrayList<String>();
    for (Person person : people) {
      names.add(person.getName());
    }

    assertTrue(names.contains("Bob Billy McTest"));
  }
  @Test
  public void compareCompositeOutput() throws Exception {
    final String queryCommand1 = "all_tables";
    final Config queriesConfig = new Config();
    queriesConfig.put(queryCommand1, "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_TABLES");
    final String queryCommand2 = "dump_tables";
    queriesConfig.put(
        queryCommand2, "SELECT ${orderbycolumns} FROM ${table} ORDER BY ${orderbycolumns}");

    final String[] commands =
        new String[] {
          SchemaTextDetailType.details + "," + Operation.count + "," + Operation.dump,
          SchemaTextDetailType.list + "," + Operation.count,
          queryCommand1
              + ","
              + queryCommand2
              + ","
              + Operation.count
              + ","
              + SchemaTextDetailType.list,
        };

    final List<String> failures = new ArrayList<String>();
    for (final OutputFormat outputFormat : OutputFormat.values()) {
      for (final String command : commands) {
        final String referenceFile = command + "." + outputFormat.name();

        final File testOutputFile =
            File.createTempFile("schemacrawler." + referenceFile + ".", ".test");
        testOutputFile.delete();

        final OutputOptions outputOptions = new OutputOptions(outputFormat.name(), testOutputFile);
        outputOptions.setNoInfo(false);
        outputOptions.setNoHeader(false);
        outputOptions.setNoFooter(false);

        final Config config =
            Config.load(
                SchemaCrawlerOutputTest.class.getResourceAsStream(
                    "/hsqldb.INFORMATION_SCHEMA.config.properties"));
        final SchemaCrawlerOptions schemaCrawlerOptions = new SchemaCrawlerOptions(config);
        schemaCrawlerOptions.setSchemaInfoLevel(SchemaInfoLevel.maximum());

        final DatabaseConnectionOptions connectionOptions =
            testUtility.getDatabaseConnectionOptions();

        final SchemaCrawlerExecutable executable = new SchemaCrawlerExecutable(command);
        executable.setSchemaCrawlerOptions(schemaCrawlerOptions);
        executable.setOutputOptions(outputOptions);
        executable.setAdditionalConfiguration(queriesConfig);
        executable.execute(connectionOptions.getConnection());

        failures.addAll(
            TestUtility.compareOutput(
                COMPOSITE_OUTPUT + referenceFile, testOutputFile, outputFormat));
      }
    }
    if (failures.size() > 0) {
      fail(failures.toString());
    }
  }
Пример #19
0
 /**
  * Setup the No4j server for testing purposes.
  *
  * @throws Exception
  */
 @BeforeClass
 public static void setUp() throws Exception {
   server = TestUtility.createServer(LocationResource.class);
   databaseService = server.graph();
   TestUtility.createCommonEntities(databaseService);
 }