Exemplo n.º 1
0
 public List<ContainerService> getContainerServices(String name) {
   List<ContainerService> services = new ArrayList<>();
   for (ContainerService s : containerServices.values()) {
     if (s.getName().equals(name)) {
       services.add(s);
     }
   }
   return services;
 }
  /** This is a test which expands two paths with cardinalities 1-*-1-*-1 and 1-1-1-*-1. */
  public void testQueryJobsDeepExpandAndMultiple() {
    Query<Job> query =
        service
            .createJobQuery("/Job")
            .expand("jobParts/description/literals/language,jobPosting/name/literals/language");

    for (Job job : query) {
      String jobPostingPath = String.format("/Job(%d)/jobPosting", job.getId());

      JobPosting jobPosting = job.getJobPosting();

      Assert.assertNotNull("Should have fetched " + jobPostingPath, jobPosting);

      assertFullExpansionOfMultilingualField(jobPosting.getName(), jobPostingPath + "/name");

      if (job.getJobParts() != null) {

        for (JobPart jobPart : job.getJobParts()) {

          String jobPartDescriptionPath =
              String.format("/Job(%d)/jobParts(%d)/description", job.getId(), jobPart.getId());

          assertFullExpansionOfMultilingualField(jobPart.getDescription(), jobPartDescriptionPath);
        }
      }
    }
  }
  /**
   * This is a test which expands three parallel and partially overlapping paths with cardinalities
   * 1-1-*-1, 1*-1-*-1 and 1-*-*-1-*-1.
   */
  public void testQueryUniversitiesExpandDepartmentsDivisionsAndAllNames() {

    Query<University> query =
        service
            .createUniversityQuery("University")
            .expand(
                "name/literals/language,departments/name/literals/language,departments/divisions/name/literals/language");

    for (University university : query) {

      String universityPath = String.format("/University(%d)", university.getId());

      assertFullExpansionOfMultilingualField(university.getName(), universityPath + "/name");

      for (Department department : university.getDepartments()) {

        String departmentPath =
            String.format("%s/departments(%d)", universityPath, department.getId());

        assertFullExpansionOfMultilingualField(department.getName(), departmentPath + "/name");

        for (Division division : department.getDivisions()) {

          String divisionPath = String.format("%s/divisions(%d)", departmentPath, division.getId());

          assertFullExpansionOfMultilingualField(division.getName(), divisionPath + "/name");
        }
      }
    }
  }
    @Test
    public void testServiceOptions() {

      EnumSet<Service.ServiceOption> expected =
          EnumSet.of(
              Service.ServiceOption.CONCURRENT_GET_HANDLING,
              Service.ServiceOption.OWNER_SELECTION,
              Service.ServiceOption.PERSISTENCE,
              Service.ServiceOption.REPLICATION);

      assertThat(containerService.getOptions(), is(expected));
    }
  /**
   * This test performs expansion and checks parsing of date forms with omitted seconds (Issue #946)
   * in the expanded hierarchy.
   */
  public void testJobExpansionAndParsingOfShortDates() {

    Query<Job> query =
        service
            .createJobQuery("/Job")
            .expand("jobParts/description/literals/language,jobPosting/name/literals/language");

    for (Job job : query) {
      Assert.assertNotNull("Failed to parse date, resulting to null value", job.getStartDate());
      Assert.assertNotNull("Failed to parse date, resulting to null value", job.getEndDate());

      if (job.getJobParts() != null) {

        for (JobPart jobPart : job.getJobParts()) {
          Assert.assertNotNull(
              "Failed to parse date, resulting to null value", jobPart.getStartDate());
          Assert.assertNotNull(
              "Failed to parse date, resulting to null value", jobPart.getEndDate());
        }
      }
    }
  }
  /**
   * This is a test which expands a path with cardinalities 1-1-*-1. At the same time, it tests for
   * correct reading of a property inside a complex property.
   */
  public void testQueryJobPostingsDeepExpandWithComplexProperty() {
    Query<JobPosting> jobPostingQuery =
        service
            .createJobPostingQuery("/JobPosting")
            .expand("name/literals/language")
            .filter("benefits/transportationOffered eq true")
            .top(10);

    for (JobPosting jobPosting : jobPostingQuery) {

      String jobPostingPath = String.format("/JobPostings(%d)", jobPosting.getId());

      assertFullExpansionOfMultilingualField(jobPosting.getName(), jobPostingPath + "/name");

      Benefits benefits = jobPosting.getBenefits();

      Assert.assertNotNull("jobPosting.benefits shouldn't be null", benefits);

      Assert.assertTrue(
          "jobPosting.benefits.transportationOffered should be true",
          benefits.getTransportationOffered());
    }
  }