Java Collections.singletonMap Examples

Java Collections.singletonMap - 30 examples found. These are the top rated real world Java examples of java.util.Collections.singletonMap extracted from open source projects. You can rate examples to help us improve the quality of examples.
  @Test
  public void testGroupKeyCodeSetExtraction() {
    PayTypeBo pstnRptGrpBo =
        boService.findByPrimaryKey(PayTypeBo.class, Collections.singletonMap("hrPayTypeId", "1"));
    Set<String> extractedGroupKeyCodeWithIdSet = pstnRptGrpBo.getGroupKeyCodeSet();
    Assert.assertEquals(extractedGroupKeyCodeWithIdSet.size(), 2);
    Assert.assertTrue(extractedGroupKeyCodeWithIdSet.contains("ISU-IA"));
    Assert.assertTrue(extractedGroupKeyCodeWithIdSet.contains("UGA-GA"));

    pstnRptGrpBo =
        boService.findByPrimaryKey(PayTypeBo.class, Collections.singletonMap("hrPayTypeId", "5"));
    extractedGroupKeyCodeWithIdSet = pstnRptGrpBo.getGroupKeyCodeSet();
    Assert.assertEquals(2, extractedGroupKeyCodeWithIdSet.size());
    Assert.assertTrue(extractedGroupKeyCodeWithIdSet.contains("IU-IN"));
    Assert.assertTrue(extractedGroupKeyCodeWithIdSet.contains("UGA-GA"));

    pstnRptGrpBo =
        boService.findByPrimaryKey(PayTypeBo.class, Collections.singletonMap("hrPayTypeId", "2"));
    extractedGroupKeyCodeWithIdSet = pstnRptGrpBo.getGroupKeyCodeSet();
    Assert.assertTrue(
        (extractedGroupKeyCodeWithIdSet == null) || extractedGroupKeyCodeWithIdSet.isEmpty());
    pstnRptGrpBo =
        boService.findByPrimaryKey(PayTypeBo.class, Collections.singletonMap("hrPayTypeId", "4"));
    extractedGroupKeyCodeWithIdSet = pstnRptGrpBo.getGroupKeyCodeSet();
    Assert.assertTrue(
        (extractedGroupKeyCodeWithIdSet == null) || extractedGroupKeyCodeWithIdSet.isEmpty());
  }
  @Test
  public void shouldNotReturnRepositoryForInvalidUrl() {
    try {
      url = "file:?Test Repository Source";
      repositoryFor(Collections.singletonMap(RepositoryFactory.URL, url));
      fail("Expected repository exception");
    } catch (RepositoryException e) {
      // expected
    }

    try {
      url = "file:src/test/resources/nonExistentFile";
      repositoryFor(Collections.singletonMap(RepositoryFactory.URL, url));
      fail("Expected repository exception");
    } catch (RepositoryException e) {
      // expected
    }

    try {
      url = "file:src/test/resources/nonExistentFile";
      repositoryFor(Collections.singletonMap(RepositoryFactory.URL, url));
      fail("Expected repository exception");
    } catch (RepositoryException e) {
      // expected
    }
  }
Example #3
0
  public void testFoo() throws Exception {
    RAMFileSystem fs = new RAMFileSystem();
    FileSystemScanner<RAMPath> scanner = new FileSystemScanner<RAMPath>(fs);

    //
    assertEquals(Collections.<String, Change>emptyMap(), scanner.scan());

    //
    RAMPath foo = fs.addDir(fs.getRoot(), "foo");
    assertEquals(Collections.<String, Change>emptyMap(), scanner.scan());

    RAMFile bar = fs.addFile(foo, "bar.txt");
    waitForOneMillis();
    assertEquals(Collections.singletonMap("foo/bar.txt", Change.ADD), scanner.scan());
    assertEquals(Collections.<String, Change>emptyMap(), scanner.scan());

    bar.update("abc");
    waitForOneMillis();
    assertEquals(Collections.singletonMap("foo/bar.txt", Change.UPDATE), scanner.scan());
    assertEquals(Collections.<String, Change>emptyMap(), scanner.scan());

    bar.remove();
    waitForOneMillis();
    assertEquals(Collections.singletonMap("foo/bar.txt", Change.REMOVE), scanner.scan());
    assertEquals(Collections.<String, Change>emptyMap(), scanner.scan());
  }
Example #4
0
 public List<SponsorDTO> getMatchingSponsors(SponsorCriteriaDto searchCriteria) {
   List<SponsorDTO> results = new ArrayList<SponsorDTO>();
   Collection<Sponsor> sponsors;
   if (ObjectUtils.isNull(searchCriteria)
       || (StringUtils.isEmpty(searchCriteria.getSponsorCode())
           && StringUtils.isEmpty(searchCriteria.getCustomerNumber()))) {
     sponsors = getBusinessObjectService().findAll(Sponsor.class);
   } else if (StringUtils.isNotEmpty(searchCriteria.getSponsorCode())) {
     sponsors =
         legacyDataAdapter.findCollectionBySearchHelper(
             Sponsor.class,
             Collections.singletonMap("sponsorCode", searchCriteria.getSponsorCode()),
             Collections.<String>emptyList(),
             true,
             false,
             0);
   } else {
     sponsors =
         legacyDataAdapter.findCollectionBySearchHelper(
             Sponsor.class,
             Collections.singletonMap("customerNumber", searchCriteria.getCustomerNumber()),
             Collections.<String>emptyList(),
             true,
             false,
             0);
   }
   if (sponsors != null && !sponsors.isEmpty()) {
     for (Sponsor sponsor : sponsors) {
       results.add(sponsorDtoService.buildDto(sponsor));
     }
   }
   return results;
 }
  protected Object executeScript(
      ScriptFactory scriptFactory,
      HttpServletRequest request,
      HttpServletResponse response,
      String scriptUrl) {
    Map<String, Object> scriptVariables = createScriptVariables(request, response);

    try {
      return scriptFactory.getScript(scriptUrl).execute(scriptVariables);
    } catch (ScriptNotFoundException e) {
      logger.error("Script not found at " + scriptUrl, e);

      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);

      return Collections.singletonMap(errorMessageModelAttributeName, "REST script not found");
    } catch (Exception e) {
      logger.error("Error executing REST script at " + scriptUrl, e);

      HttpStatusCodeAwareException cause =
          ExceptionUtils.getThrowableOfType(e, HttpStatusCodeAwareException.class);
      String errorMsg;

      if (cause != null) {
        response.setStatus(cause.getStatusCode());

        errorMsg = ((Exception) cause).getMessage();
      } else {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

        errorMsg = e.getMessage();
      }

      return Collections.singletonMap(errorMessageModelAttributeName, errorMsg);
    }
  }
 @Before
 public void setUp() {
   interceptor = new ClaimsAuthorizingInterceptor();
   interceptor.setNameAliases(Collections.singletonMap("authentication", "http://authentication"));
   interceptor.setFormatAliases(Collections.singletonMap("claims", "http://claims"));
   interceptor.setSecuredObject(new TestService());
 }