/*
   * Working directory property must point to an existing location and it must
   * be a directory
   */
  @Test
  public void testWorkingDirectory() throws Exception {
    File notExistingFile = new File("not-existing-path");
    Assert.state(!notExistingFile.exists());

    try {
      tasklet.setWorkingDirectory(notExistingFile.getCanonicalPath());
      fail();
    } catch (IllegalArgumentException e) {
      // expected
    }

    File notDirectory = File.createTempFile(this.getClass().getName(), null);
    Assert.state(notDirectory.exists());
    Assert.state(!notDirectory.isDirectory());

    try {
      tasklet.setWorkingDirectory(notDirectory.getCanonicalPath());
      fail();
    } catch (IllegalArgumentException e) {
      // expected
    }

    File directory = notDirectory.getParentFile();
    Assert.state(directory.exists());
    Assert.state(directory.isDirectory());

    // no error expected now
    tasklet.setWorkingDirectory(directory.getCanonicalPath());
  }
Пример #2
0
  private void initializeUserAccount(RestOperations client) {

    if (this.user == null) {

      UaaUser user = testAccounts.getUser();
      @SuppressWarnings("rawtypes")
      ResponseEntity<Map> results =
          client.getForEntity(
              serverRunning.getUserUri() + "?filter=userName eq '" + user.getUsername() + "'",
              Map.class);
      assertEquals(HttpStatus.OK, results.getStatusCode());
      @SuppressWarnings("unchecked")
      List<Map<String, ?>> resources = (List<Map<String, ?>>) results.getBody().get("resources");
      Map<String, ?> map;
      if (!resources.isEmpty()) {
        map = resources.get(0);
      } else {
        map = getUserAsMap(user);
        @SuppressWarnings("rawtypes")
        ResponseEntity<Map> response =
            client.postForEntity(serverRunning.getUserUri(), map, Map.class);
        Assert.state(
            response.getStatusCode() == HttpStatus.CREATED,
            "User account not created: status was " + response.getStatusCode());
        @SuppressWarnings("unchecked")
        Map<String, ?> value = response.getBody();
        map = value;
      }
      this.user = getUserFromMap(map);
    }
  }
Пример #3
0
 private List<? extends GrantedAuthority> extractAuthorities(
     Collection<Map<String, String>> groups) {
   List<SimpleGrantedAuthority> authorities = new ArrayList<SimpleGrantedAuthority>();
   for (Map<String, String> group : groups) {
     String role = group.get("display");
     Assert.state(role != null, "Role is null in this group: " + group);
     authorities.add(new SimpleGrantedAuthority(role));
   }
   return authorities;
 }
 public void afterPropertiesSet() throws Exception {
   Assert.state(channel != null, "A channel must be provided");
 }
 public Metric getObject() throws Exception {
   Assert.state(channel != null, "A channel must be provided");
   return date;
 }
 public void afterPropertiesSet() throws Exception {
   Assert.state(date != null, "A date must be provided");
 }
 // This has the potential to blow up if called before setDate().
 // Depends on bean instantiation order and IntegrationMBeanExporter
 // can influence that by aggressively instantiating other MBeanExporters
 public Date getObject() throws Exception {
   Assert.state(date != null, "A date must be provided");
   return date;
 }